equal
deleted
inserted
replaced
|
1 // widget_animate.ysl2 |
|
2 |
|
3 template "widget[@type='Animate']", mode="widget_class"{ |
|
4 || |
|
5 class AnimateWidget extends Widget{ |
|
6 frequency = 5; |
|
7 speed = 0; |
|
8 start = false; |
|
9 widget_center = undefined; |
|
10 |
|
11 dispatch(value) { |
|
12 this.speed = value / 5; |
|
13 |
|
14 //reconfigure animation |
|
15 this.request_animate(); |
|
16 } |
|
17 |
|
18 animate(){ |
|
19 // change animation properties |
|
20 for(let child of this.element.children){ |
|
21 if(child.nodeName.startsWith("animate")){ |
|
22 if(this.speed != 0 && !this.start){ |
|
23 this.start = true; |
|
24 this.element.beginElement(); |
|
25 } |
|
26 |
|
27 if(this.speed > 0){ |
|
28 child.setAttribute("dur", this.speed+"s"); |
|
29 } |
|
30 else if(this.speed < 0){ |
|
31 child.setAttribute("dur", (-1)*this.speed+"s"); |
|
32 } |
|
33 else{ |
|
34 this.start = false; |
|
35 this.element.endElement(); |
|
36 } |
|
37 } |
|
38 } |
|
39 } |
|
40 |
|
41 init() { |
|
42 let widget_pos = this.element.getBBox(); |
|
43 this.widget_center = [(widget_pos.x+widget_pos.width/2), (widget_pos.y+widget_pos.height/2)]; |
|
44 } |
|
45 } |
|
46 || |
|
47 } |
|
48 |
|
49 |
|
50 template "widget[@type='Animate']", mode="widget_defs" { |
|
51 param "hmi_element"; |
|
52 |, |
|
53 } |