implement graphical drag feedback for zooming
authorRobert Kaiser <kairo@kairo.at>
Mon, 15 Mar 2010 00:28:21 +0000 (01:28 +0100)
committerRobert Kaiser <kairo@kairo.at>
Mon, 15 Mar 2010 00:28:21 +0000 (01:28 +0100)
xulapp/chrome/mandelbrot/content/mandelbrot.js
xulapp/chrome/mandelbrot/content/mandelbrot.xul

index 788e198bd6059fba5259f21dce6bb6ab2b8b1a06..e4c7d9a77de84f7dcae94470317f5f3ac5b86319 100644 (file)
@@ -401,18 +401,23 @@ function drawPoint(context, img_x, img_y, C, iterMax, algorithm) {
 /***** 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};
 
@@ -447,6 +452,15 @@ function mouseevent(etype, event) {
         }
       }
       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;
   }
 }
index 57198726d9b3624d732a07d989ce38dbeece14c9..5115ed00a6facc7173f68308a923fcdee24fa2ed 100644 (file)
     <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>