OpenTTD Source 20260711-master-g3fb3006dff
win32_v.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "../stdafx.h"
11#include "../openttd.h"
12#include "../error_func.h"
13#include "../gfx_func.h"
14#include "../os/windows/win32.h"
17#include "../core/math_func.hpp"
19#include "../texteff.hpp"
20#include "../thread.h"
21#include "../progress.h"
22#include "../window_gui.h"
23#include "../window_func.h"
24#include "../framerate_type.h"
25#include "../library_loader.h"
26#include "../core/utf8.hpp"
27#include "win32_v.h"
28#include <windows.h>
29#include <imm.h>
30#include <objbase.h>
31#include <versionhelpers.h>
32#if defined(_MSC_VER) && defined(NTDDI_WIN10_RS4)
33#include <winrt/Windows.UI.ViewManagement.h>
34#endif
35
36#ifdef WITH_OPENGL
37#include <GL/gl.h>
38#include "../3rdparty/opengl/glext.h"
39#include "../3rdparty/opengl/wglext.h"
40#include "opengl.h"
41#endif /* WITH_OPENGL */
42
43#include "../safeguards.h"
44
45/* Missing define in MinGW headers. */
46#ifndef MAPVK_VK_TO_CHAR
47#define MAPVK_VK_TO_CHAR (2)
48#endif
49
50#ifndef PM_QS_INPUT
51#define PM_QS_INPUT 0x20000
52#endif
53
54#ifndef WM_DPICHANGED
55#define WM_DPICHANGED 0x02E0
56#endif
57
58bool _window_maximize;
59static Dimension _bck_resolution;
60DWORD _imm_props;
61
62static Palette _local_palette;
63
65{
66 MyShowCursor(false, true);
67}
68
70 uint8_t vk_from;
71 uint8_t vk_count;
72 uint8_t map_to;
73};
74
75#define AS(x, z) {x, 1, z}
76#define AM(x, y, z, w) {x, y - x + 1, z}
77
78static const Win32VkMapping _vk_mapping[] = {
79 /* Pageup stuff + up/down */
80 AM(VK_PRIOR, VK_DOWN, WKC_PAGEUP, WKC_DOWN),
81 /* Map letters & digits */
82 AM('A', 'Z', 'A', 'Z'),
83 AM('0', '9', '0', '9'),
84
85 AS(VK_ESCAPE, WKC_ESC),
86 AS(VK_PAUSE, WKC_PAUSE),
87 AS(VK_BACK, WKC_BACKSPACE),
88 AM(VK_INSERT, VK_DELETE, WKC_INSERT, WKC_DELETE),
89
90 AS(VK_SPACE, WKC_SPACE),
91 AS(VK_RETURN, WKC_RETURN),
92 AS(VK_TAB, WKC_TAB),
93
94 /* Function keys */
95 AM(VK_F1, VK_F12, WKC_F1, WKC_F12),
96
97 /* Numeric part */
98 AM(VK_NUMPAD0, VK_NUMPAD9, '0', '9'),
99 AS(VK_DIVIDE, WKC_NUM_DIV),
100 AS(VK_MULTIPLY, WKC_NUM_MUL),
101 AS(VK_SUBTRACT, WKC_NUM_MINUS),
102 AS(VK_ADD, WKC_NUM_PLUS),
103 AS(VK_DECIMAL, WKC_NUM_DECIMAL),
104
105 /* Other non-letter keys */
106 AS(0xBF, WKC_SLASH),
107 AS(0xBA, WKC_SEMICOLON),
108 AS(0xBB, WKC_EQUALS),
109 AS(0xDB, WKC_L_BRACKET),
110 AS(0xDC, WKC_BACKSLASH),
111 AS(0xDD, WKC_R_BRACKET),
112
113 AS(0xDE, WKC_SINGLEQUOTE),
114 AS(0xBC, WKC_COMMA),
115 AS(0xBD, WKC_MINUS),
116 AS(0xBE, WKC_PERIOD)
117};
118
119static uint MapWindowsKey(uint sym)
120{
121 uint key = 0;
122
123 for (const auto &map : _vk_mapping) {
124 if (IsInsideBS(sym, map.vk_from, map.vk_count)) {
125 key = sym - map.vk_from + map.map_to;
126 break;
127 }
128 }
129
130 if (GetAsyncKeyState(VK_SHIFT) < 0) key |= WKC_SHIFT;
131 if (GetAsyncKeyState(VK_CONTROL) < 0) key |= WKC_CTRL;
132 if (GetAsyncKeyState(VK_MENU) < 0) key |= WKC_ALT;
133 return key;
134}
135
141{
142 /* Check modes for the relevant fullscreen bpp */
144}
145
152bool VideoDriver_Win32Base::MakeWindow(bool full_screen, bool resize)
153{
154 /* full_screen is whether the new window should be fullscreen,
155 * _wnd.fullscreen is whether the current window is. */
156 _fullscreen = full_screen;
157
158 /* recreate window? */
159 if ((full_screen != this->fullscreen) && this->main_wnd) {
160 DestroyWindow(this->main_wnd);
161 this->main_wnd = 0;
162 }
163
164 if (full_screen) {
165 DEVMODE settings{};
166 settings.dmSize = sizeof(settings);
167 settings.dmFields =
168 DM_BITSPERPEL |
169 DM_PELSWIDTH |
170 DM_PELSHEIGHT;
171 settings.dmBitsPerPel = this->GetFullscreenBpp();
172 settings.dmPelsWidth = this->width_org;
173 settings.dmPelsHeight = this->height_org;
174
175 /* Check for 8 bpp support. */
176 if (settings.dmBitsPerPel == 8 && ChangeDisplaySettings(&settings, CDS_FULLSCREEN | CDS_TEST) != DISP_CHANGE_SUCCESSFUL) {
177 settings.dmBitsPerPel = 32;
178 }
179
180 /* Test fullscreen with current resolution, if it fails use desktop resolution. */
181 if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN | CDS_TEST) != DISP_CHANGE_SUCCESSFUL) {
182 RECT r;
183 GetWindowRect(GetDesktopWindow(), &r);
184 /* Guard against recursion. If we already failed here once, just fall through to
185 * the next ChangeDisplaySettings call which will fail and error out appropriately. */
186 if ((int)settings.dmPelsWidth != r.right - r.left || (int)settings.dmPelsHeight != r.bottom - r.top) {
187 return this->ChangeResolution(r.right - r.left, r.bottom - r.top);
188 }
189 }
190
191 if (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
192 this->MakeWindow(false, resize); // don't care about the result
193 return false; // the request failed
194 }
195 } else if (this->fullscreen) {
196 /* restore display? */
197 ChangeDisplaySettings(nullptr, 0);
198 /* restore the resolution */
199 this->width = _bck_resolution.width;
200 this->height = _bck_resolution.height;
201 }
202
203 {
204 RECT r;
205 DWORD style, showstyle;
206 int w, h;
207
208 showstyle = SW_SHOWNORMAL;
209 this->fullscreen = full_screen;
210 if (this->fullscreen) {
211 style = WS_POPUP;
212 SetRect(&r, 0, 0, this->width_org, this->height_org);
213 } else {
214 style = WS_OVERLAPPEDWINDOW;
215 /* On window creation, check if we were in maximize mode before */
216 if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
217 SetRect(&r, 0, 0, this->width, this->height);
218 }
219
220 AdjustWindowRect(&r, style, FALSE);
221 w = r.right - r.left;
222 h = r.bottom - r.top;
223
224 if (this->main_wnd != nullptr) {
225 if (!_window_maximize && resize) SetWindowPos(this->main_wnd, 0, 0, 0, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOMOVE);
226 } else {
227 int x = 0;
228 int y = 0;
229
230 /* For windowed mode, center on the workspace of the primary display. */
231 if (!this->fullscreen) {
232 MONITORINFO mi;
233 mi.cbSize = sizeof(mi);
234 GetMonitorInfo(MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY), &mi);
235
236 x = (mi.rcWork.right - mi.rcWork.left - w) / 2;
237 y = (mi.rcWork.bottom - mi.rcWork.top - h) / 2;
238 }
239
240 std::string caption = VideoDriver::GetCaption();
241 this->main_wnd = CreateWindow(L"OTTD", OTTD2FS(caption).c_str(), style, x, y, w, h, 0, 0, GetModuleHandle(nullptr), this);
242 if (this->main_wnd == nullptr) UserError("CreateWindow failed");
243 ShowWindow(this->main_wnd, showstyle);
244 }
245 }
246
248
250 return true;
251}
252
259static LRESULT HandleCharMsg(uint keycode, char32_t charcode)
260{
261 static char32_t prev_char = 0;
262
263 /* Did we get a lead surrogate? If yes, store and exit. */
264 if (Utf16IsLeadSurrogate(charcode)) {
265 if (prev_char != 0) Debug(driver, 1, "Got two UTF-16 lead surrogates, dropping the first one");
266 prev_char = charcode;
267 return 0;
268 }
269
270 /* Stored lead surrogate and incoming trail surrogate? Combine and forward to input handling. */
271 if (prev_char != 0) {
272 if (Utf16IsTrailSurrogate(charcode)) {
273 charcode = Utf16DecodeSurrogate(prev_char, charcode);
274 } else {
275 Debug(driver, 1, "Got an UTF-16 lead surrogate without a trail surrogate, dropping the lead surrogate");
276 }
277 }
278 prev_char = 0;
279
280 HandleKeypress(keycode, charcode);
281
282 return 0;
283}
284
290{
291 return (_imm_props & IME_PROP_AT_CARET) && !(_imm_props & IME_PROP_SPECIAL_UI);
292}
293
298static void SetCompositionPos(HWND hwnd)
299{
300 HIMC hIMC = ImmGetContext(hwnd);
301 if (hIMC != nullptr) {
302 COMPOSITIONFORM cf;
303 cf.dwStyle = CFS_POINT;
304
305 if (EditBoxInGlobalFocus()) {
306 /* Get caret position. */
307 Point pt = _focused_window->GetCaretPosition();
308 cf.ptCurrentPos.x = _focused_window->left + pt.x;
309 cf.ptCurrentPos.y = _focused_window->top + pt.y;
310 } else {
311 cf.ptCurrentPos.x = 0;
312 cf.ptCurrentPos.y = 0;
313 }
314 ImmSetCompositionWindow(hIMC, &cf);
315 }
316 ImmReleaseContext(hwnd, hIMC);
317}
318
323static void SetCandidatePos(HWND hwnd)
324{
325 HIMC hIMC = ImmGetContext(hwnd);
326 if (hIMC != nullptr) {
327 CANDIDATEFORM cf;
328 cf.dwIndex = 0;
329 cf.dwStyle = CFS_EXCLUDE;
330
331 if (EditBoxInGlobalFocus()) {
332 Point pt = _focused_window->GetCaretPosition();
333 cf.ptCurrentPos.x = _focused_window->left + pt.x;
334 cf.ptCurrentPos.y = _focused_window->top + pt.y;
335 if (_focused_window->window_class == WindowClass::Console) {
336 cf.rcArea.left = _focused_window->left;
337 cf.rcArea.top = _focused_window->top;
338 cf.rcArea.right = _focused_window->left + _focused_window->width;
339 cf.rcArea.bottom = _focused_window->top + _focused_window->height;
340 } else {
341 cf.rcArea.left = _focused_window->left + _focused_window->nested_focus->pos_x;
342 cf.rcArea.top = _focused_window->top + _focused_window->nested_focus->pos_y;
343 cf.rcArea.right = cf.rcArea.left + _focused_window->nested_focus->current_x;
344 cf.rcArea.bottom = cf.rcArea.top + _focused_window->nested_focus->current_y;
345 }
346 } else {
347 cf.ptCurrentPos.x = 0;
348 cf.ptCurrentPos.y = 0;
349 SetRectEmpty(&cf.rcArea);
350 }
351 ImmSetCandidateWindow(hIMC, &cf);
352 }
353 ImmReleaseContext(hwnd, hIMC);
354}
355
363static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam)
364{
365 HIMC hIMC = ImmGetContext(hwnd);
366
367 if (hIMC != nullptr) {
368 if (lParam & GCS_RESULTSTR) {
369 /* Read result string from the IME. */
370 LONG len = ImmGetCompositionString(hIMC, GCS_RESULTSTR, nullptr, 0); // Length is always in bytes, even in UNICODE build.
371 std::wstring str(len + 1, L'\0');
372 len = ImmGetCompositionString(hIMC, GCS_RESULTSTR, str.data(), len);
373 str[len / sizeof(wchar_t)] = L'\0';
374
375 /* Transmit text to windowing system. */
376 if (len > 0) {
377 HandleTextInput({}, true); // Clear marked string.
379 }
380 SetCompositionPos(hwnd);
381
382 /* Don't pass the result string on to the default window proc. */
383 lParam &= ~(GCS_RESULTSTR | GCS_RESULTCLAUSE | GCS_RESULTREADCLAUSE | GCS_RESULTREADSTR);
384 }
385
386 if ((lParam & GCS_COMPSTR) && DrawIMECompositionString()) {
387 /* Read composition string from the IME. */
388 LONG len = ImmGetCompositionString(hIMC, GCS_COMPSTR, nullptr, 0); // Length is always in bytes, even in UNICODE build.
389 std::wstring str(len + 1, L'\0');
390 len = ImmGetCompositionString(hIMC, GCS_COMPSTR, str.data(), len);
391 str[len / sizeof(wchar_t)] = L'\0';
392
393 if (len > 0) {
394 static char utf8_buf[1024];
395 convert_from_fs(str, utf8_buf);
396
397 /* Convert caret position from bytes in the input string to a position in the UTF-8 encoded string. */
398 LONG caret_bytes = ImmGetCompositionString(hIMC, GCS_CURSORPOS, nullptr, 0);
399 Utf8View view(utf8_buf);
400 auto caret = view.begin();
401 const auto end = view.end();
402 for (const wchar_t *c = str.c_str(); *c != '\0' && caret != end && caret_bytes > 0; c++, caret_bytes--) {
403 /* Skip DBCS lead bytes or leading surrogates. */
404 if (Utf16IsLeadSurrogate(*c)) {
405 c++;
406 caret_bytes--;
407 }
408 ++caret;
409 }
410
411 HandleTextInput(utf8_buf, true, caret.GetByteOffset());
412 } else {
413 HandleTextInput({}, true);
414 }
415
416 lParam &= ~(GCS_COMPSTR | GCS_COMPATTR | GCS_COMPCLAUSE | GCS_CURSORPOS | GCS_DELTASTART);
417 }
418 }
419 ImmReleaseContext(hwnd, hIMC);
420
421 return lParam != 0 ? DefWindowProc(hwnd, WM_IME_COMPOSITION, wParam, lParam) : 0;
422}
423
428static void CancelIMEComposition(HWND hwnd)
429{
430 HIMC hIMC = ImmGetContext(hwnd);
431 if (hIMC != nullptr) ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
432 ImmReleaseContext(hwnd, hIMC);
433 /* Clear any marked string from the current edit box. */
434 HandleTextInput({}, true);
435}
436
437#if defined(_MSC_VER) && defined(NTDDI_WIN10_RS4)
438/* We only use WinRT functions on Windows 10 or later. Unfortunately, newer Windows SDKs are now
439 * linking the two functions below directly instead of using dynamic linking as previously.
440 * To avoid any runtime linking errors on Windows 7 or older, we stub in our own dynamic
441 * linking trampoline. */
442
443static LibraryLoader _combase("combase.dll");
444
445extern "C" int32_t __stdcall WINRT_IMPL_RoOriginateLanguageException(int32_t error, void *message, void *languageException) noexcept
446{
447 typedef BOOL(WINAPI *PFNRoOriginateLanguageException)(int32_t, void *, void *);
448 static PFNRoOriginateLanguageException RoOriginateLanguageException = _combase.GetFunction("RoOriginateLanguageException");
449
450 if (RoOriginateLanguageException != nullptr) {
451 return RoOriginateLanguageException(error, message, languageException);
452 } else {
453 return TRUE;
454 }
455}
456
457extern "C" int32_t __stdcall WINRT_IMPL_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept
458{
459 typedef BOOL(WINAPI *PFNRoGetActivationFactory)(void *, winrt::guid const &, void **);
460 static PFNRoGetActivationFactory RoGetActivationFactory = _combase.GetFunction("RoGetActivationFactory");
461
462 if (RoGetActivationFactory != nullptr) {
463 return RoGetActivationFactory(classId, iid, factory);
464 } else {
465 *factory = nullptr;
466 return winrt::impl::error_class_not_available;
467 }
468}
469#endif
470
471static bool IsDarkModeEnabled()
472{
473 /* Only build if SDK is Windows 10 1803 or later. */
474#if defined(_MSC_VER) && defined(NTDDI_WIN10_RS4)
475 if (IsWindows10OrGreater()) {
476 try {
477 /*
478 * The official documented way to find out if the system is running in dark mode is to
479 * check the brightness of the current theme's colour.
480 * See: https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/ui/apply-windows-themes#know-when-dark-mode-is-enabled
481 *
482 * There are other variants floating around on the Internet, but they all rely on internal,
483 * undocumented Windows functions that may or may not work in the future.
484 */
485 winrt::Windows::UI::ViewManagement::UISettings settings;
486 auto foreground = settings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Foreground);
487
488 /* If the Foreground colour is a light colour, the system is running in dark mode. */
489 return ((5 * foreground.G) + (2 * foreground.R) + foreground.B) > (8 * 128);
490 } catch (...) {
491 /* Some kind of error, like a too old Windows version. Just return false. */
492 return false;
493 }
494 }
495#endif /* defined(_MSC_VER) && defined(NTDDI_WIN10_RS4) */
496
497 return false;
498}
499
500static void SetDarkModeForWindow(HWND hWnd, bool dark_mode)
501{
502 /* Only build if SDK is Windows 10+. */
503#if defined(NTDDI_WIN10)
504 if (!IsWindows10OrGreater()) return;
505
506 /* This function is documented, but not supported on all Windows 10/11 SDK builds. For this
507 * reason, the code uses dynamic loading and ignores any errors for a best-effort result. */
508 static LibraryLoader _dwmapi("dwmapi.dll");
509 typedef HRESULT(WINAPI *PFNDWMSETWINDOWATTRIBUTE)(HWND, DWORD, LPCVOID, DWORD);
510 static const PFNDWMSETWINDOWATTRIBUTE DwmSetWindowAttribute = _dwmapi.GetFunction("DwmSetWindowAttribute");
511
512 if (DwmSetWindowAttribute != nullptr) {
513 /* Contrary to the published documentation, DWMWA_USE_IMMERSIVE_DARK_MODE does not change the
514 * window chrome according to the current theme, but forces it to either light or dark mode.
515 * As such, the set value has to depend on the current theming mode.*/
516 BOOL value = dark_mode ? TRUE : FALSE;
517 if (DwmSetWindowAttribute(hWnd, 20 /* DWMWA_USE_IMMERSIVE_DARK_MODE */, &value, sizeof(value)) != S_OK) {
518 DwmSetWindowAttribute(hWnd, 19 /* DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 */, &value, sizeof(value)); // Ignore errors. It works or it doesn't.
519 }
520 }
521#endif /* defined(NTDDI_WIN10) */
522}
523
524LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
525{
526 static uint32_t keycode = 0;
527 static bool console = false;
528
529 const float SCROLL_BUILTIN_MULTIPLIER = 14.0f / WHEEL_DELTA;
530
531 VideoDriver_Win32Base *video_driver = (VideoDriver_Win32Base *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
532
533 switch (msg) {
534 case WM_CREATE:
535 SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams);
536 _cursor.in_window = false; // Win32 has mouse tracking.
537 SetCompositionPos(hwnd);
538 _imm_props = ImmGetProperty(GetKeyboardLayout(0), IGP_PROPERTY);
539
540 /* Enable dark mode theming for window chrome. */
541 SetDarkModeForWindow(hwnd, IsDarkModeEnabled());
542 break;
543
544 case WM_SETTINGCHANGE:
545 /* Synchronize dark mode theming state. */
546 SetDarkModeForWindow(hwnd, IsDarkModeEnabled());
547 break;
548
549 case WM_PAINT: {
550 RECT r;
551 GetUpdateRect(hwnd, &r, FALSE);
552 video_driver->MakeDirty(r.left, r.top, r.right - r.left, r.bottom - r.top);
553
554 ValidateRect(hwnd, nullptr);
555 return 0;
556 }
557
558 case WM_PALETTECHANGED:
559 if ((HWND)wParam == hwnd) return 0;
560 [[fallthrough]];
561
562 case WM_QUERYNEWPALETTE:
563 video_driver->PaletteChanged(hwnd);
564 return 0;
565
566 case WM_CLOSE:
567 HandleExitGameRequest();
568 return 0;
569
570 case WM_DESTROY:
571 if (_window_maximize) _cur_resolution = _bck_resolution;
572 return 0;
573
574 case WM_LBUTTONDOWN:
575 SetCapture(hwnd);
576 _left_button_down = true;
578 return 0;
579
580 case WM_LBUTTONUP:
581 ReleaseCapture();
582 _left_button_down = false;
583 _left_button_clicked = false;
585 return 0;
586
587 case WM_RBUTTONDOWN:
588 SetCapture(hwnd);
589 _right_button_down = true;
592 return 0;
593
594 case WM_RBUTTONUP:
595 ReleaseCapture();
596 _right_button_down = false;
598 return 0;
599
600 case WM_MOUSELEAVE:
601 UndrawMouseCursor();
602 _cursor.in_window = false;
603
604 if (!_left_button_down && !_right_button_down) MyShowCursor(true);
605 return 0;
606
607 case WM_MOUSEMOVE: {
608 int x = (int16_t)LOWORD(lParam);
609 int y = (int16_t)HIWORD(lParam);
610
611 /* If the mouse was not in the window and it has moved it means it has
612 * come into the window, so start drawing the mouse. Also start
613 * tracking the mouse for exiting the window */
614 if (!_cursor.in_window) {
615 _cursor.in_window = true;
616 TRACKMOUSEEVENT tme;
617 tme.cbSize = sizeof(tme);
618 tme.dwFlags = TME_LEAVE;
619 tme.hwndTrack = hwnd;
620
621 TrackMouseEvent(&tme);
622 }
623
624 if (_cursor.fix_at) {
625 /* Get all queued mouse events now in case we have to warp the cursor. In the
626 * end, we only care about the current mouse position and not bygone events. */
627 MSG m;
628 while (PeekMessage(&m, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE | PM_NOYIELD | PM_QS_INPUT)) {
629 x = (int16_t)LOWORD(m.lParam);
630 y = (int16_t)HIWORD(m.lParam);
631 }
632 }
633
634 if (_cursor.UpdateCursorPosition(x, y)) {
635 POINT pt;
636 pt.x = _cursor.pos.x;
637 pt.y = _cursor.pos.y;
638 ClientToScreen(hwnd, &pt);
639 SetCursorPos(pt.x, pt.y);
640 }
641 MyShowCursor(false);
643 return 0;
644 }
645
646 case WM_INPUTLANGCHANGE:
647 _imm_props = ImmGetProperty(GetKeyboardLayout(0), IGP_PROPERTY);
648 break;
649
650 case WM_IME_SETCONTEXT:
651 /* Don't show the composition window if we draw the string ourself. */
652 if (DrawIMECompositionString()) lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
653 break;
654
655 case WM_IME_STARTCOMPOSITION:
656 SetCompositionPos(hwnd);
657 if (DrawIMECompositionString()) return 0;
658 break;
659
660 case WM_IME_COMPOSITION:
661 return HandleIMEComposition(hwnd, wParam, lParam);
662
663 case WM_IME_ENDCOMPOSITION:
664 /* Clear any pending composition string. */
665 HandleTextInput({}, true);
666 if (DrawIMECompositionString()) return 0;
667 break;
668
669 case WM_IME_NOTIFY:
670 if (wParam == IMN_OPENCANDIDATE) SetCandidatePos(hwnd);
671 break;
672
673 case WM_DEADCHAR:
674 console = GB(lParam, 16, 8) == 41;
675 return 0;
676
677 case WM_CHAR: {
678 uint scancode = GB(lParam, 16, 8);
679 uint charcode = wParam;
680
681 /* If the console key is a dead-key, we need to press it twice to get a WM_CHAR message.
682 * But we then get two WM_CHAR messages, so ignore the first one */
683 if (console && scancode == 41) {
684 console = false;
685 return 0;
686 }
687
688 /* IMEs and other input methods sometimes send a WM_CHAR without a WM_KEYDOWN,
689 * clear the keycode so a previous WM_KEYDOWN doesn't become 'stuck'. */
690 uint cur_keycode = keycode;
691 keycode = 0;
692
693 return HandleCharMsg(cur_keycode, charcode);
694 }
695
696 case WM_KEYDOWN: {
697 /* No matter the keyboard layout, we will map the '~' to the console. */
698 uint scancode = GB(lParam, 16, 8);
699 keycode = scancode == 41 ? (uint)WKC_BACKQUOTE : MapWindowsKey(wParam);
700
701 uint charcode = MapVirtualKey(wParam, MAPVK_VK_TO_CHAR);
702
703 /* No character translation? */
704 if (charcode == 0) {
705 HandleKeypress(keycode, 0);
706 return 0;
707 }
708
709 /* If an edit box is in focus, wait for the corresponding WM_CHAR message. */
710 if (!EditBoxInGlobalFocus()) {
711 /* Is the console key a dead key? If yes, ignore the first key down event. */
712 if (HasBit(charcode, 31) && !console) {
713 if (scancode == 41) {
714 console = true;
715 return 0;
716 }
717 }
718 console = false;
719
720 /* IMEs and other input methods sometimes send a WM_CHAR without a WM_KEYDOWN,
721 * clear the keycode so a previous WM_KEYDOWN doesn't become 'stuck'. */
722 uint cur_keycode = keycode;
723 keycode = 0;
724
725 return HandleCharMsg(cur_keycode, LOWORD(charcode));
726 }
727
728 return 0;
729 }
730
731 case WM_SYSKEYDOWN: // user presses F10 or Alt, both activating the title-menu
732 switch (wParam) {
733 case VK_RETURN:
734 case 'F': // Full Screen on ALT + ENTER/F
735 ToggleFullScreen(!video_driver->fullscreen);
736 return 0;
737
738 case VK_MENU: // Just ALT
739 return 0; // do nothing
740
741 case VK_F10: // F10, ignore activation of menu
742 HandleKeypress(MapWindowsKey(wParam), 0);
743 return 0;
744
745 default: // ALT in combination with something else
746 HandleKeypress(MapWindowsKey(wParam), 0);
747 break;
748 }
749 break;
750
751 case WM_SIZE:
752 if (wParam != SIZE_MINIMIZED) {
753 /* Set maximized flag when we maximize (obviously), but also when we
754 * switched to fullscreen from a maximized state */
755 _window_maximize = (wParam == SIZE_MAXIMIZED || (_window_maximize && _fullscreen));
756 if (_window_maximize || _fullscreen) _bck_resolution = _cur_resolution;
757 video_driver->ClientSizeChanged(LOWORD(lParam), HIWORD(lParam));
758 }
759 return 0;
760
761 case WM_SIZING: {
762 RECT *r = (RECT*)lParam;
763 RECT r2;
764 int w, h;
765
766 SetRect(&r2, 0, 0, 0, 0);
767 AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
768
769 w = r->right - r->left - (r2.right - r2.left);
770 h = r->bottom - r->top - (r2.bottom - r2.top);
771 w = std::max(w, 64);
772 h = std::max(h, 64);
773 SetRect(&r2, 0, 0, w, h);
774
775 AdjustWindowRect(&r2, GetWindowLong(hwnd, GWL_STYLE), FALSE);
776 w = r2.right - r2.left;
777 h = r2.bottom - r2.top;
778
779 switch (wParam) {
780 case WMSZ_BOTTOM:
781 r->bottom = r->top + h;
782 break;
783
784 case WMSZ_BOTTOMLEFT:
785 r->bottom = r->top + h;
786 r->left = r->right - w;
787 break;
788
789 case WMSZ_BOTTOMRIGHT:
790 r->bottom = r->top + h;
791 r->right = r->left + w;
792 break;
793
794 case WMSZ_LEFT:
795 r->left = r->right - w;
796 break;
797
798 case WMSZ_RIGHT:
799 r->right = r->left + w;
800 break;
801
802 case WMSZ_TOP:
803 r->top = r->bottom - h;
804 break;
805
806 case WMSZ_TOPLEFT:
807 r->top = r->bottom - h;
808 r->left = r->right - w;
809 break;
810
811 case WMSZ_TOPRIGHT:
812 r->top = r->bottom - h;
813 r->right = r->left + w;
814 break;
815 }
816 return TRUE;
817 }
818
819 case WM_DPICHANGED: {
820 auto did_adjust = AdjustGUIZoom(true);
821
822 /* Resize the window to match the new DPI setting. */
823 RECT *prcNewWindow = (RECT *)lParam;
824 SetWindowPos(hwnd,
825 nullptr,
826 prcNewWindow->left,
827 prcNewWindow->top,
828 prcNewWindow->right - prcNewWindow->left,
829 prcNewWindow->bottom - prcNewWindow->top,
830 SWP_NOZORDER | SWP_NOACTIVATE);
831
832 if (did_adjust) ReInitAllWindows(true);
833
834 return 0;
835 }
836
837/* needed for wheel */
838#if !defined(WM_MOUSEWHEEL)
839# define WM_MOUSEWHEEL 0x020A
840#endif /* WM_MOUSEWHEEL */
841#if !defined(WM_MOUSEHWHEEL)
842# define WM_MOUSEHWHEEL 0x020E
843#endif /* WM_MOUSEHWHEEL */
844#if !defined(GET_WHEEL_DELTA_WPARAM)
845# define GET_WHEEL_DELTA_WPARAM(wparam) ((short)HIWORD(wparam))
846#endif /* GET_WHEEL_DELTA_WPARAM */
847
848 case WM_MOUSEWHEEL: {
849 int delta = GET_WHEEL_DELTA_WPARAM(wParam);
850
851 if (delta < 0) {
852 _cursor.wheel++;
853 } else if (delta > 0) {
854 _cursor.wheel--;
855 }
856
857 _cursor.v_wheel -= static_cast<float>(delta) * SCROLL_BUILTIN_MULTIPLIER * _settings_client.gui.scrollwheel_multiplier;
858 _cursor.wheel_moved = true;
860 return 0;
861 }
862
863 case WM_MOUSEHWHEEL: {
864 int delta = GET_WHEEL_DELTA_WPARAM(wParam);
865
866 _cursor.h_wheel += static_cast<float>(delta) * SCROLL_BUILTIN_MULTIPLIER * _settings_client.gui.scrollwheel_multiplier;
867 _cursor.wheel_moved = true;
869 return 0;
870 }
871
872 case WM_SETFOCUS:
873 video_driver->has_focus = true;
874 SetCompositionPos(hwnd);
875 break;
876
877 case WM_KILLFOCUS:
878 video_driver->has_focus = false;
879 break;
880
881 case WM_ACTIVATE: {
882 /* Don't do anything if we are closing openttd */
883 if (_exit_game) break;
884
885 bool active = (LOWORD(wParam) != WA_INACTIVE);
886 bool minimized = (HIWORD(wParam) != 0);
887 if (video_driver->fullscreen) {
888 if (active && minimized) {
889 /* Restore the game window */
890 Dimension d = _bck_resolution; // Save current non-fullscreen window size as it will be overwritten by ShowWindow.
891 ShowWindow(hwnd, SW_RESTORE);
892 _bck_resolution = d;
893 video_driver->MakeWindow(true);
894 } else if (!active && !minimized) {
895 /* Minimise the window and restore desktop */
896 ShowWindow(hwnd, SW_MINIMIZE);
897 ChangeDisplaySettings(nullptr, 0);
898 }
899 }
900 break;
901 }
902 }
903
904 return DefWindowProc(hwnd, msg, wParam, lParam);
905}
906
907static void RegisterWndClass()
908{
909 static bool registered = false;
910
911 if (registered) return;
912
913 HINSTANCE hinst = GetModuleHandle(nullptr);
914 WNDCLASS wnd = {
915 CS_OWNDC,
916 WndProcGdi,
917 0,
918 0,
919 hinst,
920 LoadIcon(hinst, MAKEINTRESOURCE(100)),
921 LoadCursor(nullptr, IDC_ARROW),
922 0,
923 0,
924 L"OTTD"
925 };
926
927 registered = true;
928 if (!RegisterClass(&wnd)) UserError("RegisterClass failed");
929}
930
931static const Dimension default_resolutions[] = {
932 { 640, 480 },
933 { 800, 600 },
934 { 1024, 768 },
935 { 1152, 864 },
936 { 1280, 800 },
937 { 1280, 960 },
938 { 1280, 1024 },
939 { 1400, 1050 },
940 { 1600, 1200 },
941 { 1680, 1050 },
942 { 1920, 1200 }
943};
944
945static void FindResolutions(uint8_t bpp)
946{
947 _resolutions.clear();
948
949 DEVMODE dm;
950 for (uint i = 0; EnumDisplaySettings(nullptr, i, &dm) != 0; i++) {
951 if (dm.dmBitsPerPel != bpp || dm.dmPelsWidth < 640 || dm.dmPelsHeight < 480) continue;
952 if (std::ranges::find(_resolutions, Dimension(dm.dmPelsWidth, dm.dmPelsHeight)) != _resolutions.end()) continue;
953 _resolutions.emplace_back(dm.dmPelsWidth, dm.dmPelsHeight);
954 }
955
956 /* We have found no resolutions, show the default list */
957 if (_resolutions.empty()) {
958 _resolutions.assign(std::begin(default_resolutions), std::end(default_resolutions));
959 }
960
961 SortResolutions();
962}
963
964std::optional<std::string_view> VideoDriver_Win32Base::Initialize()
965{
966 /* Initialize COM */
967 if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) return "COM initialization failed";
968
969 this->UpdateAutoResolution();
970
971 RegisterWndClass();
973
974 /* fullscreen uses those */
975 this->width = this->width_org = _cur_resolution.width;
976 this->height = this->height_org = _cur_resolution.height;
977
978 Debug(driver, 2, "Resolution for display: {}x{}", _cur_resolution.width, _cur_resolution.height);
979 return std::nullopt;
980}
981
983{
984 DestroyWindow(this->main_wnd);
985
986 if (this->fullscreen) ChangeDisplaySettings(nullptr, 0);
987 MyShowCursor(true);
988}
989void VideoDriver_Win32Base::MakeDirty(int left, int top, int width, int height)
990{
991 Rect r = {left, top, left + width, top + height};
992 this->dirty_rect = BoundingRect(this->dirty_rect, r);
993}
994
996{
997 if (!CopyPalette(_local_palette)) return;
998 this->MakeDirty(0, 0, _screen.width, _screen.height);
999}
1000
1002{
1003 bool old_ctrl_pressed = _ctrl_pressed;
1004
1005 _ctrl_pressed = this->has_focus && GetAsyncKeyState(VK_CONTROL) < 0;
1006 _shift_pressed = this->has_focus && GetAsyncKeyState(VK_SHIFT) < 0;
1007
1008 /* Speedup when pressing tab, except when using ALT+TAB
1009 * to switch to another application. */
1010 this->fast_forward_key_pressed = this->has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0;
1011
1012 /* Determine which directional keys are down. */
1013 if (this->has_focus) {
1014 _dirkeys.Set(DirectionKey::Left, GetAsyncKeyState(VK_LEFT));
1015 _dirkeys.Set(DirectionKey::Up, GetAsyncKeyState(VK_UP));
1016 _dirkeys.Set(DirectionKey::Right, GetAsyncKeyState(VK_RIGHT));
1017 _dirkeys.Set(DirectionKey::Down, GetAsyncKeyState(VK_DOWN));
1018 } else {
1019 _dirkeys.Reset();
1020 }
1021
1022 if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
1023}
1024
1026{
1027 MSG mesg;
1028
1029 if (!PeekMessage(&mesg, nullptr, 0, 0, PM_REMOVE)) return false;
1030
1031 /* Convert key messages to char messages if we want text input. */
1032 if (EditBoxInGlobalFocus()) TranslateMessage(&mesg);
1033 DispatchMessage(&mesg);
1034
1035 return true;
1036}
1037
1039{
1040 this->StartGameThread();
1041
1042 for (;;) {
1043 if (_exit_game) break;
1044
1045 this->Tick();
1046 this->SleepTillNextTick();
1047 }
1048
1049 this->StopGameThread();
1050}
1051
1058void VideoDriver_Win32Base::ClientSizeChanged(int w, int h, bool force)
1059{
1060 /* Allocate backing store of the new size. */
1061 if (this->AllocateBackingStore(w, h, force)) {
1063
1065
1067 }
1068}
1069
1071{
1072 if (_window_maximize) ShowWindow(this->main_wnd, SW_SHOWNORMAL);
1073
1074 this->width = this->width_org = w;
1075 this->height = this->height_org = h;
1076
1077 return this->MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching
1078}
1079
1081{
1082 bool res = this->MakeWindow(full_screen);
1083
1084 InvalidateWindowClassesData(WindowClass::GameOptions, 3);
1085 return res;
1086}
1087
1094
1095static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC, LPRECT, LPARAM data)
1096{
1097 auto &list = *reinterpret_cast<std::vector<int>*>(data);
1098
1099 MONITORINFOEX monitorInfo = {};
1100 monitorInfo.cbSize = sizeof(MONITORINFOEX);
1101 GetMonitorInfo(hMonitor, &monitorInfo);
1102
1103 DEVMODE devMode = {};
1104 devMode.dmSize = sizeof(DEVMODE);
1105 devMode.dmDriverExtra = 0;
1106 EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
1107
1108 if (devMode.dmDisplayFrequency != 0) list.push_back(devMode.dmDisplayFrequency);
1109 return true;
1110}
1111
1113{
1114 std::vector<int> rates = {};
1115 EnumDisplayMonitors(nullptr, nullptr, MonitorEnumProc, reinterpret_cast<LPARAM>(&rates));
1116 return rates;
1117}
1118
1120{
1121 return { static_cast<uint>(GetSystemMetrics(SM_CXSCREEN)), static_cast<uint>(GetSystemMetrics(SM_CYSCREEN)) };
1122}
1123
1125{
1126 if (this->buffer_locked) return false;
1127 this->buffer_locked = true;
1128
1129 _screen.dst_ptr = this->GetVideoPointer();
1130 assert(_screen.dst_ptr != nullptr);
1131
1132 return true;
1133}
1134
1136{
1137 assert(_screen.dst_ptr != nullptr);
1138 if (_screen.dst_ptr != nullptr) {
1139 /* Hand video buffer back to the drawing backend. */
1140 this->ReleaseVideoPointer();
1141 _screen.dst_ptr = nullptr;
1142 }
1143
1144 this->buffer_locked = false;
1145}
1146
1147
1148static FVideoDriver_Win32GDI iFVideoDriver_Win32GDI;
1149
1150std::optional<std::string_view> VideoDriver_Win32GDI::Start(const StringList &param)
1151{
1152 if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return "Only real blitters supported";
1153
1154 auto err = this->Initialize();
1155 if (err) return err;
1156
1157 this->MakePalette();
1159 this->MakeWindow(_fullscreen);
1160
1162
1163 this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread");
1164
1165 return std::nullopt;
1166}
1167
1169{
1170 DeleteObject(this->gdi_palette);
1171 DeleteObject(this->dib_sect);
1172
1174}
1175
1177{
1179
1180 w = std::max(w, 64);
1181 h = std::max(h, 64);
1182
1183 if (!force && w == _screen.width && h == _screen.height) return false;
1184
1185 BITMAPINFO *bi = (BITMAPINFO *)new char[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256]();
1186 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1187
1188 bi->bmiHeader.biWidth = this->width = w;
1189 bi->bmiHeader.biHeight = -(this->height = h);
1190
1191 bi->bmiHeader.biPlanes = 1;
1192 bi->bmiHeader.biBitCount = bpp;
1193 bi->bmiHeader.biCompression = BI_RGB;
1194
1195 if (this->dib_sect) DeleteObject(this->dib_sect);
1196
1197 HDC dc = GetDC(0);
1198 this->dib_sect = CreateDIBSection(dc, bi, DIB_RGB_COLORS, (VOID **)&this->buffer_bits, nullptr, 0);
1199 if (this->dib_sect == nullptr) {
1200 delete[] bi;
1201 UserError("CreateDIBSection failed");
1202 }
1203 ReleaseDC(0, dc);
1204
1205 _screen.width = w;
1206 _screen.pitch = (bpp == 8) ? Align(w, 4) : w;
1207 _screen.height = h;
1208 _screen.dst_ptr = this->GetVideoPointer();
1209
1210 delete[] bi;
1211 return true;
1212}
1213
1215{
1216 assert(BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 0);
1217 return this->AllocateBackingStore(_screen.width, _screen.height, true) && this->MakeWindow(_fullscreen, false);
1218}
1219
1220void VideoDriver_Win32GDI::MakePalette()
1221{
1223
1224 LOGPALETTE *pal = (LOGPALETTE *)new char[sizeof(LOGPALETTE) + (256 - 1) * sizeof(PALETTEENTRY)]();
1225
1226 pal->palVersion = 0x300;
1227 pal->palNumEntries = 256;
1228
1229 for (uint i = 0; i != 256; i++) {
1230 pal->palPalEntry[i].peRed = _local_palette.palette[i].r;
1231 pal->palPalEntry[i].peGreen = _local_palette.palette[i].g;
1232 pal->palPalEntry[i].peBlue = _local_palette.palette[i].b;
1233 pal->palPalEntry[i].peFlags = 0;
1234
1235 }
1236 this->gdi_palette = CreatePalette(pal);
1237 delete[] pal;
1238 if (this->gdi_palette == nullptr) UserError("CreatePalette failed!\n");
1239}
1240
1241void VideoDriver_Win32GDI::UpdatePalette(HDC dc, uint start, uint count)
1242{
1243 RGBQUAD rgb[256];
1244
1245 for (uint i = 0; i != count; i++) {
1246 rgb[i].rgbRed = _local_palette.palette[start + i].r;
1247 rgb[i].rgbGreen = _local_palette.palette[start + i].g;
1248 rgb[i].rgbBlue = _local_palette.palette[start + i].b;
1249 rgb[i].rgbReserved = 0;
1250 }
1251
1252 SetDIBColorTable(dc, start, count, rgb);
1253}
1254
1256{
1257 HDC hDC = GetWindowDC(hWnd);
1258 HPALETTE hOldPalette = SelectPalette(hDC, this->gdi_palette, FALSE);
1259 UINT nChanged = RealizePalette(hDC);
1260
1261 SelectPalette(hDC, hOldPalette, TRUE);
1262 ReleaseDC(hWnd, hDC);
1263 if (nChanged != 0) this->MakeDirty(0, 0, _screen.width, _screen.height);
1264}
1265
1267{
1269
1270 if (IsEmptyRect(this->dirty_rect)) return;
1271
1272 HDC dc = GetDC(this->main_wnd);
1273 HDC dc2 = CreateCompatibleDC(dc);
1274
1275 HBITMAP old_bmp = (HBITMAP)SelectObject(dc2, this->dib_sect);
1276 HPALETTE old_palette = SelectPalette(dc, this->gdi_palette, FALSE);
1277
1278 if (_local_palette.count_dirty != 0) {
1280
1281 switch (blitter->UsePaletteAnimation()) {
1283 this->UpdatePalette(dc2, _local_palette.first_dirty, _local_palette.count_dirty);
1284 break;
1285
1288 break;
1289 }
1290
1292 break;
1293
1294 default:
1295 NOT_REACHED();
1296 }
1297 _local_palette.count_dirty = 0;
1298 }
1299
1300 BitBlt(dc, 0, 0, this->width, this->height, dc2, 0, 0, SRCCOPY);
1301 SelectPalette(dc, old_palette, TRUE);
1302 SelectObject(dc2, old_bmp);
1303 DeleteDC(dc2);
1304
1305 ReleaseDC(this->main_wnd, dc);
1306
1307 this->dirty_rect = {};
1308}
1309
1310#ifdef _DEBUG
1311/* Keep this function here..
1312 * It allows you to redraw the screen from within the MSVC debugger */
1313/* static */ int VideoDriver_Win32GDI::RedrawScreenDebug()
1314{
1315 static int _fooctr;
1316
1318
1319 _screen.dst_ptr = drv->GetVideoPointer();
1320 UpdateWindows();
1321
1322 drv->Paint();
1323 GdiFlush();
1324
1325 return _fooctr++;
1326}
1327#endif
1328
1329#ifdef WITH_OPENGL
1330
1331#ifndef PFD_SUPPORT_COMPOSITION
1332# define PFD_SUPPORT_COMPOSITION 0x00008000
1333#endif
1334
1335static PFNWGLCREATECONTEXTATTRIBSARBPROC _wglCreateContextAttribsARB = nullptr;
1336static PFNWGLSWAPINTERVALEXTPROC _wglSwapIntervalEXT = nullptr;
1337static bool _hasWGLARBCreateContextProfile = false;
1338
1344static OGLProc GetOGLProcAddressCallback(const char *proc)
1345{
1346 OGLProc ret = reinterpret_cast<OGLProc>(wglGetProcAddress(proc));
1347 if (ret == nullptr) {
1348 /* Non-extension GL function? Try normal loading. */
1349 ret = reinterpret_cast<OGLProc>(GetProcAddress(GetModuleHandle(L"opengl32"), proc));
1350 }
1351 return ret;
1352}
1353
1359static std::optional<std::string_view> SelectPixelFormat(HDC dc)
1360{
1361 PIXELFORMATDESCRIPTOR pfd = {
1362 sizeof(PIXELFORMATDESCRIPTOR), // Size of this struct.
1363 1, // Version of this struct.
1364 PFD_DRAW_TO_WINDOW | // Require window support.
1365 PFD_SUPPORT_OPENGL | // Require OpenGL support.
1366 PFD_DOUBLEBUFFER | // Use double buffering.
1367 PFD_DEPTH_DONTCARE,
1368 PFD_TYPE_RGBA, // Request RGBA format.
1369 24, // 24 bpp (excluding alpha).
1370 0, 0, 0, 0, 0, 0, 0, 0, // Colour bits and shift ignored.
1371 0, 0, 0, 0, 0, // No accumulation buffer.
1372 0, 0, // No depth/stencil buffer.
1373 0, // No aux buffers.
1374 PFD_MAIN_PLANE, // Main layer.
1375 0, 0, 0, 0 // Ignored/reserved.
1376 };
1377
1378 pfd.dwFlags |= PFD_SUPPORT_COMPOSITION; // Make OpenTTD compatible with Aero.
1379
1380 /* Choose a suitable pixel format. */
1381 int format = ChoosePixelFormat(dc, &pfd);
1382 if (format == 0) return "No suitable pixel format found";
1383 if (!SetPixelFormat(dc, format, &pfd)) return "Can't set pixel format";
1384
1385 return std::nullopt;
1386}
1387
1389static void LoadWGLExtensions()
1390{
1391 /* Querying the supported WGL extensions and loading the matching
1392 * functions requires a valid context, even for the extensions
1393 * regarding context creation. To get around this, we create
1394 * a dummy window with a dummy context. The extension functions
1395 * remain valid even after this context is destroyed. */
1396 HWND wnd = CreateWindow(L"STATIC", L"dummy", WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
1397 HDC dc = GetDC(wnd);
1398
1399 /* Set pixel format of the window. */
1400 if (SelectPixelFormat(dc) == std::nullopt) {
1401 /* Create rendering context. */
1402 HGLRC rc = wglCreateContext(dc);
1403 if (rc != nullptr) {
1404 wglMakeCurrent(dc, rc);
1405
1406#ifdef __MINGW32__
1407 /* GCC doesn't understand the expected usage of wglGetProcAddress(). */
1408#pragma GCC diagnostic push
1409#pragma GCC diagnostic ignored "-Wcast-function-type"
1410#endif /* __MINGW32__ */
1411
1412 /* Get list of WGL extensions. */
1413 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
1414 if (wglGetExtensionsStringARB != nullptr) {
1415 std::string_view wgl_exts = wglGetExtensionsStringARB(dc);
1416 /* Bind supported functions. */
1417 if (HasStringInExtensionList(wgl_exts, "WGL_ARB_create_context")) {
1418 _wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
1419 }
1420 _hasWGLARBCreateContextProfile = HasStringInExtensionList(wgl_exts, "WGL_ARB_create_context_profile");
1421 if (HasStringInExtensionList(wgl_exts, "WGL_EXT_swap_control")) {
1422 _wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
1423 }
1424 }
1425
1426#ifdef __MINGW32__
1427#pragma GCC diagnostic pop
1428#endif
1429 wglMakeCurrent(nullptr, nullptr);
1430 wglDeleteContext(rc);
1431 }
1432 }
1433
1434 ReleaseDC(wnd, dc);
1435 DestroyWindow(wnd);
1436}
1437
1438static FVideoDriver_Win32OpenGL iFVideoDriver_Win32OpenGL;
1439
1440std::optional<std::string_view> VideoDriver_Win32OpenGL::Start(const StringList &param)
1441{
1442 if (BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 0) return "Only real blitters supported";
1443
1444 Dimension old_res = _cur_resolution; // Save current screen resolution in case of errors, as MakeWindow invalidates it.
1445
1446 LoadWGLExtensions();
1447
1448 auto err = this->Initialize();
1449 if (err) {
1450 this->Stop();
1451 _cur_resolution = old_res;
1452 return err;
1453 }
1454 this->MakeWindow(_fullscreen);
1455
1456 /* Create and initialize OpenGL context. */
1457 err = this->AllocateContext();
1458 if (err) {
1459 this->Stop();
1460 _cur_resolution = old_res;
1461 return err;
1462 }
1463
1464 this->driver_info = GetName();
1465 this->driver_info += " (";
1466 this->driver_info += OpenGLBackend::Get()->GetDriverName();
1467 this->driver_info += ")";
1468
1469 this->ClientSizeChanged(this->width, this->height, true);
1470 /* We should have a valid screen buffer now. If not, something went wrong and we should abort. */
1471 if (_screen.dst_ptr == nullptr) {
1472 this->Stop();
1473 _cur_resolution = old_res;
1474 return "Can't get pointer to screen buffer";
1475 }
1476 /* Main loop expects to start with the buffer unmapped. */
1477 this->ReleaseVideoPointer();
1478
1480
1481 this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread");
1482
1483 return std::nullopt;
1484}
1485
1486void VideoDriver_Win32OpenGL::Stop()
1487{
1488 this->DestroyContext();
1490}
1491
1492void VideoDriver_Win32OpenGL::DestroyContext()
1493{
1495
1496 wglMakeCurrent(nullptr, nullptr);
1497 if (this->gl_rc != nullptr) {
1498 wglDeleteContext(this->gl_rc);
1499 this->gl_rc = nullptr;
1500 }
1501 if (this->dc != nullptr) {
1502 ReleaseDC(this->main_wnd, this->dc);
1503 this->dc = nullptr;
1504 }
1505}
1506
1507void VideoDriver_Win32OpenGL::ToggleVsync(bool vsync)
1508{
1509 if (_wglSwapIntervalEXT != nullptr) {
1510 _wglSwapIntervalEXT(vsync);
1511 } else if (vsync) {
1512 Debug(driver, 0, "OpenGL: Vsync requested, but not supported by driver");
1513 }
1514}
1515
1516std::optional<std::string_view> VideoDriver_Win32OpenGL::AllocateContext()
1517{
1518 this->dc = GetDC(this->main_wnd);
1519
1520 auto err = SelectPixelFormat(this->dc);
1521 if (err) return err;
1522
1523 HGLRC rc = nullptr;
1524
1525 /* Create OpenGL device context. Try to get an 3.2+ context if possible. */
1526 if (_wglCreateContextAttribsARB != nullptr) {
1527 /* Try for OpenGL 4.5 first. */
1528 int attribs[] = {
1529 WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
1530 WGL_CONTEXT_MINOR_VERSION_ARB, 5,
1531 WGL_CONTEXT_FLAGS_ARB, _debug_driver_level >= 8 ? WGL_CONTEXT_DEBUG_BIT_ARB : 0,
1532 _hasWGLARBCreateContextProfile ? WGL_CONTEXT_PROFILE_MASK_ARB : 0, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, // Terminate list if WGL_ARB_create_context_profile isn't supported.
1533 0
1534 };
1535 rc = _wglCreateContextAttribsARB(this->dc, nullptr, attribs);
1536
1537 if (rc == nullptr) {
1538 /* Try again for a 3.2 context. */
1539 attribs[1] = 3;
1540 attribs[3] = 2;
1541 rc = _wglCreateContextAttribsARB(this->dc, nullptr, attribs);
1542 }
1543 }
1544
1545 if (rc == nullptr) {
1546 /* Old OpenGL or old driver, let's hope for the best. */
1547 rc = wglCreateContext(this->dc);
1548 if (rc == nullptr) return "Can't create OpenGL context";
1549 }
1550 if (!wglMakeCurrent(this->dc, rc)) return "Can't activate GL context";
1551
1552 this->ToggleVsync(_video_vsync);
1553
1554 this->gl_rc = rc;
1555 return OpenGLBackend::Create(&GetOGLProcAddressCallback, this->GetScreenSize());
1556}
1557
1558bool VideoDriver_Win32OpenGL::ToggleFullscreen(bool full_screen)
1559{
1560 if (_screen.dst_ptr != nullptr) this->ReleaseVideoPointer();
1561 this->DestroyContext();
1562 bool res = this->VideoDriver_Win32Base::ToggleFullscreen(full_screen);
1563 res &= this->AllocateContext() == std::nullopt;
1564 this->ClientSizeChanged(this->width, this->height, true);
1565 return res;
1566}
1567
1568bool VideoDriver_Win32OpenGL::AfterBlitterChange()
1569{
1570 assert(BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 0);
1571 this->ClientSizeChanged(this->width, this->height, true);
1572 return true;
1573}
1574
1575void VideoDriver_Win32OpenGL::PopulateSystemSprites()
1576{
1577 OpenGLBackend::Get()->PopulateCursorCache();
1578}
1579
1580void VideoDriver_Win32OpenGL::ClearSystemSprites()
1581{
1583}
1584
1585bool VideoDriver_Win32OpenGL::AllocateBackingStore(int w, int h, bool force)
1586{
1587 if (!force && w == _screen.width && h == _screen.height) return false;
1588
1589 this->width = w = std::max(w, 64);
1590 this->height = h = std::max(h, 64);
1591
1592 if (this->gl_rc == nullptr) return false;
1593
1594 if (_screen.dst_ptr != nullptr) this->ReleaseVideoPointer();
1595
1596 this->dirty_rect = {};
1597 bool res = OpenGLBackend::Get()->Resize(w, h, force);
1598 SwapBuffers(this->dc);
1599 _screen.dst_ptr = this->GetVideoPointer();
1600
1601 return res;
1602}
1603
1604void *VideoDriver_Win32OpenGL::GetVideoPointer()
1605{
1606 if (BlitterFactory::GetCurrentBlitter()->NeedsAnimationBuffer()) {
1607 this->anim_buffer = OpenGLBackend::Get()->GetAnimBuffer();
1608 }
1610}
1611
1612void VideoDriver_Win32OpenGL::ReleaseVideoPointer()
1613{
1614 if (this->anim_buffer != nullptr) OpenGLBackend::Get()->ReleaseAnimBuffer(this->dirty_rect);
1615 OpenGLBackend::Get()->ReleaseVideoBuffer(this->dirty_rect);
1616 this->dirty_rect = {};
1617 _screen.dst_ptr = nullptr;
1618 this->anim_buffer = nullptr;
1619}
1620
1621void VideoDriver_Win32OpenGL::Paint()
1622{
1624
1625 if (_local_palette.count_dirty != 0) {
1627
1628 /* Always push a changed palette to OpenGL. */
1629 OpenGLBackend::Get()->UpdatePalette(_local_palette.palette, _local_palette.first_dirty, _local_palette.count_dirty);
1632 }
1633
1634 _local_palette.count_dirty = 0;
1635 }
1636
1639
1640 SwapBuffers(this->dc);
1641}
1642
1643#endif /* WITH_OPENGL */
#define AS(ap_name, size_x, size_y, min_year, max_year, catchment, noise, maint_cost, ttdpatch_type, class_id, name, preview)
AirportSpec definition for airports with at least one depot.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
Definition factory.hpp:139
How all blitters should look like.
Definition base.hpp:29
virtual uint8_t GetScreenDepth()=0
Get the screen depth this blitter works for.
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
virtual void PaletteAnimate(const Palette &palette)=0
Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to...
@ None
No palette animation.
Definition base.hpp:51
@ Blitter
The blitter takes care of the palette animation.
Definition base.hpp:53
@ VideoBackend
Palette animation should be done by video backend (8bpp only!).
Definition base.hpp:52
virtual void PostResize()
Post resize event.
Definition base.hpp:211
The factory for Windows' video driver.
Definition win32_v.h:124
void Paint()
Render video buffer to the screen.
Definition opengl.cpp:1065
uint8_t * GetAnimBuffer()
Get a pointer to the memory for the separate animation buffer.
Definition opengl.cpp:1196
void * GetVideoBuffer()
Get a pointer to the memory for the video driver to draw to.
Definition opengl.cpp:1174
bool Resize(int w, int h, bool force=false)
Change the size of the drawing window and allocate matching resources.
Definition opengl.cpp:939
static std::optional< std::string_view > Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res)
Create and initialize the singleton back-end class.
Definition opengl.cpp:490
void UpdatePalette(const Colour *pal, uint first, uint length)
Update the stored palette.
Definition opengl.cpp:1051
void ReleaseAnimBuffer(const Rect &update_rect)
Update animation buffer texture after the animation buffer was filled.
Definition opengl.cpp:1257
void ClearCursorCache()
Queue a request for cursor cache clear.
Definition opengl.cpp:1161
static OpenGLBackend * Get()
Get singleton instance of this class.
Definition opengl.h:86
void DrawMouseCursor()
Draw mouse cursor on screen.
Definition opengl.cpp:1097
void ReleaseVideoBuffer(const Rect &update_rect)
Update video buffer texture after the video buffer was filled.
Definition opengl.cpp:1219
static void Destroy()
Free resources and destroy singleton back-end class.
Definition opengl.cpp:503
RAII class for measuring simple elements of performance.
Constant span of UTF-8 encoded data.
Definition utf8.hpp:28
Base class for Windows video drivers.
Definition win32_v.h:19
int height
Height in pixels of our display surface.
Definition win32_v.h:45
bool has_focus
Does our window have system focus?
Definition win32_v.h:42
void EditBoxLostFocus() override
An edit box lost the input focus.
Definition win32_v.cpp:1088
void CheckPaletteAnim() override
Process any pending palette animation.
Definition win32_v.cpp:995
void Stop() override
Stop this driver.
Definition win32_v.cpp:982
int height_org
Original monitor resolution height, before we changed it.
Definition win32_v.h:47
HWND main_wnd
Handle to system window.
Definition win32_v.h:40
bool fullscreen
Whether to use (true) fullscreen mode.
Definition win32_v.h:41
int width_org
Original monitor resolution width, before we changed it.
Definition win32_v.h:46
bool MakeWindow(bool full_screen, bool resize=true)
Instantiate a new window.
Definition win32_v.cpp:152
bool buffer_locked
Video buffer was locked by the main thread.
Definition win32_v.h:49
virtual void * GetVideoPointer()=0
Get a pointer to the video buffer.
void MakeDirty(int left, int top, int width, int height) override
Mark a particular area dirty.
Definition win32_v.cpp:989
bool PollEvent() override
Process a single system event.
Definition win32_v.cpp:1025
virtual void PaletteChanged(HWND hWnd)=0
Palette of the window has changed.
bool LockVideoBuffer() override
Make sure the video buffer is ready for drawing.
Definition win32_v.cpp:1124
std::vector< int > GetListOfMonitorRefreshRates() override
Get a list of refresh rates of each available monitor.
Definition win32_v.cpp:1112
virtual bool AllocateBackingStore(int w, int h, bool force=false)=0
(Re-)create the backing store.
int width
Width in pixels of our display surface.
Definition win32_v.h:44
void InputLoop() override
Handle input logic, is CTRL pressed, should we fast-forward, etc.
Definition win32_v.cpp:1001
virtual uint8_t GetFullscreenBpp()
Colour depth to use for fullscreen display modes.
Definition win32_v.cpp:140
Dimension GetScreenSize() const override
Get the resolution of the main screen.
Definition win32_v.cpp:1119
virtual void ReleaseVideoPointer()
Hand video buffer back to the painting backend.
Definition win32_v.h:80
void UnlockVideoBuffer() override
Unlock a previously locked video buffer.
Definition win32_v.cpp:1135
void ClientSizeChanged(int w, int h, bool force=false)
Indicate to the driver the client-size might have changed.
Definition win32_v.cpp:1058
void MainLoop() override
Perform the actual drawing.
Definition win32_v.cpp:1038
void ClaimMousePointer() override
Claim the exclusive rights for the mouse pointer.
Definition win32_v.cpp:64
Rect dirty_rect
Region of the screen that needs redrawing.
Definition win32_v.h:43
bool ToggleFullscreen(bool fullscreen) override
Change the full screen setting.
Definition win32_v.cpp:1080
bool ChangeResolution(int w, int h) override
Change the resolution of the window.
Definition win32_v.cpp:1070
The GDI video driver for windows.
Definition win32_v.h:92
void * buffer_bits
Internal rendering buffer.
Definition win32_v.h:107
HBITMAP dib_sect
System bitmap object referencing our rendering buffer.
Definition win32_v.h:105
void PaletteChanged(HWND hWnd) override
Palette of the window has changed.
Definition win32_v.cpp:1255
std::optional< std::string_view > Start(const StringList &param) override
Start this driver.
Definition win32_v.cpp:1150
void * GetVideoPointer() override
Get a pointer to the video buffer.
Definition win32_v.h:110
HPALETTE gdi_palette
Palette object for 8bpp blitter.
Definition win32_v.h:106
bool AllocateBackingStore(int w, int h, bool force=false) override
(Re-)create the backing store.
Definition win32_v.cpp:1176
void Paint() override
Paint the window.
Definition win32_v.cpp:1266
bool AfterBlitterChange() override
Callback invoked after the blitter was changed.
Definition win32_v.cpp:1214
void Stop() override
Stop this driver.
Definition win32_v.cpp:1168
bool fast_forward_key_pressed
The fast-forward key is being pressed.
void Tick()
Give the video-driver a tick.
void SleepTillNextTick()
Sleep till the next tick is about to happen.
void StartGameThread()
Start the loop for game-tick.
static std::string GetCaption()
Get the caption to use for the game's title bar.
void StopGameThread()
Stop the loop for the game-tick.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
void UpdateAutoResolution()
Apply resolution auto-detection and clamp to sensible defaults.
static Palette _local_palette
Current palette to use for drawing.
Definition cocoa_ogl.mm:42
static OGLProc GetOGLProcAddressCallback(const char *proc)
Platform-specific callback to get an OpenGL function pointer.
Definition cocoa_ogl.mm:49
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
bool GetDriverParamBool(const StringList &parm, std::string_view name)
Get a boolean parameter the list of parameters.
Definition driver.cpp:67
std::vector< Dimension > _resolutions
List of resolutions.
Definition driver.cpp:28
Dimension _cur_resolution
The current resolution.
Definition driver.cpp:29
Error reporting related functions.
Factory to 'query' all available blitters.
fluid_settings_t * settings
FluidSynth settings handle.
Types for recording game performance data.
@ Video
Speed of painting drawn video buffer.
Rect BoundingRect(const Rect &r1, const Rect &r2)
Compute the bounding rectangle around two rectangles.
Geometry functions.
bool IsEmptyRect(const Rect &r)
Check if a rectangle is empty.
bool _shift_pressed
Is Shift pressed?
Definition gfx.cpp:40
bool _left_button_down
Is left mouse button pressed?
Definition gfx.cpp:42
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
bool _left_button_clicked
Is left mouse button clicked?
Definition gfx.cpp:43
bool _right_button_clicked
Is right mouse button clicked?
Definition gfx.cpp:45
Support8bpp _support8bpp
State of the support for 8bpp graphics.
Definition gfx.cpp:37
DirectionKeys _dirkeys
Pressed direction keys.
Definition gfx.cpp:35
bool _right_button_down
Is right mouse button pressed?
Definition gfx.cpp:44
bool AdjustGUIZoom(bool automatic)
Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
Definition gfx.cpp:1836
Functions related to the gfx engine.
void HandleCtrlChanged()
State of CONTROL key has changed.
Definition window.cpp:2715
void UpdateWindows()
Update the continuously changing contents of the windows, such as the viewports.
Definition window.cpp:3141
void GameSizeChanged()
Size of the application screen changed.
Definition main_gui.cpp:597
void HandleMouseEvents()
Handle a mouse event from the video driver.
Definition window.cpp:2979
void HandleKeypress(uint keycode, char32_t key)
Handle keyboard input.
Definition window.cpp:2659
void HandleTextInput(std::string_view str, bool marked=false, std::optional< size_t > caret=std::nullopt, std::optional< size_t > insert_location=std::nullopt, std::optional< size_t > replacement_end=std::nullopt)
Handle text input.
Definition window.cpp:2751
@ Hardware
Full 8bpp support by OS and hardware.
Definition gfx_type.h:430
@ Down
Down.
Definition gfx_type.h:438
@ Right
Right.
Definition gfx_type.h:437
@ Left
Left.
Definition gfx_type.h:435
@ WKC_BACKSLASH
\ Backslash
Definition gfx_type.h:101
@ WKC_MINUS
Definition gfx_type.h:106
@ WKC_COMMA
, Comma
Definition gfx_type.h:104
@ WKC_PERIOD
. Period
Definition gfx_type.h:105
@ WKC_EQUALS
= Equals
Definition gfx_type.h:99
@ WKC_SLASH
/ Forward slash
Definition gfx_type.h:97
@ WKC_SINGLEQUOTE
' Single quote
Definition gfx_type.h:103
@ WKC_R_BRACKET
] Right square bracket
Definition gfx_type.h:102
@ WKC_L_BRACKET
[ Left square bracket
Definition gfx_type.h:100
@ WKC_SEMICOLON
; Semicolon
Definition gfx_type.h:98
@ Stop
Stop button.
Definition goal_type.h:36
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1553
Functions/types related to loading libraries dynamically.
#define Point
Macro that prevents name conflicts between included headers.
Integer math functions.
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
constexpr T Align(const T x, uint n)
Return the smallest multiple of n equal or greater than x.
Definition math_func.hpp:37
bool HasStringInExtensionList(std::string_view string, std::string_view substring)
Find a substring in a string made of space delimited elements.
Definition opengl.cpp:150
OpenGL video driver support.
Some generic types.
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
Definition osk_gui.cpp:357
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
Definition palette.cpp:230
Functions related to modal progress.
Pseudo random number generator.
A number of safeguards to prevent using unsafe methods.
static void FindResolutions()
Find and store all possible resolutions into _resolutions.
Definition sdl2_v.cpp:59
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
Definition of base types and functions in a cross-platform compatible way.
char32_t Utf16DecodeSurrogate(uint lead, uint trail)
Convert an UTF-16 surrogate pair to the corresponding Unicode character.
Definition string_func.h:84
bool Utf16IsLeadSurrogate(uint c)
Is the given character a lead surrogate code point?
Definition string_func.h:63
bool Utf16IsTrailSurrogate(uint c)
Is the given character a lead surrogate code point?
Definition string_func.h:73
std::vector< std::string > StringList
Type for a list of strings.
Definition string_type.h:61
T y
Y coordinate.
T x
X coordinate.
Dimensions (a width and height) of a rectangle in 2D.
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition gfx_type.h:421
Specification of a rectangle with absolute coordinates of all edges.
Functions related to text effects.
Base of all threads.
Handling of UTF-8 encoded data.
bool _video_vsync
Whether we should use vsync (only if active video driver supports HW acceleration).
std::string_view convert_from_fs(const std::wstring_view src, std::span< char > dst_buf)
Convert to OpenTTD's encoding from that of the environment in UNICODE.
Definition win32.cpp:405
std::wstring OTTD2FS(std::string_view name)
Convert from OpenTTD's encoding to a wide string.
Definition win32.cpp:387
std::string FS2OTTD(std::wstring_view name)
Convert to OpenTTD's encoding from a wide string.
Definition win32.cpp:371
Declarations of functions for MS windows systems.
static LRESULT HandleCharMsg(uint keycode, char32_t charcode)
Forward key presses to the window system.
Definition win32_v.cpp:259
static bool DrawIMECompositionString()
Should we draw the composition string ourself, i.e is this a normal IME?
Definition win32_v.cpp:289
static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam)
Handle WM_IME_COMPOSITION messages.
Definition win32_v.cpp:363
static void SetCandidatePos(HWND hwnd)
Set the position of the candidate window.
Definition win32_v.cpp:323
static void CancelIMEComposition(HWND hwnd)
Clear the current composition string.
Definition win32_v.cpp:428
static void SetCompositionPos(HWND hwnd)
Set position of the composition window to the caret position.
Definition win32_v.cpp:298
Base of the Windows video driver.
Window * _focused_window
Window that currently has focus.
Definition window.cpp:77
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition window.cpp:3432
bool EditBoxInGlobalFocus()
Check if an edit box is in global focus.
Definition window.cpp:453
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3333
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.