From 2ce29f1f6b2b387e6018881204b3d6a3bbb14619 Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 18 Oct 2010 13:11:28 +0200 Subject: [PATCH] Changed: Added isWindowMaximized and getRyzomModes functions --- code/ryzom/client/src/misc.cpp | 87 ++++++++++++++++++++++++++++++++++ code/ryzom/client/src/misc.h | 6 +++ 2 files changed, 93 insertions(+) diff --git a/code/ryzom/client/src/misc.cpp b/code/ryzom/client/src/misc.cpp index bd45482b6..0e6d42491 100644 --- a/code/ryzom/client/src/misc.cpp +++ b/code/ryzom/client/src/misc.cpp @@ -1440,13 +1440,31 @@ void setVideoMode(const UDriver::CMode &mode) UDriver::CMode oldMode; oldMode.Windowed = true; // getCurrentScreenMode may fail if first init ... Driver->getCurrentScreenMode(oldMode); + bool wasMaximized = isWindowMaximized(); Driver->setMode(mode); + bool isMaximized = isWindowMaximized(); if (oldMode.Windowed && !mode.Windowed) // going to fullscreen ? { /*CInterfaceManager *pIM = CInterfaceManager::getInstance(); pIM->movePointerAbs((sint32) mode.Width / 2, (sint32) mode.Height / 2); Driver->setMousePos(0.5f, 0.5f);*/ } + else if ((!oldMode.Windowed || wasMaximized) && (mode.Windowed && !isMaximized)) // leaving fullscreen ? + { + UDriver::CMode screenMode; + + uint32 posX = 0; + uint32 posY = 0; + + if (Driver->getCurrentScreenMode(screenMode)) + { + // position is not saved in config so center the window + posX = (screenMode.Width - Driver->getWindowWidth())/2; + posY = (screenMode.Height - Driver->getWindowHeight())/2; + } + + Driver->setWindowPos(posX, posY); + } } uint getCurrentColorDepth() @@ -1464,3 +1482,72 @@ uint getCurrentColorDepth() return CSystemUtils::getCurrentColorDepth(); } +bool isWindowMaximized() +{ + UDriver::CMode screenMode; + uint32 width, height; + + Driver->getWindowSize(width, height); + + return (Driver->getCurrentScreenMode(screenMode) && screenMode.Windowed && + screenMode.Width == width && screenMode.Height == height); +} + +sint getRyzomModes(std::vector &videoModes, std::vector &stringModeList) +{ + // **** Init Video Modes + Driver->getModes(videoModes); + // Remove modes under 800x600 and get the unique strings + sint i, j, nFoundMode = -1; + for (i=0; i < (sint)videoModes.size(); ++i) + { + if ((videoModes[i].Width < 800) || (videoModes[i].Height < 600)) + { + videoModes.erase(videoModes.begin()+i); + --i; + } + else + { + bool bFound = false; + string tmp = toString(videoModes[i].Width)+" x "+toString(videoModes[i].Height); + for (j = 0; j < (sint)stringModeList.size(); ++j) + { + if (stringModeList[j] == tmp) + { + bFound = true; + break; + } + } + if (!bFound) + { + stringModeList.push_back(tmp); + if ((videoModes[i].Width <= ClientCfg.Width) && (videoModes[i].Height <= ClientCfg.Height)) + { + if (nFoundMode == -1) + { + nFoundMode = j; + } + else + { + if ((videoModes[i].Width >= videoModes[nFoundMode].Width) && + (videoModes[i].Height >= videoModes[nFoundMode].Height)) + nFoundMode = j; + } + } + } + } + } + + // If no modes are available, display a message and exit + if (!ClientCfg.Windowed && (nFoundMode == -1 || stringModeList.empty())) + { + Driver->systemMessageBox("No Video Modes available!\n" + "Minimum Video mode to play Ryzom is 800x600.\n", + "No Video Mode!", + NL3D::UDriver::okType, + NL3D::UDriver::exclamationIcon); + exit(EXIT_SUCCESS); + } + + return nFoundMode; +} diff --git a/code/ryzom/client/src/misc.h b/code/ryzom/client/src/misc.h index 7f9bd8593..7a4dff95f 100644 --- a/code/ryzom/client/src/misc.h +++ b/code/ryzom/client/src/misc.h @@ -29,6 +29,7 @@ #include "nel/misc/quat.h" #include "nel/misc/rgba.h" #include "nel/3d/u_instance.h" +#include "nel/3d/u_driver.h" #include "game_share/slot_types.h" #include "game_share/mode_and_behaviour.h" @@ -242,6 +243,11 @@ void setVideoMode(const NL3D::UDriver::CMode &mode); // Get the current color depth (8, 16, or 32). In windowed mode, this will be the desktop color depth, in fullscreen mode, the color depth of the framebuffer. uint getCurrentColorDepth(); +// get maximized +bool isWindowMaximized(); + +sint getRyzomModes(std::vector &videoModes, std::vector &stringModeList); + #endif // CL_MISC_H /* End of misc.h */