support Fullscreen with Win32 API
This commit is contained in:
parent
48ee0c06d2
commit
486a0a09d4
17
src/init.c
17
src/init.c
@ -2081,8 +2081,7 @@ void Set_all_video_modes(void)
|
|||||||
// Note that we voluntarily omit the first entry: the default mode.
|
// 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);
|
qsort(&Video_mode[1], Nb_video_modes - 1, sizeof(T_Video_mode), Compare_video_modes);
|
||||||
}
|
}
|
||||||
#endif
|
#elif defined(USE_SDL2)
|
||||||
#if defined(USE_SDL2)
|
|
||||||
{
|
{
|
||||||
SDL_DisplayMode dm;
|
SDL_DisplayMode dm;
|
||||||
if (SDL_GetDesktopDisplayMode(0, &dm) == 0)
|
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);
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -216,10 +216,17 @@ static void Win32_CreateWindow(int width, int height, int fullscreen)
|
|||||||
DWORD style;
|
DWORD style;
|
||||||
RECT r;
|
RECT r;
|
||||||
|
|
||||||
style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
|
if (fullscreen)
|
||||||
/* allow window to be resized */
|
{
|
||||||
style |= WS_THICKFRAME;
|
style = WS_POPUP;
|
||||||
style |= WS_MAXIMIZEBOX;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
|
||||||
|
/* allow window to be resized */
|
||||||
|
style |= WS_THICKFRAME;
|
||||||
|
style |= WS_MAXIMIZEBOX;
|
||||||
|
}
|
||||||
|
|
||||||
r.left = 0;
|
r.left = 0;
|
||||||
r.top = 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)
|
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);
|
Video_AllocateDib(*width, *height);
|
||||||
if (Win32_hwnd == NULL)
|
if (Win32_hwnd == NULL)
|
||||||
Win32_CreateWindow(*width, *height, fullscreen);
|
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)
|
byte Get_Screen_pixel(int x, int y)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user