svghmi/widget_animaterotation.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 22 Mar 2022 14:50:46 +0100
branchwxPython4
changeset 3442 29dbdb09da2e
parent 3241 fe945f1f48b7
permissions -rw-r--r--
Tests: fix project edit test sikuli IDE test.

Background click based on bitmap matching doesn't work.
Grid dots are not good match candidates.
Rendering probably affected by virtual display's bpp or rasterizer approximations.
// widget_animaterotation.ysl2

widget_desc("AnimateRotation") {
    longdesc
    ||
    AnimateRotation - DEPRECATED, do not use.
    Doesn't follow WYSIWYG principle, and forces user to add animateTransform tag in SVG (using inkscape XML editor for exemple)
    ||

    shortdesc > AnimateRotation - DEPRECATED

    path name="speed" accepts="HMI_INT,HMI_REAL" > speed
    
}

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
           // TODO : rewrite with proper es6
           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)];
        }
    ||
}