~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to lib/ui/anim/lib/BoneWheel.ahx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.lib;
 
7
 
 
8
import ui.Widget;
 
9
 
 
10
DEFACTOR(BoneWheel)
 
11
 
 
12
        PARAM(actors,Array<Widget>,new Array<Widget>())
 
13
        PARAM(divisions,T_Int(7),Number divisions on the half-wheel)
 
14
        PARAM(smallScale,T_Float(0.35),Scale of widgets in the small position   )
 
15
        PARAM(speed,T_Float(0.20),Angular speed of the wheel, rotations per second, use negative for opposite direction)
 
16
        PARAM(yOffset,T_Float(0.0),How far the y is offset in wheel as well, factor of height, does not compensate widget size)
 
17
        PARAM(yScale,T_Float(1.0),Scale of widgets to height, used in conjunction with yOffset normally)
 
18
        
 
19
        var actors : Array<Widget>;
 
20
        VAR(current,Array<Widget>,new Array<Widget>())
 
21
        VAR(startSlot,T_Int(0))
 
22
        VAR(phase,T_Float(0))
 
23
        
 
24
        ONINIT()
 
25
        {
 
26
                //TODO: taken basically from BoneCircle
 
27
                actors = params.actors;
 
28
                if( actors != null )
 
29
                        for( actor in actors )
 
30
                        {
 
31
                                addChild( actor.getNative() );
 
32
                                actor.setVisible( false );
 
33
                        }
 
34
                params.actors = null;
 
35
                
 
36
                //
 
37
                ASSERT( actors.length >= params.divisions );
 
38
                startSlot = 0;
 
39
                reslot();
 
40
         }
 
41
         
 
42
         function reslot()
 
43
         {
 
44
                if( startSlot >= actors.length )
 
45
                        startSlot = 0;
 
46
                else if( startSlot < 0 )
 
47
                        startSlot = actors.length - 1;
 
48
                        
 
49
                for( i in 0...actors.length )
 
50
                        actors[i].setVisible( false );
 
51
                        
 
52
                for( i in 0...params.divisions )
 
53
                {
 
54
                        //invert natural order as wheel is reversed mathematically
 
55
                        var ndx = params.divisions - (i +startSlot) - 1;
 
56
                        ndx = mathx.MathUtil.pmodi( ndx, actors.length );
 
57
                        current[i] = actors[ndx];
 
58
                        actors[ndx].setVisible( true );
 
59
                        
 
60
                        //ensure Z-order overlap is correct on edges (items in back are in back)
 
61
                        setChildIndex( 
 
62
                                current[i].getNative(),  
 
63
                                if( i > params.divisions/2 )
 
64
                                        (params.divisions-i) *2 - 1
 
65
                                else
 
66
                                        i * 2
 
67
                                );
 
68
                }
 
69
                
 
70
                reposition();
 
71
        }
 
72
        
 
73
        //not used now (didn't make sense)
 
74
        VAR(zOrderNormal,T_Bool(true))
 
75
        TRAIT(ZOrder,Normal,DEFAULT,zOrderNormal=true;)
 
76
        
 
77
        SEQUENCE(Rotate,DEFAULT)
 
78
        {
 
79
        }
 
80
        ONSTEP()
 
81
        {
 
82
                phase += elapsed * params.divisions * params.speed;
 
83
                if( phase >= 1.0 )
 
84
                {
 
85
                        phase = 0;
 
86
                        startSlot++;
 
87
                        reslot();
 
88
                }
 
89
                else if( phase <= 0.0 )
 
90
                {
 
91
                        phase = 1.0;
 
92
                        startSlot--;
 
93
                        reslot();
 
94
                }
 
95
                else
 
96
                        reposition();
 
97
        }
 
98
        
 
99
        function reposition()
 
100
        {
 
101
                //TODO: both height and width go a "tad" bit outside of bounds, hmm...
 
102
                
 
103
                //FEATURE: making this algorithm more generic would add all sorts
 
104
                //of need FX for the path taken
 
105
                var loss = actorSize.y * params.yScale * params.smallScale;
 
106
                var width = actorSize.x - loss;
 
107
                
 
108
                var offDelta = Math.PI/params.divisions;
 
109
                for( i in 0...params.divisions )
 
110
                {
 
111
                        //all slots at phase 0 are right-aligned in their slot
 
112
                        
 
113
                        var angle = (i + 1.0 - phase) * offDelta;
 
114
                        
 
115
                        var size = 1.0 - (1.0 - Math.sin( angle ) ) * (1.0 - params.smallScale);
 
116
                        
 
117
                        var po = Math.cos( angle ) * width/2;
 
118
                        var py = params.yOffset * actorSize.y * Math.sin(angle);
 
119
                        
 
120
                        current[i].resize( actorSize.y * params.yScale * size, actorSize.y * params.yScale * size );
 
121
                        current[i].move( po, py );
 
122
                        
 
123
                        if( i == 0 )
 
124
                                current[i].getNative().alpha = 1.0 - phase;
 
125
                        else if( i == (params.divisions-1) )
 
126
                                current[i].getNative().alpha = phase;
 
127
                }
 
128
        }
 
129
        
 
130
        ONRESIZE()
 
131
        {
 
132
                for( actor in actors )
 
133
                        actor.resize( actorSize.y * params.yScale, actorSize.y * params.yScale );       //yes, square
 
134
        }
 
135
        
 
136
ENDACTOR()
 
 
b'\\ No newline at end of file'