ManaPlus
Functions
SDL Namespace Reference

Functions

bool getAllVideoModes (StringVect &modeList)
 
void SetWindowTitle (const SDL_Surface *const window, const char *const title)
 
void SetWindowIcon (const SDL_Surface *const window, SDL_Surface *const icon)
 
void grabInput (const SDL_Surface *const window, const bool grab)
 
void setGamma (const SDL_Surface *const window, const float gamma)
 
void setVsync (const int val)
 
bool getWindowWMInfo (const SDL_Surface *const window, SDL_SysWMinfo *const info)
 
SDL_Thread * createThread (int(*fn)(void *), const char *const name, void *const data)
 
void * createGLContext (SDL_Surface *const window, const int major, const int minor, const int profile)
 
void makeCurrentContext (void *const context)
 
void initLogger ()
 
void setLogLevel (const int level)
 
void WaitThread (SDL_Thread *const thread)
 
bool PollEvent (SDL_Event *event)
 
void allowScreenSaver (const bool allow)
 
int MixOpenAudio (const int frequency, const uint16_t format, const int nchannels, const int chunksize)
 
Mix_Music * LoadMUSOgg_RW (SDL_RWops *const rw)
 
void showCursor (const bool show)
 

Function Documentation

◆ allowScreenSaver()

void SDL::allowScreenSaver ( const bool  allow)

Definition at line 209 of file sdlhelper.cpp.

References setEnv().

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), and Client::gameInit().

210 {
211  if (allow)
212  setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "1");
213  else
214  setEnv("SDL_VIDEO_ALLOW_SCREENSAVER", "0");
215 }
void setEnv(const char *const name, const char *const value)
Definition: env.cpp:59

◆ createGLContext()

void * SDL::createGLContext ( SDL_Surface *const  window,
const int  major,
const int  minor,
const int  profile 
)

Definition at line 173 of file sdlhelper.cpp.

Referenced by ModernOpenGLGraphics::createGLContext(), and createThread().

177 {
178  return nullptr;
179 }

◆ createThread()

SDL_Thread * SDL::createThread ( int(*)(void *)  fn,
const char *const  name,
void *const  data 
)

Definition at line 117 of file sdlhelper.cpp.

References A_UNUSED, createGLContext(), Actions::info(), Logger::log(), logger, and makeCurrentContext().

Referenced by Ea::Network::connect(), WhoIsOnline::download(), IPC::init(), and Net::Download::start().

120 {
121  return SDL_CreateThread(fn, data);
122 }
uint32_t data

◆ getAllVideoModes()

bool SDL::getAllVideoModes ( StringVect modeList)

< Surface is a full screen display

< Surface is in video memory

Definition at line 43 of file sdlhelper.cpp.

References CAST_S32, Logger::log(), Logger::log1(), logger, and Catch::toString().

Referenced by ModeListModel::ModeListModel(), and GraphicsManager::setVideoMode().

44 {
45  /* Get available fullscreen/hardware modes */
46  SDL_Rect *const *const modes = SDL_ListModes(nullptr,
47  SDL_FULLSCREEN | SDL_HWSURFACE);
48 
49 #ifdef ANDROID
50  const std::string modeString =
51  toString(CAST_S32(modes[0]->w)).append("x")
52  .append(toString(CAST_S32(modes[0]->h)));
53  logger->log("support mode: " + modeString);
54  modeList.push_back(modeString);
55  return true;
56 #else // ANDROID
57 
58  /* Check which modes are available */
59  if (modes == static_cast<SDL_Rect **>(nullptr))
60  {
61  logger->log1("No modes available");
62  return false;
63  }
64  else if (modes == reinterpret_cast<SDL_Rect **>(-1))
65  {
66  logger->log1("All resolutions available");
67  return true;
68  }
69  else
70  {
71  for (int i = 0; modes[i] != nullptr; ++ i)
72  {
73  const std::string modeString =
74  toString(CAST_S32(modes[i]->w)).append("x")
75  .append(toString(CAST_S32(modes[i]->h)));
76  logger->log("support mode: " + modeString);
77  modeList.push_back(modeString);
78  }
79  return true;
80  }
81 #endif // ANDROID
82 }
void log1(const char *const log_text)
Definition: logger.cpp:222
Logger * logger
Definition: logger.cpp:95
#define CAST_S32
Definition: cast.h:29
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void log(const char *const log_text,...)
Definition: logger.cpp:243

◆ getWindowWMInfo()

bool SDL::getWindowWMInfo ( const SDL_Surface *const  window,
SDL_SysWMinfo *const  info 
)

Definition at line 111 of file sdlhelper.cpp.

Referenced by GraphicsManager::detectPixelSize(), WindowManager::setIcon(), and GraphicsManager::updatePlanformExtensions().

113 {
114  return SDL_GetWMInfo(info) != 0;
115 }
bool info(InputEvent &event)
Definition: commands.cpp:56

◆ grabInput()

void SDL::grabInput ( const SDL_Surface *const  window,
const bool  grab 
)

Definition at line 96 of file sdlhelper.cpp.

Referenced by WindowManager::applyGrabMode().

97 {
98  SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
99 }

◆ initLogger()

void SDL::initLogger ( )

Definition at line 186 of file sdlhelper.cpp.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), Client::gameInit(), main(), and mainGui().

187 {
188 }

◆ LoadMUSOgg_RW()

Mix_Music * SDL::LoadMUSOgg_RW ( SDL_RWops *const  rw)

Definition at line 38 of file sdlmusichelper.cpp.

Referenced by anonymous_namespace{musicloader.cpp}::ResourceLoader::load().

39 {
40  return Mix_LoadMUS_RW(rw);
41 }

◆ makeCurrentContext()

void SDL::makeCurrentContext ( void *const  context)

Definition at line 181 of file sdlhelper.cpp.

Referenced by ModernOpenGLGraphics::createGLContext(), and createThread().

182 {
183 }

◆ MixOpenAudio()

int SDL::MixOpenAudio ( const int  frequency,
const uint16_t  format,
const int  nchannels,
const int  chunksize 
)

Definition at line 27 of file sdlmusichelper.cpp.

Referenced by SoundManager::init().

31 {
32  return Mix_OpenAudio(frequency,
33  format,
34  nchannels,
35  chunksize);
36 }

◆ PollEvent()

bool SDL::PollEvent ( SDL_Event *  event)

Definition at line 200 of file sdlhelper.cpp.

Referenced by EventsManager::handleEvents(), and EventsManager::handleGameEvents().

201 {
202  SDL_PumpEvents();
203  return SDL_PeepEvents(event,
204  1,
205  SDL_GETEVENT,
206  SDL_ALLEVENTS) > 0;
207 }

◆ setGamma()

void SDL::setGamma ( const SDL_Surface *const  window,
const float  gamma 
)

Definition at line 101 of file sdlhelper.cpp.

Referenced by WindowManager::applyGamma().

102 {
103  SDL_SetGamma(gamma, gamma, gamma);
104 }

◆ setLogLevel()

void SDL::setLogLevel ( const int  level)

Definition at line 190 of file sdlhelper.cpp.

Referenced by anonymous_namespace{client.cpp}::LoginListener::action(), and Client::gameInit().

191 {
192 }

◆ setVsync()

void SDL::setVsync ( const int  val)

Definition at line 106 of file sdlhelper.cpp.

Referenced by WindowManager::applyVSync().

107 {
108  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, val);
109 }

◆ SetWindowIcon()

void SDL::SetWindowIcon ( const SDL_Surface *const  window,
SDL_Surface *const  icon 
)

Definition at line 90 of file sdlhelper.cpp.

Referenced by WindowManager::setIcon().

92 {
93  SDL_WM_SetIcon(icon, nullptr);
94 }

◆ SetWindowTitle()

void SDL::SetWindowTitle ( const SDL_Surface *const  window,
const char *const  title 
)

Definition at line 84 of file sdlhelper.cpp.

Referenced by WindowManager::initTitle(), WindowManager::newChatMessage(), WindowManager::setIsMinimized(), and WindowManager::updateTitle().

86 {
87  SDL_WM_SetCaption(title, nullptr);
88 }

◆ showCursor()

void SDL::showCursor ( const bool  show)

Definition at line 37 of file sdlsharedhelper.cpp.

Referenced by Gui::setUseCustomCursor().

38 {
39 #ifdef __native_client__
40  PP_MouseCursor_Type cursor;
41  if (show)
42  cursor = PP_MOUSECURSOR_TYPE_POINTER; // show default cursor
43  else
44  cursor = PP_MOUSECURSOR_TYPE_NONE; // hide cursor
45 
46  pp::MouseCursor::SetCursor(
47  pp::InstanceHandle(PSGetInstanceId()),
48  cursor);
49 #endif // __native_client__
50 
51  if (show)
52  SDL_ShowCursor(SDL_ENABLE);
53  else
54  SDL_ShowCursor(SDL_DISABLE);
55 }

◆ WaitThread()

void SDL::WaitThread ( SDL_Thread *const  thread)

Definition at line 194 of file sdlhelper.cpp.

Referenced by WhoIsOnline::action(), Ea::Network::disconnect(), WhoIsOnline::download(), Net::Download::start(), Net::Download::~Download(), IPC::~IPC(), and WhoIsOnline::~WhoIsOnline().

195 {
196  if (thread != nullptr && SDL_GetThreadID(thread) != 0u)
197  SDL_WaitThread(thread, nullptr);
198 }