[hw] rename haxework package to hw

This commit is contained in:
2020-03-24 20:58:54 +03:00
parent 7b7819fe6e
commit 279baa1113
162 changed files with 613 additions and 540 deletions

View File

@@ -0,0 +1,64 @@
package hw.animate;
import flash.display.DisplayObject;
import flash.display.Stage;
import flash.events.Event;
import hw.view.IView;
class Animate implements IAnimate {
public static var defaultDuraion = 300;
private static var running:Array<IAnimate> = new Array<IAnimate>();
public static function bind(stage:Stage):Void {
stage.addEventListener(Event.ENTER_FRAME, function(_) {
Animate.updateAll();
});
}
public static function updateAll():Void {
if (running.length > 0) {
var time = Date.now().getTime();
for (animate in running) animate.update(time);
}
}
private var callback:Animate -> Void;
private var view:IView<Dynamic>;
private var duration:Int;
private var startTime:Float;
private var progress:Float;
private var object(get, null):DisplayObject;
public function new(view:IView<Dynamic>, duration:Int = -1) {
this.view = view;
this.duration = duration > -1 ? duration : defaultDuraion;
}
private inline function get_object():DisplayObject {
return cast view.content;
}
public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
startTime = Date.now().getTime();
this.callback = callback;
if (!custom) running.push(this);
update(startTime);
}
private function update(time:Float):Void {
progress = (time - startTime) / duration;
if (progress >= 1) {
running.remove(this);
if (callback != null) {
callback(this);
callback = null;
}
}
}
public function cancel():Void {
if (!Math.isNaN(startTime)) update(startTime + duration);
}
}

View File

@@ -0,0 +1,62 @@
package hw.animate;
import flash.display.DisplayObject;
import flash.display.Sprite;
import hw.animate.Animate;
import hw.animate.IAnimate;
import hw.view.IView;
class CircleMaskAnimate extends Animate {
private var mask:Sprite;
private var cyrcle:Sprite;
private var size:Float;
public function new(view:IView<DisplayObject>, duration:Int = -1) {
super(view, 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.container.addChild(mask);
view.content.mask = mask;
view.parent.container.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(4, 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.container.removeChild(cyrcle);
}
}
}

View File

@@ -0,0 +1,20 @@
package hw.animate;
import hw.animate.Animate;
import hw.animate.IAnimate;
class FadeAnimate extends Animate {
override public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
object.alpha = 1.0;
super.start(callback, custom);
}
override private function update(time:Float):Void {
super.update(time);
object.alpha = 1 - (progress * 1.0);
if (progress >= 1) {
object.alpha = 0.0;
}
}
}

View File

@@ -0,0 +1,10 @@
package hw.animate;
interface IAnimate {
public function start(callback:IAnimate -> Void, custom:Bool = false):Void;
public function cancel():Void;
private function update(time:Float):Void;
}

View File

@@ -0,0 +1,14 @@
package hw.animate;
class SlideAnimate extends Animate {
override public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
object.x = view.x - this.view.width + this.view.width / progress;
super.start(callback, custom);
}
override private function update(time:Float):Void {
super.update(time);
object.x = view.x - this.view.width + this.view.width / Math.min(1, progress);
}
}

View File

@@ -0,0 +1,19 @@
package hw.animate;
import hw.animate.Animate;
class UnFadeAnimate extends Animate {
override public function start(callback:IAnimate -> Void, custom:Bool = false):Void {
object.alpha = 0.0;
super.start(callback, custom);
}
override private function update(time:Float):Void {
super.update(time);
object.alpha = progress * 1.0;
if (progress >= 1) {
object.alpha = 1.0;
}
}
}