From 71789a55b3c835dc7125c07f8229d66435e791a1 Mon Sep 17 00:00:00 2001 From: and3md Date: Mon, 27 Mar 2017 18:40:18 +0200 Subject: [PATCH] Implemented setWindowState for SDL issue #258 (based on windows platform code) --- src/dlangui/platforms/sdl/sdlapp.d | 67 ++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 69285637..173c09c9 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -263,6 +263,73 @@ 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)) { + + 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;