[hw.app] add hw.app package
This commit is contained in:
86
src/haxe/hw/app/App.hx
Normal file
86
src/haxe/hw/app/App.hx
Normal file
@@ -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<Dynamic>;
|
||||
|
||||
private function set_view(value:IView<Dynamic>):IView<Dynamic> {
|
||||
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<Bool> = 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<Dynamic>):IAnimate {
|
||||
return new UnFadeAnimate(view);
|
||||
}
|
||||
|
||||
private function createCloseAnimate(view:IView<Dynamic>):IAnimate {
|
||||
return new FadeAnimate(view);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.m.puzzlez;
|
||||
package hw.app;
|
||||
|
||||
import flash.Lib;
|
||||
import flash.system.Capabilities;
|
||||
29
src/haxe/hw/app/LinuxIcon.hx
Normal file
29
src/haxe/hw/app/LinuxIcon.hx
Normal file
@@ -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<Float> = [];
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 _:
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,5 +16,5 @@ views:
|
||||
geometry.vAlign: bottom
|
||||
geometry.margin: 10
|
||||
style: icon.expand
|
||||
+onPress: ~Device.toggleFullScreen()
|
||||
+onPress: ~_ -> app.fullScreen = !app.fullScreen
|
||||
visible: false
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user