3 template "widget[@type='Animate']", mode="widget_class"{ |
3 template "widget[@type='Animate']", mode="widget_class"{ |
4 || |
4 || |
5 class AnimateWidget extends Widget{ |
5 class AnimateWidget extends Widget{ |
6 frequency = 5; |
6 frequency = 5; |
7 speed = 0; |
7 speed = 0; |
|
8 widget_center = undefined; |
8 |
9 |
9 dispatch(value) { |
10 dispatch(value) { |
10 this.speed = value; |
11 this.speed = value / 5; |
11 |
12 |
12 //reconfigure animation |
13 //reconfigure animation |
13 this.request_animate(); |
14 this.request_animate(); |
14 } |
15 } |
15 |
16 |
16 animate(){ |
17 animate(){ |
17 // change animation properties |
18 // change animation properties |
18 this.element.children[0].setAttribute("dur", String(this.speed)+"s") |
19 for(let child of this.element.children){ |
|
20 if(child.nodeName == "animateTransform"){ |
|
21 if(this.speed > 0){ |
|
22 child.setAttribute("dur", this.speed+"s"); |
|
23 child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]); |
|
24 child.setAttribute("to", "360 "+this.widget_center[0]+" "+this.widget_center[1]); |
|
25 } |
|
26 else if(this.speed < 0){ |
|
27 child.setAttribute("dur", (-1)*this.speed+"s"); |
|
28 child.setAttribute("from", "360 "+this.widget_center[0]+" "+this.widget_center[1]); |
|
29 child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]); |
|
30 } |
|
31 else{ |
|
32 child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]); |
|
33 child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]); |
|
34 } |
|
35 } |
|
36 } |
19 } |
37 } |
20 |
38 |
21 init() { |
39 init() { |
22 let width = this.element.getAttribute("width"); |
40 let widget_pos = this.element.getBBox(); |
23 let height = this.element.getAttribute("height"); |
41 this.widget_center = [(widget_pos.x+widget_pos.width/2), (widget_pos.y+widget_pos.height/2)]; |
24 this.element.setAttribute("x",width/-2); |
|
25 this.element.setAttribute("y",height/-2); |
|
26 } |
42 } |
27 } |
43 } |
28 || |
44 || |
29 } |
45 } |
30 |
46 |