Improved handling if WindowBorder changes when the window is WindowState is Maximized or Fullscreen. Maximized windows now correctly retain their maximized state, while fullscreen windows do not become non-fullscreen when their border is modified.

This commit is contained in:
the_fiddler 2009-10-18 14:56:53 +00:00
parent 6be563211f
commit 590789a684

View file

@ -61,8 +61,9 @@ namespace OpenTK.Platform.Windows
bool exists; bool exists;
WinWindowInfo window, child_window; WinWindowInfo window, child_window;
WindowBorder windowBorder = WindowBorder.Resizable, previous_window_border; WindowBorder windowBorder = WindowBorder.Resizable, previous_window_border;
WindowBorder deferred_window_border; // Set to avoid changing borders during fullscreen states.
WindowState windowState = WindowState.Normal; WindowState windowState = WindowState.Normal;
bool borderless_maximized_window_state = false; bool borderless_maximized_window_state = false; // Hack to get maximized mode with hidden border (not normally possible).
System.Drawing.Rectangle System.Drawing.Rectangle
bounds = new System.Drawing.Rectangle(), bounds = new System.Drawing.Rectangle(),
@ -856,6 +857,7 @@ namespace OpenTK.Platform.Windows
return; return;
ShowWindowCommand command = 0; ShowWindowCommand command = 0;
bool exiting_fullscreen = false;
borderless_maximized_window_state = false; borderless_maximized_window_state = false;
switch (value) switch (value)
@ -863,11 +865,9 @@ namespace OpenTK.Platform.Windows
case WindowState.Normal: case WindowState.Normal:
command = ShowWindowCommand.RESTORE; command = ShowWindowCommand.RESTORE;
// If we are leaving fullscreen mode, restore previous border. // If we are leaving fullscreen mode we need to restore the border.
if (WindowState == WindowState.Fullscreen) if (WindowState == WindowState.Fullscreen)
{ exiting_fullscreen = true;
WindowBorder = previous_window_border;
}
break; break;
case WindowState.Maximized: case WindowState.Maximized:
@ -918,12 +918,19 @@ namespace OpenTK.Platform.Windows
if (command != 0) if (command != 0)
Functions.ShowWindow(window.WindowHandle, command); Functions.ShowWindow(window.WindowHandle, command);
// Restore previous window size when leaving fullscreen mode // Restore previous window size/location if necessary
if (command == ShowWindowCommand.RESTORE && previous_bounds != System.Drawing.Rectangle.Empty) if (command == ShowWindowCommand.RESTORE && previous_bounds != System.Drawing.Rectangle.Empty)
{ {
Bounds = previous_bounds; Bounds = previous_bounds;
previous_bounds = System.Drawing.Rectangle.Empty; previous_bounds = System.Drawing.Rectangle.Empty;
} }
// Restore previous window border or apply pending border change when leaving fullscreen mode.
if (exiting_fullscreen)
{
WindowBorder = deferred_window_border != 0 ? deferred_window_border : previous_window_border;
deferred_window_border = previous_window_border = 0;
}
} }
} }
@ -939,9 +946,22 @@ namespace OpenTK.Platform.Windows
} }
set set
{ {
// Do not allow border changes during fullscreen mode.
// Defer them for when we leave fullscreen.
if (WindowState == WindowState.Fullscreen)
{
deferred_window_border = value;
return;
}
if (windowBorder == value) if (windowBorder == value)
return; return;
// To ensure maximized/minimized windows work correctly, reset state to normal,
// change the border, then go back to maximized/minimized.
WindowState state = WindowState;
WindowState = WindowState.Normal;
WindowStyle style = WindowStyle.ClipChildren | WindowStyle.ClipSiblings; WindowStyle style = WindowStyle.ClipChildren | WindowStyle.ClipSiblings;
switch (value) switch (value)
@ -975,6 +995,8 @@ namespace OpenTK.Platform.Windows
Visible = true; Visible = true;
WindowState = state;
if (WindowBorderChanged != null) if (WindowBorderChanged != null)
WindowBorderChanged(this, EventArgs.Empty); WindowBorderChanged(this, EventArgs.Empty);
} }