1
by edA-qa mort-ora-y
first |
1 |
/* <license> |
2 |
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y |
|
3 |
* For full copyright and license information please refer to doc/license.txt. |
|
4 |
* </license> |
|
5 |
*/
|
|
6 |
package ui.anim; |
|
7 |
||
8 |
import ui.Widget; |
|
9 |
import ui.Action; |
|
10 |
||
11 |
/*hidden*/ class __FXDescriptor implements FXDescriptor |
|
12 |
{
|
|
13 |
public var cl : Class<Dynamic>; |
|
14 |
public var seq : String; |
|
15 |
public var args : Dynamic; |
|
16 |
||
17 |
public function new() { } |
|
18 |
}
|
|
19 |
||
20 |
/**
|
|
21 |
* An assistance class for using effects/transformations on widgets on |
|
22 |
* the screen. |
|
23 |
*/
|
|
24 |
class FXBuilder |
|
25 |
{
|
|
26 |
/**
|
|
27 |
* Used to create an FX description which can be used by other functions |
|
28 |
* in this class. This provides future compatibility to other methods of |
|
29 |
* providing effects. |
|
30 |
*/
|
|
31 |
static public function createActorFX( cl : Class<Dynamic>, seq : String, ?args : Dynamic ) : FXDescriptor |
|
32 |
{
|
|
33 |
var fx = new __FXDescriptor(); |
|
34 |
fx.cl = cl; |
|
35 |
fx.seq = seq; |
|
36 |
fx.args = args; |
|
37 |
return fx; |
|
38 |
}
|
|
39 |
||
40 |
/**
|
|
41 |
* Ends the lifetime of a Widget with the provided FX. At the end of the |
|
42 |
* FX the widget will have been removed from the parent. |
|
43 |
*
|
|
44 |
* @param widget [in] the widget to apply the fx to |
|
45 |
* @param fx [in] an FXDescriptor as created by FXBuilder |
|
46 |
* @param completion [in] what to do when the FX is complete |
|
47 |
*/
|
|
48 |
static public function endWidget( widget : Widget, fx : FXDescriptor, ?completion : ui.Action ) |
|
49 |
{
|
|
50 |
ASSERT_IS( fx, __FXDescriptor ); |
|
51 |
var _fx = cast( fx, __FXDescriptor ); |
|
52 |
ASSERT_NOTNULL( widget.getNative().parent ); |
|
53 |
var p = widget.getNative().parent; |
|
54 |
p.removeChild( widget.getNative() ); |
|
55 |
||
56 |
//translate position (TODO: Handle scaling and non-0 origins, etc...) |
|
57 |
||
58 |
var x = widget.getNative().x; |
|
59 |
var y = widget.getNative().y; |
|
60 |
widget.getNative().x = 0; |
|
61 |
widget.getNative().y = 0; |
|
62 |
||
63 |
var c : ui.anim.Actor = Type.createInstance( |
|
64 |
_fx.cl, |
|
65 |
[ DynamicUtil.merge( { item: widget }, _fx.args ) ] |
|
66 |
);
|
|
67 |
//resize and move container |
|
68 |
c.resize( widget.getNative().width, widget.getNative().height ); |
|
69 |
c.move( x, y ); |
|
70 |
p.addChild( c ); |
|
71 |
c.actorSetSequence( _fx.seq, Action.bind2( __endFX, c, completion ) ); |
|
72 |
}
|
|
73 |
||
74 |
/**
|
|
75 |
* Begins the lifetime of a Widget with the provided FX. The parent of the |
|
76 |
* widget should already be set, and the initial sizing complete. |
|
77 |
*/
|
|
78 |
static public function beginWidget( widget : Widget, fx : FXDescriptor, ?completion : Action ) |
|
79 |
{
|
|
80 |
ASSERT_IS( fx, __FXDescriptor ); |
|
81 |
var _fx = cast( fx, __FXDescriptor ); |
|
82 |
ASSERT_NOTNULL( widget.getNative().parent ); |
|
83 |
var p = widget.getNative().parent; |
|
84 |
p.removeChild( widget.getNative() ); |
|
85 |
||
86 |
//translate position (TODO: Handle scaling and non-0 origins, etc...) |
|
87 |
||
88 |
var x = widget.getNative().x; |
|
89 |
var y = widget.getNative().y; |
|
90 |
widget.getNative().x = 0; |
|
91 |
widget.getNative().y = 0; |
|
92 |
||
93 |
var c : ui.anim.Actor = Type.createInstance( |
|
94 |
_fx.cl, |
|
95 |
[ DynamicUtil.merge( { item: widget }, _fx.args ) ] |
|
96 |
);
|
|
97 |
//resize and move container |
|
98 |
c.resize( widget.getNative().width, widget.getNative().height ); |
|
99 |
c.move( x, y ); |
|
100 |
p.addChild( c ); |
|
101 |
c.actorSetSequence( _fx.seq, Action.bind1( __beginFX, { |
|
102 |
parent: p, |
|
103 |
actor: c, |
|
104 |
completion: completion, |
|
105 |
widget: widget, |
|
106 |
x: x, |
|
107 |
y: y |
|
108 |
} ) ); |
|
109 |
}
|
|
110 |
||
111 |
/**
|
|
112 |
* onWidget does an FX on an existing widget. Though at the moment this does |
|
113 |
* the same thing as beginWidget, there are some exception cases whcih will be |
|
114 |
* implemented later which will diverge the two, thus, use this call if the widget |
|
115 |
* is not a new one. |
|
116 |
*/
|
|
117 |
static public function onWidget( widget : Widget, fx : FXDescriptor, ?completion : Action ) |
|
118 |
{
|
|
119 |
beginWidget( widget, fx, completion ); |
|
120 |
}
|
|
121 |
||
122 |
/*hidden*/ static function __beginFX( data : Dynamic ) |
|
123 |
{
|
|
124 |
data.actor.destroy(); |
|
125 |
data.parent.addChild( data.widget.getNative() ); |
|
126 |
data.widget.move( data.x, data.y ); |
|
127 |
if( data.completion != null ) |
|
128 |
Action.handle( data.widget.getNative(), data.completion ); |
|
129 |
}
|
|
130 |
||
131 |
/*hidden*/ static function __endFX( act : ui.anim.Actor, action : ui.Action ) |
|
132 |
{
|
|
133 |
act.parent.removeChild( act ); |
|
134 |
if( action != null ) |
|
135 |
ui.Action.handle( act.getNative(), action ); |
|
136 |
}
|
|
137 |
||
138 |
}
|