svghmi/widget_animaterotation.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Sun, 02 May 2021 23:01:08 +0200
branchsvghmi
changeset 3232 7bdb766c2a4d
parent 3064 4b44d09c48a7
child 3241 fe945f1f48b7
permissions -rw-r--r--
SVGHMI: In order to allow widget signature and description to coexist in same ysl2 file, introduced widget_class, widget_defs to declare widget codegen templates and gen_index_xhtml to mark templates that are only usefull in gen_index_xhtml.xslt.
// widget_animaterotation.ysl2

widget_class("AnimateRotation") {
    ||
        frequency = 5;
        speed = 0;
        widget_center = undefined;

        dispatch(value) {
            this.speed = value / 5;

            //reconfigure animation
            this.request_animate();
        }

        animate(){
           // change animation properties
           for(let child of this.element.children){
                if(child.nodeName == "animateTransform"){
                    if(this.speed > 0){
                        child.setAttribute("dur", this.speed+"s");
                        child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
                        child.setAttribute("to", "360 "+this.widget_center[0]+" "+this.widget_center[1]);
                    }
                    else if(this.speed < 0){
                        child.setAttribute("dur", (-1)*this.speed+"s");
                        child.setAttribute("from", "360 "+this.widget_center[0]+" "+this.widget_center[1]);
                        child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
                    }
                    else{
                        child.setAttribute("from", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
                        child.setAttribute("to", "0 "+this.widget_center[0]+" "+this.widget_center[1]);
                    }
                }
           }
        }

        init() {
            let widget_pos = this.element.getBBox();
            this.widget_center = [(widget_pos.x+widget_pos.width/2), (widget_pos.y+widget_pos.height/2)];
        }
    ||
}


widget_defs("AnimateRotation") {
    param "hmi_element";
    |,
}