# HG changeset patch # User usveticic # Date 1597743748 -7200 # Node ID f6d428330e0471cbb7c4f75a4c8edf7785f3cd4f # Parent 61b0491fe05b56b398118952ad2a3f7b9338f686 All widgets reworked to use widget class and animate function if needed diff -r 61b0491fe05b -r f6d428330e04 svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Mon Aug 17 10:00:25 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Tue Aug 18 11:42:28 2020 +0200 @@ -1,9 +1,9 @@ - - - - - + + + + + HMI_PLC_STATUS @@ -12,11 +12,11 @@ HMI_CURRENT_PAGE - + - + @@ -63,8 +63,8 @@ - - + + @@ -96,7 +96,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -114,16 +114,16 @@ - + - - - + + + @@ -134,7 +134,7 @@ - + @@ -160,15 +160,15 @@ - + - - + + @@ -202,7 +202,7 @@ - + @@ -215,12 +215,12 @@ - - + + - + @@ -266,7 +266,7 @@ - + @@ -301,8 +301,8 @@ - - + + @@ -324,10 +324,10 @@ - + - + @@ -337,13 +337,13 @@ - - - + + + - - + + @@ -383,13 +383,13 @@ - - + + - - - + + + @@ -401,9 +401,9 @@ - - - + + + @@ -417,13 +417,13 @@ - - + + - - - + + + @@ -437,8 +437,8 @@ - - + + @@ -472,18 +472,18 @@ - - - + + + - - - - - - - - + + + + + + + + " ": { @@ -540,10 +540,10 @@ jumps: [ - + - + @@ -576,7 +576,7 @@ } - + } @@ -670,16 +670,18 @@ All units must be set to "px" in Inkscape's document properties - - - - + + + + - + + - + + @@ -705,8 +707,11 @@ y + + id + - + transform @@ -715,11 +720,16 @@ style - + - + + + + + + @@ -746,7 +756,7 @@ - + @@ -756,7 +766,7 @@ - + @@ -773,6 +783,12 @@ + + + + + + @@ -786,7 +802,7 @@ - + @@ -795,7 +811,7 @@ - + @@ -845,8 +861,8 @@ - - + + " @@ -913,7 +929,7 @@ ],{ - + }) @@ -926,7 +942,7 @@ - + @@ -1024,8 +1040,6 @@ let defaultval = local_defaults[varname]; - console.log("page_local_index creat local", varname, pagename, new_index, defaultval); - if(defaultval != undefined) cache[new_index] = defaultval; @@ -1284,7 +1298,7 @@ - + @@ -1301,8 +1315,8 @@ } - - + + @@ -1322,14 +1336,14 @@ - - - + + + - + - - + + @@ -1354,8 +1368,8 @@ _sub: { - - + + @@ -1508,109 +1522,121 @@ - + active inactive - + + + class CircularBarWidget extends Widget{ + + frequency = 10; + + range = undefined; + + + + dispatch(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))); + + } + + + + init() { + + 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: 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]; - - }, + @@ -1624,23 +1650,59 @@ handle_pos = undefined; + svg_dist = undefined; + drag = false; enTimer = false; + last_drag = false; + dispatch(value) { - if(!this.drag){ - - if(this.value_elt) - - this.value_elt.textContent = String(value); - - - - this.handle_position(value); + if(this.value_elt) + + this.value_elt.textContent = String(value); + + + + this.update_DOM(value, this.handle_elt); + + } + + + + update_DOM(value, elt){ + + let [min,max,totalDistance] = this.range; + + let length = Math.max(0,Math.min((totalDistance),(Number(value)-min)/(max-min)*(totalDistance))); + + let tip = this.range_elt.getPointAtLength(length); + + elt.setAttribute('transform',"translate("+(tip.x-this.handle_pos.x)+","+(tip.y-this.handle_pos.y)+")"); + + + + if(this.setpoint_elt != undefined){ + + if(this.last_drag!= this.drag){ + + if(this.drag){ + + this.setpoint_elt.setAttribute("style", this.setpoint_style); + + }else{ + + this.setpoint_elt.setAttribute("style", "display:none"); + + } + + this.last_drag = this.drag; + + } } @@ -1648,28 +1710,46 @@ - handle_position(value){ - - let [min,max,totalDistance] = this.range; - - let length = Math.max(0,Math.min((totalDistance),(Number(value)-min)/(max-min)*(totalDistance))); - - let tip = this.range_elt.getPointAtLength(length); - - this.handle_elt.setAttribute('transform',"translate("+(tip.x-this.handle_pos.x)+","+(tip.y-this.handle_pos.y)+")"); - - } - - - on_release(evt) { + window.removeEventListener("touchmove", this.on_bound_drag, true); + + window.removeEventListener("mousemove", this.on_bound_drag, true); + + + + window.removeEventListener("mouseup", this.bound_on_release, true) + + window.removeEventListener("touchend", this.bound_on_release, true); + + window.removeEventListener("touchcancel", this.bound_on_release, true); + if(this.drag){ this.drag = false; } + this.update_position(evt); + + } + + + + on_drag(evt){ + + if(this.enTimer && this.drag){ + + this.update_position(evt); + + //reset timer + + this.enTimer = false; + + setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100); + + } + } @@ -1762,41 +1842,37 @@ if(fi<fiEnd){ - svg_dist=(fi)/(fiEnd)*(this.range[1]-this.range[0]); + this.svg_dist=(fi)/(fiEnd)*(this.range[1]-this.range[0]); } else if(fiEnd<fi && fi<fiEnd+minMax){ - svg_dist = this.range[1]; + this.svg_dist = this.range[1]; } else{ - svg_dist = this.range[0]; + this.svg_dist = this.range[0]; } - //redraw handle --TODO is it fast enough if I just call change_hmi_value??? - - this.handle_position(svg_dist); - - if(this.value_elt) - - this.value_elt.textContent = String(Math.ceil(svg_dist)); - - this.apply_hmi_value(0, Math.ceil(svg_dist)); - - - - //reset timer - - this.enTimer = false; - - setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100); + + + this.apply_hmi_value(0, Math.ceil(this.svg_dist)); + + + + // update ghost cursor + + if(this.setpoint_elt != undefined){ + + this.request_animate(); + + } } @@ -1806,12 +1882,32 @@ + animate(){ + + this.update_DOM(this.svg_dist, this.setpoint_elt); + + } + + + on_select(evt){ this.drag = true; this.enTimer = true; + window.addEventListener("touchmove", this.on_bound_drag, true); + + window.addEventListener("mousemove", this.on_bound_drag, true); + + + + window.addEventListener("mouseup", this.bound_on_release, true) + + window.addEventListener("touchend", this.bound_on_release, true); + + window.addEventListener("touchcancel", this.bound_on_release, true); + this.update_position(evt); } @@ -1880,13 +1976,33 @@ + //bind functions + + this.bound_on_select = this.on_select.bind(this); + + this.bound_on_release = this.on_release.bind(this); + + this.on_bound_drag = this.on_drag.bind(this); + + + //init events - this.handle_elt.addEventListener("touchstart", hmi_widgets[this.element_id].on_select.bind(this)); - - this.handle_elt.addEventListener("mousedown", hmi_widgets[this.element_id].on_select.bind(this)); - - this.element.addEventListener("mousedown", hmi_widgets[this.element_id].on_select.bind(this)); + this.element.addEventListener("mousedown", this.bound_on_select); + + this.element.addEventListener("touchstart", this.bound_on_select); + + + + if(this.setpoint_elt != undefined){ + + this.setpoint_style = this.setpoint_elt.getAttribute("style"); + + this.setpoint_elt.setAttribute("style", "display:none"); + + } + + @@ -1912,17 +2028,17 @@ - + handle range - + value min max - + @@ -2454,7 +2570,7 @@ - + text box button @@ -2980,13 +3096,13 @@ must have one argument given : a class name. - - - - - - - + + + + + + + index_pool: [ @@ -3002,11 +3118,11 @@ init: function() { - - - + + + - + id(" ").setAttribute("onclick", "hmi_widgets[' @@ -3020,13 +3136,13 @@ this.items = [ - - + + - - - - + + + + [ /* item=" " path=" @@ -3217,22 +3333,22 @@ - + key_pos - + - + value - + - + frequency: 5, @@ -3250,7 +3366,7 @@ }, - + init: function() { @@ -3365,27 +3481,50 @@ . + + - - - - - Clones (svg:use) in JsonTable Widget must point to a valid HMI:List widget or HMI:List item. Reference " - - " is not valid. - - - id(" - - ").setAttribute("xlink:href", - - "#"+hmi_widgets[" - - "].items[ - - ]); - + + + + + + id(" + + ").setAttribute("xlink:href", + + "#"+hmi_widgets[" + + "].items[ + + ]); + + + + console.log("from_textsylelist"," + + ", " + + ", + + , + + hmi_widgets[" + + "].items[ + + ]); + + + + + Clones (svg:use) in JsonTable Widget must point to a valid HMI:List or HMI:TextStyleList widget or item. Reference " + + " is not valid and will not be updated. + + + @@ -3401,7 +3540,7 @@ - + @@ -3411,7 +3550,7 @@ = - + ; @@ -3424,23 +3563,23 @@ - + data - + forward backward cursor - + - + spread_json_data: function(jdata) { - + } @@ -3448,38 +3587,38 @@ - + active inactive - + - + disabled - + - + - + - + - + active: false, @@ -3682,9 +3821,9 @@ var keypads = { - + - + " ":[" @@ -3707,7 +3846,7 @@ moving = undefined; - enTimer = undefined; + click = undefined; offset = undefined; @@ -3717,7 +3856,21 @@ this.moving = true; - this.enTimer = true; + + + // chatch window events + + window.addEventListener("touchmove", this.bound_on_drag, true); + + window.addEventListener("mousemove", this.bound_on_drag, true); + + + + window.addEventListener("mouseup", this.bound_on_release, true) + + window.addEventListener("touchend", this.bound_on_release, true); + + window.addEventListener("touchcancel", this.bound_on_release, true); @@ -3751,7 +3904,23 @@ - off_position_click(evt) { + on_release(evt) { + + //relase binds + + window.removeEventListener("touchmove", this.bound_on_drag, true); + + window.removeEventListener("mousemove", this.bound_on_drag, true); + + + + window.removeEventListener("mouseup", this.bound_on_release, true) + + window.removeEventListener("touchend", this.bound_on_release, true); + + window.removeEventListener("touchcancel", this.bound_on_release, true); + + if(this.moving) @@ -3761,63 +3930,65 @@ - on_move(evt) { - - if(this.moving && this.enTimer){ - - //get keyboard pos in html - - let [eltid, tmpgrp] = current_modal; - - let [xcoord,ycoord] = this.coordinates; - - let [xdest,ydest,svgWidth,svgHeight] = page_desc[current_visible_page].bbox; - - - - //get mouse coordinates - - var clickX = undefined; - - var clickY = undefined; - - if (evt.type == "touchmove"){ - - clickX = Math.ceil(evt.touches[0].clientX); - - clickY = Math.ceil(evt.touches[0].clientY); - - } - - else{ - - clickX = evt.pageX; - - clickY = evt.pageY; - - } - - - - //translate keyboard position - - let mouseX = ((clickX-this.offset[0])/window.innerWidth)*svgWidth; - - let mouseY = ((clickY-this.offset[1])/window.innerHeight)*svgHeight; - - tmpgrp.setAttribute("transform","translate("+String(xdest-xcoord+mouseX)+","+String(ydest-ycoord+mouseY)+")"); - - - - //reset timer - - this.enTimer = false; - - setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100); - - } - - + on_drag(evt) { + + if(this.moving) + + //get mouse coordinates + + var clickX = undefined; + + var clickY = undefined; + + if (evt.type == "touchmove"){ + + clickX = Math.ceil(evt.touches[0].clientX); + + clickY = Math.ceil(evt.touches[0].clientY); + + } + + else{ + + clickX = evt.pageX; + + clickY = evt.pageY; + + } + + this.click = [clickX,clickY] + + + + //requeset redraw + + this.request_animate(); + + } + + + + animate(){ + + //get keyboard pos in html + + let [eltid, tmpgrp] = current_modal; + + let [xcoord,ycoord] = this.coordinates; + + let [clickX,clickY] = this.click; + + let [xdest,ydest,svgWidth,svgHeight] = page_desc[current_visible_page].bbox; + + + + //translate keyboard position + + let mouseX = ((clickX-this.offset[0])/window.innerWidth)*svgWidth; + + let mouseY = ((clickY-this.offset[1])/window.innerHeight)*svgHeight; + + tmpgrp.setAttribute("transform","translate("+String(xdest-xcoord+mouseX)+","+String(ydest-ycoord+mouseY)+")"); } @@ -3997,25 +4168,25 @@ - + Esc Enter BackSpace Keys Info Value - + Sign Space NumDot position - + - + CapsLock Shift - - + + init: function() { @@ -4045,27 +4216,23 @@ if(this.position_elt){ + this.bound_on_release = this.on_release.bind(this); + + this.bound_on_drag = this.on_drag.bind(this); + + + this.position_elt.setAttribute("onmousedown", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)"); this.position_elt.setAttribute("ontouchstart", "hmi_widgets['"+this.element_id+"'].on_position_click(evt)"); - window.addEventListener("mouseup", hmi_widgets[this.element_id].off_position_click.bind(this)); - - window.addEventListener("touchend", hmi_widgets[this.element_id].off_position_click.bind(this)); - - window.addEventListener("touchcancel", hmi_widgets[this.element_id].off_position_click.bind(this)); - - window.addEventListener("mousemove", hmi_widgets[this.element_id].on_move.bind(this)); - - window.addEventListener("touchmove", hmi_widgets[this.element_id].on_move.bind(this)); - } }, - + coordinates: [ , @@ -4073,7 +4240,7 @@ ], - + items: { @@ -4088,62 +4255,76 @@ }, + + class MeterWidget extends Widget{ + + frequency = 10; + + origin = undefined; + + range = undefined; + + + + dispatch(value) { + + if(this.value_elt) + + this.value_elt.textContent = String(value); + + let [min,max,totallength] = this.range; + + let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); + + let tip = this.range_elt.getPointAtLength(length); + + this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); + + } + + + + init() { + + 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, this.range_elt.getTotalLength()] + + this.origin = this.needle_elt.getPointAtLength(0); + + } + + + + } + + - frequency: 10, - - + needle range - + value min max - + - dispatch: function(value) { - - if(this.value_elt) - - this.value_elt.textContent = String(value); - - let [min,max,totallength] = this.range; - - let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); - - let tip = this.range_elt.getPointAtLength(length); - - this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); - - }, - - origin: undefined, - - range: undefined, - - init: function() { - - 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, this.range_elt.getTotalLength()] - - this.origin = this.needle_elt.getPointAtLength(0); - - }, + @@ -4232,9 +4413,9 @@ choices: [ - + - + { elt:id(" @@ -4268,6 +4449,8 @@ fi = undefined; + svg_dist = undefined; + drag = false; enTimer = false; @@ -4578,17 +4761,17 @@ - + handle range - + value min max setpoint - + @@ -4623,9 +4806,9 @@ choices: [ - + - + { elt:id(" @@ -4713,7 +4896,7 @@ - + active inactive diff -r 61b0491fe05b -r f6d428330e04 svghmi/widget_circularbar.ysl2 --- a/svghmi/widget_circularbar.ysl2 Mon Aug 17 10:00:25 2020 +0200 +++ b/svghmi/widget_circularbar.ysl2 Tue Aug 18 11:42:28 2020 +0200 @@ -1,48 +1,57 @@ // widget_circularbar.ysl2 +template "widget[@type='CircularBar']", mode="widget_class"{ + || + class CircularBarWidget extends Widget{ + frequency = 10; + range = undefined; + + dispatch(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))); + } + + init() { + 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]; + } + } + || +} 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 diff -r 61b0491fe05b -r f6d428330e04 svghmi/widget_circularslider.ysl2 --- a/svghmi/widget_circularslider.ysl2 Mon Aug 17 10:00:25 2020 +0200 +++ b/svghmi/widget_circularslider.ysl2 Tue Aug 18 11:42:28 2020 +0200 @@ -7,29 +7,56 @@ range = undefined; circle = undefined; handle_pos = undefined; + svg_dist = undefined; drag = false; enTimer = false; + last_drag = false; dispatch(value) { - if(!this.drag){ - if(this.value_elt) - this.value_elt.textContent = String(value); - - this.handle_position(value); - } - } - - handle_position(value){ + if(this.value_elt) + this.value_elt.textContent = String(value); + + this.update_DOM(value, this.handle_elt); + } + + update_DOM(value, elt){ let [min,max,totalDistance] = this.range; let length = Math.max(0,Math.min((totalDistance),(Number(value)-min)/(max-min)*(totalDistance))); let tip = this.range_elt.getPointAtLength(length); - this.handle_elt.setAttribute('transform',"translate("+(tip.x-this.handle_pos.x)+","+(tip.y-this.handle_pos.y)+")"); + elt.setAttribute('transform',"translate("+(tip.x-this.handle_pos.x)+","+(tip.y-this.handle_pos.y)+")"); + + if(this.setpoint_elt != undefined){ + if(this.last_drag!= this.drag){ + if(this.drag){ + this.setpoint_elt.setAttribute("style", this.setpoint_style); + }else{ + this.setpoint_elt.setAttribute("style", "display:none"); + } + this.last_drag = this.drag; + } + } } on_release(evt) { + window.removeEventListener("touchmove", this.on_bound_drag, true); + window.removeEventListener("mousemove", this.on_bound_drag, true); + + window.removeEventListener("mouseup", this.bound_on_release, true) + window.removeEventListener("touchend", this.bound_on_release, true); + window.removeEventListener("touchcancel", this.bound_on_release, true); if(this.drag){ this.drag = false; } + this.update_position(evt); + } + + on_drag(evt){ + if(this.enTimer && this.drag){ + this.update_position(evt); + //reset timer + this.enTimer = false; + setTimeout("{hmi_widgets['"+this.element_id+"'].enTimer = true;}", 100); + } } update_position(evt){ @@ -76,31 +103,39 @@ //get handle distance from mouse position if(fi= 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, this.range_elt.getTotalLength()] + this.origin = this.needle_elt.getPointAtLength(0); + } + + } + || +} template "widget[@type='Meter']", mode="widget_defs" { param "hmi_element"; - | frequency: 10, labels("needle range"); optional_labels("value min max"); - | dispatch: function(value) { - | if(this.value_elt) - | this.value_elt.textContent = String(value); - | let [min,max,totallength] = this.range; - | let length = Math.max(0,Math.min(totallength,(Number(value)-min)*totallength/(max-min))); - | let tip = this.range_elt.getPointAtLength(length); - | this.needle_elt.setAttribute('d', "M "+this.origin.x+","+this.origin.y+" "+tip.x+","+tip.y); - | }, - | origin: undefined, - | range: undefined, - | init: function() { - | 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, this.range_elt.getTotalLength()] - | this.origin = this.needle_elt.getPointAtLength(0); - | }, + |, } diff -r 61b0491fe05b -r f6d428330e04 svghmi/widget_slider.ysl2 --- a/svghmi/widget_slider.ysl2 Mon Aug 17 10:00:25 2020 +0200 +++ b/svghmi/widget_slider.ysl2 Tue Aug 18 11:42:28 2020 +0200 @@ -6,6 +6,7 @@ frequency = 5; range = undefined; fi = undefined; + svg_dist = undefined; drag = false; enTimer = false;