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