author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 02 Feb 2021 10:43:43 +0100 | |
branch | svghmi |
changeset 3120 | 7ecaefe38f6f |
parent 3064 | 4b44d09c48a7 |
child 3232 | 7bdb766c2a4d |
permissions | -rw-r--r-- |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
1 |
// widget_animate.ysl2 |
2944 | 2 |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
3 |
template "widget[@type='Animate']", mode="widget_class"{ |
3009 | 4 |
|| |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
5 |
class AnimateWidget extends Widget{ |
3009 | 6 |
frequency = 5; |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
7 |
speed = 0; |
3064
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
8 |
start = false; |
3062 | 9 |
widget_center = undefined; |
3009 | 10 |
|
3056
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
11 |
dispatch(value) { |
3062 | 12 |
this.speed = value / 5; |
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
13 |
|
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
14 |
//reconfigure animation |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
15 |
this.request_animate(); |
3056
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
16 |
} |
827bf284feec
Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents:
3024
diff
changeset
|
17 |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
18 |
animate(){ |
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
19 |
// change animation properties |
3062 | 20 |
for(let child of this.element.children){ |
3064
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
21 |
if(child.nodeName.startsWith("animate")){ |
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
22 |
if(this.speed != 0 && !this.start){ |
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
23 |
this.start = true; |
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
24 |
this.element.beginElement(); |
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
25 |
} |
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
26 |
|
3062 | 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{ |
|
3064
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
34 |
this.start = false; |
4b44d09c48a7
- New widget customHtml which allows to insert block of html code
usveticic
parents:
3062
diff
changeset
|
35 |
this.element.endElement(); |
3062 | 36 |
} |
37 |
} |
|
38 |
} |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
39 |
} |
3009 | 40 |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
41 |
init() { |
3062 | 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)]; |
|
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
44 |
} |
3009 | 45 |
} |
46 |
|| |
|
3024 | 47 |
} |
3009 | 48 |
|
49 |
||
3059
e0db3f6a5f39
Button and toggle reworked to use animate and dispatch
usveticic
parents:
3058
diff
changeset
|
50 |
template "widget[@type='Animate']", mode="widget_defs" { |
2976
99c4521bb844
SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents:
2961
diff
changeset
|
51 |
param "hmi_element"; |
3009 | 52 |
|, |
3000
a9a45977bac0
SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2976
diff
changeset
|
53 |
} |