From 71789a55b3c835dc7125c07f8229d66435e791a1 Mon Sep 17 00:00:00 2001 From: and3md Date: Mon, 27 Mar 2017 18:40:18 +0200 Subject: [PATCH 1/2] 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; From c8bc160e58affe00c45e490c3ac6e53174521bc1 Mon Sep 17 00:00:00 2001 From: and3md Date: Sat, 8 Apr 2017 14:29:41 +0200 Subject: [PATCH 2/2] Better pos/resize code in SDL setWindowState() --- src/dlangui/platforms/sdl/sdlapp.d | 33 +++++++++++------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 173c09c9..c88e5878 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -300,30 +300,21 @@ class SDLWindow : Window { } // 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; - } + + // 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) - { + if (activate) { SDL_RaiseWindow(_win); res = true; }