Implemented setWindowState for SDL issue #258 (based on windows platform code)

This commit is contained in:
and3md 2017-03-27 18:40:18 +02:00
parent 2433db588a
commit 71789a55b3
1 changed files with 67 additions and 0 deletions

View File

@ -264,6 +264,73 @@ class SDLWindow : Window {
_platform.closeWindow(this); _platform.closeWindow(this);
} }
override bool setWindowState(WindowState newState, bool activate = false, Rect newWindowRect = RECT_VALUE_IS_NOT_SET) {
// override for particular platforms
if (_win is null)
return false;
bool res = false;
// change state
switch(newState) {
case WindowState.maximized:
if (_windowState != WindowState.maximized)
SDL_MaximizeWindow(_win);
res = true;
break;
case WindowState.minimized:
if (_windowState != WindowState.minimized)
SDL_MinimizeWindow(_win);
res = true;
break;
case WindowState.hidden:
if (_windowState != WindowState.hidden)
SDL_HideWindow(_win);
res = true;
break;
case WindowState.normal:
if (_windowState != WindowState.normal) {
SDL_RestoreWindow(_win);
}
res = true;
break;
default:
break;
}
// change size and/or position
if (newWindowRect != RECT_VALUE_IS_NOT_SET && (newState == WindowState.normal || newState == WindowState.unspecified)) {
if (newWindowRect.top == int.min || newWindowRect.left == int.min) {
// no position specified
if (newWindowRect.bottom != int.min && newWindowRect.right != int.min) {
// change size only
SDL_SetWindowSize(_win, newWindowRect.right, newWindowRect.bottom);
res = true;
}
} else {
if (newWindowRect.bottom != int.min && newWindowRect.right != int.min) {
// change size and position
SDL_SetWindowPosition(_win, newWindowRect.left, newWindowRect.top);
SDL_SetWindowSize(_win, newWindowRect.right, newWindowRect.bottom);
res = true;
} else {
// change position only
SDL_SetWindowPosition(_win, newWindowRect.left, newWindowRect.top);
res = true;
}
}
}
if (activate)
{
SDL_RaiseWindow(_win);
res = true;
}
return res;
}
protected dstring _caption; protected dstring _caption;