From 486a0a09d47300d04f160328d73219efa13684df Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Thu, 21 Jun 2018 22:48:07 +0200 Subject: [PATCH] support Fullscreen with Win32 API --- src/init.c | 17 +++++++++++++++-- src/win32screen.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/init.c b/src/init.c index e2065c5f..99322abe 100644 --- a/src/init.c +++ b/src/init.c @@ -2081,8 +2081,7 @@ void Set_all_video_modes(void) // Note that we voluntarily omit the first entry: the default mode. qsort(&Video_mode[1], Nb_video_modes - 1, sizeof(T_Video_mode), Compare_video_modes); } -#endif -#if defined(USE_SDL2) +#elif defined(USE_SDL2) { SDL_DisplayMode dm; if (SDL_GetDesktopDisplayMode(0, &dm) == 0) @@ -2091,6 +2090,20 @@ void Set_all_video_modes(void) Set_video_mode(dm.w, dm.h, 0, 1); } } +#elif defined(WIN32) + { + int width = GetSystemMetrics(SM_CXSCREEN); + int height = GetSystemMetrics(SM_CYSCREEN); + if (width > 0 && height > 0) + { + Video_mode[Nb_video_modes].Width = width; + Video_mode[Nb_video_modes].Height = height; + Video_mode[Nb_video_modes].Mode = 0; + Video_mode[Nb_video_modes].Fullscreen = 1; + Video_mode[Nb_video_modes].State = 1; + Nb_video_modes ++; + } + } #endif } diff --git a/src/win32screen.c b/src/win32screen.c index bd14d7d7..1e3c1cd5 100644 --- a/src/win32screen.c +++ b/src/win32screen.c @@ -216,10 +216,17 @@ static void Win32_CreateWindow(int width, int height, int fullscreen) DWORD style; RECT r; - style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; - /* allow window to be resized */ - style |= WS_THICKFRAME; - style |= WS_MAXIMIZEBOX; + if (fullscreen) + { + style = WS_POPUP; + } + else + { + style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; + /* allow window to be resized */ + style |= WS_THICKFRAME; + style |= WS_MAXIMIZEBOX; + } r.left = 0; r.top = 0; @@ -240,9 +247,40 @@ static void Win32_CreateWindow(int width, int height, int fullscreen) void GFX2_Set_mode(int *width, int *height, int fullscreen) { + static RECT backup_pos = { 0 }; // Last window position used when not in fullscreen + Video_AllocateDib(*width, *height); if (Win32_hwnd == NULL) Win32_CreateWindow(*width, *height, fullscreen); + else + { + DWORD style = GetWindowLong(Win32_hwnd, GWL_STYLE); + if (fullscreen) + { + style &= ~WS_OVERLAPPEDWINDOW; + style |= WS_POPUP; + SetWindowLong(Win32_hwnd, GWL_STYLE, style); + SetWindowPos(Win32_hwnd, HWND_TOPMOST, 0, 0, *width, *height, SWP_FRAMECHANGED | SWP_NOCOPYBITS); + } + else if ((style & WS_POPUP) != 0) + { + style &= ~WS_POPUP; + style |= WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX; + SetWindowLong(Win32_hwnd, GWL_STYLE, style); + if (backup_pos.bottom == 0 || backup_pos.left == 0) + { // could happen if we started in fullscreen mode + backup_pos.left = backup_pos.right + *width; + backup_pos.bottom = backup_pos.top + *height; + AdjustWindowRect(&backup_pos, style, FALSE); + } + SetWindowPos(Win32_hwnd, HWND_TOPMOST, + backup_pos.left, backup_pos.top, + backup_pos.right - backup_pos.left, backup_pos.bottom - backup_pos.top, + SWP_FRAMECHANGED | SWP_NOCOPYBITS); + } + } + if (!fullscreen) + GetWindowRect(Win32_hwnd, &backup_pos); } byte Get_Screen_pixel(int x, int y)