svghmi/widget_button.ysl2
branchsvghmi
changeset 3067 2263f2ecf9bb
parent 3062 9ec338a99a18
child 3085 6b1b23971960
equal deleted inserted replaced
3063:466c3df67835 3067:2263f2ecf9bb
     2 
     2 
     3 template "widget[@type='Button']", mode="widget_class"{
     3 template "widget[@type='Button']", mode="widget_class"{
     4     ||
     4     ||
     5     class ButtonWidget extends Widget{
     5     class ButtonWidget extends Widget{
     6         frequency = 5;
     6         frequency = 5;
     7         state = 0;
     7         state_plc = 0;
       
     8         state_hmi = 0;
     8         plc_lock = false;
     9         plc_lock = false;
     9         active_style = undefined;
    10         active_style = undefined;
    10         inactive_style = undefined;
    11         inactive_style = undefined;
    11 
    12 
    12         dispatch(value) {
    13         dispatch(value) {
    13             if(value){
    14             this.state_plc = value;
    14                 this.button_release();
    15             if(this.plc_lock){
       
    16                 if(this.state_plc == 1){
       
    17                     this.apply_hmi_value(0, 0);
       
    18                     this.plc_lock = false;
       
    19                 }
    15             }
    20             }
       
    21 
       
    22             //redraw button
       
    23             this.state_hmi = this.state_plc;
       
    24             this.request_animate();
    16         }
    25         }
    17 
    26 
    18          on_mouse_down(evt) {
    27         animate(){
    19              if (this.active_style && this.inactive_style) {
    28             if (this.active_style && this.inactive_style) {
    20                  this.active_elt.setAttribute("style", this.active_style);
    29                // redraw button on screen refresh
    21                  this.inactive_elt.setAttribute("style", "display:none");
    30                if (this.state_hmi) {
    22              }
    31                    this.active_elt.setAttribute("style", this.active_style);
    23              this.apply_hmi_value(0, 1);
    32                    this.inactive_elt.setAttribute("style", "display:none");
    24              this.plc_lock = false;
    33                } else {
    25          }
    34                    this.inactive_elt.setAttribute("style", this.inactive_style);
       
    35                    this.active_elt.setAttribute("style", "display:none");
       
    36                }
       
    37            }
       
    38         }
    26 
    39 
    27          on_mouse_up(evt) {
    40         on_click(evt) {
    28              this.button_release();
    41             //set state and apply if plc is 0
    29          }
    42             this.plc_lock = true;
       
    43             if(this.state_plc == 0){
       
    44                 this.apply_hmi_value(0, 1);
       
    45             }
       
    46             //redraw button
       
    47             this.request_animate();
       
    48         }
    30 
    49 
    31          button_release(){
    50         on_press(evt) {
    32             if(!this.plc_lock){
    51             //set graphic
    33                 this.plc_lock = true;
    52             this.state_hmi = 1;
    34             }
    53             //redraw button
    35             else{
    54             this.request_animate();
    36                 if (this.active_style && this.inactive_style) {
    55         }
    37                      this.active_elt.setAttribute("style", "display:none");
       
    38                      this.inactive_elt.setAttribute("style", this.inactive_style);
       
    39                  }
       
    40                  this.apply_hmi_value(0, 0);
       
    41             }
       
    42          }
       
    43 
    56 
    44          init() {
    57          init() {
    45             this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
    58             this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
    46             this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
    59             this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
    47 
    60 
    48             if (this.active_style && this.inactive_style) {
    61             if (this.active_style && this.inactive_style) {
    49                 this.active_elt.setAttribute("style", "display:none");
    62                 this.active_elt.setAttribute("style", "display:none");
    50                 this.inactive_elt.setAttribute("style", this.inactive_style);
    63                 this.inactive_elt.setAttribute("style", this.inactive_style);
    51             }
    64             }
    52 
    65 
    53             this.element.setAttribute("onmousedown", "hmi_widgets["+this.element_id+"].on_mouse_down(evt)");
    66             this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
    54             this.element.setAttribute("onmouseup", "hmi_widgets["+this.element_id+"].on_mouse_up(evt)");
    67             this.element.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_press(evt)");
    55          }
    68          }
    56     }
    69     }
    57     ||
    70     ||
    58 }
    71 }
    59 
    72