From 38ceb7eecb0ced92d7c594f383a7f7b828b0ce5f Mon Sep 17 00:00:00 2001 From: shmyga Date: Tue, 30 Jun 2015 11:11:10 +0300 Subject: [PATCH] added popupmanager & animates --- haxework/animate/CircleMaskAnimate.hx | 62 ++++++++++++++++++++++ haxework/animate/FadeAnimate.hx | 29 ++++++++++ haxework/animate/UnFadeAnimate.hx | 28 ++++++++++ haxework/gui/GuiBuilder.hx | 2 +- haxework/gui/InputTextField.hx | 4 +- haxework/{ => gui}/frame/FrameSwitcher.hx | 2 +- haxework/{ => gui}/frame/IFrameSwitcher.hx | 2 +- haxework/gui/popup/PopupManager.hx | 47 ++++++++++++++++ haxework/gui/popup/PopupView.hx | 58 ++++++++++++++++++++ haxework/text/BitmapTextField.hx | 43 ++++----------- 10 files changed, 240 insertions(+), 37 deletions(-) create mode 100644 haxework/animate/CircleMaskAnimate.hx create mode 100644 haxework/animate/FadeAnimate.hx create mode 100644 haxework/animate/UnFadeAnimate.hx rename haxework/{ => gui}/frame/FrameSwitcher.hx (98%) rename haxework/{ => gui}/frame/IFrameSwitcher.hx (87%) create mode 100644 haxework/gui/popup/PopupManager.hx create mode 100755 haxework/gui/popup/PopupView.hx diff --git a/haxework/animate/CircleMaskAnimate.hx b/haxework/animate/CircleMaskAnimate.hx new file mode 100644 index 0000000..8e54b2a --- /dev/null +++ b/haxework/animate/CircleMaskAnimate.hx @@ -0,0 +1,62 @@ +package haxework.animate; + +import haxework.animate.IAnimate; +import flash.display.Sprite; +import haxework.gui.IView; +import haxework.animate.Animate; + +class CircleMaskAnimate extends Animate { + + private var view:IView; + private var mask:Sprite; + private var cyrcle:Sprite; + private var size:Float; + + public function new(view:IView, ?duration:Int = 1000) { + super(duration); + this.view = view; + this.mask = new Sprite(); + this.cyrcle = new Sprite(); + } + + override public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void { + var width = view.parent.width; + var height = view.parent.height; + size = Math.sqrt(width * width + height * height); + //size = Math.max(width, height); + cyrcle.x = mask.x = -(size - width) / 2 - size; + cyrcle.y = mask.y = -(size - height) / 2 - size; + + redraw(size, size); + + view.parent.content.addChild(mask); + view.content.mask = mask; + view.parent.content.addChild(cyrcle); + + super.start(callback, custom); + } + + private function redraw(size:Float, r:Float):Void { + mask.graphics.clear(); + mask.graphics.beginFill(0xffffff); + mask.graphics.drawCircle(size + size / 2, size + size / 2, r / 2); + mask.graphics.endFill(); + + cyrcle.graphics.clear(); + cyrcle.graphics.lineStyle(8, 0xffffff); + cyrcle.graphics.drawCircle(size + size / 2, size + size / 2, r / 2); + cyrcle.graphics.lineStyle(); + } + + override private function update(time:Float):Void { + super.update(time); + + redraw(size, size * progress); + + if (progress >= 1 && view.content.parent != null) { + if (view.content.parent.contains(mask)) view.content.parent.removeChild(mask); + view.content.mask = null; + if (view.content.parent.contains(cyrcle)) view.parent.content.removeChild(cyrcle); + } + } +} diff --git a/haxework/animate/FadeAnimate.hx b/haxework/animate/FadeAnimate.hx new file mode 100644 index 0000000..41930a8 --- /dev/null +++ b/haxework/animate/FadeAnimate.hx @@ -0,0 +1,29 @@ +package haxework.animate; + +import haxework.animate.IAnimate; +import flash.display.Sprite; +import haxework.gui.IView; +import haxework.animate.Animate; + +class FadeAnimate extends Animate { + + private var view:IView; + + public function new(view:IView, ?duration = 500) { + super(duration); + this.view = view; + } + + override public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void { + view.content.alpha = 1.0; + super.start(callback, custom); + } + + override private function update(time:Float):Void { + super.update(time); + view.content.alpha = 1 - (progress * 1.0); + if (progress >= 1) { + view.content.alpha = 0.0; + } + } +} diff --git a/haxework/animate/UnFadeAnimate.hx b/haxework/animate/UnFadeAnimate.hx new file mode 100644 index 0000000..9d79081 --- /dev/null +++ b/haxework/animate/UnFadeAnimate.hx @@ -0,0 +1,28 @@ +package haxework.animate; + +import flash.display.Sprite; +import haxework.gui.IView; +import haxework.animate.Animate; + +class UnFadeAnimate extends Animate { + + private var view:IView; + + public function new(view:IView, ?duration = 500) { + super(duration); + this.view = view; + } + + override public function start(callback:IAnimate -> Void, ?custom:Bool = false):Void { + view.content.alpha = 0.0; + super.start(callback, custom); + } + + override private function update(time:Float):Void { + super.update(time); + view.content.alpha = progress * 1.0; + if (progress >= 1) { + view.content.alpha = 1.0; + } + } +} diff --git a/haxework/gui/GuiBuilder.hx b/haxework/gui/GuiBuilder.hx index 65e109f..0cf3a85 100755 --- a/haxework/gui/GuiBuilder.hx +++ b/haxework/gui/GuiBuilder.hx @@ -27,7 +27,7 @@ import haxework.gui.skin.BitmapSkin; import haxework.gui.skin.ButtonColorSkin; import haxework.gui.skin.ButtonBitmapSkin; import haxework.gui.skin.ProgressSkin; -import haxework.frame.FrameSwitcher; +import haxework.gui.frame.FrameSwitcher; class GuiBuilder { diff --git a/haxework/gui/InputTextField.hx b/haxework/gui/InputTextField.hx index 7c1cb1b..c8e6b88 100644 --- a/haxework/gui/InputTextField.hx +++ b/haxework/gui/InputTextField.hx @@ -16,12 +16,12 @@ class InputTextField extends TextField { super(); #if flash type = TextFieldType.INPUT; - #elseif html5 + #elseif js addEventListener(MouseEvent.CLICK, onMouseClick); #end } - #if html5 + #if js private function onMouseClick(event:MouseEvent):Void { focused = true; border = true; diff --git a/haxework/frame/FrameSwitcher.hx b/haxework/gui/frame/FrameSwitcher.hx similarity index 98% rename from haxework/frame/FrameSwitcher.hx rename to haxework/gui/frame/FrameSwitcher.hx index 7206bc8..96e204d 100755 --- a/haxework/frame/FrameSwitcher.hx +++ b/haxework/gui/frame/FrameSwitcher.hx @@ -1,4 +1,4 @@ -package haxework.frame; +package haxework.gui.frame; import haxework.animate.IAnimate; import flash.display.Sprite; diff --git a/haxework/frame/IFrameSwitcher.hx b/haxework/gui/frame/IFrameSwitcher.hx similarity index 87% rename from haxework/frame/IFrameSwitcher.hx rename to haxework/gui/frame/IFrameSwitcher.hx index 7919d20..afe0304 100755 --- a/haxework/frame/IFrameSwitcher.hx +++ b/haxework/gui/frame/IFrameSwitcher.hx @@ -1,4 +1,4 @@ -package haxework.frame; +package haxework.gui.frame; import haxework.gui.IView; diff --git a/haxework/gui/popup/PopupManager.hx b/haxework/gui/popup/PopupManager.hx new file mode 100644 index 0000000..ac34f6a --- /dev/null +++ b/haxework/gui/popup/PopupManager.hx @@ -0,0 +1,47 @@ +package haxework.gui.popup; + +import haxework.animate.IAnimate; +import haxework.gui.Root; +import haxework.gui.IGroupView; + +class PopupManager { + + public var showAnimateFactory(default, default):Class; + public var closeAnimateFactory(default, default):Class; + + private var popups:Array; + + public function new() { + popups = new Array(); + } + + public function show(popup:PopupView):Void { + cast(Root.instance.view, IGroupView).addView(popup); + if (showAnimateFactory != null) { + Type.createInstance(showAnimateFactory, [popup]).start(null); + } + popups.push(popup); + popup.onShow(); + } + + public function close(popup:PopupView):Void { + popups.remove(popup); + if (closeAnimateFactory != null) { + Type.createInstance(closeAnimateFactory, [popup]).start(function(_) { + cast(Root.instance.view, IGroupView).removeView(popup); + popup.onClose(); + }); + } else { + cast(Root.instance.view, IGroupView).removeView(popup); + popup.onClose(); + } + } + + public function closeTop():Bool { + if (popups.length > 0) { + close(popups[popups.length - 1]); + return true; + } + return false; + } +} diff --git a/haxework/gui/popup/PopupView.hx b/haxework/gui/popup/PopupView.hx new file mode 100755 index 0000000..c6a5d6d --- /dev/null +++ b/haxework/gui/popup/PopupView.hx @@ -0,0 +1,58 @@ +package haxework.gui.popup; + +import haxework.net.callback.Callback; +import haxework.net.callback.ICallback; +import haxe.Timer; +import haxework.provider.Provider; +import haxework.dispath.Dispatcher; +import haxework.dispath.IDispatcher; +import haxework.gui.IGroupView; +import haxework.gui.ButtonView; +import haxework.gui.skin.ColorSkin; +import haxework.gui.GuiBuilder; +import haxework.gui.GroupView; + +class PopupView extends GroupView { + + private var buttonId:String; + private var contentView:IGroupView; + private var callback:ICallback; + + public function new(resource:String, ?key:String = null) { + super(); + + pWidth = 100; + pHeight = 100; + inLayout = false; + skin = new ColorSkin(0x000000, 0.6); + + contentView = GuiBuilder.buildFromAssets(resource, key, {listener:this}); + addView(contentView); + } + + public function onPress(button:ButtonView) { + this.buttonId = button.id; + close(); + } + + public function show():ICallback { + Provider.get(PopupManager).show(this); + callback = Callback.build(); + return callback; + } + + public function close():Void { + Provider.get(PopupManager).close(this); + } + + public function onShow():Void { + buttonId = "close"; + } + + public function onClose():Void { + if (callback != null) { + callback.callSuccess(buttonId); + callback = null; + } + } +} diff --git a/haxework/text/BitmapTextField.hx b/haxework/text/BitmapTextField.hx index 8cd8147..6b2f91a 100755 --- a/haxework/text/BitmapTextField.hx +++ b/haxework/text/BitmapTextField.hx @@ -118,41 +118,20 @@ class BitmapTextField extends TextField { textField.setTextFormat(tf); textField.alpha = alpha; - //ToDo: matrix arrays if (stroke) { - var m = new Matrix(); - m.translate(1, 2); - bd.draw(textField, m); - - var m = new Matrix(); - m.translate(2, 1); - bd.draw(textField, m); - - var m = new Matrix(); - m.translate(1, 0); - bd.draw(textField, m); - - var m = new Matrix(); - m.translate(0, 1); - bd.draw(textField, m); + for (p in [[1, 2], [2, 1], [1, 0], [0, 1]]) { + var m = new Matrix(); + m.translate(p[0], p[1]); + bd.draw(textField, m, null, null, null, false); + } } if (shadow) { - var m = new Matrix(); - m.translate(2, 3); - bd.draw(textField, m); - - var m = new Matrix(); - m.translate(3, 2); - bd.draw(textField, m); - - var m = new Matrix(); - m.translate(1, 0); - bd.draw(textField, m); - - var m = new Matrix(); - m.translate(0, 1); - bd.draw(textField, m); + for (p in [[2, 3], [3, 2], [1, 0], [0, 1]]) { + var m = new Matrix(); + m.translate(p[0], p[1]); + bd.draw(textField, m, null, null, null, false); + } } textField.alpha = 1.0; @@ -161,7 +140,7 @@ class BitmapTextField extends TextField { var m = new Matrix(); m.translate(1, 1); - bd.draw(textField, m); + bd.draw(textField, m, null, null, null, false); textField.visible = false; return bd;