diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-30 22:32:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-05-01 17:27:14 +0300 |
commit | 097b17e588ed430482fa1e5e4938618db838e468 (patch) | |
tree | adb9f3122b1e5fac635e439c722ed983ae36d289 /src | |
parent | 1889feb70ddd6d1eaa33da7584ecd20955f94f5c (diff) | |
download | plus-097b17e588ed430482fa1e5e4938618db838e468.tar.gz plus-097b17e588ed430482fa1e5e4938618db838e468.tar.bz2 plus-097b17e588ed430482fa1e5e4938618db838e468.tar.xz plus-097b17e588ed430482fa1e5e4938618db838e468.zip |
add pixel size detection fo X11 and windows.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/client.cpp | 1 | ||||
-rw-r--r-- | src/graphicsmanager.cpp | 91 | ||||
-rw-r--r-- | src/graphicsmanager.h | 16 |
4 files changed, 85 insertions, 25 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8741a1c86..bb55c84eb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -116,7 +116,7 @@ SET(SRCS gui/widgets/button.h gui/widgets/characterdisplay.cpp gui/widgets/characterdisplay.h - gui/widgets/charviewbase.h + gui/widgets/characterviewbase.h gui/widgets/characterviewnormal.cpp gui/widgets/characterviewnormal.h gui/widgets/characterviewsmall.cpp diff --git a/src/client.cpp b/src/client.cpp index e1b92733c..45fb3a5ad 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -585,6 +585,7 @@ void Client::gameInit() #endif logVars(); graphicsManager.initGraphics(mOptions.noOpenGL); + graphicsManager.detectPixelSize(); runCounters = config.getBoolValue("packetcounters"); applyVSync(); graphicsManager.setVideoMode(); diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 7c5c94ed6..52006ad6c 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -27,9 +27,12 @@ #include <GLES2/gl2.h> #include <GLES/glext.h> #include <EGL/egl.h> +#include <SDL_android.h> #else #include "GL/glx.h" #endif +#else +//#include <winuser.h> #endif #endif @@ -76,6 +79,18 @@ GraphicsManager graphicsManager; +const int densitySize = 6; + +const std::string densityNames[] = +{ + "low", + "medium", + "tv", + "high", + "xhigh", + "xxhigh" +}; + GraphicsManager::GraphicsManager() : mExtensions(), mPlatformExtensions(), @@ -88,6 +103,11 @@ GraphicsManager::GraphicsManager() : mPlatformMajor(0), mMaxVertices(500), mMaxFboSize(0), + mMaxWidth(0), + mMaxHeight(0), + mWidthMM(0), + mHeightMM(0), + mDensity(-1), #ifdef USE_OPENGL mUseTextureSampler(true), mTextureSampler(0), @@ -246,28 +266,6 @@ void GraphicsManager::initGraphics(const bool noOpenGL A_UNUSED) #endif } -Graphics *GraphicsManager::createGraphics() -{ -#ifdef USE_OPENGL - switch (config.getIntValue("opengl")) - { - case 0: - return new Graphics; - case 1: - default: -#ifndef ANDROID - return new NormalOpenGLGraphics; - case 2: - return new SafeOpenGLGraphics; -#endif - case 3: - return new MobileOpenGLGraphics; - }; -#else - return new Graphics; -#endif -} - void GraphicsManager::setVideoMode() { const int bpp = 0; @@ -484,6 +482,7 @@ void GraphicsManager::updatePlanformExtensions() logger->log1(extensions2); } } + logger->log("width=%d", DisplayWidth(display, screenNum)); } #endif } @@ -992,3 +991,51 @@ void GraphicsManager::updateDebugLog() const } } #endif + +void GraphicsManager::detectPixelSize() +{ + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + if (SDL_GetWMInfo(&info)) + { +#ifdef WIN32 + HDC hdc = GetDC(info.window); + if (hdc) + { +// SetProcessDPIAware(); + mMaxWidth = GetDeviceCaps(hdc, HORZRES); + mMaxHeight = GetDeviceCaps(hdc, VERTRES); + mWidthMM = GetDeviceCaps(hdc, HORZSIZE); + mHeightMM = GetDeviceCaps(hdc, VERTSIZE); + } +#elif defined USE_X11 + Display *const display = info.info.x11.display; + if (display) + { + Screen *const screen = XDefaultScreenOfDisplay(display); + if (!screen) + return; + + const int screenNum = XScreenNumberOfScreen(screen); + mMaxWidth = DisplayWidth(display, screenNum); + mMaxHeight = DisplayHeight(display, screenNum); + mWidthMM = DisplayWidthMM(display, screenNum); + mHeightMM = DisplayHeightMM(display, screenNum); + } +#endif + } +#if defined ANDROID + SDL_ANDROID_GetMetrics(&mMaxWidth, &mMaxHeight, + &mWidthMM, &mHeightMM, &mDensity); +#endif + logger->log("screen size in pixels: %dx%d", mMaxWidth, mMaxHeight); + logger->log("screen size in millimeters: %dx%d", mWidthMM, mHeightMM); + logger->log("screen density: %d", mDensity); +} + +std::string GraphicsManager::getDensityString() const +{ + if (mDensity >= 0 && mDensity < densitySize) + return densityNames[mDensity]; + return ""; +} diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h index 4efcf98af..c97935283 100644 --- a/src/graphicsmanager.h +++ b/src/graphicsmanager.h @@ -62,10 +62,12 @@ class GraphicsManager final void setVideoMode(); - Graphics *createGraphics() A_WARN_UNUSED; - bool getAllVideoModes(StringVect &modeList); + void detectPixelSize(); + + std::string getDensityString() const; + #ifdef USE_OPENGL TestMain *startDetection() A_WARN_UNUSED; @@ -147,6 +149,16 @@ class GraphicsManager final int mMaxFboSize; + uint32_t mMaxWidth; + + uint32_t mMaxHeight; + + uint32_t mWidthMM; + + uint32_t mHeightMM; + + int32_t mDensity; + #ifdef USE_OPENGL bool mUseTextureSampler; |