ManaPlus
Functions
WindowManager Namespace Reference

Functions

void init ()
 
bool getIsMinimized ()
 
void setIsMinimized (const bool n)
 
void newChatMessage ()
 
bool isKeyboardVisible ()
 
void setFramerate (const unsigned int fpsLimit)
 
int getFramerate ()
 
void applyGrabMode ()
 
void applyGamma ()
 
void applyVSync ()
 
void applyKeyRepeat ()
 
void doResizeVideo (const int actualWidth, const int actualHeight, const bool always)
 
void resizeVideo (int actualWidth, int actualHeight, const bool always)
 
bool setFullScreen (const bool fs)
 
void applyScale ()
 
void updateScreenKeyboard (const int height)
 
void reloadWallpaper ()
 
void createWindows ()
 
void deleteWindows ()
 
void initTitle ()
 
void setIcon ()
 
void deleteIcon ()
 
void updateTitle ()
 
void createValidateWindows ()
 
void deleteValidateWindows ()
 

Function Documentation

◆ applyGamma()

void WindowManager::applyGamma ( )

Definition at line 354 of file windowmanager.cpp.

355 {
356  if (config.getBoolValue("enableGamma"))
357  {
359  config.getFloatValue("gamma"));
360  }
361 }
bool getBoolValue(const std::string &key) const
float getFloatValue(const std::string &key) const
SDL_Surface * getWindow() const
Definition: graphics.h:144
Configuration config
Graphics * mainGraphics
Definition: graphics.cpp:109
void setGamma(const SDL_Surface *const window, const float gamma)
Definition: sdlhelper.cpp:102

References config, Configuration::getBoolValue(), Configuration::getFloatValue(), Graphics::getWindow(), mainGraphics, and SDL::setGamma().

Referenced by Client::initGraphics(), and Client::optionChanged().

◆ applyGrabMode()

void WindowManager::applyGrabMode ( )

Definition at line 348 of file windowmanager.cpp.

349 {
351  config.getBoolValue("grabinput"));
352 }
void grabInput(const SDL_Surface *const window, const bool grab)
Definition: sdlhelper.cpp:97

References config, Configuration::getBoolValue(), Graphics::getWindow(), SDL::grabInput(), and mainGraphics.

Referenced by Setup_Visual::apply(), and Client::initGraphics().

◆ applyKeyRepeat()

void WindowManager::applyKeyRepeat ( )

Definition at line 370 of file windowmanager.cpp.

371 {
372 #ifndef USE_SDL2
373  SDL_EnableKeyRepeat(config.getIntValue("repeateDelay"),
374  config.getIntValue("repeateInterval"));
375 #endif // USE_SDL2
376 }
int getIntValue(const std::string &key) const

References config, and Configuration::getIntValue().

Referenced by Client::gameInit(), and Client::optionChanged().

◆ applyScale()

void WindowManager::applyScale ( )

Definition at line 378 of file windowmanager.cpp.

379 {
380  const int scale = config.getIntValue("scale");
381  if (mainGraphics->getScale() == scale)
382  return;
383  mainGraphics->setScale(scale);
386  true);
387 }
int mActualHeight
Definition: graphics.h:487
int getScale() const
Definition: graphics.h:366
void setScale(int scale)
Definition: graphics.cpp:206
int mActualWidth
Definition: graphics.h:486
void doResizeVideo(const int actualWidth, const int actualHeight, const bool always)

References config, doResizeVideo(), Configuration::getIntValue(), Graphics::getScale(), Graphics::mActualHeight, Graphics::mActualWidth, mainGraphics, and Graphics::setScale().

Referenced by Setup_Visual::apply().

◆ applyVSync()

void WindowManager::applyVSync ( )

Definition at line 363 of file windowmanager.cpp.

364 {
365  const int val = config.getIntValue("vsync");
366  if (val > 0 && val < 2)
367  SDL::setVsync(val);
368 }
void setVsync(const int val)
Definition: sdlhelper.cpp:107

References config, Configuration::getIntValue(), and SDL::setVsync().

Referenced by Client::initGraphics(), and Client::optionChanged().

◆ createValidateWindows()

void WindowManager::createValidateWindows ( )

Definition at line 161 of file windowmanager.cpp.

162 {
163 #ifndef DYECMD
167  nullptr, nullptr, true);
169 #endif // DYECMD
170 }
void loadSkills()
#define CREATEWIDGETV0(var, type)
Definition: createwidget.h:32
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
EquipmentWindow * beingEquipmentWindow
QuestsWindow * questsWindow
SkillDialog * skillDialog
Definition: skilldialog.cpp:66

References beingEquipmentWindow, CREATEWIDGETV, CREATEWIDGETV0, SkillDialog::loadSkills(), questsWindow, and skillDialog.

Referenced by Client::runValidate().

◆ createWindows()

void WindowManager::createWindows ( )

Definition at line 123 of file windowmanager.cpp.

124 {
125  userPalette = new UserPalette;
126 #ifndef DYECMD
137  if (chatWindow != nullptr)
138  {
140  chatWindow = nullptr;
141  }
143  "DebugChat");
144  // TRANSLATORS: chat tab header
145  debugChatTab = new ChatTab(chatWindow, _("Debug"), "",
146  "#Debug", ChatTabType::DEBUG);
149  if (debugWindow != nullptr)
150  {
152  debugWindow = nullptr;
153  }
155  "DebugDebug");
156 #endif // DYECMD
157 
159 }
BeingPopup * beingPopup
Definition: beingpopup.cpp:47
ChatTab * debugChatTab
Definition: chattab.cpp:63
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
void setAllowHighlight(const bool n)
Definition: chattab.h:161
void scheduleDelete()
void setVisible(Visible visible)
virtual void scheduleDelete()
Definition: window.cpp:831
DebugWindow * debugWindow
Definition: debugwindow.cpp:43
#define delete2(var)
Definition: delete2.h:25
DidYouKnowWindow * didYouKnowWindow
#define _(s)
Definition: gettext.h:35
HelpWindow * helpWindow
Definition: helpwindow.cpp:54
ItemPopup * itemPopup
Definition: itempopup.cpp:64
PopupMenu * popupMenu
Definition: popupmenu.cpp:103
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
SkillPopup * skillPopup
Definition: skillpopup.cpp:42
SpellPopup * spellPopup
Definition: spellpopup.cpp:34
TextBoxPopup * textBoxPopup
TextPopup * textPopup
Definition: textpopup.cpp:33
UserPalette * userPalette
Definition: userpalette.cpp:34
const bool Visible_false
Definition: visible.h:30

References _, beingPopup, chatWindow, CREATEWIDGETV, CREATEWIDGETV0, ChatTabType::DEBUG, debugChatTab, debugWindow, delete2, didYouKnowWindow, helpWindow, itemPopup, popupMenu, Window::scheduleDelete(), ChatWindow::scheduleDelete(), ChatTab::setAllowHighlight(), setupWindow, ChatWindow::setVisible(), skillPopup, spellPopup, textBoxPopup, textPopup, userPalette, and Visible_false.

Referenced by Client::gameInit().

◆ deleteIcon()

void WindowManager::deleteIcon ( )

Definition at line 495 of file windowmanager.cpp.

496 {
498  mIcon = nullptr;
499 }
#define MSDL_FreeSurface(surface)
Definition: debug.h:54

References anonymous_namespace{windowmanager.cpp}::mIcon(), and MSDL_FreeSurface.

Referenced by Client::gameClear().

◆ deleteValidateWindows()

void WindowManager::deleteValidateWindows ( )

Definition at line 172 of file windowmanager.cpp.

173 {
174 #ifndef DYECMD
178 #endif // DYECMD
179 }

References beingEquipmentWindow, delete2, questsWindow, and skillDialog.

Referenced by Client::runValidate().

◆ deleteWindows()

void WindowManager::deleteWindows ( )

Definition at line 181 of file windowmanager.cpp.

182 {
183 #ifndef DYECMD
196 
200 #endif // DYECMD
201 
203 }
SpellManager * spellManager
SpellShortcut * spellShortcut

References beingPopup, chatWindow, debugChatTab, debugWindow, delete2, didYouKnowWindow, helpWindow, itemPopup, popupMenu, setupWindow, skillPopup, spellManager, spellPopup, spellShortcut, textBoxPopup, textPopup, and userPalette.

Referenced by Client::gameClear().

◆ doResizeVideo()

void WindowManager::doResizeVideo ( const int  actualWidth,
const int  actualHeight,
const bool  always 
)

Definition at line 268 of file windowmanager.cpp.

271 {
272  if (!always
273  && mainGraphics->mActualWidth == actualWidth
274  && mainGraphics->mActualHeight == actualHeight)
275  {
276  return;
277  }
278 
279 #ifdef __native_client__
280  naclPostMessage("resize-window",
281  strprintf("%d,%d", actualWidth, actualHeight));
282 #else // __native_client__
283 
284  resizeVideo(actualWidth, actualHeight, always);
285 #endif // __native_client__
286 }
void resizeVideo(int actualWidth, int actualHeight, const bool always)
std::string strprintf(const char *const format,...)

References Graphics::mActualHeight, Graphics::mActualWidth, mainGraphics, resizeVideo(), and strprintf().

Referenced by Setup_Video::action(), and applyScale().

◆ getFramerate()

int WindowManager::getFramerate ( )

Definition at line 260 of file windowmanager.cpp.

261 {
262  if (!settings.limitFps)
263  return 0;
264 
265  return SDL_getFramerate(&fpsManager);
266 }
int SDL_getFramerate(FPSmanager *manager)
Return the current target framerate in Hz.
bool limitFps
Definition: settings.h:154
Settings settings
Definition: settings.cpp:32
FPSmanager fpsManager

References fpsManager, Settings::limitFps, SDL_getFramerate(), and settings.

Referenced by Game::adjustPerfomance().

◆ getIsMinimized()

bool WindowManager::getIsMinimized ( )

Definition at line 483 of file windowmanager.cpp.

484 {
485  return mIsMinimized;
486 }

References anonymous_namespace{windowmanager.cpp}::mIsMinimized().

Referenced by ChatTab::chatLog(), and Client::gameExec().

◆ init()

void WindowManager::init ( )

Definition at line 114 of file windowmanager.cpp.

115 {
116  // Initialize frame limiting
118  fpsManager.rateticks = 0;
119  fpsManager.lastticks = 0;
120  fpsManager.rate = 0;
121 }
Uint32 framecount
float rateticks
Uint32 lastticks

References fpsManager, FPSmanager::framecount, FPSmanager::lastticks, FPSmanager::rate, and FPSmanager::rateticks.

Referenced by Client::Client().

◆ initTitle()

void WindowManager::initTitle ( )

Definition at line 205 of file windowmanager.cpp.

206 {
207  if (settings.options.test.empty())
208  {
209  settings.windowCaption = strprintf("%s %s",
210  branding.getStringValue("appName").c_str(),
211  SMALL_VERSION);
212  }
213  else
214  {
216  "Please wait - VIDEO MODE TEST - %s %s - Please wait",
217  branding.getStringValue("appName").c_str(),
218  SMALL_VERSION);
219  }
220 
222  settings.windowCaption.c_str());
223 }
std::string getStringValue(const std::string &key) const
Options options
Definition: settings.h:130
std::string windowCaption
Definition: settings.h:124
Configuration branding
#define SMALL_VERSION
Definition: main.h:44
void SetWindowTitle(const SDL_Surface *const window, const char *const title)
Definition: sdlhelper.cpp:85
std::string test
Definition: options.h:88

References branding, Configuration::getStringValue(), Graphics::getWindow(), mainGraphics, Settings::options, settings, SDL::SetWindowTitle(), SMALL_VERSION, strprintf(), Options::test, and Settings::windowCaption.

Referenced by Client::gameInit().

◆ isKeyboardVisible()

bool WindowManager::isKeyboardVisible ( )

Definition at line 473 of file windowmanager.cpp.

474 {
475 #ifdef USE_SDL2
476  return SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE;
477 #else // USE_SDL2
478 
479  return mKeyboardHeight > 1;
480 #endif // USE_SDL2
481 }

References anonymous_namespace{windowmanager.cpp}::mKeyboardHeight().

Referenced by TextField::focusGained(), and TextField::mousePressed().

◆ newChatMessage()

void WindowManager::newChatMessage ( )

◆ reloadWallpaper()

void WindowManager::reloadWallpaper ( )

◆ resizeVideo()

void WindowManager::resizeVideo ( int  actualWidth,
int  actualHeight,
const bool  always 
)

Definition at line 288 of file windowmanager.cpp.

291 {
292  // Keep a minimum size. This isn't adhered to by the actual window, but
293  // it keeps some window positions from getting messed up.
294  actualWidth = std::max(470, actualWidth);
295  actualHeight = std::max(320, actualHeight);
296 
297  if (mainGraphics == nullptr)
298  return;
299  if (!always
300  && mainGraphics->mActualWidth == actualWidth
301  && mainGraphics->mActualHeight == actualHeight)
302  {
303  return;
304  }
305 
306  if (mainGraphics->resizeScreen(actualWidth, actualHeight))
307  {
308  const int width = mainGraphics->mWidth;
309  const int height = mainGraphics->mHeight;
310  touchManager.resize(width, height);
311 
312  if (gui != nullptr)
313  gui->videoResized();
314 
315  if (desktop != nullptr)
316  desktop->setSize(width, height);
317 
318  client->moveButtons(width);
319 
320 #ifndef DYECMD
321  Game *const game = Game::instance();
322  if (game != nullptr)
323  Game::videoResized(width, height);
324 #endif // DYECMD
325 
326  if (gui != nullptr)
327  gui->draw();
328 
329  config.setValue("screenwidth", actualWidth);
330  config.setValue("screenheight", actualHeight);
331  }
332 }
void moveButtons(const int width)
Definition: client.cpp:774
void setValue(const std::string &key, const std::string &value)
Definition: game.h:64
static Game * instance()
Definition: game.h:82
static void videoResized(const int width, const int height)
Definition: game.cpp:1289
int mWidth
Definition: graphics.h:484
virtual bool resizeScreen(const int width, const int height)
Definition: graphics.cpp:558
int mHeight
Definition: graphics.h:485
void draw()
Definition: gui.cpp:470
void videoResized() const
Definition: gui.cpp:536
void resize(const int width, const int height)
void setSize(const int width, const int height)
Definition: widget.cpp:367
Desktop * desktop
Definition: desktop.cpp:49
Client * client
Definition: client.cpp:118
Gui * gui
Definition: gui.cpp:111
TouchManager touchManager

References client, config, desktop, Gui::draw(), gui, Game::instance(), Graphics::mActualHeight, Graphics::mActualWidth, mainGraphics, Graphics::mHeight, Client::moveButtons(), Graphics::mWidth, TouchManager::resize(), Graphics::resizeScreen(), Widget::setSize(), Configuration::setValue(), touchManager, Gui::videoResized(), and Game::videoResized().

Referenced by doResizeVideo(), and EventsManager::handleCommonEvents().

◆ setFramerate()

void WindowManager::setFramerate ( const unsigned int  fpsLimit)

Definition at line 249 of file windowmanager.cpp.

250 {
251  if (fpsLimit == 0U)
252  return;
253 
254  if (!settings.limitFps)
255  return;
256 
257  SDL_setFramerate(&fpsManager, fpsLimit);
258 }
int SDL_setFramerate(FPSmanager *manager, Uint32 rate)
Set the framerate in Hz.

References fpsManager, Settings::limitFps, SDL_setFramerate(), and settings.

Referenced by Client::gameInit(), Client::optionChanged(), Game::slowLogic(), and Game::updateFrameRate().

◆ setFullScreen()

bool WindowManager::setFullScreen ( const bool  fs)

Definition at line 334 of file windowmanager.cpp.

335 {
336 #ifdef __native_client__
337  naclPostMessage("set-fullscreen",
338  fs ? "on" : "off");
339  return true;
340 #else // __native_client__
341 
342  if (mainGraphics == nullptr)
343  return false;
344  return mainGraphics->setFullscreen(fs);
345 #endif // __native_client__
346 }
bool setFullscreen(const bool fs)
Definition: graphics.cpp:542

References mainGraphics, and Graphics::setFullscreen().

Referenced by Setup_Video::apply().

◆ setIcon()

void WindowManager::setIcon ( )

< Blit uses source alpha blending

Definition at line 411 of file windowmanager.cpp.

412 {
413 #if !defined(ANDROID) && !defined(__SWITCH__)
414  std::string iconFile = branding.getValue("appIcon", "icons/manaplus");
415 #ifdef WIN32
416  iconFile.append(".ico");
417 #else // WIN32
418 
419  iconFile.append(".png");
420 #endif // WIN32
421 
422  iconFile = VirtFs::getPath(iconFile);
423  logger->log("Loading icon from file: %s", iconFile.c_str());
424 
425 #ifdef WIN32
426  static SDL_SysWMinfo pInfo;
427  if (mainGraphics)
429  else
430  SDL::getWindowWMInfo(nullptr, &pInfo);
431  // Attempt to load icon from .ico file
432  HICON icon = static_cast<HICON>(LoadImage(nullptr,
433  iconFile.c_str(),
434  IMAGE_ICON,
435  64, 64,
436  LR_LOADFROMFILE));
437  // If it's failing, we load the default resource file.
438  if (!icon)
439  {
440  logger->log("icon load error");
441  icon = LoadIcon(GetModuleHandle(nullptr), "A");
442  }
443  if (icon)
444  {
445 #ifdef WIN64
446  SetClassLongPtr(pInfo.window,
447  GCLP_HICON,
448  reinterpret_cast<LONG_PTR>(icon));
449 #else // WIN64
450  SetClassLong(pInfo.window,
451  GCL_HICON,
452  reinterpret_cast<LONG>(icon));
453 #endif // WIN64
454  }
455 #else // WIN32
456 
457  mIcon = MIMG_Load(iconFile.c_str());
458  if (mIcon != nullptr)
459  {
460 #ifdef USE_SDL2
461  SDL_SetSurfaceAlphaMod(mIcon, SDL_ALPHA_OPAQUE);
462 #else // USE_SDL2
463 
464  SDL_SetAlpha(mIcon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
465 #endif // USE_SDL2
466 
468  }
469 #endif // WIN32
470 #endif // ANDROID
471 }
std::string getValue(const std::string &key, const std::string &deflt) const
void log(const char *const log_text,...)
Definition: logger.cpp:269
#define MIMG_Load(file)
Definition: debug.h:61
Logger * logger
Definition: logger.cpp:89
bool getWindowWMInfo(const SDL_Surface *const window, SDL_SysWMinfo *const info)
Definition: sdlhelper.cpp:112
void SetWindowIcon(const SDL_Surface *const window, SDL_Surface *const icon)
Definition: sdlhelper.cpp:91
std::string getPath(const std::string &file)
Definition: tools.cpp:97

References branding, VirtFs::getPath(), ConfigurationObject::getValue(), Graphics::getWindow(), SDL::getWindowWMInfo(), Logger::log(), logger, mainGraphics, anonymous_namespace{windowmanager.cpp}::mIcon(), MIMG_Load, and SDL::SetWindowIcon().

Referenced by Client::gameInit().

◆ setIsMinimized()

void WindowManager::setIsMinimized ( const bool  n)

◆ updateScreenKeyboard()

void WindowManager::updateScreenKeyboard ( const int  height)

Definition at line 489 of file windowmanager.cpp.

490 {
491  mKeyboardHeight = height;
492 }

References anonymous_namespace{windowmanager.cpp}::mKeyboardHeight().

Referenced by Client::gameInit(), and EventsManager::handleCommonEvents().

◆ updateTitle()

void WindowManager::updateTitle ( )

Definition at line 225 of file windowmanager.cpp.

226 {
227  std::string str;
228  if (settings.login.empty())
229  str = settings.serverName;
230  else
231  str.append(settings.login).append(" ").append(settings.serverName);
232  if (str.empty())
233  {
234  settings.windowCaption = strprintf("%s %s",
235  branding.getStringValue("appName").c_str(),
236  SMALL_VERSION);
237  }
238  else
239  {
240  settings.windowCaption = strprintf("%s %s - %s",
241  branding.getStringValue("appName").c_str(),
243  str.c_str());
244  }
246  settings.windowCaption.c_str());
247 }
std::string serverName
Definition: settings.h:114
std::string login
Definition: settings.h:108

References branding, Configuration::getStringValue(), Graphics::getWindow(), Settings::login, mainGraphics, Settings::serverName, settings, SDL::SetWindowTitle(), SMALL_VERSION, strprintf(), and Settings::windowCaption.

Referenced by Client::stateConnectServer1().