|
1 // widget_animaterotation.ysl2 |
|
2 |
|
3 template "widget[@type='AnimateRotation']", mode="widget_class"{ |
|
4 || |
|
5 class AnimateRotationWidget extends Widget{ |
|
6 frequency = 5; |
|
7 speed = 0; |
|
8 widget_center = undefined; |
|
9 |
|
10 dispatch(value) { |
|
11 this.speed = value / 5; |
|
12 |
|
13 //reconfigure animation |
|
14 this.request_animate(); |
|
15 } |
|
16 |
|
17 animate(){ |
|
18 // change animation properties |
|
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 } |
|
37 } |
|
38 |
|
39 init() { |
|
40 let widget_pos = this.element.getBBox(); |
|
41 this.widget_center = [(widget_pos.x+widget_pos.width/2), (widget_pos.y+widget_pos.height/2)]; |
|
42 } |
|
43 } |
|
44 || |
|
45 } |
|
46 |
|
47 |
|
48 template "widget[@type='AnimateRotation']", mode="widget_defs" { |
|
49 param "hmi_element"; |
|
50 |, |
|
51 } |