From e02458669e468221c1d4a681826f6e1007e5cbaa Mon Sep 17 00:00:00 2001 From: Ian Harrigan Date: Sat, 30 Mar 2019 10:32:41 +0100 Subject: [PATCH] refactor --- haxe/ui/backend/{AppBase.hx => AppImpl.hx} | 17 +-- .../backend/{AssetsBase.hx => AssetsImpl.hx} | 29 +---- haxe/ui/backend/BackendBase.hx | 5 - haxe/ui/backend/BackendImpl.hx | 5 + .../{CallLaterBase.hx => CallLaterImpl.hx} | 2 +- .../{ComponentBase.hx => ComponentImpl.hx} | 108 +++--------------- haxe/ui/backend/ComponentSurface.hx | 6 + haxe/ui/backend/EventBase.hx | 13 --- haxe/ui/backend/EventImpl.hx | 4 + haxe/ui/backend/ImageDisplayBase.hx | 35 ------ haxe/ui/backend/ImageDisplayImpl.hx | 4 + haxe/ui/backend/ImageSurface.hx | 6 + .../{PlatformBase.hx => PlatformImpl.hx} | 7 +- .../backend/{ScreenBase.hx => ScreenImpl.hx} | 48 +++----- haxe/ui/backend/TextDisplayBase.hx | 47 -------- haxe/ui/backend/TextDisplayImpl.hx | 4 + haxe/ui/backend/TextInputBase.hx | 18 --- haxe/ui/backend/TextInputImpl.hx | 4 + .../ui/backend/{TimerBase.hx => TimerImpl.hx} | 2 +- haxe/ui/backend/ToolkitOptions.hx | 2 +- 20 files changed, 81 insertions(+), 285 deletions(-) rename haxe/ui/backend/{AppBase.hx => AppImpl.hx} (79%) rename haxe/ui/backend/{AssetsBase.hx => AssetsImpl.hx} (51%) delete mode 100644 haxe/ui/backend/BackendBase.hx create mode 100644 haxe/ui/backend/BackendImpl.hx rename haxe/ui/backend/{CallLaterBase.hx => CallLaterImpl.hx} (80%) rename haxe/ui/backend/{ComponentBase.hx => ComponentImpl.hx} (72%) create mode 100644 haxe/ui/backend/ComponentSurface.hx delete mode 100644 haxe/ui/backend/EventBase.hx create mode 100644 haxe/ui/backend/EventImpl.hx delete mode 100644 haxe/ui/backend/ImageDisplayBase.hx create mode 100644 haxe/ui/backend/ImageDisplayImpl.hx create mode 100644 haxe/ui/backend/ImageSurface.hx rename haxe/ui/backend/{PlatformBase.hx => PlatformImpl.hx} (64%) rename haxe/ui/backend/{ScreenBase.hx => ScreenImpl.hx} (55%) delete mode 100644 haxe/ui/backend/TextDisplayBase.hx create mode 100644 haxe/ui/backend/TextDisplayImpl.hx delete mode 100644 haxe/ui/backend/TextInputBase.hx create mode 100644 haxe/ui/backend/TextInputImpl.hx rename haxe/ui/backend/{TimerBase.hx => TimerImpl.hx} (97%) diff --git a/haxe/ui/backend/AppBase.hx b/haxe/ui/backend/AppImpl.hx similarity index 79% rename from haxe/ui/backend/AppBase.hx rename to haxe/ui/backend/AppImpl.hx index f6f6be2..de3c2b3 100644 --- a/haxe/ui/backend/AppBase.hx +++ b/haxe/ui/backend/AppImpl.hx @@ -1,11 +1,10 @@ package haxe.ui.backend; +import cs.system.drawing.Size; import cs.system.windows.forms.Application; import cs.system.windows.forms.Form; -import haxe.ui.Preloader.PreloadItem; -import cs.system.drawing.Size; -class AppBase { +class AppImpl extends AppBase { private var _form:Form; private var _onEnd:Void->Void; @@ -14,12 +13,12 @@ class AppBase { Application.SetCompatibleTextRenderingDefault(false); } - private function build() { + private override function build() { _form = new Form(); _form.Text = Toolkit.backendProperties.getProp("haxe.ui.winforms.form.title", ""); } - private function init(onReady:Void->Void, onEnd:Void->Void = null) { + private override function init(onReady:Void->Void, onEnd:Void->Void = null) { _onEnd = onEnd; var formAutoSize = Toolkit.backendProperties.getPropBool("haxe.ui.winforms.form.autosize", true); @@ -37,20 +36,16 @@ class AppBase { onReady(); } - private function getToolkitInit():ToolkitOptions { + private override function getToolkitInit():ToolkitOptions { return { form: _form }; } - public function start() { + public override function start() { Application.Run(_form); if (_onEnd != null) { _onEnd(); } } - - private function buildPreloadList():Array { - return null; - } } diff --git a/haxe/ui/backend/AssetsBase.hx b/haxe/ui/backend/AssetsImpl.hx similarity index 51% rename from haxe/ui/backend/AssetsBase.hx rename to haxe/ui/backend/AssetsImpl.hx index 43aa672..9e92b03 100644 --- a/haxe/ui/backend/AssetsBase.hx +++ b/haxe/ui/backend/AssetsImpl.hx @@ -1,31 +1,22 @@ package haxe.ui.backend; -import haxe.io.Bytes; -import haxe.ui.assets.ImageInfo; -import haxe.ui.assets.FontInfo; import cs.system.drawing.Image; import cs.system.io.MemoryStream; +import haxe.io.Bytes; +import haxe.ui.assets.ImageInfo; -class AssetsBase { - public function new() { - - } - - private function getTextDelegate(resourceId:String):String { - return null; - } - - private function getImageInternal(resourceId:String, callback:ImageInfo->Void) { +class AssetsImpl extends AssetsBase { + private override function getImageInternal(resourceId:String, callback:ImageInfo->Void) { imageFromBytes(Resource.getBytes(resourceId), callback); } - private function getImageFromHaxeResource(resourceId:String, callback:String->ImageInfo->Void) { + private override function getImageFromHaxeResource(resourceId:String, callback:String->ImageInfo->Void) { imageFromBytes(Resource.getBytes(resourceId), function(imageInfo) { callback(resourceId, imageInfo); }); } - public function imageFromBytes(bytes:Bytes, callback:ImageInfo->Void) { + public override function imageFromBytes(bytes:Bytes, callback:ImageInfo->Void) { if (bytes == null) { callback(null); } @@ -39,12 +30,4 @@ class AssetsBase { } callback(imageInfo); } - - private function getFontInternal(resourceId:String, callback:FontInfo->Void) { - callback(null); - } - - private function getFontFromHaxeResource(resourceId:String, callback:String->FontInfo->Void) { - callback(resourceId, null); - } } \ No newline at end of file diff --git a/haxe/ui/backend/BackendBase.hx b/haxe/ui/backend/BackendBase.hx deleted file mode 100644 index b5d2f1f..0000000 --- a/haxe/ui/backend/BackendBase.hx +++ /dev/null @@ -1,5 +0,0 @@ -package haxe.ui.backend; - -class BackendBase { - public static var id:String = "blank"; -} diff --git a/haxe/ui/backend/BackendImpl.hx b/haxe/ui/backend/BackendImpl.hx new file mode 100644 index 0000000..0340406 --- /dev/null +++ b/haxe/ui/backend/BackendImpl.hx @@ -0,0 +1,5 @@ +package haxe.ui.backend; + +class BackendImpl { + public static var id:String = "winforms"; +} diff --git a/haxe/ui/backend/CallLaterBase.hx b/haxe/ui/backend/CallLaterImpl.hx similarity index 80% rename from haxe/ui/backend/CallLaterBase.hx rename to haxe/ui/backend/CallLaterImpl.hx index 5bd2089..423d553 100644 --- a/haxe/ui/backend/CallLaterBase.hx +++ b/haxe/ui/backend/CallLaterImpl.hx @@ -1,6 +1,6 @@ package haxe.ui.backend; -class CallLaterBase { +class CallLaterImpl { public function new(fn:Void->Void) { fn(); } diff --git a/haxe/ui/backend/ComponentBase.hx b/haxe/ui/backend/ComponentImpl.hx similarity index 72% rename from haxe/ui/backend/ComponentBase.hx rename to haxe/ui/backend/ComponentImpl.hx index e9a28ac..9cbd781 100644 --- a/haxe/ui/backend/ComponentBase.hx +++ b/haxe/ui/backend/ComponentImpl.hx @@ -12,23 +12,20 @@ import cs.system.windows.forms.Panel; import haxe.ui.backend.winforms.StyleHelper; import haxe.ui.containers.Box; import haxe.ui.core.Component; -import haxe.ui.core.ImageDisplay; -import haxe.ui.core.TextDisplay; -import haxe.ui.core.TextInput; import haxe.ui.events.MouseEvent; import haxe.ui.events.UIEvent; import haxe.ui.styles.Style; -import haxe.ui.geom.Rectangle; -class ComponentBase { +class ComponentImpl extends ComponentBase { private var _eventMap:MapVoid> = new MapVoid>(); public var control:Control; public function new() { + super(); } - public function handleCreate(native:Bool) { + public override function handleCreate(native:Bool) { var className:String = Type.getClassName(Type.getClass(this)); var nativeComponentClass:String = Toolkit.nativeConfig.query('component[id=${className}].@class', 'System.Windows.Forms.Panel', null); @@ -44,7 +41,7 @@ class ComponentBase { } } - private function handlePosition(left:Null, top:Null, style:Style) { + private override function handlePosition(left:Null, top:Null, style:Style) { if (control == null) { return; } @@ -52,7 +49,7 @@ class ComponentBase { control.Location = new Point(Std.int(left), Std.int(top)); } - private function handleSize(width:Null, height:Null, style:Style) { + private override function handleSize(width:Null, height:Null, style:Style) { if (control == null) { return; } @@ -66,7 +63,7 @@ class ComponentBase { control.Size = new Size(Std.int(width), Std.int(height)); } - private function handleReady() { + private override function handleReady() { if (Std.is(control, cs.system.windows.forms.TrackBar)) { // super crappy hack, trackbars _always_ have a grey background... if you can believe that! var parent = findParent(cs.system.windows.forms.TabControl); if (parent != null) { @@ -75,92 +72,17 @@ class ComponentBase { } } - private function handleClipRect(value:Rectangle) { - } - - public function handlePreReposition() { - } - - public function handlePostReposition() { - } - - private function handleVisibility(show:Bool) { - } - - //*********************************************************************************************************** - // Text related - //*********************************************************************************************************** - private var _textDisplay:TextDisplay; - public function createTextDisplay(text:String = null):TextDisplay { - if (_textDisplay == null) { - _textDisplay = new TextDisplay(); - } - if (text != null) { - _textDisplay.text = text; - } - return _textDisplay; - } - - public function getTextDisplay():TextDisplay { - return createTextDisplay(); - } - - public function hasTextDisplay():Bool { - return (_textDisplay != null); - } - - private var _textInput:TextInput; - public function createTextInput(text:String = null):TextInput { - if (_textInput == null) { - _textInput = new TextInput(); - } - if (text != null) { - _textInput.text = text; - } - return _textInput; - } - - public function getTextInput():TextInput { - return createTextInput(); - } - - public function hasTextInput():Bool { - return (_textInput != null); - } - - //*********************************************************************************************************** - // Image related - //*********************************************************************************************************** - private var _imageDisplay:ImageDisplay; - public function createImageDisplay():ImageDisplay { - if (_imageDisplay == null) { - _imageDisplay = new ImageDisplay(); - } - return _imageDisplay; - } - - public function getImageDisplay():ImageDisplay { - return createImageDisplay(); - } - - public function hasImageDisplay():Bool { - return (_imageDisplay != null); - } - - public function removeImageDisplay() { - if (_imageDisplay != null) { - _imageDisplay = null; - } + private override function handleVisibility(show:Bool) { } //*********************************************************************************************************** // Display tree //*********************************************************************************************************** - private function handleSetComponentIndex(child:Component, index:Int) { + private override function handleSetComponentIndex(child:Component, index:Int) { } - private function handleAddComponent(child:Component):Component { + private override function handleAddComponent(child:Component):Component { if (Std.is(this.control, cs.system.windows.forms.TabControl)) { var tabControl = cast(this.control, cs.system.windows.forms.TabControl); @@ -191,20 +113,20 @@ class ComponentBase { return child; } - private function handleAddComponentAt(child:Component, index:Int):Component { + private override function handleAddComponentAt(child:Component, index:Int):Component { return child; } - private function handleRemoveComponent(child:Component, dispose:Bool = true):Component { + private override function handleRemoveComponent(child:Component, dispose:Bool = true):Component { control.Controls.Remove(child.control); return child; } - private function handleRemoveComponentAt(index:Int, dispose:Bool = true):Component { + private override function handleRemoveComponentAt(index:Int, dispose:Bool = true):Component { return null; } - private function applyStyle(style:Style) { + private override function applyStyle(style:Style) { if (control == null) { return; } @@ -249,7 +171,7 @@ class ComponentBase { //*********************************************************************************************************** // Events //*********************************************************************************************************** - private function mapEvent(type:String, listener:UIEvent->Void) { + private override function mapEvent(type:String, listener:UIEvent->Void) { switch (type) { case MouseEvent.CLICK: if (_eventMap.exists(type) == false) { @@ -270,7 +192,7 @@ class ComponentBase { } } - private function unmapEvent(type:String, listener:UIEvent->Void) { + private override function unmapEvent(type:String, listener:UIEvent->Void) { switch (type) { case MouseEvent.CLICK: _eventMap.remove(type); diff --git a/haxe/ui/backend/ComponentSurface.hx b/haxe/ui/backend/ComponentSurface.hx new file mode 100644 index 0000000..cc58586 --- /dev/null +++ b/haxe/ui/backend/ComponentSurface.hx @@ -0,0 +1,6 @@ +package haxe.ui.backend; + +class ComponentSurface { + public function new() { + } +} \ No newline at end of file diff --git a/haxe/ui/backend/EventBase.hx b/haxe/ui/backend/EventBase.hx deleted file mode 100644 index 3226d5d..0000000 --- a/haxe/ui/backend/EventBase.hx +++ /dev/null @@ -1,13 +0,0 @@ -package haxe.ui.backend; -import haxe.ui.events.UIEvent; - -class EventBase { - public function new() { - } - - public function cancel() { - } - - private function postClone(event:UIEvent) { - } -} \ No newline at end of file diff --git a/haxe/ui/backend/EventImpl.hx b/haxe/ui/backend/EventImpl.hx new file mode 100644 index 0000000..d5e2b01 --- /dev/null +++ b/haxe/ui/backend/EventImpl.hx @@ -0,0 +1,4 @@ +package haxe.ui.backend; + +class EventImpl extends EventBase { +} \ No newline at end of file diff --git a/haxe/ui/backend/ImageDisplayBase.hx b/haxe/ui/backend/ImageDisplayBase.hx deleted file mode 100644 index a76ee48..0000000 --- a/haxe/ui/backend/ImageDisplayBase.hx +++ /dev/null @@ -1,35 +0,0 @@ -package haxe.ui.backend; - -import haxe.ui.core.Component; -import haxe.ui.geom.Rectangle; -import haxe.ui.assets.ImageInfo; - -class ImageDisplayBase { - public var parentComponent:Component; - - private var _left:Float; - private var _top:Float; - private var _imageWidth:Float; - private var _imageHeight:Float; - private var _imageInfo:ImageInfo; - private var _imageClipRect:Rectangle; - - public function new() { - } - - private function validateData() { - - } - - private function validateStyle():Bool { - return false; - } - - private function validatePosition() { - - } - - private function validateDisplay() { - - } -} \ No newline at end of file diff --git a/haxe/ui/backend/ImageDisplayImpl.hx b/haxe/ui/backend/ImageDisplayImpl.hx new file mode 100644 index 0000000..6b3d24a --- /dev/null +++ b/haxe/ui/backend/ImageDisplayImpl.hx @@ -0,0 +1,4 @@ +package haxe.ui.backend; + +class ImageDisplayImpl extends ImageBase { +} \ No newline at end of file diff --git a/haxe/ui/backend/ImageSurface.hx b/haxe/ui/backend/ImageSurface.hx new file mode 100644 index 0000000..518dcb1 --- /dev/null +++ b/haxe/ui/backend/ImageSurface.hx @@ -0,0 +1,6 @@ +package haxe.ui.backend; + +class ImageSurface { + public function new() { + } +} \ No newline at end of file diff --git a/haxe/ui/backend/PlatformBase.hx b/haxe/ui/backend/PlatformImpl.hx similarity index 64% rename from haxe/ui/backend/PlatformBase.hx rename to haxe/ui/backend/PlatformImpl.hx index e4151b5..56aca25 100644 --- a/haxe/ui/backend/PlatformBase.hx +++ b/haxe/ui/backend/PlatformImpl.hx @@ -1,14 +1,15 @@ package haxe.ui.backend; + import haxe.ui.core.Platform; -class PlatformBase { - public function getMetric(id:String):Float { +class PlatformImpl extends PlatformBase { + public override function getMetric(id:String):Float { switch (id) { case Platform.METRIC_VSCROLL_WIDTH: return 16; case Platform.METRIC_HSCROLL_HEIGHT: return 16; } - return 0; + return super.getMetric(id); } } \ No newline at end of file diff --git a/haxe/ui/backend/ScreenBase.hx b/haxe/ui/backend/ScreenImpl.hx similarity index 55% rename from haxe/ui/backend/ScreenBase.hx rename to haxe/ui/backend/ScreenImpl.hx index d6b26a8..8cc5f11 100644 --- a/haxe/ui/backend/ScreenBase.hx +++ b/haxe/ui/backend/ScreenImpl.hx @@ -1,40 +1,21 @@ package haxe.ui.backend; +import cs.system.windows.forms.Form; import haxe.ui.core.Component; import haxe.ui.events.UIEvent; -import cs.system.windows.forms.Form; -class ScreenBase { +class ScreenImpl extends ScreenBase { public function new() { } - - public var focus:Component; - - private var _options:Dynamic; - public var options(get, set):Dynamic; - private function get_options():Dynamic { - return _options; - } - private function set_options(value:Dynamic):Dynamic { - _options = value; - return value; - } - - public var width(get, null):Float; - private function get_width():Float { + + private override function get_width():Float { return form.ClientSize.Width; } - public var height(get, null):Float; - private function get_height():Float { + private override function get_height():Float { return form.ClientSize.Height; } - public var dpi(get, null):Float; - private function get_dpi():Float { - return 72; - } - public var form(get, null):Form; private function get_form():Form { if (options == null || options.form == null) { @@ -43,30 +24,29 @@ class ScreenBase { return options.form; } - public var title(get, set):String; - private inline function get_title():String { + private override function get_title():String { return form.Text; } - private inline function set_title(t:String):String { + private override function set_title(t:String):String { return form.Text = t; } private var __topLevelComponents:Array = new Array(); - public function addComponent(component:Component) { + public override function addComponent(component:Component) { __topLevelComponents.push(component); form.Controls.Add(component.control); resizeComponent(component); } - public function removeComponent(component:Component) { + public override function removeComponent(component:Component) { __topLevelComponents.remove(component); form.Controls.Remove(component.control); } - private function handleSetComponentIndex(child:Component, index:Int) { + private override function handleSetComponentIndex(child:Component, index:Int) { } - private function resizeComponent(c:Component) { + private override function resizeComponent(c:Component) { //c.lock(); var cx:Null = null; var cy:Null = null; @@ -83,13 +63,13 @@ class ScreenBase { //*********************************************************************************************************** // Events //*********************************************************************************************************** - private function supportsEvent(type:String):Bool { + private override function supportsEvent(type:String):Bool { return false; } - private function mapEvent(type:String, listener:UIEvent->Void) { + private override function mapEvent(type:String, listener:UIEvent->Void) { } - private function unmapEvent(type:String, listener:UIEvent->Void) { + private override function unmapEvent(type:String, listener:UIEvent->Void) { } } \ No newline at end of file diff --git a/haxe/ui/backend/TextDisplayBase.hx b/haxe/ui/backend/TextDisplayBase.hx deleted file mode 100644 index 9af12a6..0000000 --- a/haxe/ui/backend/TextDisplayBase.hx +++ /dev/null @@ -1,47 +0,0 @@ -package haxe.ui.backend; - -import haxe.ui.assets.FontInfo; -import haxe.ui.core.Component; -import haxe.ui.core.TextDisplay.TextDisplayData; -import haxe.ui.styles.Style; - -class TextDisplayBase { - public var parentComponent:Component; - - private var _text:String; - private var _textStyle:Style; - - private var _left:Float; - private var _top:Float; - private var _width:Float; - private var _height:Float; - private var _textWidth:Float; - private var _textHeight:Float; - - private var _fontInfo:FontInfo; - - private var _displayData:TextDisplayData = new TextDisplayData(); - - public function new() { - } - - private function validateData() { - - } - - private function validateStyle():Bool { - return false; - } - - private function validatePosition() { - - } - - private function validateDisplay() { - - } - - private function measureText() { - - } -} \ No newline at end of file diff --git a/haxe/ui/backend/TextDisplayImpl.hx b/haxe/ui/backend/TextDisplayImpl.hx new file mode 100644 index 0000000..136a962 --- /dev/null +++ b/haxe/ui/backend/TextDisplayImpl.hx @@ -0,0 +1,4 @@ +package haxe.ui.backend; + +class TextDisplayImpl extends TextBase { +} \ No newline at end of file diff --git a/haxe/ui/backend/TextInputBase.hx b/haxe/ui/backend/TextInputBase.hx deleted file mode 100644 index c7bedef..0000000 --- a/haxe/ui/backend/TextInputBase.hx +++ /dev/null @@ -1,18 +0,0 @@ -package haxe.ui.backend; -import haxe.ui.core.TextInput.TextInputData; - -class TextInputBase extends TextDisplayBase { - private var _inputData:TextInputData = new TextInputData(); - - public function new() { - super(); - } - - public function focus() { - - } - - public function blur() { - - } -} diff --git a/haxe/ui/backend/TextInputImpl.hx b/haxe/ui/backend/TextInputImpl.hx new file mode 100644 index 0000000..2b24fab --- /dev/null +++ b/haxe/ui/backend/TextInputImpl.hx @@ -0,0 +1,4 @@ +package haxe.ui.backend; + +class TextInputImpl extends TextDisplayImpl { +} diff --git a/haxe/ui/backend/TimerBase.hx b/haxe/ui/backend/TimerImpl.hx similarity index 97% rename from haxe/ui/backend/TimerBase.hx rename to haxe/ui/backend/TimerImpl.hx index e7a4428..8f0de77 100644 --- a/haxe/ui/backend/TimerBase.hx +++ b/haxe/ui/backend/TimerImpl.hx @@ -4,7 +4,7 @@ import cs.system.windows.forms.Timer; import cs.system.EventHandler; import cs.system.EventArgs; -class TimerBase { +class TimerImpl { private var _timer:Timer; private var _callback:Void->Void; diff --git a/haxe/ui/backend/ToolkitOptions.hx b/haxe/ui/backend/ToolkitOptions.hx index c769e20..1d7189d 100644 --- a/haxe/ui/backend/ToolkitOptions.hx +++ b/haxe/ui/backend/ToolkitOptions.hx @@ -3,5 +3,5 @@ package haxe.ui.backend; import cs.system.windows.forms.Form; typedef ToolkitOptions = { - form:Form + ?form:Form }