added popupmanager & animates
This commit is contained in:
62
haxework/animate/CircleMaskAnimate.hx
Normal file
62
haxework/animate/CircleMaskAnimate.hx
Normal file
@@ -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<Sprite>;
|
||||||
|
private var mask:Sprite;
|
||||||
|
private var cyrcle:Sprite;
|
||||||
|
private var size:Float;
|
||||||
|
|
||||||
|
public function new(view:IView<Sprite>, ?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
haxework/animate/FadeAnimate.hx
Normal file
29
haxework/animate/FadeAnimate.hx
Normal file
@@ -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<Sprite>;
|
||||||
|
|
||||||
|
public function new(view:IView<Sprite>, ?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
haxework/animate/UnFadeAnimate.hx
Normal file
28
haxework/animate/UnFadeAnimate.hx
Normal file
@@ -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<Sprite>;
|
||||||
|
|
||||||
|
public function new(view:IView<Sprite>, ?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ import haxework.gui.skin.BitmapSkin;
|
|||||||
import haxework.gui.skin.ButtonColorSkin;
|
import haxework.gui.skin.ButtonColorSkin;
|
||||||
import haxework.gui.skin.ButtonBitmapSkin;
|
import haxework.gui.skin.ButtonBitmapSkin;
|
||||||
import haxework.gui.skin.ProgressSkin;
|
import haxework.gui.skin.ProgressSkin;
|
||||||
import haxework.frame.FrameSwitcher;
|
import haxework.gui.frame.FrameSwitcher;
|
||||||
|
|
||||||
class GuiBuilder {
|
class GuiBuilder {
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ class InputTextField extends TextField {
|
|||||||
super();
|
super();
|
||||||
#if flash
|
#if flash
|
||||||
type = TextFieldType.INPUT;
|
type = TextFieldType.INPUT;
|
||||||
#elseif html5
|
#elseif js
|
||||||
addEventListener(MouseEvent.CLICK, onMouseClick);
|
addEventListener(MouseEvent.CLICK, onMouseClick);
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
#if html5
|
#if js
|
||||||
private function onMouseClick(event:MouseEvent):Void {
|
private function onMouseClick(event:MouseEvent):Void {
|
||||||
focused = true;
|
focused = true;
|
||||||
border = true;
|
border = true;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package haxework.frame;
|
package haxework.gui.frame;
|
||||||
|
|
||||||
import haxework.animate.IAnimate;
|
import haxework.animate.IAnimate;
|
||||||
import flash.display.Sprite;
|
import flash.display.Sprite;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package haxework.frame;
|
package haxework.gui.frame;
|
||||||
|
|
||||||
import haxework.gui.IView;
|
import haxework.gui.IView;
|
||||||
|
|
||||||
47
haxework/gui/popup/PopupManager.hx
Normal file
47
haxework/gui/popup/PopupManager.hx
Normal file
@@ -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<IAnimate>;
|
||||||
|
public var closeAnimateFactory(default, default):Class<IAnimate>;
|
||||||
|
|
||||||
|
private var popups:Array<PopupView>;
|
||||||
|
|
||||||
|
public function new() {
|
||||||
|
popups = new Array<PopupView>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(popup:PopupView):Void {
|
||||||
|
cast(Root.instance.view, IGroupView<Dynamic>).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<Dynamic>).removeView(popup);
|
||||||
|
popup.onClose();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cast(Root.instance.view, IGroupView<Dynamic>).removeView(popup);
|
||||||
|
popup.onClose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function closeTop():Bool {
|
||||||
|
if (popups.length > 0) {
|
||||||
|
close(popups[popups.length - 1]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
haxework/gui/popup/PopupView.hx
Executable file
58
haxework/gui/popup/PopupView.hx
Executable file
@@ -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<Dynamic>;
|
||||||
|
private var callback:ICallback<String>;
|
||||||
|
|
||||||
|
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<String> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,41 +118,20 @@ class BitmapTextField extends TextField {
|
|||||||
textField.setTextFormat(tf);
|
textField.setTextFormat(tf);
|
||||||
textField.alpha = alpha;
|
textField.alpha = alpha;
|
||||||
|
|
||||||
//ToDo: matrix arrays
|
|
||||||
if (stroke) {
|
if (stroke) {
|
||||||
|
for (p in [[1, 2], [2, 1], [1, 0], [0, 1]]) {
|
||||||
var m = new Matrix();
|
var m = new Matrix();
|
||||||
m.translate(1, 2);
|
m.translate(p[0], p[1]);
|
||||||
bd.draw(textField, m);
|
bd.draw(textField, m, null, null, null, false);
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shadow) {
|
if (shadow) {
|
||||||
|
for (p in [[2, 3], [3, 2], [1, 0], [0, 1]]) {
|
||||||
var m = new Matrix();
|
var m = new Matrix();
|
||||||
m.translate(2, 3);
|
m.translate(p[0], p[1]);
|
||||||
bd.draw(textField, m);
|
bd.draw(textField, m, null, null, null, false);
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textField.alpha = 1.0;
|
textField.alpha = 1.0;
|
||||||
@@ -161,7 +140,7 @@ class BitmapTextField extends TextField {
|
|||||||
|
|
||||||
var m = new Matrix();
|
var m = new Matrix();
|
||||||
m.translate(1, 1);
|
m.translate(1, 1);
|
||||||
bd.draw(textField, m);
|
bd.draw(textField, m, null, null, null, false);
|
||||||
|
|
||||||
textField.visible = false;
|
textField.visible = false;
|
||||||
return bd;
|
return bd;
|
||||||
|
|||||||
Reference in New Issue
Block a user