diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index dc4146142..2db40ab27 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -48,6 +48,8 @@ namespace lime { virtual void Move (int x, int y) = 0; virtual void ReadPixels (ImageBuffer *buffer, Rectangle *rect) = 0; virtual void Resize (int width, int height) = 0; + virtual void SetMinimumSize (int width, int height) = 0; + virtual void SetMaximumSize (int width, int height) = 0; virtual bool SetBorderless (bool borderless) = 0; virtual void SetCursor (Cursor cursor) = 0; virtual void SetDisplayMode (DisplayMode* displayMode) = 0; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 298a55316..4fd7c5518 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -3518,6 +3518,38 @@ namespace lime { } + void lime_window_set_minimum_size (value window, int width, int height) { + + Window* targetWindow = (Window*)val_data (window); + targetWindow->SetMinimumSize (width, height); + + } + + + HL_PRIM void HL_NAME(hl_window_set_minimum_size) (HL_CFFIPointer* window, int width, int height) { + + Window* targetWindow = (Window*)window->ptr; + targetWindow->SetMinimumSize (width, height); + + } + + + void lime_window_set_maximum_size (value window, int width, int height) { + + Window* targetWindow = (Window*)val_data (window); + targetWindow->SetMaximumSize (width, height); + + } + + + HL_PRIM void HL_NAME(hl_window_set_maximum_size) (HL_CFFIPointer* window, int width, int height) { + + Window* targetWindow = (Window*)window->ptr; + targetWindow->SetMaximumSize (width, height); + + } + + bool lime_window_set_borderless (value window, bool borderless) { Window* targetWindow = (Window*)val_data (window); @@ -3986,6 +4018,8 @@ namespace lime { DEFINE_PRIME3v (lime_window_move); DEFINE_PRIME3 (lime_window_read_pixels); DEFINE_PRIME3v (lime_window_resize); + DEFINE_PRIME3v (lime_window_set_minimum_size); + DEFINE_PRIME3v (lime_window_set_maximum_size); DEFINE_PRIME2 (lime_window_set_borderless); DEFINE_PRIME2v (lime_window_set_cursor); DEFINE_PRIME2 (lime_window_set_display_mode); @@ -4173,6 +4207,8 @@ namespace lime { DEFINE_HL_PRIM (_VOID, hl_window_move, _TCFFIPOINTER _I32 _I32); DEFINE_HL_PRIM (_DYN, hl_window_read_pixels, _TCFFIPOINTER _TRECTANGLE _TIMAGEBUFFER); DEFINE_HL_PRIM (_VOID, hl_window_resize, _TCFFIPOINTER _I32 _I32); + DEFINE_HL_PRIM (_VOID, hl_window_set_minimum_size, _TCFFIPOINTER _I32 _I32); + DEFINE_HL_PRIM (_VOID, hl_window_set_maximum_size, _TCFFIPOINTER _I32 _I32); DEFINE_HL_PRIM (_BOOL, hl_window_set_borderless, _TCFFIPOINTER _BOOL); DEFINE_HL_PRIM (_VOID, hl_window_set_cursor, _TCFFIPOINTER _I32); DEFINE_HL_PRIM (_VOID, hl_window_set_display_mode, _TCFFIPOINTER _TDISPLAYMODE _TDISPLAYMODE); diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index 871c2e7ec..59ff7435f 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -745,6 +745,20 @@ namespace lime { } + void SDLWindow::SetMinimumSize (int width, int height) { + + SDL_SetWindowMinimumSize (sdlWindow, width, height); + + } + + + void SDLWindow::SetMaximumSize (int width, int height) { + + SDL_SetWindowMaximumSize (sdlWindow, width, height); + + } + + bool SDLWindow::SetBorderless (bool borderless) { if (borderless) { diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index e66569f9c..50ee4638e 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -42,6 +42,8 @@ namespace lime { virtual void Move (int x, int y); virtual void ReadPixels (ImageBuffer *buffer, Rectangle *rect); virtual void Resize (int width, int height); + virtual void SetMinimumSize (int width, int height); + virtual void SetMaximumSize (int width, int height); virtual bool SetBorderless (bool borderless); virtual void SetCursor (Cursor cursor); virtual void SetDisplayMode (DisplayMode* displayMode); diff --git a/src/lime/_internal/backend/air/AIRWindow.hx b/src/lime/_internal/backend/air/AIRWindow.hx index 821ec79cd..3dccc8264 100644 --- a/src/lime/_internal/backend/air/AIRWindow.hx +++ b/src/lime/_internal/backend/air/AIRWindow.hx @@ -5,6 +5,7 @@ import flash.display.NativeWindow; import flash.display.NativeWindowInitOptions; import flash.display.NativeWindowRenderMode; import flash.display.NativeWindowSystemChrome; +import flash.geom.Point; import flash.events.Event; import flash.events.NativeWindowBoundsEvent; import flash.html.HTMLLoader; @@ -231,6 +232,22 @@ class AIRWindow extends FlashWindow } } + public override function setMinSize(width:Int, height:Int):Void + { + if (nativeWindow != null) + { + nativeWindow.minSize = new Point(width, height); + } + } + + public override function setMaxSize(width:Int, height:Int):Void + { + if (nativeWindow != null) + { + nativeWindow.maxSize = new Point(width, height); + } + } + public override function setMaximized(value:Bool):Bool { if (nativeWindow != null) diff --git a/src/lime/_internal/backend/flash/FlashWindow.hx b/src/lime/_internal/backend/flash/FlashWindow.hx index 2d3988e5c..a1f3dc7b6 100644 --- a/src/lime/_internal/backend/flash/FlashWindow.hx +++ b/src/lime/_internal/backend/flash/FlashWindow.hx @@ -586,6 +586,10 @@ class FlashWindow public function resize(width:Int, height:Int):Void {} + public function setMinSize(width:Int, height:Int):Void {} + + public function setMaxSize(width:Int, height:Int):Void {} + public function setBorderless(value:Bool):Bool { return value; diff --git a/src/lime/_internal/backend/html5/HTML5Window.hx b/src/lime/_internal/backend/html5/HTML5Window.hx index 185972d97..6ca19adb8 100644 --- a/src/lime/_internal/backend/html5/HTML5Window.hx +++ b/src/lime/_internal/backend/html5/HTML5Window.hx @@ -966,6 +966,10 @@ class HTML5Window public function resize(width:Int, height:Int):Void {} + public function setMinSize(width:Int, height:Int):Void {} + + public function setMaxSize(width:Int, height:Int):Void {} + public function setBorderless(value:Bool):Bool { return value; diff --git a/src/lime/_internal/backend/native/NativeCFFI.hx b/src/lime/_internal/backend/native/NativeCFFI.hx index 6372a96bc..5b1fee433 100644 --- a/src/lime/_internal/backend/native/NativeCFFI.hx +++ b/src/lime/_internal/backend/native/NativeCFFI.hx @@ -323,6 +323,10 @@ class NativeCFFI @:cffi private static function lime_window_resize(handle:Dynamic, width:Int, height:Int):Void; + @:cffi private static function lime_window_set_minimum_size(handle:Dynamic, width:Int, height:Int):Void; + + @:cffi private static function lime_window_set_maximum_size(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_cursor(handle:Dynamic, cursor:Int):Void; @@ -582,6 +586,10 @@ class NativeCFFI "lime_window_read_pixels", "oooo", false)); private static var lime_window_resize = new cpp.CallableInt->Int->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_resize", "oiiv", false)); + private static var lime_window_set_minimum_size = new cpp.CallableInt->Int->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_set_minimum_size", "oiiv", + false)); + private static var lime_window_set_maximum_size = new cpp.CallableInt->Int->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_set_maximum_size", "oiiv", + false)); private static var lime_window_set_borderless = new cpp.CallableBool->Bool>(cpp.Prime._loadPrime("lime", "lime_window_set_borderless", "obb", false)); private static var lime_window_set_cursor = new cpp.CallableInt->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_set_cursor", "oiv", @@ -753,6 +761,8 @@ class NativeCFFI private static var lime_window_move = CFFI.load("lime", "lime_window_move", 3); private static var lime_window_read_pixels = CFFI.load("lime", "lime_window_read_pixels", 3); private static var lime_window_resize = CFFI.load("lime", "lime_window_resize", 3); + private static var lime_window_set_minimum_size = CFFI.load("lime", "lime_window_set_minimum_size", 3); + private static var lime_window_set_maximum_size = CFFI.load("lime", "lime_window_set_maximum_size", 3); private static var lime_window_set_borderless = CFFI.load("lime", "lime_window_set_borderless", 2); private static var lime_window_set_cursor = CFFI.load("lime", "lime_window_set_cursor", 2); private static var lime_window_set_display_mode = CFFI.load("lime", "lime_window_set_display_mode", 2); @@ -1324,6 +1334,10 @@ class NativeCFFI @:hlNative("lime", "hl_window_resize") private static function lime_window_resize(handle:CFFIPointer, width:Int, height:Int):Void {} + @:hlNative("lime", "hl_window_set_minimum_size") private static function lime_window_set_minimum_size(handle:CFFIPointer, width:Int, height:Int):Void {} + + @:hlNative("lime", "hl_window_set_maximum_size") private static function lime_window_set_maximum_size(handle:CFFIPointer, width:Int, height:Int):Void {} + @:hlNative("lime", "hl_window_set_borderless") private static function lime_window_set_borderless(handle:CFFIPointer, borderless:Bool):Bool { return false; diff --git a/src/lime/_internal/backend/native/NativeWindow.hx b/src/lime/_internal/backend/native/NativeWindow.hx index 4b0e94253..36790c5f4 100644 --- a/src/lime/_internal/backend/native/NativeWindow.hx +++ b/src/lime/_internal/backend/native/NativeWindow.hx @@ -461,6 +461,26 @@ class NativeWindow } } + public function setMinSize(width:Int, height:Int):Void + { + if (handle != null) + { + #if (!macro && lime_cffi) + NativeCFFI.lime_window_set_minimum_size(handle, width, height); + #end + } + } + + public function setMaxSize(width:Int, height:Int):Void + { + if (handle != null) + { + #if (!macro && lime_cffi) + NativeCFFI.lime_window_set_maximum_size(handle, width, height); + #end + } + } + public function setBorderless(value:Bool):Bool { if (handle != null) diff --git a/src/lime/ui/Window.hx b/src/lime/ui/Window.hx index 177214835..f1abc1758 100644 --- a/src/lime/ui/Window.hx +++ b/src/lime/ui/Window.hx @@ -50,8 +50,12 @@ class Window public var height(get, set):Int; public var hidden(get, null):Bool; public var id(default, null):Int; + public var maxHeight(get, set):Int; public var maximized(get, set):Bool; + public var maxWidth(get, set):Int; + public var minHeight(get, set):Int; public var minimized(get, set):Bool; + public var minWidth(get, set):Int; public var mouseLock(get, set):Bool; public var onActivate(default, null) = new EventVoid>(); public var onClose(default, null) = new EventVoid>(); @@ -114,6 +118,10 @@ class Window @:noCompletion private var __width:Int; @:noCompletion private var __x:Int; @:noCompletion private var __y:Int; + @:noCompletion private var __minWidth:Int; + @:noCompletion private var __minHeight:Int; + @:noCompletion private var __maxWidth:Int; + @:noCompletion private var __maxHeight:Int; #if commonjs private static function __init__() @@ -128,8 +136,12 @@ class Window "frameRate": {get: p.get_frameRate, set: p.set_frameRate}, "fullscreen": {get: p.get_fullscreen, set: p.set_fullscreen}, "height": {get: p.get_height, set: p.set_height}, + "maxHeight": {get: p.get_maxHeight, set: p.set_maxHeight}, "maximized": {get: p.get_maximized, set: p.set_maximized}, + "maxWidth": {get: p.get_maxWidth, set: p.set_maxWidth}, + "minHeight": {get: p.get_minHeight, set: p.set_minHeight}, "minimized": {get: p.get_minimized, set: p.set_minimized}, + "minWidth": {get: p.get_minWidth, set: p.set_minWidth}, "mouseLock": {get: p.get_mouseLock, set: p.set_mouseLock}, "resizable": {get: p.get_resizable, set: p.set_resizable}, "scale": {get: p.get_scale}, @@ -396,12 +408,57 @@ class Window public function resize(width:Int, height:Int):Void { + if (width < __minWidth) + { + width = __minWidth; + } + else if (width > __maxWidth) + { + width = __maxWidth; + } + if (height < __minHeight) + { + height = __minHeight; + } + else if (height > __maxHeight) + { + height = __maxHeight; + } + __backend.resize(width, height); __width = width; __height = height; } + public function setMinSize(width:Int, height:Int):Void + { + __backend.setMinSize(width, height); + + __minWidth = width; + __minHeight = height; + if (__width < __minWidth) { + __width = __minWidth; + } + if (__height < __minHeight) { + __height = __minHeight; + } + } + + public function setMaxSize(width:Int, height:Int):Void + { + __backend.setMaxSize(width, height); + + __maxWidth = width; + __maxHeight = height; + if (__width > __maxWidth) { + __width = __maxWidth; + } + if (__height > __maxHeight) { + __height = __maxHeight; + } + } + public function setIcon(image:Image):Void { if (image == null) @@ -494,6 +551,17 @@ class Window return __hidden; } + @:noCompletion private inline function get_maxHeight():Int + { + return __maxHeight; + } + + @:noCompletion private function set_maxHeight(value:Int):Int + { + setMaxSize(__maxWidth, value); + return __maxHeight; + } + @:noCompletion private inline function get_maximized():Bool { return __maximized; @@ -505,6 +573,28 @@ class Window return __maximized = __backend.setMaximized(value); } + @:noCompletion private inline function get_maxWidth():Int + { + return __maxWidth; + } + + @:noCompletion private function set_maxWidth(value:Int):Int + { + setMinSize(value, __maxHeight); + return __maxWidth; + } + + @:noCompletion private inline function get_minHeight():Int + { + return __minHeight; + } + + @:noCompletion private function set_minHeight(value:Int):Int + { + setMinSize(__minWidth, value); + return __minHeight; + } + @:noCompletion private inline function get_minimized():Bool { return __minimized; @@ -516,6 +606,17 @@ class Window return __minimized = __backend.setMinimized(value); } + @:noCompletion private inline function get_minWidth():Int + { + return __minWidth; + } + + @:noCompletion private function set_minWidth(value:Int):Int + { + setMinSize(value, __minHeight); + return __minWidth; + } + @:noCompletion private function get_mouseLock():Bool { return __backend.getMouseLock();