|
@@ -35,21 +35,12 @@
|
|
|
#endif
|
|
|
|
|
|
#ifndef PM_QS_INPUT
|
|
|
#define PM_QS_INPUT 0x20000
|
|
|
#endif
|
|
|
|
|
|
static struct {
|
|
|
int width; ///< Width in pixels of our display surface.
|
|
|
int height; ///< Height in pixels of our display surface.
|
|
|
int width_org; ///< Original monitor resolution width, before we changed it.
|
|
|
int height_org; ///< Original monitor resolution height, before we changed it.
|
|
|
bool has_focus; ///< Does our window have system focus?
|
|
|
bool running; ///< Is the main loop running?
|
|
|
} _wnd;
|
|
|
|
|
|
bool _window_maximize;
|
|
|
static Dimension _bck_resolution;
|
|
|
DWORD _imm_props;
|
|
|
|
|
|
/** Local copy of the palette for use in the drawing thread. */
|
|
|
static Palette _local_palette;
|
|
@@ -159,14 +150,14 @@ bool VideoDriver_Win32Base::MakeWindow(b
|
|
|
settings.dmSize = sizeof(settings);
|
|
|
settings.dmFields =
|
|
|
DM_BITSPERPEL |
|
|
|
DM_PELSWIDTH |
|
|
|
DM_PELSHEIGHT;
|
|
|
settings.dmBitsPerPel = this->GetFullscreenBpp();
|
|
|
settings.dmPelsWidth = _wnd.width_org;
|
|
|
settings.dmPelsHeight = _wnd.height_org;
|
|
|
settings.dmPelsWidth = this->width_org;
|
|
|
settings.dmPelsHeight = this->height_org;
|
|
|
|
|
|
/* Check for 8 bpp support. */
|
|
|
if (settings.dmBitsPerPel == 8 && ChangeDisplaySettings(&settings, CDS_FULLSCREEN | CDS_TEST) != DISP_CHANGE_SUCCESSFUL) {
|
|
|
settings.dmBitsPerPel = 32;
|
|
|
}
|
|
|
|
|
@@ -186,31 +177,31 @@ bool VideoDriver_Win32Base::MakeWindow(b
|
|
|
return false; // the request failed
|
|
|
}
|
|
|
} else if (this->fullscreen) {
|
|
|
/* restore display? */
|
|
|
ChangeDisplaySettings(nullptr, 0);
|
|
|
/* restore the resolution */
|
|
|
_wnd.width = _bck_resolution.width;
|
|
|
_wnd.height = _bck_resolution.height;
|
|
|
this->width = _bck_resolution.width;
|
|
|
this->height = _bck_resolution.height;
|
|
|
}
|
|
|
|
|
|
{
|
|
|
RECT r;
|
|
|
DWORD style, showstyle;
|
|
|
int w, h;
|
|
|
|
|
|
showstyle = SW_SHOWNORMAL;
|
|
|
this->fullscreen = full_screen;
|
|
|
if (this->fullscreen) {
|
|
|
style = WS_POPUP;
|
|
|
SetRect(&r, 0, 0, _wnd.width_org, _wnd.height_org);
|
|
|
SetRect(&r, 0, 0, this->width_org, this->height_org);
|
|
|
} else {
|
|
|
style = WS_OVERLAPPEDWINDOW;
|
|
|
/* On window creation, check if we were in maximize mode before */
|
|
|
if (_window_maximize) showstyle = SW_SHOWMAXIMIZED;
|
|
|
SetRect(&r, 0, 0, _wnd.width, _wnd.height);
|
|
|
SetRect(&r, 0, 0, this->width, this->height);
|
|
|
}
|
|
|
|
|
|
AdjustWindowRect(&r, style, FALSE);
|
|
|
w = r.right - r.left;
|
|
|
h = r.bottom - r.top;
|
|
|
|
|
@@ -755,18 +746,18 @@ LRESULT CALLBACK WndProcGdi(HWND hwnd, U
|
|
|
}
|
|
|
HandleMouseEvents();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
case WM_SETFOCUS:
|
|
|
_wnd.has_focus = true;
|
|
|
video_driver->has_focus = true;
|
|
|
SetCompositionPos(hwnd);
|
|
|
break;
|
|
|
|
|
|
case WM_KILLFOCUS:
|
|
|
_wnd.has_focus = false;
|
|
|
video_driver->has_focus = false;
|
|
|
break;
|
|
|
|
|
|
case WM_ACTIVATE: {
|
|
|
/* Don't do anything if we are closing openttd */
|
|
|
if (_exit_game) break;
|
|
|
|
|
@@ -848,20 +839,18 @@ static void FindResolutions(uint8 bpp)
|
|
|
}
|
|
|
|
|
|
void VideoDriver_Win32Base::Initialize()
|
|
|
{
|
|
|
this->UpdateAutoResolution();
|
|
|
|
|
|
memset(&_wnd, 0, sizeof(_wnd));
|
|
|
|
|
|
RegisterWndClass();
|
|
|
FindResolutions(this->GetFullscreenBpp());
|
|
|
|
|
|
/* fullscreen uses those */
|
|
|
_wnd.width = _wnd.width_org = _cur_resolution.width;
|
|
|
_wnd.height = _wnd.height_org = _cur_resolution.height;
|
|
|
this->width = this->width_org = _cur_resolution.width;
|
|
|
this->height = this->height_org = _cur_resolution.height;
|
|
|
|
|
|
DEBUG(driver, 2, "Resolution for display: %ux%u", _cur_resolution.width, _cur_resolution.height);
|
|
|
}
|
|
|
|
|
|
void VideoDriver_Win32Base::Stop()
|
|
|
{
|
|
@@ -885,14 +874,14 @@ void VideoDriver_Win32Base::CheckPalette
|
|
|
}
|
|
|
|
|
|
void VideoDriver_Win32Base::InputLoop()
|
|
|
{
|
|
|
bool old_ctrl_pressed = _ctrl_pressed;
|
|
|
|
|
|
_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL) < 0;
|
|
|
_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0;
|
|
|
_ctrl_pressed = this->has_focus && GetAsyncKeyState(VK_CONTROL) < 0;
|
|
|
_shift_pressed = this->has_focus && GetAsyncKeyState(VK_SHIFT) < 0;
|
|
|
|
|
|
#if defined(_DEBUG)
|
|
|
if (_shift_pressed)
|
|
|
#else
|
|
|
/* Speedup when pressing tab, except when using ALT+TAB
|
|
|
* to switch to another application. */
|
|
@@ -902,13 +891,13 @@ void VideoDriver_Win32Base::InputLoop()
|
|
|
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
|
|
} else if (_fast_forward & 2) {
|
|
|
_fast_forward = 0;
|
|
|
}
|
|
|
|
|
|
/* Determine which directional keys are down. */
|
|
|
if (_wnd.has_focus) {
|
|
|
if (this->has_focus) {
|
|
|
_dirkeys =
|
|
|
(GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
|
|
|
(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
|
|
|
(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
|
|
|
(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
|
|
|
} else {
|
|
@@ -953,14 +942,12 @@ void VideoDriver_Win32Base::MainLoop()
|
|
|
/* Wait till the draw thread has started itself. */
|
|
|
this->draw_signal->wait(*this->draw_mutex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_wnd.running = true;
|
|
|
|
|
|
for (;;) {
|
|
|
InteractiveRandom(); // randomness
|
|
|
|
|
|
while (PeekMessage(&mesg, nullptr, 0, 0, PM_REMOVE)) {
|
|
|
/* Convert key messages to char messages if we want text input. */
|
|
|
if (EditBoxInGlobalFocus()) TranslateMessage(&mesg);
|
|
@@ -1016,14 +1003,14 @@ bool VideoDriver_Win32Base::ChangeResolu
|
|
|
{
|
|
|
std::unique_lock<std::recursive_mutex> lock;
|
|
|
if (this->draw_mutex != nullptr) lock = std::unique_lock<std::recursive_mutex>(*this->draw_mutex);
|
|
|
|
|
|
if (_window_maximize) ShowWindow(this->main_wnd, SW_SHOWNORMAL);
|
|
|
|
|
|
_wnd.width = _wnd.width_org = w;
|
|
|
_wnd.height = _wnd.height_org = h;
|
|
|
this->width = this->width_org = w;
|
|
|
this->height = this->height_org = h;
|
|
|
|
|
|
return this->MakeWindow(_fullscreen); // _wnd.fullscreen screws up ingame resolution switching
|
|
|
}
|
|
|
|
|
|
bool VideoDriver_Win32Base::ToggleFullscreen(bool full_screen)
|
|
|
{
|
|
@@ -1154,14 +1141,14 @@ bool VideoDriver_Win32GDI::AllocateBacki
|
|
|
if (!force && w == _screen.width && h == _screen.height) return false;
|
|
|
|
|
|
BITMAPINFO *bi = (BITMAPINFO *)alloca(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
|
|
|
memset(bi, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
|
|
|
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
|
|
bi->bmiHeader.biWidth = _wnd.width = w;
|
|
|
bi->bmiHeader.biHeight = -(_wnd.height = h);
|
|
|
bi->bmiHeader.biWidth = this->width = w;
|
|
|
bi->bmiHeader.biHeight = -(this->height = h);
|
|
|
|
|
|
bi->bmiHeader.biPlanes = 1;
|
|
|
bi->bmiHeader.biBitCount = bpp;
|
|
|
bi->bmiHeader.biCompression = BI_RGB;
|
|
|
|
|
|
if (this->dib_sect) DeleteObject(this->dib_sect);
|
|
@@ -1262,13 +1249,13 @@ void VideoDriver_Win32GDI::Paint()
|
|
|
default:
|
|
|
NOT_REACHED();
|
|
|
}
|
|
|
_cur_palette.count_dirty = 0;
|
|
|
}
|
|
|
|
|
|
BitBlt(dc, 0, 0, _wnd.width, _wnd.height, dc2, 0, 0, SRCCOPY);
|
|
|
BitBlt(dc, 0, 0, this->width, this->height, dc2, 0, 0, SRCCOPY);
|
|
|
SelectPalette(dc, old_palette, TRUE);
|
|
|
SelectObject(dc2, old_bmp);
|
|
|
DeleteDC(dc2);
|
|
|
|
|
|
ReleaseDC(this->main_wnd, dc);
|
|
|
|
|
@@ -1346,13 +1333,13 @@ const char *VideoDriver_Win32OpenGL::Sta
|
|
|
if (err != nullptr) {
|
|
|
this->Stop();
|
|
|
_cur_resolution = old_res;
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
this->ClientSizeChanged(_wnd.width, _wnd.height);
|
|
|
this->ClientSizeChanged(this->width, this->height);
|
|
|
|
|
|
this->draw_threaded = false;
|
|
|
MarkWholeScreenDirty();
|
|
|
|
|
|
return nullptr;
|
|
|
}
|
|
@@ -1416,29 +1403,29 @@ const char *VideoDriver_Win32OpenGL::All
|
|
|
|
|
|
bool VideoDriver_Win32OpenGL::ToggleFullscreen(bool full_screen)
|
|
|
{
|
|
|
this->DestroyContext();
|
|
|
bool res = this->VideoDriver_Win32Base::ToggleFullscreen(full_screen);
|
|
|
res &= this->AllocateContext() == nullptr;
|
|
|
this->ClientSizeChanged(_wnd.width, _wnd.height);
|
|
|
this->ClientSizeChanged(this->width, this->height);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
bool VideoDriver_Win32OpenGL::AfterBlitterChange()
|
|
|
{
|
|
|
assert(BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 0);
|
|
|
this->ClientSizeChanged(_wnd.width, _wnd.height);
|
|
|
this->ClientSizeChanged(this->width, this->height);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool VideoDriver_Win32OpenGL::AllocateBackingStore(int w, int h, bool force)
|
|
|
{
|
|
|
if (!force && w == _screen.width && h == _screen.height) return false;
|
|
|
|
|
|
_wnd.width = w = std::max(w, 64);
|
|
|
_wnd.height = h = std::max(h, 64);
|
|
|
this->width = w = std::max(w, 64);
|
|
|
this->height = h = std::max(h, 64);
|
|
|
|
|
|
if (this->gl_rc == nullptr) return false;
|
|
|
|
|
|
this->dirty_rect = {};
|
|
|
return OpenGLBackend::Get()->Resize(w, h, force);
|
|
|
}
|