svghmi/widget_animaterotation.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 12 Feb 2021 21:58:03 +0100
branchsvghmi
changeset 3135 d723472a18a4
parent 3064 4b44d09c48a7
child 3232 7bdb766c2a4d
permissions -rw-r--r--
SVGHMI: propagate default local variables (HMI_LOCAL, PAGE_LOCAL) to widgets at startup
3064
4b44d09c48a7 - New widget customHtml which allows to insert block of html code
usveticic
parents: 3062
diff changeset
     1
// widget_animaterotation.ysl2
2944
2a20038fbea9 Added button and circular bar widgets.
dgaberscek
parents:
diff changeset
     2
3064
4b44d09c48a7 - New widget customHtml which allows to insert block of html code
usveticic
parents: 3062
diff changeset
     3
template "widget[@type='AnimateRotation']", mode="widget_class"{
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     4
    ||
3064
4b44d09c48a7 - New widget customHtml which allows to insert block of html code
usveticic
parents: 3062
diff changeset
     5
    class AnimateRotationWidget extends Widget{
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     6
        frequency = 5;
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
     7
        speed = 0;
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
     8
        widget_center = undefined;
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
     9
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    10
        dispatch(value) {
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    11
            this.speed = value / 5;
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    12
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    13
            //reconfigure animation
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    14
            this.request_animate();
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    15
        }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3024
diff changeset
    16
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    17
        animate(){
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    18
           // change animation properties
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    19
           for(let child of this.element.children){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    20
                if(child.nodeName == "animateTransform"){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    21
                    if(this.speed > 0){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    22
                        child.setAttribute("dur", this.speed+"s");
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    23
                        child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    24
                        child.setAttribute("to", "360 "+this.widget_center[0]+" "+this.widget_center[1]);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    25
                    }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    26
                    else if(this.speed < 0){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    27
                        child.setAttribute("dur", (-1)*this.speed+"s");
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    28
                        child.setAttribute("from", "360 "+this.widget_center[0]+" "+this.widget_center[1]);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    29
                        child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    30
                    }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    31
                    else{
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    32
                        child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    33
                        child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    34
                    }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    35
                }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    36
           }
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    37
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    38
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3058
diff changeset
    39
        init() {
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    40
            let widget_pos = this.element.getBBox();
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    41
            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
    42
        }
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    43
    }
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    44
    ||
3024
Edouard Tisserant
parents: 3018
diff changeset
    45
}
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    46
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    47
3064
4b44d09c48a7 - New widget customHtml which allows to insert block of html code
usveticic
parents: 3062
diff changeset
    48
template "widget[@type='AnimateRotation']", mode="widget_defs" {
2976
99c4521bb844 SVGHMI: Changed widget button handler to element attribute.
dgaberscek
parents: 2961
diff changeset
    49
    param "hmi_element";
3009
7c6960f09881 Reworked button widget so it uses classes.
usveticic
parents: 3004
diff changeset
    50
    |,
3000
a9a45977bac0 SVGHMI: prefer apply_hmi_value() to change_hmi_value() when possible
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2976
diff changeset
    51
}