svghmi/widget_slider.ysl2
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 18 May 2021 09:22:17 +0200
branchsvghmi
changeset 3241 fe945f1f48b7
parent 3232 7bdb766c2a4d
child 3283 71ae6f02a7ff
permissions -rw-r--r--
SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
     1
// widget_slider.ysl2
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
     2
3241
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     3
widget_desc("Slider") {
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     4
    longdesc
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     5
    || 
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     6
    Slider - DEPRECATED - use ScrollBar or PathSlider instead
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     7
    ||
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     8
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
     9
    shortdesc > Slider - DEPRECATED - use ScrollBar instead
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    10
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    11
    path name="value" accepts="HMI_INT" > value
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    12
    path name="range" accepts="HMI_INT" > range
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    13
    path name="visible" accepts="HMI_INT" > visible
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    14
    
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    15
}
fe945f1f48b7 SVGHMI: WIP on Widget DnD UI : Added documentation to widgets, that is injected in widget parse tree during widget analysis
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3232
diff changeset
    16
3232
7bdb766c2a4d 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.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3062
diff changeset
    17
widget_class("Slider")
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    18
    ||
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    19
    class SliderWidget extends Widget{
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    20
        frequency = 5;
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    21
        range = undefined;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    22
        handle_orig = undefined;
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    23
        scroll_size = undefined;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    24
        scroll_range = 0;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    25
        scroll_visible = 7;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    26
        min_size = 0.07;
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    27
        fi = undefined;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    28
        curr_value = 0;
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    29
        drag = false;
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    30
        enTimer = false;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    31
        handle_click = undefined;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    32
        last_drag = false;
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    33
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    34
        dispatch(value,oldval, index) {
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    35
            if (index == 0){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    36
                let [min,max,start,totallength] = this.range;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    37
                //save current value inside widget
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    38
                this.curr_value = value;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    39
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    40
                //check if in range
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    41
                if (this.curr_value > max){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    42
                    this.curr_value = max;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    43
                    this.apply_hmi_value(0, this.curr_value);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    44
                }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    45
                else if (this.curr_value < min){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    46
                    this.curr_value = min;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    47
                    this.apply_hmi_value(0, this.curr_value);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    48
                }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    49
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    50
                if(this.value_elt)
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    51
                    this.value_elt.textContent = String(value);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    52
            }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    53
            else if(index == 1){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    54
                this.scroll_range = value;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    55
                this.set_scroll();
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    56
            }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    57
            else if(index == 2){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    58
                this.scroll_visible = value;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    59
                this.set_scroll();
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    60
            }
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    61
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    62
            //don't update if draging and setpoint ghost doesn't exist
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    63
            if(!this.drag || (this.setpoint_elt != undefined)){
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    64
                this.update_DOM(this.curr_value, this.handle_elt);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    65
            }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    66
        }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    67
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    68
        set_scroll(){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    69
            //check if range is bigger than visible and set scroll size
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    70
            if(this.scroll_range > this.scroll_visible){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    71
                this.scroll_size = this.scroll_range - this.scroll_visible;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    72
                this.range[0] = 0;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    73
                this.range[1] = this.scroll_size;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    74
            }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    75
            else{
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    76
                this.scroll_size = 1;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    77
                this.range[0] = 0;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
    78
                this.range[1] = 1;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    79
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    80
        }
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
    81
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
    82
        update_DOM(value, elt){
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
    83
            let [min,max,start,totallength] = this.range;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    84
            // check if handle is resizeable
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    85
            if (this.scroll_size != undefined){ //size changes
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    86
                //get parameters
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    87
                let length = Math.max(min,Math.min(max,(Number(value)-min)*max/(max-min)));
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    88
                let tip = this.range_elt.getPointAtLength(length);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    89
                let handle_min = totallength*this.min_size;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    90
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    91
                let step = 1;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    92
                //check if range is bigger than  max displayed and recalculate step
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    93
                if ((totallength/handle_min) < (max-min+1)){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    94
                    step = (max-min+1)/(totallength/handle_min-1);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    95
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    96
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    97
                let kx,ky,offseY,offseX = undefined;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    98
                //scale on x or y axes
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
    99
                if (this.fi > 0.75){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   100
                    //get scale factor
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   101
                    if(step > 1){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   102
                        ky = handle_min/this.handle_orig.height;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   103
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   104
                    else{
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   105
                        ky = (totallength-handle_min*(max-min))/this.handle_orig.height;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   106
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   107
                    kx = 1;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   108
                    //get 0 offset to stay inside range
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   109
                    offseY = start.y - (this.handle_orig.height + this.handle_orig.y) * ky;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   110
                    offseX = 0;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   111
                    //get distance from value
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   112
                    tip.y =this.range_elt.getPointAtLength(0).y - length/step *handle_min;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   113
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   114
                else{
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   115
                    //get scale factor
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   116
                    if(step > 1){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   117
                        kx = handle_min/this.handle_orig.width;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   118
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   119
                    else{
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   120
                        kx = (totallength-handle_min*(max-min))/this.handle_orig.width;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   121
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   122
                    ky = 1;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   123
                    //get 0 offset to stay inside range
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   124
                    offseX = start.x - (this.handle_orig.x * kx);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   125
                    offseY = 0;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   126
                    //get distance from value
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   127
                    tip.x =this.range_elt.getPointAtLength(0).x + length/step *handle_min;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   128
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   129
                elt.setAttribute('transform',"matrix("+(kx)+" 0 0 "+(ky)+" "+(tip.x-start.x+offseX)+" "+(tip.y-start.y+offseY)+")");
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   130
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   131
            else{ //size stays the same
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   132
                let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min)));
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   133
                let tip = this.range_elt.getPointAtLength(length);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   134
                elt.setAttribute('transform',"translate("+(tip.x-start.x)+","+(tip.y-start.y)+")");
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   135
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   136
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   137
            // show or hide ghost if exists
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   138
            if(this.setpoint_elt != undefined){
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   139
                if(this.last_drag!= this.drag){
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   140
                    if(this.drag){
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   141
                        this.setpoint_elt.setAttribute("style", this.setpoint_style);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   142
                    }else{
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   143
                        this.setpoint_elt.setAttribute("style", "display:none");
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   144
                    }
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   145
                    this.last_drag = this.drag;
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   146
                }
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   147
            }
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   148
        }
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   149
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   150
        on_release(evt) {
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   151
            //unbind events
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   152
            window.removeEventListener("touchmove", this.on_bound_drag, true);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   153
            window.removeEventListener("mousemove", this.on_bound_drag, true);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   154
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
   155
            window.removeEventListener("mouseup", this.bound_on_release, true);
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   156
            window.removeEventListener("touchend", this.bound_on_release, true);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   157
            window.removeEventListener("touchcancel", this.bound_on_release, true);
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   158
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   159
            //reset drag flag
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   160
            if(this.drag){
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   161
                this.drag = false;
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   162
            }
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   163
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   164
            // get final position
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   165
            this.update_position(evt);
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   166
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   167
        }
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   168
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   169
        on_drag(evt){
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   170
            //ignore drag event for X amount of time and if not selected
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   171
            if(this.enTimer && this.drag){
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   172
                this.update_position(evt);
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   173
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   174
                //reset timer
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   175
                this.enTimer = false;
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   176
                setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   177
            }
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   178
        }
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   179
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   180
        update_position(evt){
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   181
            var html_dist = 0;
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   182
            let [min,max,start,totallength] = this.range;
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   183
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   184
            //calculate size of widget in html
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   185
            var range_borders = this.range_elt.getBoundingClientRect();
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   186
            var [minX,minY,maxX,maxY] = [range_borders.left,range_borders.bottom,range_borders.right,range_borders.top];
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   187
            var range_length = Math.sqrt( range_borders.height*range_borders.height + range_borders.width*range_borders.width );
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   188
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   189
            //get range and mouse coordinates
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   190
            var mouseX = undefined;
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   191
            var mouseY = undefined;
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   192
            if (evt.type.startsWith("touch")){
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   193
                mouseX = Math.ceil(evt.touches[0].clientX);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   194
                mouseY = Math.ceil(evt.touches[0].clientY);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   195
            }
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   196
            else{
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   197
                mouseX = evt.pageX;
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   198
                mouseY = evt.pageY;
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   199
            }
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   200
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   201
            // calculate position
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   202
            if (this.handle_click){ //if clicked on handle
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   203
                let moveDist = 0, resizeAdd = 0;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   204
                let range_percent = 1;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   205
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   206
                //set paramters for resizeable handle
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   207
                if (this.scroll_size != undefined){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   208
                    // add one more object to stay inside range
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   209
                    resizeAdd = 1;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   210
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   211
                    //chack if range is bigger than display option and
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   212
                    // calculate percent of range with out handle
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   213
                    if(((max/(max*this.min_size)) < (max-min+1))){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   214
                        range_percent = 1-this.min_size;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   215
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   216
                    else{
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   217
                        range_percent = 1-(max-max*this.min_size*(max-min))/max;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   218
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   219
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   220
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   221
                //calculate value difference on x or y axis
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   222
                if(this.fi > 0.7){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   223
                    moveDist = ((max-min+resizeAdd)/(range_length*range_percent))*((this.handle_click[1]-mouseY)/Math.sin(this.fi));
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   224
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   225
                else{
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   226
                    moveDist = ((max-min+resizeAdd)/(range_length*range_percent))*((mouseX-this.handle_click[0])/Math.cos(this.fi));
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   227
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   228
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   229
                this.curr_value = Math.ceil(this.handle_click[2] + moveDist);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   230
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   231
            else{ //if clicked on widget
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   232
                //get handle distance from mouse position
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   233
                if (minX > mouseX && minY < mouseY){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   234
                    html_dist = 0;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   235
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   236
                else if (maxX < mouseX && maxY > mouseY){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   237
                    html_dist = range_length;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   238
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   239
                else{
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   240
                    if(this.fi > 0.7){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   241
                        html_dist = (minY - mouseY)/Math.sin(this.fi);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   242
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   243
                    else{
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   244
                        html_dist = (mouseX - minX)/Math.cos(this.fi);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   245
                    }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   246
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   247
                //calculate distance
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   248
                this.curr_value=Math.ceil((html_dist/range_length)*(this.range[1]-this.range[0])+this.range[0]);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   249
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   250
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   251
            //check if in range and apply
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   252
            if (this.curr_value > max){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   253
                this.curr_value = max;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   254
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   255
            else if (this.curr_value < min){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   256
                this.curr_value = min;
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   257
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   258
            this.apply_hmi_value(0, this.curr_value);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   259
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   260
            //redraw handle
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   261
            this.request_animate();
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   262
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   263
        }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   264
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   265
        animate(){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   266
            // redraw handle on screen refresh
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   267
            // check if setpoint(ghost) handle exsist otherwise update main handle
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   268
            if(this.setpoint_elt != undefined){
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   269
                this.update_DOM(this.curr_value, this.setpoint_elt);
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   270
            }
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   271
            else{
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   272
                this.update_DOM(this.curr_value, this.handle_elt);
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   273
            }
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   274
        }
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   275
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   276
        on_select(evt){
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   277
            //enable drag flag and timer
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   278
            this.drag = true;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   279
            this.enTimer = true;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   280
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   281
            //bind events
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   282
            window.addEventListener("touchmove", this.on_bound_drag, true);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   283
            window.addEventListener("mousemove", this.on_bound_drag, true);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   284
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   285
            window.addEventListener("mouseup", this.bound_on_release, true);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   286
            window.addEventListener("touchend", this.bound_on_release, true);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   287
            window.addEventListener("touchcancel", this.bound_on_release, true);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   288
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   289
            // check if handle was pressed
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   290
            if (evt.currentTarget == this.handle_elt){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   291
                //get mouse position on the handle
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   292
                let mouseX = undefined;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   293
                let mouseY = undefined;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   294
                if (evt.type.startsWith("touch")){
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   295
                    mouseX = Math.ceil(evt.touches[0].clientX);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   296
                    mouseY = Math.ceil(evt.touches[0].clientY);
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   297
                }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   298
                else{
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   299
                    mouseX = evt.pageX;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   300
                    mouseY = evt.pageY;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   301
                }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   302
                //save coordinates and orig value
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   303
                this.handle_click = [mouseX,mouseY,this.curr_value];
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   304
            }
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   305
            else{
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   306
                // get new handle position and reset if handle was not pressed
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   307
                this.handle_click = undefined;
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   308
                this.update_position(evt);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   309
            }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   310
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   311
            //prevent next events
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   312
            evt.stopPropagation();
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   313
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   314
        }
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   315
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   316
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   317
        init() {
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   318
            //set min max value if not defined
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   319
            let min = this.min_elt ?
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   320
                        Number(this.min_elt.textContent) :
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   321
                        this.args.length >= 1 ? this.args[0] : 0;
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   322
            let max = this.max_elt ?
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   323
                        Number(this.max_elt.textContent) :
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   324
                        this.args.length >= 2 ? this.args[1] : 100;
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   325
3059
e0db3f6a5f39 Button and toggle reworked to use animate and dispatch
usveticic
parents: 3056
diff changeset
   326
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   327
            // save initial parameters
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   328
            this.range_elt.style.strokeMiterlimit="0";
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   329
            this.range = [min, max, this.range_elt.getPointAtLength(0),this.range_elt.getTotalLength()];
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   330
            let start = this.range_elt.getPointAtLength(0);
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   331
            let end = this.range_elt.getPointAtLength(this.range_elt.getTotalLength());
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   332
            this.fi = Math.atan2(start.y-end.y, end.x-start.x);
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   333
            this.handle_orig = this.handle_elt.getBBox();
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   334
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   335
            //bind functions
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   336
            this.bound_on_select = this.on_select.bind(this);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   337
            this.bound_on_release = this.on_release.bind(this);
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   338
            this.on_bound_drag = this.on_drag.bind(this);
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   339
3056
827bf284feec Button, ToggleButton and slider updated. Error to warning when building
usveticic
parents: 3045
diff changeset
   340
            this.handle_elt.addEventListener("mousedown", this.bound_on_select);
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   341
            this.element.addEventListener("mousedown", this.bound_on_select);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   342
            this.element.addEventListener("touchstart", this.bound_on_select);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   343
            //touch recognised as page drag without next command
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   344
            document.body.addEventListener("touchstart", function(e){}, false);
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   345
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   346
            //save ghost style
3021
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   347
            if(this.setpoint_elt != undefined){
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   348
                this.setpoint_style = this.setpoint_elt.getAttribute("style");
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   349
                this.setpoint_elt.setAttribute("style", "display:none");
49799de67540 SVGHMI: add a SetPoint to Slider Widget, visible only when operating the slider.
Edouard Tisserant
parents: 3020
diff changeset
   350
            }
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   351
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   352
        }
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   353
    }
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   354
    ||
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   355
3232
7bdb766c2a4d 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.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3062
diff changeset
   356
widget_defs("Slider") {
3012
65471f50b421 Create new slider widget which extand class widget
usveticic
parents:
diff changeset
   357
    labels("handle range");
3062
9ec338a99a18 Button fix if no active or inactive state,
usveticic
parents: 3059
diff changeset
   358
    optional_labels("value min max setpoint");
3018
Edouard Tisserant
parents: 3012
diff changeset
   359
}