From e86ac9cc75f61bb044eaa49d84932d56194e6364 Mon Sep 17 00:00:00 2001 From: "Lars A. Doucet" Date: Tue, 24 Nov 2015 13:27:14 -0600 Subject: [PATCH] added borderless, resizable, and fullscreenBorderless properties to Window.hx. Caveats: resizable can only be set at runtime for windows right now as SDL does not support it natively and has to be added per platform. --- lime/_backend/flash/FlashWindow.hx | 13 +++ lime/_backend/native/NativeWindow.hx | 30 ++++++ lime/ui/Window.hx | 133 ++++++++++++++++++++++++++ project/include/ui/Window.h | 2 + project/src/ExternalInterface.cpp | 16 ++++ project/src/backend/sdl/SDLWindow.cpp | 51 ++++++++++ project/src/backend/sdl/SDLWindow.h | 2 + 7 files changed, 247 insertions(+) diff --git a/lime/_backend/flash/FlashWindow.hx b/lime/_backend/flash/FlashWindow.hx index 4593376ed..58650e3e1 100644 --- a/lime/_backend/flash/FlashWindow.hx +++ b/lime/_backend/flash/FlashWindow.hx @@ -88,6 +88,12 @@ class FlashWindow { } + public function setBorderless (value:Bool):Bool { + + return value; + + } + public function setEnableTextEvents (value:Bool):Bool { return enableTextEvents = value; @@ -116,6 +122,13 @@ class FlashWindow { } + public function setResizable (value:Bool):Bool { + + return value; + + } + + public function setTitle (value:String):String { return value; diff --git a/lime/_backend/native/NativeWindow.hx b/lime/_backend/native/NativeWindow.hx index 5f7675a9e..2606c96e6 100644 --- a/lime/_backend/native/NativeWindow.hx +++ b/lime/_backend/native/NativeWindow.hx @@ -190,6 +190,20 @@ class NativeWindow { } + public function setBorderless (value:Bool):Bool { + + if (handle != null) { + + #if !macro + lime_window_set_borderless (handle, value); + #end + + } + + return value; + } + + public function setEnableTextEvents (value:Bool):Bool { if (handle != null) { @@ -254,6 +268,20 @@ class NativeWindow { } + public function setResizable (value:Bool):Bool { + + if (handle != null) { + + #if !macro + lime_window_set_resizable (handle, value); + #end + + } + + return value; + } + + public function setTitle (value:String):String { if (handle != null) { @@ -282,10 +310,12 @@ class NativeWindow { @:cffi private static function lime_window_get_y (handle:Dynamic):Int; @:cffi private static function lime_window_move (handle:Dynamic, x:Int, y:Int):Void; @:cffi private static function lime_window_resize (handle:Dynamic, width:Int, height:Int):Void; + @:cffi private static function lime_window_set_borderless (handle:Dynamic, borderless:Bool):Bool; @:cffi private static function lime_window_set_enable_text_events (handle:Dynamic, enabled:Bool):Void; @:cffi private static function lime_window_set_fullscreen (handle:Dynamic, fullscreen:Bool):Bool; @:cffi private static function lime_window_set_icon (handle:Dynamic, buffer:Dynamic):Void; @:cffi private static function lime_window_set_minimized (handle:Dynamic, minimized:Bool):Bool; + @:cffi private static function lime_window_set_resizable (handle:Dynamic, resizable:Bool):Bool; @:cffi private static function lime_window_set_title (handle:Dynamic, title:String):Dynamic; #end diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index e8832aab4..9fd15a865 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -21,10 +21,12 @@ class Window { public var application (default, null):Application; + public var borderless(get, set):Bool; public var config:WindowConfig; public var display (get, null):Display; public var enableTextEvents (get, set):Bool; public var fullscreen (get, set):Bool; + public var fullscreenBorderless (get, set):Bool; public var height (get, set):Int; public var id (default, null):Int; public var minimized (get, set):Bool; @@ -51,6 +53,7 @@ class Window { public var onTextEdit = new EventInt->Int->Void> (); public var onTextInput = new EventVoid> (); public var renderer:Renderer; + public var resizable (get, set):Bool; public var scale (get, null):Float; public var stage:Stage; public var title (get, set):String; @@ -59,14 +62,17 @@ class Window { public var y (get, set):Int; @:noCompletion private var backend:WindowBackend; + @:noCompletion private var __borderless:Bool; @:noCompletion private var __fullscreen:Bool; @:noCompletion private var __height:Int; @:noCompletion private var __minimized:Bool; + @:noCompletion private var __resizable:Bool; @:noCompletion private var __scale:Float; @:noCompletion private var __title:String; @:noCompletion private var __width:Int; @:noCompletion private var __x:Int; @:noCompletion private var __y:Int; + @:noCompletion private var __returnState: { width:Int, height:Int, x:Int, y:Int, resizable:Bool, borderless:Bool }; public function new (config:WindowConfig = null) { @@ -89,6 +95,8 @@ class Window { if (Reflect.hasField (config, "x")) __x = config.x; if (Reflect.hasField (config, "y")) __y = config.y; if (Reflect.hasField (config, "fullscreen")) __fullscreen = config.fullscreen; + if (Reflect.hasField (config, "borderless")) __borderless = config.borderless; + if (Reflect.hasField (config, "resizable")) __resizable = config.resizable; if (Reflect.hasField (config, "title")) __title = config.title; } @@ -315,6 +323,20 @@ class Window { } + @:noCompletion private inline function get_borderless ():Bool { + + return __borderless; + + } + + + @:noCompletion private function set_borderless (value:Bool):Bool { + + return __borderless = backend.setBorderless (value); + + } + + @:noCompletion private inline function get_enableTextEvents ():Bool { return backend.getEnableTextEvents (); @@ -343,6 +365,101 @@ class Window { } + @:noCompletion private function get_fullscreenBorderless():Bool { + + return (width == display.currentMode.width && + height == display.currentMode.height && + borderless == true && + resizable == false); + + } + + @:noCompletion private function set_fullscreenBorderless(value:Bool):Bool { + + if (value) { + + if(!get_fullscreenBorderless()) { + + __returnState = { width:__width, height:__height, x:__x, y:__y, borderless:__borderless, resizable:__resizable}; + + width = display.currentMode.width; + height = display.currentMode.height; + borderless = true; + resizable = false; + x = 0; + y = 0; + + } + + } + else { + + if (__returnState != null) { + + width = __returnState.width; + height = __returnState.height; + borderless = __returnState.borderless; + resizable = __returnState.resizable; + x = __returnState.x; + y = __returnState.y; + __returnState = null; + + } + + } + + return get_fullscreenBorderless(); + } + + /* + private static function get_fullscreenBorderless():Bool + { + #if desktop + return (stage.stageWidth == Capabilities.screenResolutionX && + stage.stageHeight == Capabilities.screenResolutionY && + stage.window.borderless == true && + stage.window.resizable == false); + #end + return false; + } + + /*private static var _fullscreenBorderlessReturnWidth:Int = 0; + private static var _fullscreenBorderlessReturnHeight:Int = 0; + private static var _fullscreenBorderlessReturnBorderless:Bool = false; + private static var _fullscreenBorderlessReturnResizable:Bool = false; + private static var _fullscreenBorderlessReturnX:Int = 0; + private static var _fullscreenBorderlessReturnY:Int = 0; + + private static function set_fullscreenBorderless(Value:Bool):Bool + { + #if desktop + if (Value) { + _fullscreenBorderlessReturnWidth = stage.stageWidth; + _fullscreenBorderlessReturnHeight = stage.stageHeight; + _fullscreenBorderlessReturnBorderless = stage.window.borderless; + _fullscreenBorderlessReturnResizable = stage.window.resizable; + _fullscreenBorderlessReturnX = stage.window.x; + _fullscreenBorderlessReturnY = stage.window.y; + resizeGame(Std.int(Capabilities.screenResolutionX), Std.int(Capabilities.screenResolutionY)); + stage.window.borderless = true; + stage.window.resizable = false; + stage.window.x = 0; + stage.window.y = 0; + } + else { + if(_fullscreenBorderlessReturnWidth != 0 && _fullscreenBorderlessReturnHeight != 0) { + resizeGame(_fullscreenBorderlessReturnWidth, _fullscreenBorderlessReturnHeight); + stage.window.borderless = _fullscreenBorderlessReturnBorderless; + stage.window.resizable = _fullscreenBorderlessReturnResizable; + stage.window.x = _fullscreenBorderlessReturnX; + stage.window.y = _fullscreenBorderlessReturnY; + } + } + return get_fullscreenBorderless(); + #end + return false; + }*/ + @:noCompletion private inline function get_height ():Int { return __height; @@ -372,6 +489,22 @@ class Window { } + @:noCompletion private inline function get_resizable ():Bool { + + return __resizable; + + } + + + @:noCompletion private function set_resizable (value:Bool):Bool { + + __resizable = backend.setResizable(value); + backend.setBorderless(!__borderless); //resizable property won't update until you change another property like the borderless property + backend.setBorderless(__borderless); + return __resizable; + } + + @:noCompletion private inline function get_scale ():Float { return __scale; diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index 40c33de36..453cbffde 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -30,10 +30,12 @@ namespace lime { virtual int GetY () = 0; virtual void Move (int x, int y) = 0; virtual void Resize (int width, int height) = 0; + virtual bool SetBorderless (bool borderless) = 0; virtual void SetEnableTextEvents (bool enable) = 0; virtual bool SetFullscreen (bool fullscreen) = 0; virtual void SetIcon (ImageBuffer *imageBuffer) = 0; virtual bool SetMinimized (bool minimized) = 0; + virtual bool SetResizable (bool resizable) = 0; virtual const char* SetTitle (const char* title) = 0; Application* currentApplication; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 34f77b62a..2ac53cf14 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -1364,6 +1364,13 @@ namespace lime { } + bool lime_window_set_borderless (value window, bool borderless) { + + Window* targetWindow = (Window*)val_data (window); + return targetWindow->SetBorderless (borderless); + + } + void lime_window_set_enable_text_events (value window, bool enabled) { Window* targetWindow = (Window*)val_data (window); @@ -1397,6 +1404,13 @@ namespace lime { } + bool lime_window_set_resizable (value window, bool resizable) { + + Window* targetWindow = (Window*)val_data (window); + return targetWindow->SetResizable (resizable); + + } + value lime_window_set_title (value window, HxString title) { Window* targetWindow = (Window*)val_data (window); @@ -1519,10 +1533,12 @@ namespace lime { DEFINE_PRIME1 (lime_window_get_y); DEFINE_PRIME3v (lime_window_move); DEFINE_PRIME3v (lime_window_resize); + DEFINE_PRIME2 (lime_window_set_borderless); DEFINE_PRIME2v (lime_window_set_enable_text_events); DEFINE_PRIME2 (lime_window_set_fullscreen); DEFINE_PRIME2v (lime_window_set_icon); DEFINE_PRIME2 (lime_window_set_minimized); + DEFINE_PRIME2 (lime_window_set_resizable); DEFINE_PRIME2 (lime_window_set_title); diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 4c252a0ca..75478229b 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -255,6 +255,23 @@ namespace lime { } + bool SDLWindow::SetBorderless (bool borderless) { + + if (borderless) { + + SDL_SetWindowBordered (sdlWindow, SDL_FALSE); + + } else { + + SDL_SetWindowBordered (sdlWindow, SDL_TRUE); + + } + + return borderless; + + } + + void SDLWindow::SetEnableTextEvents (bool enabled) { if (enabled) { @@ -327,6 +344,40 @@ namespace lime { } + bool SDLWindow::SetResizable (bool resizable) { + + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(sdlWindow, &info); + + #ifdef HX_WINDOWS + //toggling the window "resizable" property after window creation is not currently supported in SDL, so we have to do it manually + + HWND hwnd = info.info.win.window; + DWORD style = GetWindowLong(hwnd, GWL_STYLE); + if (resizable) + style |= WS_THICKFRAME; + else + style &= ~WS_THICKFRAME; + SetWindowLong(hwnd, GWL_STYLE, style); + + #endif + #ifdef HX_MACOS + + //TODO + + #endif + #ifdef HX_LINUX + + //TODO + + #endif + + return resizable; + + } + + Window* CreateWindow (Application* application, int width, int height, int flags, const char* title) { return new SDLWindow (application, width, height, flags, title); diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index 3f6b9fafe..6de21a22b 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -28,10 +28,12 @@ namespace lime { virtual int GetY (); virtual void Move (int x, int y); virtual void Resize (int width, int height); + virtual bool SetBorderless (bool borderless); virtual void SetEnableTextEvents (bool enabled); virtual bool SetFullscreen (bool fullscreen); virtual void SetIcon (ImageBuffer *imageBuffer); virtual bool SetMinimized (bool minimized); + virtual bool SetResizable (bool resizable); virtual const char* SetTitle (const char* title); SDL_Window* sdlWindow;