Ticket #2349: hidpi.patch
File hidpi.patch, 6.3 KB (added by , 8 years ago) |
---|
-
source/gui/CGUI.cpp
79 79 // Yes the mouse position is stored as float to avoid 80 80 // constant conversions when operating in a 81 81 // float-based environment. 82 m_MousePos = CPos((float)ev->ev.motion.x * g_GuiScale , (float)ev->ev.motion.y * g_GuiScale);82 m_MousePos = CPos((float)ev->ev.motion.x * g_GuiScale * g_DpiScale, (float)ev->ev.motion.y * g_GuiScale * g_DpiScale); 83 83 84 84 SGUIMessage msg(GUIM_MOUSE_MOTION); 85 85 GUI<SGUIMessage>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject, … … 106 106 CPos oldMousePos = m_MousePos; 107 107 if (ev->ev.type == SDL_MOUSEBUTTONDOWN || ev->ev.type == SDL_MOUSEBUTTONUP) 108 108 { 109 m_MousePos = CPos((float)ev->ev.button.x * g_GuiScale , (float)ev->ev.button.y * g_GuiScale);109 m_MousePos = CPos((float)ev->ev.button.x * g_GuiScale * g_DpiScale, (float)ev->ev.button.y * g_GuiScale * g_DpiScale); 110 110 } 111 111 112 112 // Only one object can be hovered -
source/gui/scripting/GuiScriptConversions.cpp
109 109 { 110 110 // SET(obj, "which", (int)val.ev.motion.which); // (not in wsdl.h) 111 111 // SET(obj, "state", (int)val.ev.motion.state); // (not in wsdl.h) 112 SET(obj, "x", (int)val.ev.motion.x );113 SET(obj, "y", (int)val.ev.motion.y );112 SET(obj, "x", (int)val.ev.motion.x * g_DpiScale); 113 SET(obj, "y", (int)val.ev.motion.y * g_DpiScale); 114 114 // SET(obj, "xrel", (int)val.ev.motion.xrel); // (not in wsdl.h) 115 115 // SET(obj, "yrel", (int)val.ev.motion.yrel); // (not in wsdl.h) 116 116 break; … … 121 121 // SET(obj, "which", (int)val.ev.button.which); // (not in wsdl.h) 122 122 SET(obj, "button", (int)val.ev.button.button); 123 123 SET(obj, "state", (int)val.ev.button.state); 124 SET(obj, "x", (int)val.ev.button.x );125 SET(obj, "y", (int)val.ev.button.y );124 SET(obj, "x", (int)val.ev.button.x * g_DpiScale); 125 SET(obj, "y", (int)val.ev.button.y * g_DpiScale); 126 126 break; 127 127 } 128 128 case SDL_HOTKEYDOWN: -
source/ps/GameSetup/Config.cpp
59 59 60 60 int g_xres, g_yres; 61 61 float g_GuiScale = 1.0f; 62 float g_DpiScale = 1.0f; 62 63 bool g_VSync = false; 63 64 64 65 bool g_Quickstart = false; -
source/ps/GameSetup/Config.h
82 82 83 83 extern int g_xres, g_yres; 84 84 extern float g_GuiScale; 85 extern float g_DpiScale; 85 86 extern bool g_VSync; 86 87 87 88 extern bool g_Quickstart; -
source/ps/Globals.cpp
90 90 #endif 91 91 92 92 case SDL_MOUSEMOTION: 93 g_mouse_x = ev->ev.motion.x ;94 g_mouse_y = ev->ev.motion.y ;93 g_mouse_x = ev->ev.motion.x * g_DpiScale; 94 g_mouse_y = ev->ev.motion.y * g_DpiScale; 95 95 return IN_PASS; 96 96 97 97 case SDL_MOUSEBUTTONDOWN: -
source/ps/VideoMode.cpp
79 79 if (!m_Window) 80 80 { 81 81 // Note: these flags only take affect in SDL_CreateWindow 82 flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ;82 flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; 83 83 m_WindowedX = m_WindowedY = SDL_WINDOWPOS_CENTERED_DISPLAY(m_ConfigDisplay); 84 84 85 85 m_Window = SDL_CreateWindow("0 A.D.", m_WindowedX, m_WindowedY, w, h, flags); … … 148 148 // Grab the current video settings 149 149 SDL_GetWindowSize(m_Window, &m_CurrentW, &m_CurrentH); 150 150 m_CurrentBPP = bpp; 151 LOGMESSAGE("Window Size: %dx%d", m_CurrentW, m_CurrentH); 152 153 // This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI drawable 154 int drawingWidth, drawingHeight; 155 SDL_GL_GetDrawableSize(m_Window, &drawingWidth, &drawingHeight); 156 LOGMESSAGE("Drawable Size: %dx%d", drawingWidth, drawingHeight); 151 157 158 UpdateRenderer(); 159 152 160 if (fullscreen) 153 161 SDL_SetWindowGrab(m_Window, SDL_TRUE); 154 162 else … … 197 205 198 206 m_IsFullscreen = fullscreen; 199 207 200 g_xres = m_CurrentW;201 g_yres = m_CurrentH;202 203 208 return true; 204 209 } 205 210 … … 389 394 390 395 m_WindowedW = w; 391 396 m_WindowedH = h; 392 393 UpdateRenderer(w, h); 394 397 395 398 return true; 396 399 } 397 400 … … 434 437 if (!SetVideoMode(w, h, bpp, fullscreen)) 435 438 return false; 436 439 437 UpdateRenderer(m_CurrentW, m_CurrentH);438 439 440 return true; 440 441 } 441 442 else … … 450 451 if (!SetVideoMode(w, h, bpp, fullscreen)) 451 452 return false; 452 453 453 UpdateRenderer(w, h);454 455 454 return true; 456 455 } 457 456 } … … 470 469 } 471 470 } 472 471 472 void CVideoMode::UpdateRenderer() { 473 // This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI drawable 474 int drawingWidth, drawingHeight; 475 SDL_GL_GetDrawableSize(m_Window, &drawingWidth, &drawingHeight); 476 UpdateRenderer(drawingWidth, drawingHeight); 477 478 g_xres = drawingWidth; 479 g_yres = drawingHeight; 480 g_GuiScale = m_CurrentW / ((float)drawingWidth); 481 g_DpiScale = ((float)drawingWidth) / m_CurrentW; 482 } 483 473 484 void CVideoMode::UpdateRenderer(int w, int h) 474 485 { 475 486 if (w < 2) w = 2; // avoid GL errors caused by invalid sizes -
source/ps/VideoMode.h
62 62 */ 63 63 void UpdatePosition(int x, int y); 64 64 65 /** 66 * Update the graphics code to start drawing to the new size set for the SDL context. 67 * This should be called after the GL context has been resized. 68 */ 69 void UpdateRenderer(); 70 65 71 /** 66 * Update the graphics code to start drawing to the newsize.72 * Update the graphics code to start drawing to the specified size. 67 73 * This should be called after the GL context has been resized. 68 74 * This can also be used when the GL context is managed externally, not via SDL. 69 75 */