diff --git a/src/haxe/ru/m/puzzlez/LinuxIcon.hx b/src/haxe/ru/m/puzzlez/LinuxIcon.hx deleted file mode 100644 index f73d94b..0000000 --- a/src/haxe/ru/m/puzzlez/LinuxIcon.hx +++ /dev/null @@ -1,27 +0,0 @@ -package ru.m.puzzlez; - -import flash.display.BitmapData; -import flash.filters.ColorMatrixFilter; -import flash.geom.Point; -import flash.Lib; -import openfl.Assets; - -class LinuxIcon { - - 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; - } - - public static function apply() { - var icon = Assets.getBitmapData("resources/icon.png"); - Lib.current.stage.window.setIcon(prepareIcon(icon).image); - } -} diff --git a/src/haxe/ru/m/puzzlez/PuzzlezApp.hx b/src/haxe/ru/m/puzzlez/PuzzlezApp.hx index 7ee74ff..d61751a 100644 --- a/src/haxe/ru/m/puzzlez/PuzzlezApp.hx +++ b/src/haxe/ru/m/puzzlez/PuzzlezApp.hx @@ -8,10 +8,7 @@ class PuzzlezApp extends App { public static function main() { L.push(new TraceLogger()); - #if linux - LinuxIcon.apply(); - #end - var app = new PuzzlezApp(new PuzzlezTheme()); + var app = new PuzzlezApp(new PuzzlezTheme(), openfl.Assets.getBitmapData("resources/icon.png")); var view = new PuzzlezAppView(); app.start(view); view.launch(); diff --git a/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx b/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx index c24d5c8..d7e0cfe 100644 --- a/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx +++ b/src/haxe/ru/m/puzzlez/PuzzlezTheme.hx @@ -1,5 +1,7 @@ package ru.m.puzzlez; +import haxework.view.geometry.VAlign; +import haxework.view.geometry.HAlign; import haxework.color.Color; import haxework.view.geometry.Box; import haxework.view.geometry.SizeValue; @@ -11,7 +13,9 @@ class PuzzlezTheme extends Theme { public function new() { super({embed: true}, {light: "gray"}, {base: 22}); - data.get("frame").data.set("geometry.padding", Box.fromFloat(8)); + register(new Style("frame", [ + "geometry.padding" => Box.fromFloat(8), + ])); register(new Style("view", [ "skin.background.color" => colors.light, "skin.border.color" => colors.border, @@ -22,25 +26,31 @@ class PuzzlezTheme extends Theme { register(new Style("text.error", [ "font.color" => Color.fromString("red"), ], "text")); - registerButton("close", "times-circle-solid.svg", false, 0xcc5500); - registerButton("close-red", "times-circle-solid.svg", false, 0xcc0000); - } - private function registerButton(name:String, resource:String, solid:Bool = false, color:Color = null):Void { - if (color == null) { - color = colors.light; - } var size = 42; var smallSize = 32; - register(new Style('button.$name', [ + register(new Style("icon", [ "geometry.width" => SizeValue.fromInt(size), "geometry.height" => SizeValue.fromInt(size), - "skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), color, solid), + "skin" => function() return new ButtonSVGSkin(), ])); - register(new Style('button.$name.small', [ + register(new Style("icon.close", [ + "skin.svg" => Assets.getText("resources/image/icon/times-circle-solid.svg"), + ])); + register(new Style("icon.small", [ "geometry.width" => SizeValue.fromInt(smallSize), "geometry.height" => SizeValue.fromInt(smallSize), - "skin" => function() return new ButtonSVGSkin(Assets.getText('resources/image/icon/$resource'), color, solid), + ])); + register(new Style("icon.red", [ + "skin.color" => 0xcc0000, + ])); + register(new Style("icon.orange", [ + "skin.color" => 0xcc5500, + ])); + register(new Style("icon.control", [ + "geometry.hAlign" => HAlign.RIGHT, + "geometry.vAlign" => VAlign.TOP, + "geometry.margin" => Box.fromFloat(3), ])); } } diff --git a/src/haxe/ru/m/puzzlez/core/Game.hx b/src/haxe/ru/m/puzzlez/core/Game.hx index adbac12..b25a3d5 100644 --- a/src/haxe/ru/m/puzzlez/core/Game.hx +++ b/src/haxe/ru/m/puzzlez/core/Game.hx @@ -1,6 +1,6 @@ package ru.m.puzzlez.core; -import flash.geom.Point; +import haxework.geom.Point; import haxework.signal.Signal; import ru.m.puzzlez.core.GameEvent; import ru.m.puzzlez.core.PartLocation; @@ -66,7 +66,7 @@ class Game implements IGame { signal.emit(CHANGE(PART_UPDATE(id, part.location))); case ACTION(PART_PUT(id, point)): var part:Part = partsById[id]; - var target:Point = state.preset.imageRect.topLeft.clone(); + var target:Point = state.preset.imageRect.position.clone(); target = target.add(new Point(part.gridX * part.rect.width, part.gridY * part.rect.height)); var d = distance(target, point); if (d < 70) { diff --git a/src/haxe/ru/m/puzzlez/core/GameEvent.hx b/src/haxe/ru/m/puzzlez/core/GameEvent.hx index 024f0ac..6a03050 100644 --- a/src/haxe/ru/m/puzzlez/core/GameEvent.hx +++ b/src/haxe/ru/m/puzzlez/core/GameEvent.hx @@ -1,6 +1,6 @@ package ru.m.puzzlez.core; -import flash.geom.Point; +import haxework.geom.Point; enum GameAction { PART_TAKE(id:Int); diff --git a/src/haxe/ru/m/puzzlez/core/GamePreset.hx b/src/haxe/ru/m/puzzlez/core/GamePreset.hx index 61ef6bc..d6de9ed 100644 --- a/src/haxe/ru/m/puzzlez/core/GamePreset.hx +++ b/src/haxe/ru/m/puzzlez/core/GamePreset.hx @@ -1,6 +1,6 @@ package ru.m.puzzlez.core; -import flash.geom.Rectangle; +import haxework.geom.Rectangle; import ru.m.puzzlez.core.Id; typedef GamePreset = { diff --git a/src/haxe/ru/m/puzzlez/core/GameUtil.hx b/src/haxe/ru/m/puzzlez/core/GameUtil.hx index 2ff8f73..c2de29f 100644 --- a/src/haxe/ru/m/puzzlez/core/GameUtil.hx +++ b/src/haxe/ru/m/puzzlez/core/GameUtil.hx @@ -1,7 +1,7 @@ package ru.m.puzzlez.core; -import flash.geom.Point; -import flash.geom.Rectangle; +import haxework.geom.Point; +import haxework.geom.Rectangle; import ru.m.puzzlez.core.BoundType; import ru.m.puzzlez.core.Id; import ru.m.puzzlez.core.Part; @@ -90,7 +90,7 @@ class GameUtil { var parts:Array = []; var partWidth = preset.imageRect.width / preset.grid.width; var partHeight = preset.imageRect.height / preset.grid.height; - var topLeft = preset.imageRect.topLeft; + var position = preset.imageRect.position; var boundsMap = new BoundsMap(preset.grid); for (y in 0...preset.grid.height) { for (x in 0...preset.grid.width) { @@ -113,7 +113,7 @@ class GameUtil { bounds.bottom = boundsMap.buildNonePartBound(); } var id = (x << 16) + y; - var position = new Point(topLeft.x + x * partWidth, topLeft.y + y * partHeight); + var position = new Point(position.x + x * partWidth, position.y + y * partHeight); parts.push({ id: id, gridX: x, diff --git a/src/haxe/ru/m/puzzlez/core/Part.hx b/src/haxe/ru/m/puzzlez/core/Part.hx index 9e55fb4..0311308 100644 --- a/src/haxe/ru/m/puzzlez/core/Part.hx +++ b/src/haxe/ru/m/puzzlez/core/Part.hx @@ -1,6 +1,6 @@ package ru.m.puzzlez.core; -import flash.geom.Rectangle; +import haxework.geom.Rectangle; typedef PartBound = { var spike:BoundType; diff --git a/src/haxe/ru/m/puzzlez/core/PartLocation.hx b/src/haxe/ru/m/puzzlez/core/PartLocation.hx index 46061ef..cf0881d 100644 --- a/src/haxe/ru/m/puzzlez/core/PartLocation.hx +++ b/src/haxe/ru/m/puzzlez/core/PartLocation.hx @@ -1,6 +1,6 @@ package ru.m.puzzlez.core; -import flash.geom.Point; +import haxework.geom.Point; enum PartLocation { //PANEL(index:Int); diff --git a/src/haxe/ru/m/puzzlez/render/PartView.hx b/src/haxe/ru/m/puzzlez/render/PartView.hx index c63164e..d2de079 100644 --- a/src/haxe/ru/m/puzzlez/render/PartView.hx +++ b/src/haxe/ru/m/puzzlez/render/PartView.hx @@ -1,10 +1,10 @@ package ru.m.puzzlez.render; +import haxework.geom.Point; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.PixelSnapping; import flash.display.Sprite; -import flash.geom.Point; import ru.m.puzzlez.core.Part; class PartView extends Sprite { diff --git a/src/haxe/ru/m/puzzlez/render/Render.hx b/src/haxe/ru/m/puzzlez/render/Render.hx index d6d31e4..5ce20bd 100644 --- a/src/haxe/ru/m/puzzlez/render/Render.hx +++ b/src/haxe/ru/m/puzzlez/render/Render.hx @@ -1,10 +1,11 @@ package ru.m.puzzlez.render; +import haxework.geom.Point; import flash.display.BitmapData; import flash.display.PNGEncoderOptions; import flash.display.Sprite; import flash.events.MouseEvent; -import flash.geom.Point; +import flash.geom.Point as FlashPoint; import flash.geom.Rectangle; import flash.net.FileReference; import flash.utils.ByteArray; @@ -138,7 +139,7 @@ class Render extends SpriteView implements IRender { } activePart = part; tableView.setChildIndex(activePart, tableView.numChildren - 1); - activePoint = tableView.globalToLocal(new Point(event.stageX, event.stageY)); + activePoint = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY)); tableView.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); tableView.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); signal.emit(ACTION(PART_TAKE(activePart.id))); @@ -146,14 +147,14 @@ class Render extends SpriteView implements IRender { } private function onMouseMove(event:MouseEvent):Void { - var newPoint = tableView.globalToLocal(new Point(event.stageX, event.stageY)); + var newPoint:Point = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY)); var partPosition = activePart.position.add(newPoint).subtract(activePoint); signal.emit(ACTION(PART_MOVE(activePart.id, partPosition.clone()))); activePoint = newPoint; } private function onMouseUp(event:MouseEvent):Void { - var newPoint = tableView.globalToLocal(new Point(event.stageX, event.stageY)); + var newPoint:Point = tableView.globalToLocal(new FlashPoint(event.stageX, event.stageY)); var partPosition = activePart.position.add(newPoint).subtract(activePoint); signal.emit(ACTION(PART_PUT(activePart.id, partPosition.clone()))); tableView.stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove); diff --git a/src/haxe/ru/m/puzzlez/render/RenderUtil.hx b/src/haxe/ru/m/puzzlez/render/RenderUtil.hx index 8c6c25e..cb723c5 100644 --- a/src/haxe/ru/m/puzzlez/render/RenderUtil.hx +++ b/src/haxe/ru/m/puzzlez/render/RenderUtil.hx @@ -6,7 +6,7 @@ import flash.filters.BitmapFilter; import flash.filters.BitmapFilterQuality; import flash.filters.DropShadowFilter; import flash.geom.Matrix; -import flash.geom.Rectangle; +import haxework.geom.Rectangle; import ru.m.puzzlez.core.Part; import ru.m.puzzlez.render.mask.PartMask; diff --git a/src/haxe/ru/m/puzzlez/render/mask/BaseMaskBuilder.hx b/src/haxe/ru/m/puzzlez/render/mask/BaseMaskBuilder.hx index 0eea81d..ad40d35 100644 --- a/src/haxe/ru/m/puzzlez/render/mask/BaseMaskBuilder.hx +++ b/src/haxe/ru/m/puzzlez/render/mask/BaseMaskBuilder.hx @@ -1,7 +1,7 @@ package ru.m.puzzlez.render.mask; import flash.display.GraphicsPathCommand; -import flash.geom.Rectangle; +import haxework.geom.Rectangle; import openfl.Vector; import ru.m.puzzlez.core.Part; import ru.m.puzzlez.render.mask.IPartMaskBuilder; diff --git a/src/haxe/ru/m/puzzlez/render/mask/IPartMaskBuilder.hx b/src/haxe/ru/m/puzzlez/render/mask/IPartMaskBuilder.hx index 8b5136c..43cc6e6 100644 --- a/src/haxe/ru/m/puzzlez/render/mask/IPartMaskBuilder.hx +++ b/src/haxe/ru/m/puzzlez/render/mask/IPartMaskBuilder.hx @@ -1,8 +1,8 @@ package ru.m.puzzlez.render.mask; import flash.display.GraphicsPathCommand; -import flash.geom.Rectangle; import flash.Vector; +import haxework.geom.Rectangle; import ru.m.puzzlez.core.Part; typedef DrawPath = { diff --git a/src/haxe/ru/m/puzzlez/render/mask/PartMask.hx b/src/haxe/ru/m/puzzlez/render/mask/PartMask.hx index 0746a6c..b29b656 100644 --- a/src/haxe/ru/m/puzzlez/render/mask/PartMask.hx +++ b/src/haxe/ru/m/puzzlez/render/mask/PartMask.hx @@ -1,7 +1,7 @@ package ru.m.puzzlez.render.mask; import flash.display.Shape; -import flash.geom.Rectangle; +import haxework.geom.Rectangle; import ru.m.puzzlez.core.Part; import ru.m.puzzlez.render.mask.IPartMaskBuilder; diff --git a/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx b/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx index 5acecbc..50562f8 100644 --- a/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx +++ b/src/haxe/ru/m/puzzlez/view/LoadingWrapper.hx @@ -22,8 +22,8 @@ class LoadingWrapper { private function set_promise(value:Promise):Promise { state = LOADING; value - .then(function(_) state = NONE); - //.catchError(function(error) state = ERROR(error)); + .then(function(_) state = NONE) + .catchError(function(error) state = ERROR(error)); return value; } @@ -39,7 +39,7 @@ class LoadingWrapper { overlay = loadingView; case ERROR(error): cast(errorView, TextView).text = Std.string(error); - //overlay = errorView; + overlay = errorView; } } return state; diff --git a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml index 1a376fd..20e13f7 100644 --- a/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml +++ b/src/haxe/ru/m/puzzlez/view/PuzzleImageView.yaml @@ -11,12 +11,10 @@ views: - id: remove $type: haxework.view.form.ButtonView propagation: false - geometry.hAlign: right - style: button.close-red.small + style: icon.control.small.close.red +onPress: ~emit(Action.REMOVE) - id: clean $type: haxework.view.form.ButtonView propagation: false - geometry.hAlign: right - style: button.close.small + style: icon.control.small.close.orange +onPress: ~emit(Action.CLEAN) diff --git a/src/haxe/ru/m/skin/ButtonSVGSkin.hx b/src/haxe/ru/m/skin/ButtonSVGSkin.hx index 807002e..56d993d 100644 --- a/src/haxe/ru/m/skin/ButtonSVGSkin.hx +++ b/src/haxe/ru/m/skin/ButtonSVGSkin.hx @@ -15,31 +15,36 @@ using haxework.color.ColorUtil; @:style(false) public var solid:Null; private var svgs:Map; + private var needUpdate:Bool; public function new(?svg:String, ?color:Color, ?solid:Bool) { this.svg = svg; this.color = color; this.solid = solid; - init(solid); + this.needUpdate = true; } private inline function buildSVG(color:Color):SVG { return new SVG(svg.replace("currentColor", '#${color}')); } - private function init(solid:Bool):Void { - var color = color; - if (solid) { - color = color.multiply(1.5); + private function update():Void { + if (needUpdate && svg != null) { + var color = color; + if (solid) { + color = color.multiply(1.5); + } + svgs = new Map(); + svgs.set(UP, buildSVG(color)); + svgs.set(DOWN, buildSVG(color.diff(-24))); + svgs.set(OVER, buildSVG(color.diff(24))); + svgs.set(DISABLED, buildSVG(color.grey())); + needUpdate = false; } - svgs = new Map(); - svgs.set(UP, buildSVG(color)); - svgs.set(DOWN, buildSVG(color.diff(-24))); - svgs.set(OVER, buildSVG(color.diff(24))); - svgs.set(DISABLED, buildSVG(color.grey())); } public function draw(view:ButtonView):Void { + update(); var svg = svgs.get(view.state); var graphics = view.content.graphics; graphics.beginFill(0, 0);