From fd404111ce57d16779a5a7d13d603299fbb9c613 Mon Sep 17 00:00:00 2001 From: shmyga Date: Mon, 24 Mar 2014 15:17:47 +0400 Subject: [PATCH] fixe --- haxework/gui/ButtonView.hx | 8 +++++++- haxework/gui/IView.hx | 2 ++ haxework/gui/Root.hx | 2 +- haxework/gui/View.hx | 13 +++++++++++++ haxework/gui/core/HAlign.hx | 2 +- haxework/gui/core/VAlign.hx | 2 +- haxework/gui/layout/HorizontalLayout.hx | 3 +-- haxework/gui/layout/VerticalLayout.hx | 3 +-- haxework/gui/skin/ButtonColorSkin.hx | 5 ++++- 9 files changed, 31 insertions(+), 9 deletions(-) diff --git a/haxework/gui/ButtonView.hx b/haxework/gui/ButtonView.hx index 23e138a..3ad3f6a 100755 --- a/haxework/gui/ButtonView.hx +++ b/haxework/gui/ButtonView.hx @@ -29,10 +29,12 @@ class ButtonView extends LabelView { content.buttonMode = true; content.mouseChildren = false; content.addEventListener(MouseEvent.CLICK, onMouseClick); + #if !mobile content.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver); content.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut); + #end content.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); - //content.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); + content.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); } private function onMouseClick(event:MouseEvent):Void { @@ -76,7 +78,11 @@ class ButtonView extends LabelView { } private function get_state():ButtonState { + #if mobile + return downed ? ButtonState.DOWN : ButtonState.UP; + #else return (downed && overed) ? ButtonState.DOWN : overed ? ButtonState.OVER : ButtonState.UP; + #end } private function set_onPress(value:ButtonViewListener):ButtonViewListener { diff --git a/haxework/gui/IView.hx b/haxework/gui/IView.hx index dce23f8..dc818cc 100755 --- a/haxework/gui/IView.hx +++ b/haxework/gui/IView.hx @@ -28,6 +28,8 @@ interface IView { public var w(default, set):Float; public var h(default, set):Float; + public var r(default, set):Float; + public var widthType(default, null):SizeType; public var heightType(default, null):SizeType; diff --git a/haxework/gui/Root.hx b/haxework/gui/Root.hx index 8cfb6ad..3dcee6f 100755 --- a/haxework/gui/Root.hx +++ b/haxework/gui/Root.hx @@ -38,6 +38,6 @@ class Root { var content:DisplayObject = view.content; view.width = content.stage.stageWidth; view.height = content.stage.stageHeight; - //L.d("Screen", content.stage.stageWidth + "x" + content.stage.stageHeight); + L.d("Screen", content.stage.stageWidth + "x" + content.stage.stageHeight); } } diff --git a/haxework/gui/View.hx b/haxework/gui/View.hx index d529236..e91b0ea 100755 --- a/haxework/gui/View.hx +++ b/haxework/gui/View.hx @@ -25,6 +25,8 @@ class View implements IView { public var w(default, set):Float; public var h(default, set):Float; + public var r(default, set):Float; + public var widthType(default, null):SizeType; public var heightType(default, null):SizeType; @@ -117,6 +119,7 @@ class View implements IView { private function set_w(value:Float):Float { if (w != value) { w = value; + if (!Math.isNaN(r)) h = w / r; invalidate(); } return w; @@ -124,11 +127,21 @@ class View implements IView { private function set_h(value:Float):Float { if (h != value) { h = value; + if (!Math.isNaN(r)) w = h * r; invalidate(); } return h; } + private function set_r(value:Float):Float { + if (r != value) { + r = value; + invalidate(); + invalidateParent(); + } + return r; + } + private function get_width():Float { return w; } diff --git a/haxework/gui/core/HAlign.hx b/haxework/gui/core/HAlign.hx index de5a45d..4452fd7 100755 --- a/haxework/gui/core/HAlign.hx +++ b/haxework/gui/core/HAlign.hx @@ -1,6 +1,6 @@ package haxework.gui.core; -enum HAlign { +@:fakeEnum(String) enum HAlign { NONE; LEFT; CENTER; diff --git a/haxework/gui/core/VAlign.hx b/haxework/gui/core/VAlign.hx index 5026ad9..95367b9 100755 --- a/haxework/gui/core/VAlign.hx +++ b/haxework/gui/core/VAlign.hx @@ -1,6 +1,6 @@ package haxework.gui.core; -enum VAlign { +@:fakeEnum(String) enum VAlign { NONE; TOP; MIDDLE; diff --git a/haxework/gui/layout/HorizontalLayout.hx b/haxework/gui/layout/HorizontalLayout.hx index 9ffd73a..d596f07 100755 --- a/haxework/gui/layout/HorizontalLayout.hx +++ b/haxework/gui/layout/HorizontalLayout.hx @@ -40,12 +40,11 @@ class HorizontalLayout extends DefaultLayout { } } - var x:Float; + var x:Float = 0; switch (group.layoutHAlign) { case HAlign.LEFT: x = group.leftPadding; case HAlign.CENTER: x = (group.width - fixedSize) / 2 + group.leftPadding - group.rightPadding; case HAlign.RIGHT: x = group.width - fixedSize - group.rightPadding; - case HAlign.NONE: x = 0; } for (view in views) { diff --git a/haxework/gui/layout/VerticalLayout.hx b/haxework/gui/layout/VerticalLayout.hx index a98aed1..7c0fc07 100755 --- a/haxework/gui/layout/VerticalLayout.hx +++ b/haxework/gui/layout/VerticalLayout.hx @@ -39,12 +39,11 @@ class VerticalLayout extends DefaultLayout { } } - var y:Float; + var y:Float = 0; switch (group.layoutVAlign) { case VAlign.TOP: y = group.topPadding; case VAlign.MIDDLE: y = (group.height - fixedSize) / 2 + group.topPadding - group.bottomPadding; case VAlign.BOTTOM: y = group.height - fixedSize - group.bottomPadding; - case VAlign.NONE: y = 0; } for (view in views) { diff --git a/haxework/gui/skin/ButtonColorSkin.hx b/haxework/gui/skin/ButtonColorSkin.hx index 4a18bb1..eb6323d 100755 --- a/haxework/gui/skin/ButtonColorSkin.hx +++ b/haxework/gui/skin/ButtonColorSkin.hx @@ -27,7 +27,7 @@ class ButtonColorSkin implements ISkin { } public function draw(view:ButtonView):Void { - var color:Int = view.disabled ? disable : colors.get(view.state); + var color:Int = selectColor(view); var graphics:Graphics = view.content.graphics; graphics.clear(); graphics.beginFill(color, alpha); @@ -35,4 +35,7 @@ class ButtonColorSkin implements ISkin { graphics.endFill(); } + private function selectColor(view:ButtonView):Int { + return view.disabled ? disable : colors.get(view.state); + } } \ No newline at end of file