svghmi/widget_button.ysl2
branchsvghmi
changeset 3009 7c6960f09881
parent 3004 705e34c6fe93
child 3018 22b969b409b0
equal deleted inserted replaced
3004:705e34c6fe93 3009:7c6960f09881
     1 // widget_button.ysl2
     1 // widget_button.ysl2
       
     2 
       
     3 template "widget[@type='Button']", mode="widget_class"
       
     4     ||
       
     5     class ButtonWidget extends Widget{
       
     6         frequency = 5;
       
     7         state = 0;
       
     8         active_style = undefined;
       
     9         inactive_style = undefined;
       
    10 
       
    11          on_mouse_down(evt) {
       
    12              if (this.active_style && this.inactive_style) {
       
    13                  this.active_elt.setAttribute("style", this.active_style);
       
    14                  this.inactive_elt.setAttribute("style", "display:none");
       
    15              }
       
    16              change_hmi_value(this.indexes[0], "=1");
       
    17          }
       
    18 
       
    19          on_mouse_up(evt) {
       
    20              if (this.active_style && this.inactive_style) {
       
    21                  this.active_elt.setAttribute("style", "display:none");
       
    22                  this.inactive_elt.setAttribute("style", this.inactive_style);
       
    23              }
       
    24              change_hmi_value(this.indexes[0], "=0");
       
    25          }
       
    26 
       
    27          init() {
       
    28             this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
       
    29             this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
       
    30 
       
    31             if (this.active_style && this.inactive_style) {
       
    32                 this.active_elt.setAttribute("style", "display:none");
       
    33                 this.inactive_elt.setAttribute("style", this.inactive_style);
       
    34             }
       
    35 
       
    36             this.element.setAttribute("onmousedown", "hmi_widgets['«$hmi_element/@id»'].on_mouse_down(evt)");
       
    37             this.element.setAttribute("onmouseup", "hmi_widgets['«$hmi_element/@id»'].on_mouse_up(evt)");
       
    38          }
       
    39     }
       
    40     ||
       
    41 
     2 
    42 
     3 template "widget[@type='Button']", mode="widget_defs" {
    43 template "widget[@type='Button']", mode="widget_defs" {
     4     param "hmi_element";
    44     param "hmi_element";
     5     optional_labels("active inactive");
    45     optional_labels("active inactive");
     6     | frequency: 5,
    46     |,
     7     | on_mouse_down: function(evt) {
       
     8     |     if (this.active_style && this.inactive_style) {
       
     9     |         this.active_elt.setAttribute("style", this.active_style);
       
    10     |         this.inactive_elt.setAttribute("style", "display:none");
       
    11     |     }
       
    12     |     this.apply_hmi_value(0, 1);
       
    13     | },
       
    14     | on_mouse_up: function(evt) {
       
    15     |     if (this.active_style && this.inactive_style) {
       
    16     |         this.active_elt.setAttribute("style", "display:none");
       
    17     |         this.inactive_elt.setAttribute("style", this.inactive_style);
       
    18     |     }
       
    19     |     this.apply_hmi_value(0, 0);
       
    20     | },
       
    21     | active_style: undefined,
       
    22     | inactive_style: undefined,
       
    23     | init: function() {
       
    24     |   this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined;
       
    25     |   this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined;
       
    26     |   if (this.active_style && this.inactive_style) {
       
    27     |       this.active_elt.setAttribute("style", "display:none");
       
    28     |       this.inactive_elt.setAttribute("style", this.inactive_style);
       
    29     |   }
       
    30     |   this.element.setAttribute("onmousedown", "hmi_widgets['«$hmi_element/@id»'].on_mouse_down(evt)");
       
    31     |   this.element.setAttribute("onmouseup", "hmi_widgets['«$hmi_element/@id»'].on_mouse_up(evt)");
       
    32     | },
       
    33 }
    47 }