svghmi/widget_animate.ysl2
branchsvghmi
changeset 3067 2263f2ecf9bb
parent 3064 4b44d09c48a7
child 3232 7bdb766c2a4d
equal deleted inserted replaced
3063:466c3df67835 3067:2263f2ecf9bb
       
     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 }