From 5021141a887f823e5aef63f777609ffa12d1a949 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Thu, 19 May 2016 11:08:22 +0300 Subject: [PATCH] window state and state change and signal support in base platform class -- issue #258 --- src/dlangui/core/events.d | 2 +- src/dlangui/core/types.d | 2 + src/dlangui/platforms/common/platform.d | 53 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/dlangui/core/events.d b/src/dlangui/core/events.d index 96524632..a0cd90c7 100644 --- a/src/dlangui/core/events.d +++ b/src/dlangui/core/events.d @@ -718,7 +718,7 @@ ushort mouseButtonToFlag(MouseButton btn) { } /// double click max interval, milliseconds; may be changed by platform -__gshared long DOUBLE_CLICK_THRESHOLD_MS = 300; +__gshared long DOUBLE_CLICK_THRESHOLD_MS = 400; /// Mouse button state details for MouseEvent struct ButtonDetails { diff --git a/src/dlangui/core/types.d b/src/dlangui/core/types.d index 79673260..7d9fc1cc 100644 --- a/src/dlangui/core/types.d +++ b/src/dlangui/core/types.d @@ -170,6 +170,8 @@ struct Rect { } } +/// constant acting as "rectangle not set" value +immutable Rect RECT_VALUE_IS_NOT_SET = Rect(int.min, int.min, int.min, int.min); /// widget state bit flags enum State : uint { diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index c0b5702c..dc803517 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -51,6 +51,30 @@ enum WindowFlag : uint { Modal = 4, } +/// Window states +enum WindowState : int { + /// state is unknown (not supported by platform?) + unknown, + /// normal state + normal, + /// window is maximized + maximized, + /// window is maximized + minimized, + /// fullscreen mode (supported not on all platforms) + fullscreen, + /// application is paused (e.g. on Android) + paused, + /// closed + closed, +} + +/// Window state signal listener +interface OnWindowStateHandler { + /// signal listener - called when state of window is changed + bool onWindowStateChange(Window window, WindowState winState, Rect rect); +} + /// protected event list /// references to posted messages can be stored here at least to keep live reference and avoid GC /// as well, on some platforms it's easy to send id to message queue, but not pointer @@ -200,6 +224,35 @@ class Window : CustomEventTarget { /// close window abstract void close(); + protected WindowState _windowState = WindowState.normal; + /// returns current window state + @property WindowState windowState() { + return _windowState; + } + + protected Rect _windowRect = RECT_VALUE_IS_NOT_SET; + /// returns window rectangle on screen (includes window frame and title) + @property Rect windowRect() { + if (_windowRect != RECT_VALUE_IS_NOT_SET) + return _windowRect; + // fake window rectangle -- at position 0,0 and + return Rect(0, 0, _dx, _dy); + } + /// window state change signal + Signal!OnWindowStateHandler windowStateChanged; + protected void handleWindowStateChange(WindowState newState, Rect newWindowRect) { + _windowState = newState; + _windowRect = newWindowRect; + if (windowStateChanged.assigned) + windowStateChanged(this, newState, newWindowRect); + } + + /// change window state, position, or size; returns true if successful, false if not supported by platform + bool setWindowState(WindowState newState, Rect newWindowRect = RECT_VALUE_IS_NOT_SET) { + return false; + } + + /// requests layout for main widget and popups void requestLayout() { if (_mainWidget)