@@ -34,28 +34,40 @@ public class Animator : Object {
34
34
private double ? _eox = null ; // Ending x -origin
35
35
private double ? _eoy = null ; // Ending y -origin
36
36
private int _index = 1 ; // Animation index
37
- private const int _timeout = 20 ; // Number of milliseconds between frames
37
+ private string _name = "";
38
+ private int _id ;
39
+ // private const int _timeout = 20 ; // Number of milliseconds between frames (30 fps )
40
+ private const int _timeout = 1000; // Number of milliseconds between frames (30 fps )
38
41
private const double _frames = 10; // Number of frames to animate (note : set to 1 to disable animation )
42
+ private static int _next_id = 0;
43
+
44
+ public static bool _in_progress = false ;
39
45
40
46
/* Default constructor */
41
- public Animator ( DrawArea da ) {
47
+ public Animator ( DrawArea da , string name = " unnamed " ) {
42
48
_da = da;
49
+ _name = name;
50
+ _id = _next_id++ ;
43
51
_da. stop_animation();
44
52
_spos = new AnimationPositions ( _da );
45
53
}
46
54
47
55
/* Constructor for a specified node tree */
48
- public Animator.node ( DrawArea da , Node n ) {
56
+ public Animator.node ( DrawArea da , Node n , string name = " unnamed " ) {
49
57
_da = da;
58
+ _name = name;
59
+ _id = _next_id++ ;
50
60
_da. stop_animation();
51
61
_node = n;
52
62
_spos = new AnimationPositions .for_node( _node );
53
63
_index = 0 ;
54
64
}
55
65
56
66
/* Constructor for a scale change */
57
- public Animator.scale ( DrawArea da ) {
67
+ public Animator.scale ( DrawArea da , string name = " unnamed " ) {
58
68
_da = da;
69
+ _name = name;
70
+ _id = _next_id++ ;
59
71
_da. stop_animation();
60
72
_sscale = da. get_scale_factor();
61
73
_da. get_origin( out _sox, out _soy );
@@ -66,32 +78,33 @@ public class Animator : Object {
66
78
_da. stop_animation. connect( stop_animating );
67
79
if ( _node != null ) {
68
80
_epos = new AnimationPositions .for_node( _node );
69
- animate_positions( );
81
+ Timeout . add( _timeout, animate_positions );
70
82
} else if ( _sscale != null ) {
71
83
_escale = _da. get_scale_factor();
72
84
_da. get_origin( out _eox, out _eoy );
73
- animate_scaling( );
85
+ Timeout . add( _timeout, animate_scaling );
74
86
} else {
75
87
_epos = new AnimationPositions ( _da );
76
- animate_positions( );
88
+ Timeout . add( _timeout, animate_positions );
77
89
}
78
90
}
79
91
80
92
/* Perform the animation */
81
93
private bool animate_positions () {
82
94
double divisor = _index / _frames;
83
95
_index++ ;
84
- for ( int i= 0 ; i< _spos. length; i++ ) {
96
+ for ( int i= 0 ; i< _spos. length() ; i++ ) {
85
97
double x = _spos. x( i ) + ((_epos. x( i ) - _spos. x( i )) * divisor);
86
98
double y = _spos. y( i ) + ((_epos. y( i ) - _spos. y( i )) * divisor);
87
99
_spos. node( i ). set_posx_only( x );
88
100
_spos. node( i ). set_posy_only( y );
89
101
}
90
102
_da. queue_draw();
91
- if ( _index <= _frames ) {
92
- Timeout . add( _timeout, this . animate_positions );
103
+ if ( _index > _frames ) {
104
+ _da. stop_animation. disconnect( stop_animating );
105
+ return ( false );
93
106
}
94
- return ( false );
107
+ return ( true );
95
108
}
96
109
97
110
/* Animates the given scaling and origin changes */
@@ -101,19 +114,25 @@ public class Animator : Object {
101
114
double scale_factor = _sscale + ((_escale - _sscale) * divisor);
102
115
double origin_x = _sox + ((_eox - _sox) * divisor);
103
116
double origin_y = _soy + ((_eoy - _soy) * divisor);
117
+ stdout. printf( " index: %d , divisor: %g , scale: %g , ox: %g , oy: %g\n " , _index, divisor, scale_factor, origin_x, origin_y );
104
118
_da. set_scale_factor( scale_factor );
105
119
_da. set_origin( origin_x, origin_y );
106
120
_da. queue_draw();
107
- if ( _index <= _frames ) {
108
- Timeout . add( _timeout, this . animate_scaling );
121
+ if ( _index > _frames ) {
122
+ _da. stop_animation. disconnect( stop_animating );
123
+ return ( false );
109
124
}
110
- return ( false );
125
+ return ( true );
111
126
}
112
127
113
128
/* Stops any active animations */
114
129
private void stop_animating () {
115
- stdout. printf( " Stopping animation, index: %d\n " , _index );
116
130
_index = (int )_frames;
131
+ if ( _sscale != null ) {
132
+ animate_scaling();
133
+ } else {
134
+ animate_positions();
135
+ }
117
136
}
118
137
119
138
}
@@ -128,13 +147,6 @@ public class AnimationPositions : Object {
128
147
private Array<double?> _y;
129
148
private Array<Node ?> _node;
130
149
131
- public uint length {
132
- private set {}
133
- get {
134
- return ( _node. length );
135
- }
136
- }
137
-
138
150
/* Default constructor */
139
151
public AnimationPositions ( DrawArea da ) {
140
152
_x = new Array<double?> ();
@@ -166,6 +178,11 @@ public class AnimationPositions : Object {
166
178
}
167
179
}
168
180
181
+ /* Returns the number of nodes in this structure */
182
+ public uint length () {
183
+ return ( _node. length );
184
+ }
185
+
169
186
/* Returns the X position at the given index */
170
187
public double x ( int index ) {
171
188
return ( _x. index( index ) );
0 commit comments