Merge pull request #336 from and3md/sdl_set_window_state

Implemented setWindowState for SDL issue #258
This commit is contained in:
Vadim Lopatin 2017-04-11 10:18:40 +03:00 committed by GitHub
commit 29465b3bd2
1 changed files with 58 additions and 0 deletions

View File

@ -263,6 +263,64 @@ class SDLWindow : Window {
Log.d("SDLWindow.close()");
_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)) {
// change position
if (newWindowRect.top != int.min && newWindowRect.left != int.min) {
SDL_SetWindowPosition(_win, newWindowRect.left, newWindowRect.top);
res = true;
}
// change size
if (newWindowRect.bottom != int.min && newWindowRect.right != int.min) {
SDL_SetWindowSize(_win, newWindowRect.right, newWindowRect.bottom);
res = true;
}
}
if (activate) {
SDL_RaiseWindow(_win);
res = true;
}
return res;
}
protected dstring _caption;