Window: minWidth/minHeight/setMinSize and maxWidth/maxHeight/setMaxSize

This commit is contained in:
Josh Tynjala
2023-04-11 09:46:10 -07:00
parent f43173b942
commit f07e94708b
10 changed files with 214 additions and 0 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;

View File

@@ -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.Callable<cpp.Object->Int->Int->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_resize", "oiiv",
false));
private static var lime_window_set_minimum_size = new cpp.Callable<cpp.Object->Int->Int->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_set_minimum_size", "oiiv",
false));
private static var lime_window_set_maximum_size = new cpp.Callable<cpp.Object->Int->Int->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_window_set_maximum_size", "oiiv",
false));
private static var lime_window_set_borderless = new cpp.Callable<cpp.Object->Bool->Bool>(cpp.Prime._loadPrime("lime", "lime_window_set_borderless", "obb",
false));
private static var lime_window_set_cursor = new cpp.Callable<cpp.Object->Int->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;

View File

@@ -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)

View File

@@ -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 Event<Void->Void>();
public var onClose(default, null) = new Event<Void->Void>();
@@ -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();