Permalink
Browse files

performance work for the polygon tool. fixes for curve, line, rect, e…

…llipse. small API change in PaintWeb regarding tool activation. small fix for perf test12 and updated the README file in the perf tests folder.

--HG--
extra : convert_revision : svn%3Afc1ba2b4-ac28-11dd-a772-7fcde58d38e6/trunk%4026
  • Loading branch information...
1 parent ca7c01f commit c51d4d94c803ac36ce2d7d74fd18742d1a0f4e57 mihai.sucan committed May 25, 2009
Showing with 306 additions and 171 deletions.
  1. +11 −0 CHANGES
  2. +2 −3 TODO
  3. +2 −1 src/lang/en.json
  4. +18 −7 src/paintweb.js
  5. +26 −10 src/tools/curve.js
  6. +7 −2 src/tools/ellipse.js
  7. +6 −2 src/tools/line.js
  8. +159 −112 src/tools/poly.js
  9. +7 −2 src/tools/rect.js
  10. +28 −21 src/tools/text.js
  11. +31 −2 tests/gsoc2009/0001-perf/README
  12. +9 −9 tests/gsoc2009/0001-perf/test12.js
View
11 CHANGES
@@ -1,3 +1,14 @@
+2009-05-25:
+===========
+
+- Performance and usability work for the polygon tool.
+- Bug fixes for curve, rectangle, line and ellipse tools.
+- A small change to the way tools can cancel the activation.
+- Updated the text tool to use the new activation cancellation. More work on the
+text tool will come.
+- Updated the tests/gsoc2009/0001-perf/README file and a small fix for perf
+test12.
+
2009-05-23:
===========
View
5 TODO
@@ -1,17 +1,16 @@
$Author: Mihai Şucan $
$URL: http://code.google.com/p/paintweb $
-$Date: 2009-05-08 15:10:40 +0300 $
+$Date: 2009-05-25 21:42:38 +0300 $
-TODO 2009-05-08:
+TODO 2009-05-25:
(PaintWeb will be integrated into Moodle and TinyMCE, which means I have started
working an important part of the TODO below: code reorganization.)
- Complete code reorganization: GUI separation.
- Implement the ColorEditor extension.
- Make shadows work again.
-- Test performance on the XO.
- Application packaging. Currently, all the code is split across multiple files.
For performance reasons, it's best to package all code in a single minified
file.
View
@@ -1,5 +1,5 @@
{
- // $Date: 2009-05-21 15:06:16 +0300 $
+ // $Date: 2009-05-25 17:29:44 +0300 $
"errorInitBufferCanvas": "Error: adding the new buffer canvas element failed.",
"errorInitContext": "Error while initializing the canvas context.",
@@ -41,6 +41,7 @@
"lineMousedown": "Hold the Shift key down for vertical/horizontal snapping.",
"pencilActive": "Click and drag to draw.",
"polyActive": "Click anywhere to start drawing a polygon.",
+ "polyAddPoint": "Click to add another point to the polygon.",
"polyMousedown": "Hold the Shift key down for vertical/horizontal snapping.",
"polyEnd": "To end drawing the polygon simply click in the same place as the last point.",
"rectActive": "Click and drag to draw a rectangle.",
View
@@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
- * $Date: 2009-05-23 20:48:07 +0300 $
+ * $Date: 2009-05-25 18:26:38 +0300 $
*/
/**
@@ -51,7 +51,7 @@ function PaintWeb (win_, doc_) {
* PaintWeb build date (YYYYMMDD).
* @type Number
*/
- this.build = 20090523;
+ this.build = 20090525;
/**
* Holds all the PaintWeb configuration.
@@ -1189,14 +1189,25 @@ function PaintWeb (win_, doc_) {
var tool_obj = new tool(_self, ev);
if (!tool_obj) {
- alert(_self.lang.errorToolActivate);
return false;
}
- // The activation of the tool has been cancelled. This can happen via user
- // intervention or due to technical aspects, for example the tool
- // "constructor" determines some APIs are not available.
- if (tool_obj._cancel) {
+ /*
+ * Each tool can implement its own mouse and keyboard events handler.
+ * Additionally, tool objects can implement handlers for the deactivation
+ * and activation events.
+ * Given tool1 is active and tool2 is going to be activated, then the
+ * following event handlers will be called:
+ *
+ * tool2.preActivate
+ * tool1.deactivate
+ * tool2.activate
+ *
+ * In the 'preActivate' event handler you can cancel the tool activation by
+ * returning a value which evaluates to false.
+ */
+
+ if ('preActivate' in tool_obj && !tool_obj.preActivate(ev)) {
tool_obj = null;
return false;
}
View
@@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
- * $Date: 2009-05-21 15:55:52 +0300 $
+ * $Date: 2009-05-25 18:15:04 +0300 $
*/
/**
@@ -138,16 +138,18 @@ PaintWebInstance.toolAdd('curve', function (app) {
return;
}
+ var n = points.length;
+
// Add the temporary point while the mouse button is down.
if (mouse.buttonDown) {
- if (shiftKey && points.length == 1) {
+ if (shiftKey && n == 1) {
snapXY(points[0][0], points[0][1]);
}
points.push([mouse.x, mouse.y]);
+ n++;
}
- var n = points.length,
- p0 = points[0],
+ var p0 = points[0],
p1 = points[1],
p2 = points[2],
p3 = points[3] || points[2],
@@ -162,6 +164,7 @@ PaintWebInstance.toolAdd('curve', function (app) {
context.clearRect(0, 0, image.width, image.height);
if (!n) {
+ needsRedraw = false;
return;
}
@@ -178,9 +181,12 @@ PaintWebInstance.toolAdd('curve', function (app) {
context.lineWidth = lineWidth;
context.strokeStyle = strokeStyle;
+ needsRedraw = false;
return;
}
+ // Draw the Bézier curve
+
context.beginPath();
context.moveTo(p0[0], p0[1]);
context.bezierCurveTo(
@@ -208,32 +214,42 @@ PaintWebInstance.toolAdd('curve', function (app) {
* @param {Event} ev The DOM Event object.
*/
this.mouseup = function (ev) {
+ var n = points.length;
+
+ // Allow click+mousemove+click, not only mousedown+mousemove+mouseup.
+ // Do this only for the start point.
+ if (n == 1 && mouse.x == points[0][0] && mouse.y == points[0][1]) {
+ mouse.buttonDown = true;
+ return true;
+ }
+
if (timer) {
clearInterval(timer);
timer = null;
}
- var n = points.length;
-
if (n == 1 && ev.shiftKey) {
snapXY(points[0][0], points[0][1]);
}
// We need 4 points to draw the Bézier curve: start, end, and two control
// points.
- if (n < 3) {
- statusShow('curveControlPoint' + n);
+ if (n < 4) {
points.push([mouse.x, mouse.y]);
+ needsRedraw = true;
+ n++;
}
// Make sure the canvas is up-to-date.
shiftKey = ev.shiftKey;
_self.draw();
- if (n == 3) {
+ if (n == 2 || n == 3) {
+ statusShow('curveControlPoint' + (n-1));
+ } else if (n == 4) {
statusShow('curveActive');
- points = [];
layerUpdate();
+ points = [];
}
return true;
View
@@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
- * $Date: 2009-05-20 19:53:02 +0300 $
+ * $Date: 2009-05-25 18:07:12 +0300 $
*/
/**
@@ -171,6 +171,7 @@ PaintWebInstance.toolAdd('ellipse', function (app) {
h = recty1-recty0;
if (!w || !h) {
+ needsRedraw = false;
return;
}
@@ -231,10 +232,13 @@ PaintWebInstance.toolAdd('ellipse', function (app) {
/**
* End the drawing operation, once the user releases the mouse button.
+ *
+ * @param {Event} ev The DOM Event object.
*/
- this.mouseup = function () {
+ this.mouseup = function (ev) {
// Allow click+mousemove, not only mousedown+move+up
if (mouse.x == x0 && mouse.y == y0) {
+ mouse.buttonDown = true;
return true;
}
@@ -243,6 +247,7 @@ PaintWebInstance.toolAdd('ellipse', function (app) {
timer = null;
}
+ shiftKey = ev.shiftKey;
_self.draw();
layerUpdate();
statusShow('ellipseActive');
View
@@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
- * $Date: 2009-05-20 19:53:44 +0300 $
+ * $Date: 2009-05-25 18:08:21 +0300 $
*/
/**
@@ -170,10 +170,13 @@ PaintWebInstance.toolAdd('line', function (app) {
/**
* End the drawing operation, once the user releases the mouse button.
+ *
+ * @param {Event} ev The DOM Event object.
*/
- this.mouseup = function () {
+ this.mouseup = function (ev) {
// Allow users to click then drag, not only mousedown+drag+mouseup.
if (mouse.x == x0 && mouse.y == y0) {
+ mouse.buttonDown = true;
return true;
}
@@ -182,6 +185,7 @@ PaintWebInstance.toolAdd('line', function (app) {
timer = null;
}
+ shiftKey = ev.shiftKey;
_self.draw();
statusShow('lineActive');
layerUpdate();
Oops, something went wrong.

0 comments on commit c51d4d9

Please sign in to comment.