dgaberscek@2944: // widget_button.ysl2 dgaberscek@2944: Edouard@3024: template "widget[@type='Button']", mode="widget_class"{ usveticic@3009: || usveticic@3009: class ButtonWidget extends Widget{ usveticic@3009: frequency = 5; usveticic@3009: state = 0; usveticic@3009: active_style = undefined; usveticic@3009: inactive_style = undefined; usveticic@3009: Edouard@3039: // TODO decouple update of DOM from event (i.e use animate()) usveticic@3009: usveticic@3009: Edouard@3039: // TODO State of the button should distinguish UI feedbak from current PLC value usveticic@3009: Edouard@3039: on_mouse_down(evt) { Edouard@3039: if (this.active_style && this.inactive_style) { Edouard@3039: this.active_elt.setAttribute("style", this.active_style); Edouard@3039: this.inactive_elt.setAttribute("style", "display:none"); Edouard@3039: } Edouard@3039: this.apply_hmi_value(0, 1); Edouard@3039: // TODO inhibit all mouse/touch events except mouse up (in other word grab cursor) Edouard@3039: } Edouard@3039: Edouard@3039: on_mouse_up(evt) { usveticic@3009: if (this.active_style && this.inactive_style) { usveticic@3009: this.active_elt.setAttribute("style", "display:none"); usveticic@3009: this.inactive_elt.setAttribute("style", this.inactive_style); usveticic@3009: } Edouard@3039: this.apply_hmi_value(0, 0); Edouard@3039: // TODO release inhibited events Edouard@3039: } usveticic@3009: Edouard@3039: init() { Edouard@3039: // TODO : move to widget_defs so that we can have generated string literals directly Edouard@3039: this.active_style = this.active_elt ? this.active_elt.style.cssText : undefined; Edouard@3039: this.inactive_style = this.inactive_elt ? this.inactive_elt.style.cssText : undefined; Edouard@3039: Edouard@3039: if (this.active_style && this.inactive_style) { Edouard@3039: this.active_elt.setAttribute("style", "display:none"); Edouard@3039: this.inactive_elt.setAttribute("style", this.inactive_style); Edouard@3039: } Edouard@3039: Edouard@3039: this.element.setAttribute("onmousedown", "hmi_widgets[\""+this.element_id+"\"].on_mouse_down(evt)"); Edouard@3039: this.element.setAttribute("onmouseup", "hmi_widgets[\""+this.element_id+"\"].on_mouse_up(evt)"); Edouard@3039: } usveticic@3009: } usveticic@3009: || Edouard@3024: } usveticic@3009: usveticic@3009: dgaberscek@2976: template "widget[@type='Button']", mode="widget_defs" { dgaberscek@2976: param "hmi_element"; dgaberscek@2976: optional_labels("active inactive"); usveticic@3009: |, edouard@3000: }