From 83ed6cc076800b142bb9ed84be3013e2cf743386 Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 24 Mar 2020 17:03:33 +0300 Subject: [PATCH] [hw.app] add hw.app package --- src/haxe/hw/app/App.hx | 86 +++++++++++++++++++ src/haxe/{ru/m/puzzlez => hw/app}/Const.hx | 2 +- src/haxe/hw/app/LinuxIcon.hx | 29 +++++++ src/haxe/ru/m/puzzlez/PuzzlezApp.hx | 13 +-- src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx | 18 ++-- .../ru/m/puzzlez/view/PuzzlezAppView.yaml | 2 +- src/haxe/ru/m/puzzlez/view/StartFrame.yaml | 4 +- 7 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 src/haxe/hw/app/App.hx rename src/haxe/{ru/m/puzzlez => hw/app}/Const.hx (96%) create mode 100644 src/haxe/hw/app/LinuxIcon.hx diff --git a/src/haxe/hw/app/App.hx b/src/haxe/hw/app/App.hx new file mode 100644 index 0000000..45edf36 --- /dev/null +++ b/src/haxe/hw/app/App.hx @@ -0,0 +1,86 @@ +package hw.app; + +import flash.Lib; +import haxework.animate.Animate; +import haxework.animate.FadeAnimate; +import haxework.animate.IAnimate; +import haxework.animate.UnFadeAnimate; +import haxework.resources.IResources; +import haxework.signal.Signal; +import haxework.view.IView; +import haxework.view.popup.PopupManager; +import haxework.view.Root; +import haxework.view.theme.ITheme; +import openfl.display.BitmapData; +import openfl.display.StageDisplayState; +import openfl.events.FullScreenEvent; + +class App { + + public var view(default, set):IView; + + private function set_view(value:IView):IView { + view = value; + Root.bind(view); + return view; + } + + public var icon(default, set):BitmapData; + + private function set_icon(value:BitmapData):BitmapData { + icon = value; + #if linux + if (icon != null) { + hw.app.LinuxIcon.value = icon; + } + #end + return icon; + } + + public var fullScreenSupport(get, never):Bool; + + public function get_fullScreenSupport():Bool { + return Lib.current.stage.allowsFullScreen; + } + + public var fullScreen(get, set):Bool; + + private function get_fullScreen():Bool { + return Lib.current.stage.displayState != StageDisplayState.NORMAL; + } + + private function set_fullScreen(value:Bool):Bool { + Lib.current.stage.displayState = value ? StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL; + return get_fullScreen(); + } + + public var fullScreenSignal(default, null):Signal = new Signal(); + + @:provide static var app:App; + @:provide static var resources:IResources; + @:provide static var popupManager:PopupManager; + + @:provide public var theme:ITheme; + + public function new() { + Lib.current.stage.stageFocusRect = false; + Lib.current.stage.addEventListener(FullScreenEvent.FULL_SCREEN, event -> fullScreenSignal.emit(event.fullScreen)); + Animate.bind(Lib.current.stage); + + popupManager.showAnimateFactory = createShowAnimate; + popupManager.closeAnimateFactory = createCloseAnimate; + + resources.text.put("app.version", Const.instance.VERSION); + resources.text.put("app.name", Const.instance.NAME); + + app = this; + } + + private function createShowAnimate(view:IView):IAnimate { + return new UnFadeAnimate(view); + } + + private function createCloseAnimate(view:IView):IAnimate { + return new FadeAnimate(view); + } +} diff --git a/src/haxe/ru/m/puzzlez/Const.hx b/src/haxe/hw/app/Const.hx similarity index 96% rename from src/haxe/ru/m/puzzlez/Const.hx rename to src/haxe/hw/app/Const.hx index c6bc771..7fba90c 100755 --- a/src/haxe/ru/m/puzzlez/Const.hx +++ b/src/haxe/hw/app/Const.hx @@ -1,4 +1,4 @@ -package ru.m.puzzlez; +package hw.app; import flash.Lib; import flash.system.Capabilities; diff --git a/src/haxe/hw/app/LinuxIcon.hx b/src/haxe/hw/app/LinuxIcon.hx new file mode 100644 index 0000000..6c556ce --- /dev/null +++ b/src/haxe/hw/app/LinuxIcon.hx @@ -0,0 +1,29 @@ +package hw.app; + +import flash.display.BitmapData; +import flash.filters.ColorMatrixFilter; +import flash.geom.Point; +import flash.Lib; + +class LinuxIcon { + + public static var value(default, set):BitmapData; + + private static function set_value(value:BitmapData):BitmapData { + LinuxIcon.value = value; + Lib.current.stage.window.setIcon(prepareIcon(value).image); + return LinuxIcon.value; + } + + private static function prepareIcon(bitmap:BitmapData):BitmapData { + var matrix:Array = []; + matrix = matrix.concat([0, 0, 1, 0, 0]); + matrix = matrix.concat([0, 1, 0, 0, 0]); + matrix = matrix.concat([1, 0, 0, 0, 0]); + matrix = matrix.concat([0, 0, 0, 1, 0]); + var cmf:ColorMatrixFilter = new ColorMatrixFilter(matrix); + var bitmap:BitmapData = bitmap.clone(); + bitmap.applyFilter(bitmap, bitmap.rect, new Point(0, 0), cmf); + return bitmap; + } +} diff --git a/src/haxe/ru/m/puzzlez/PuzzlezApp.hx b/src/haxe/ru/m/puzzlez/PuzzlezApp.hx index fb8b8ad..3b0e3f8 100644 --- a/src/haxe/ru/m/puzzlez/PuzzlezApp.hx +++ b/src/haxe/ru/m/puzzlez/PuzzlezApp.hx @@ -1,14 +1,15 @@ package ru.m.puzzlez; -import haxework.App; import haxework.log.TraceLogger; +import hw.app.App; +import hw.app.Const; import ru.m.puzzlez.storage.GameStorage; import ru.m.puzzlez.storage.ImageStorage; import ru.m.puzzlez.storage.SettingsStorage; import ru.m.puzzlez.view.PuzzlezAppView; import ru.m.update.Updater; -class PuzzlezApp extends App { +class PuzzlezApp { @:provide static var updater:Updater; @@ -19,10 +20,10 @@ class PuzzlezApp extends App { SettingsStorage; L.push(new TraceLogger()); updater = new Updater(Const.instance.VERSION, "https://shmyga.ru/repo/puzzlez/packages.json"); - var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png")); - var view = new PuzzlezAppView(); - app.start(view); - view.launch(); + var app = new App(); + app.theme = new PuzzlezTheme(); + app.icon = openfl.Assets.getBitmapData("resources/icon.png"); + app.view = new PuzzlezAppView(); L.d("Puzzlez", "started"); } } diff --git a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx index bae88f2..7b373b6 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx +++ b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.hx @@ -2,37 +2,31 @@ package ru.m.puzzlez.view; import flash.events.KeyboardEvent; import flash.ui.Keyboard; -import haxework.resources.IResources; import haxework.view.form.ButtonView; import haxework.view.frame.FrameSwitcher; import haxework.view.group.VGroupView; +import hw.app.App; @:template class PuzzlezAppView extends VGroupView { @:view("switcher") var switcherView:FrameSwitcher; @:view("fullscreen") var fullscreenButton:ButtonView; - @:provide var switcher:FrameSwitcher; - @:provide var resources:IResources; + @:provide static var switcher:FrameSwitcher; + @:provide static var app:App; public function new() { super(); - resources.text.put("version", Const.instance.VERSION); - resources.text.put("name", Const.instance.NAME); + fullscreenButton.visible = app.fullScreenSupport; + app.fullScreenSignal.connect(fs -> fullscreenButton.style = 'icon.${fs ? "compress" : "expand"}'); switcher = switcherView; - fullscreenButton.visible = Device.fullScreenSupport; - Device.fullScreenSignal.connect(fullscreen -> fullscreenButton.style = fullscreen ? "icon.compress" : "icon.expand"); - } - - public function launch():Void { - content.stage.stageFocusRect = false; switcher.change(StartFrame.ID); stage.addEventListener(KeyboardEvent.KEY_DOWN, (event:KeyboardEvent) -> { switch event.keyCode { case Keyboard.ESCAPE: switcher.change(StartFrame.ID); case Keyboard.F: - Device.toggleFullScreen(); + app.fullScreen = !app.fullScreen; case _: } }); diff --git a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml index 343bb54..2ea0ed6 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml +++ b/src/haxe/ru/m/puzzlez/view/PuzzlezAppView.yaml @@ -16,5 +16,5 @@ views: geometry.vAlign: bottom geometry.margin: 10 style: icon.expand - +onPress: ~Device.toggleFullScreen() + +onPress: ~_ -> app.fullScreen = !app.fullScreen visible: false diff --git a/src/haxe/ru/m/puzzlez/view/StartFrame.yaml b/src/haxe/ru/m/puzzlez/view/StartFrame.yaml index 794d4b4..16f016c 100644 --- a/src/haxe/ru/m/puzzlez/view/StartFrame.yaml +++ b/src/haxe/ru/m/puzzlez/view/StartFrame.yaml @@ -13,7 +13,7 @@ views: geometry.width: 96 geometry.height: 96 - $type: haxework.view.form.LabelView - text: $r:text:name + text: $r:text:app.name font.size: 50 - id: sources $type: haxework.view.data.DataView @@ -43,7 +43,7 @@ views: - $type: haxework.view.SpriteView geometry.width: 100% - $type: haxework.view.form.LabelView - text: $r:text:version + text: $r:text:app.version geometry.position: absolute geometry.hAlign: right geometry.vAlign: top