commit:411534db84bca553c35962646fda83ad4388cd4a
author:Chip Black
committer:Chip Black
date:Sun Oct 18 18:27:36 2015 -0500
parents:a84018384cbb7b120731ab1499b4ca44f323bc49
Only send tool events when the pixel location changes

Also fix some redraw/refresh ordering issues that were masked by the
more frequent updates.
diff --git a/src/Fill.js b/src/Fill.js
line changes: +0/-1
index 6dff74f..8d16a35
--- a/src/Fill.js
+++ b/src/Fill.js
@@ -18,7 +18,6 @@ export default class Fill extends Controller {
         right--;
 
         this.state.pixelEditor.setHLine(left, y, right - left + 1);
-        //this.state.pixelEditor.redraw(left, y, right - left + 1, 1);
         for (let i = left; i <= right; i++) {
             if (this.state.pixelEditor.getPixel(i, y - 1) == targetColor) {
                 this.fill(i, y - 1, targetColor);

diff --git a/src/Line.js b/src/Line.js
line changes: +1/-1
index c655c78..e9e1424
--- a/src/Line.js
+++ b/src/Line.js
@@ -14,8 +14,8 @@ export default class Line extends Controller {
         if (this.begin) {
             this.state.pixelEditor.resetState();
             this.state.pixelEditor.setLine(this.begin.x, this.begin.y, x, y);
-            this.state.pixelEditor.refresh();
             this.state.pixelEditor.redraw();
+            this.state.pixelEditor.refresh();
         }
     }
     up(x, y) {

diff --git a/src/PixelEditor.js b/src/PixelEditor.js
line changes: +6/-1
index d433d8e..ff1bd0e
--- a/src/PixelEditor.js
+++ b/src/PixelEditor.js
@@ -9,6 +9,7 @@ export default class PixelEditor extends Controller {
         this.node.addEventListener('mousemove', event => this.penMove(event));
         this.node.addEventListener('mouseup', event => this.penUp(event));
 
+        this.lastMoveLocation = {x: null, y: null};
         this.saveStack = [];
         this.gridShowing = true;
         this.setSize(16, 16);
@@ -235,7 +236,11 @@ export default class PixelEditor extends Controller {
     }
     penMove(event) {
         let { x, y } = this.getPixelCoords(event);
-        this.state.toolbox.getTool().move(x, y);
+        if (x != this.lastMoveLocation.x || y != this.lastMoveLocation.y) {
+            this.state.toolbox.getTool().move(x, y);
+            this.lastMoveLocation.x = x;
+            this.lastMoveLocation.y = y;
+        }
     }
     penUp(event) {
         let { x, y } = this.getPixelCoords(event);

diff --git a/src/Rect.js b/src/Rect.js
line changes: +2/-2
index ef69b37..a050cbf
--- a/src/Rect.js
+++ b/src/Rect.js
@@ -22,8 +22,8 @@ export default class Rect extends Controller {
             this.state.pixelEditor.setHLine(x0, y, w);
             this.state.pixelEditor.setVLine(this.begin.x, y0 + 1, h - 2);
             this.state.pixelEditor.setVLine(x, y0 + 1, h - 2);
-            this.state.pixelEditor.refresh();
             this.state.pixelEditor.redraw();
+            this.state.pixelEditor.refresh();
         }
     }
     up(x, y) {
@@ -37,8 +37,8 @@ export default class Rect extends Controller {
         this.state.pixelEditor.setHLine(x0, y, w);
         this.state.pixelEditor.setVLine(this.begin.x, y0 + 1, h - 2);
         this.state.pixelEditor.setVLine(x, y0 + 1, h - 2);
-        this.state.pixelEditor.refresh();
         this.state.pixelEditor.redraw();
+        this.state.pixelEditor.refresh();
         this.begin = null;
     }
 }