svghmi/widget_animaterotation.ysl2
changeset 3302 c89fc366bebd
parent 3241 fe945f1f48b7
equal deleted inserted replaced
2744:577118ebd179 3302:c89fc366bebd
       
     1 // widget_animaterotation.ysl2
       
     2 
       
     3 widget_desc("AnimateRotation") {
       
     4     longdesc
       
     5     ||
       
     6     AnimateRotation - DEPRECATED, do not use.
       
     7     Doesn't follow WYSIWYG principle, and forces user to add animateTransform tag in SVG (using inkscape XML editor for exemple)
       
     8     ||
       
     9 
       
    10     shortdesc > AnimateRotation - DEPRECATED
       
    11 
       
    12     path name="speed" accepts="HMI_INT,HMI_REAL" > speed
       
    13     
       
    14 }
       
    15 
       
    16 widget_class("AnimateRotation") {
       
    17     ||
       
    18         frequency = 5;
       
    19         speed = 0;
       
    20         widget_center = undefined;
       
    21 
       
    22         dispatch(value) {
       
    23             this.speed = value / 5;
       
    24 
       
    25             //reconfigure animation
       
    26             this.request_animate();
       
    27         }
       
    28 
       
    29         animate(){
       
    30            // change animation properties
       
    31            // TODO : rewrite with proper es6
       
    32            for(let child of this.element.children){
       
    33                 if(child.nodeName == "animateTransform"){
       
    34                     if(this.speed > 0){
       
    35                         child.setAttribute("dur", this.speed+"s");
       
    36                         child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
       
    37                         child.setAttribute("to", "360 "+this.widget_center[0]+" "+this.widget_center[1]);
       
    38                     }
       
    39                     else if(this.speed < 0){
       
    40                         child.setAttribute("dur", (-1)*this.speed+"s");
       
    41                         child.setAttribute("from", "360 "+this.widget_center[0]+" "+this.widget_center[1]);
       
    42                         child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
       
    43                     }
       
    44                     else{
       
    45                         child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
       
    46                         child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
       
    47                     }
       
    48                 }
       
    49            }
       
    50         }
       
    51 
       
    52         init() {
       
    53             let widget_pos = this.element.getBBox();
       
    54             this.widget_center = [(widget_pos.x+widget_pos.width/2), (widget_pos.y+widget_pos.height/2)];
       
    55         }
       
    56     ||
       
    57 }
       
    58