/***** pure UI functions *****/
var zoomstart;
+var imgBackup;
function mouseevent(etype, event) {
let canvas = document.getElementById("mbrotImage");
+ let context = canvas.getContext("2d");
switch (etype) {
case 'down':
- if (event.button == 0)
+ if (event.button == 0) {
// left button - start dragzoom
zoomstart = {x: event.clientX - canvas.offsetLeft,
y: event.clientY - canvas.offsetTop};
+ imgBackup = context.getImageData(0, 0, canvas.width, canvas.height);
+ }
break;
case 'up':
if (event.button == 0 && zoomstart) {
+ context.putImageData(imgBackup, 0, 0);
let zoomend = {x: event.clientX - canvas.offsetLeft,
y: event.clientY - canvas.offsetTop};
}
}
zoomstart = undefined;
+ break;
+ case 'move':
+ if (event.button == 0 && zoomstart) {
+ context.putImageData(imgBackup, 0, 0);
+ context.strokeStyle = "rgb(255,255,31)";
+ context.strokeRect(zoomstart.x, zoomstart.y,
+ event.clientX - canvas.offsetLeft - zoomstart.x,
+ event.clientY - canvas.offsetTop - zoomstart.y);
+ }
break;
}
}
<stack>
<html:canvas id="mbrotImage" width="300" height="300"
onmousedown="mouseevent('down', event);"
- onmouseup="mouseevent('up',event);">
+ onmouseup="mouseevent('up',event);"
+ onmousemove="mouseevent('move',event);">
</html:canvas>
<button id="drawButton" label="&fileDraw.label;" oncommand="drawImage();"/>
</stack>