# HG changeset patch # User dgaberscek # Date 1587562433 -7200 # Node ID 2a20038fbea90db93cee9665034f3ffdc56a24aa # Parent 304e88bae11556ec031cd281c96c4bac65eac62e Added button and circular bar widgets. diff -r 304e88bae115 -r 2a20038fbea9 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Apr 20 16:19:31 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Wed Apr 22 15:33:53 2020 +0200 @@ -1,6 +1,6 @@ - - + + @@ -896,6 +896,131 @@ }, + + + frequency: 5, + + init: function() { + + this.element.addEventListener( + + "mousedown", + + evt => { + + change_hmi_value(this.indexes[0], "=1"); + + }); + + this.element.addEventListener( + + "mouseup", + + evt => { + + change_hmi_value(this.indexes[0], "=0"); + + }); + + }, + + + + + frequency: 10, + + + + + path + + + + + + value min max + + + + dispatch: function(value) { + + if(this.value_elt) + + this.value_elt.textContent = String(value); + + let [min,max,start,end] = this.range; + + let [cx,cy] = this.center; + + let [rx,ry] = this.proportions; + + let tip = start + (end-start)*Number(value)/(max-min); + + let size = 0; + + if (tip-start > Math.PI) { + + size = 1; + + } else { + + size = 0; + + } + + this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+" A "+rx+","+ry+" 0 "+size+" 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip))); + + }, + + range: undefined, + + init: function() { + + let start = Number(this.path_elt.getAttribute('sodipodi:start')); + + let end = Number(this.path_elt.getAttribute('sodipodi:end')); + + let cx = Number(this.path_elt.getAttribute('sodipodi:cx')); + + let cy = Number(this.path_elt.getAttribute('sodipodi:cy')); + + let rx = Number(this.path_elt.getAttribute('sodipodi:rx')); + + let ry = Number(this.path_elt.getAttribute('sodipodi:ry')); + + if (ry == 0) { + + ry = rx; + + } + + if (start > end) { + + end = end + 2*Math.PI; + + } + + let min = this.min_elt ? + + Number(this.min_elt.textContent) : + + this.args.length >= 1 ? this.args[0] : 0; + + let max = this.max_elt ? + + Number(this.max_elt.textContent) : + + this.args.length >= 2 ? this.args[1] : 100; + + this.range = [min, max, start, end]; + + this.center = [cx, cy]; + + this.proportions = [rx, ry]; + + }, + + frequency: 5, @@ -2336,7 +2461,7 @@ - + diff -r 304e88bae115 -r 2a20038fbea9 svghmi/widget_button.ysl2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/svghmi/widget_button.ysl2 Wed Apr 22 15:33:53 2020 +0200 @@ -0,0 +1,18 @@ +// widget_button.ysl2 + +template "widget[@type='Button']", mode="widget_defs" { + param "hmi_element"; + | frequency: 5, + | init: function() { + | this.element.addEventListener( + | "mousedown", + | evt => { + | change_hmi_value(this.indexes[0], "=1"); + | }); + | this.element.addEventListener( + | "mouseup", + | evt => { + | change_hmi_value(this.indexes[0], "=0"); + | }); + | }, +} \ No newline at end of file diff -r 304e88bae115 -r 2a20038fbea9 svghmi/widget_circularbar.ysl2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/svghmi/widget_circularbar.ysl2 Wed Apr 22 15:33:53 2020 +0200 @@ -0,0 +1,48 @@ +// widget_circularbar.ysl2 + + +template "widget[@type='CircularBar']", mode="widget_defs" { + param "hmi_element"; + | frequency: 10, + labels("path"); + optional_labels("value min max"); + | dispatch: function(value) { + | if(this.value_elt) + | this.value_elt.textContent = String(value); + | let [min,max,start,end] = this.range; + | let [cx,cy] = this.center; + | let [rx,ry] = this.proportions; + | let tip = start + (end-start)*Number(value)/(max-min); + | let size = 0; + | if (tip-start > Math.PI) { + | size = 1; + | } else { + | size = 0; + | } + | this.path_elt.setAttribute('d', "M "+(cx+rx*Math.cos(start))+","+(cy+ry*Math.sin(start))+" A "+rx+","+ry+" 0 "+size+" 1 "+(cx+rx*Math.cos(tip))+","+(cy+ry*Math.sin(tip))); + | }, + | range: undefined, + | init: function() { + | let start = Number(this.path_elt.getAttribute('sodipodi:start')); + | let end = Number(this.path_elt.getAttribute('sodipodi:end')); + | let cx = Number(this.path_elt.getAttribute('sodipodi:cx')); + | let cy = Number(this.path_elt.getAttribute('sodipodi:cy')); + | let rx = Number(this.path_elt.getAttribute('sodipodi:rx')); + | let ry = Number(this.path_elt.getAttribute('sodipodi:ry')); + | if (ry == 0) { + | ry = rx; + | } + | if (start > end) { + | end = end + 2*Math.PI; + | } + | let min = this.min_elt ? + | Number(this.min_elt.textContent) : + | this.args.length >= 1 ? this.args[0] : 0; + | let max = this.max_elt ? + | Number(this.max_elt.textContent) : + | this.args.length >= 2 ? this.args[1] : 100; + | this.range = [min, max, start, end]; + | this.center = [cx, cy]; + | this.proportions = [rx, ry]; + | }, +} \ No newline at end of file