Skip to content

Commit

Permalink
PaintWeb generic bug fixes.
Browse files Browse the repository at this point in the history
- Fixed the simple demo to "work" in MSIE. That is: it should nicely tell the
user that PaintWeb does not work. Before this update, the scripts had JS
"errors".

- Improved the Bézier curve. When only two points were available, the line drawn
didn't use the correct color.

- Fixed an image save bug. At times it did "err", because the first argument of
the imageSave() method is a DOM event object instead of a string when invoked as
a command from the toolbar.

--HG--
extra : convert_revision : svn%3Afc1ba2b4-ac28-11dd-a772-7fcde58d38e6/trunk%40119
  • Loading branch information
mihai.sucan committed Aug 24, 2009
1 parent 4169ee4 commit a5cc173
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 45 deletions.
14 changes: 14 additions & 0 deletions CHANGES
@@ -1,3 +1,17 @@
2009-08-24:
===========

- Fixed the simple demo to "work" in MSIE. That is: it should nicely tell the
user that PaintWeb does not work. Before this update, the scripts had JS
"errors".

- Improved the Bézier curve. When only two points were available, the line drawn
didn't use the correct color.

- Fixed an image save bug. At times it did "err", because the first argument of
the imageSave() method is a DOM event object instead of a string when invoked as
a command from the toolbar.

2009-08-23:
===========

Expand Down
12 changes: 9 additions & 3 deletions demos/demo1.html
Expand Up @@ -7,7 +7,7 @@
title="Marius and Mihai Şucan, ROBO Design">

<!-- $URL: http://code.google.com/p/paintweb $
$Date: 2009-07-21 19:51:44 +0300 $ -->
$Date: 2009-08-24 14:14:53 +0300 $ -->
</head>
<body>
<h1>PaintWeb simple demo</h1>
Expand All @@ -26,7 +26,7 @@ <h1>PaintWeb simple demo</h1>
href="http://moodle.org/mod/forum/discuss.php?d=126528">post it over at
Moodle</a>!</p>

<!--[if IE]>
<!--[if lte IE 8]>
<p>Please note that this application does not work in Internet Explorer. Any
other modern browser should work fine. Try <a
href="http://www.google.com/chrome">Chrome</a>, <a
Expand Down Expand Up @@ -91,7 +91,13 @@ <h1>PaintWeb simple demo</h1>
pw.config.configFile = 'config-example.json';
loadp.appendChild(document.createTextNode('Loading, please wait...'));

btn.addEventListener('click', pwStart, false);
if (btn.addEventListener) {
btn.addEventListener('click', pwStart, false);
} else if (btn.attachEvent) {
btn.attachEvent('onclick', pwStart);
} else {
btn.onclick = pwStart;
}
})();
--></script>
</body>
Expand Down
6 changes: 3 additions & 3 deletions ext/moodle/config.json
@@ -1,5 +1,5 @@
{
// $Date: 2009-08-23 16:28:45 +0300 $
// $Date: 2009-08-24 21:08:14 +0300 $

/**
* The list of available languages. This associated language IDs to their
Expand Down Expand Up @@ -244,8 +244,8 @@
"toolDefault": "line",

/**
* Tool drawing delay. Some tools delay their drawing operations for
* performance reasons.
* Tool drawing delay (milliseconds). Some tools delay their drawing
* operations for performance reasons.
*
* @type Number
* @default 80
Expand Down
6 changes: 3 additions & 3 deletions src/config-example.json
@@ -1,5 +1,5 @@
{
// $Date: 2009-08-22 12:05:52 +0300 $
// $Date: 2009-08-24 20:54:41 +0300 $
// TODO: try jsdoc-toolkit on this json (!)

/**
Expand Down Expand Up @@ -241,8 +241,8 @@
"toolDefault": "line",

/**
* Tool drawing delay. Some tools delay their drawing operations for
* performance reasons.
* Tool drawing delay (milliseconds). Some tools delay their drawing
* operations for performance reasons.
*
* @type Number
* @default 80
Expand Down
7 changes: 4 additions & 3 deletions src/interfaces/default/script.js
Expand Up @@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
* $Date: 2009-08-13 20:20:10 +0300 $
* $Date: 2009-08-24 20:28:00 +0300 $
*/

/**
Expand Down Expand Up @@ -946,15 +946,16 @@ pwlib.gui = function (app) {

// Make PaintWeb visible.
var placeholder = config.guiPlaceholder,
placeholderStyle = placeholder.style,
cs = win.getComputedStyle(placeholder, null);
placeholderStyle = placeholder.style;

// We do not reset the display property. We leave this for the stylesheet.
placeholderStyle.height = '';
placeholderStyle.overflow = '';
placeholderStyle.position = '';
placeholderStyle.visibility = '';

var cs = win.getComputedStyle(placeholder, null);

// Do not allow the static positioning for the PaintWeb placeholder.
// Usually, the GUI requires absolute/relative positioning.
if (cs.position === 'static') {
Expand Down
21 changes: 10 additions & 11 deletions src/paintweb.js
Expand Up @@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
* $Date: 2009-08-20 17:51:19 +0300 $
* $Date: 2009-08-24 19:22:53 +0300 $
*/

/**
Expand Down Expand Up @@ -1140,15 +1140,14 @@ function PaintWeb (win, doc) {
* dispatched.
*/
this.updateCanvasScaling = function () {
var res = _self.resolution,
cs = win.getComputedStyle(res.elem, null),
image = _self.image;
bufferStyle = _self.buffer.canvas.style,
layerStyle = _self.layer.canvas.style,
scaleNew = 1;

var width = parseInt(cs.width),
height = parseInt(cs.height);
var res = _self.resolution,
cs = win.getComputedStyle(res.elem, null),
image = _self.image;
bufferStyle = _self.buffer.canvas.style,
layerStyle = _self.layer.canvas.style,
scaleNew = 1,
width = parseInt(cs.width),
height = parseInt(cs.height);

if (pwlib.browser.opera) {
// Opera zoom level detection.
Expand Down Expand Up @@ -2533,7 +2532,7 @@ function PaintWeb (win, doc) {
: 'image/png', 'gif' : 'image/gif'};

// Detect the MIME type of the image currently loaded.
if (!type) {
if (typeof type !== 'string' || !type) {
if (imageLoad && imageLoad.src && imageLoad.src.substr(0, 5) !== 'data:') {
src = imageLoad.src;
pos = src.indexOf('?');
Expand Down
51 changes: 29 additions & 22 deletions src/tools/bcurve.js
Expand Up @@ -17,7 +17,7 @@
* along with PaintWeb. If not, see <http://www.gnu.org/licenses/>.
*
* $URL: http://code.google.com/p/paintweb $
* $Date: 2009-07-01 18:43:53 +0300 $
* $Date: 2009-08-24 13:18:05 +0300 $
*/

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ pwlib.tools.bcurve = function (app) {
timer = null;
}

if (points.length) {
if (points.length > 0) {
context.clearRect(0, 0, image.width, image.height);
}

Expand All @@ -102,7 +102,7 @@ pwlib.tools.bcurve = function (app) {
* @param {Event} ev The DOM Event object.
*/
this.mousedown = function (ev) {
if (points.length == 0) {
if (points.length === 0) {
gui.statusShow('bcurveSnapping');
points.push([mouse.x, mouse.y]);
}
Expand Down Expand Up @@ -141,19 +141,17 @@ pwlib.tools.bcurve = function (app) {

// Add the temporary point while the mouse button is down.
if (mouse.buttonDown) {
if (shiftKey && n == 1) {
if (shiftKey && n === 1) {
snapXY(points[0][0], points[0][1]);
}
points.push([mouse.x, mouse.y]);
n++;
}

var p0 = points[0],
p1 = points[1],
p2 = points[2],
p3 = points[3] || points[2],
lineWidth = context.lineWidth,
strokeStyle = context.strokeStyle;
var p0 = points[0],
p1 = points[1],
p2 = points[2],
p3 = points[3] || points[2];

if (mouse.buttonDown) {
points.pop();
Expand All @@ -167,17 +165,26 @@ pwlib.tools.bcurve = function (app) {
}

// Draw the main line
if (n == 2) {
if (n === 2) {
context.beginPath();
context.moveTo(p0[0], p0[1]+2);
context.lineTo(p1[0], p1[1]+2);
context.lineWidth = 1;
context.strokeStyle = '#000000';

if (config.shapeType === 'fill') {
var lineWidth = context.lineWidth,
strokeStyle = context.strokeStyle;

context.lineWidth = 1;
context.strokeStyle = context.fillStyle;
}

context.stroke();
context.closePath();

context.lineWidth = lineWidth;
context.strokeStyle = strokeStyle;
if (config.shapeType === 'fill') {
context.lineWidth = lineWidth;
context.strokeStyle = strokeStyle;
}

needsRedraw = false;
return;
Expand All @@ -192,11 +199,11 @@ pwlib.tools.bcurve = function (app) {
p3[0], p3[1],
p1[0], p1[1]);

if (config.shapeType != 'stroke') {
if (config.shapeType !== 'stroke') {
context.fill();
}

if (config.shapeType != 'fill') {
if (config.shapeType !== 'fill') {
context.stroke();
}

Expand All @@ -216,7 +223,7 @@ pwlib.tools.bcurve = function (app) {

// 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]) {
if (n === 1 && mouse.x === points[0][0] && mouse.y === points[0][1]) {
mouse.buttonDown = true;
return true;
}
Expand All @@ -226,7 +233,7 @@ pwlib.tools.bcurve = function (app) {
timer = null;
}

if (n == 1 && ev.shiftKey) {
if (n === 1 && ev.shiftKey) {
snapXY(points[0][0], points[0][1]);
}

Expand All @@ -242,9 +249,9 @@ pwlib.tools.bcurve = function (app) {
shiftKey = ev.shiftKey;
_self.draw();

if (n == 2 || n == 3) {
if (n === 2 || n === 3) {
gui.statusShow('bcurveControlPoint' + (n-1));
} else if (n == 4) {
} else if (n === 4) {
gui.statusShow('bcurveActive');
app.layerUpdate();
points = [];
Expand All @@ -263,7 +270,7 @@ pwlib.tools.bcurve = function (app) {
* if not.
*/
this.keydown = function (ev) {
if (!points.length || ev.kid_ != 'Escape') {
if (!points.length || ev.kid_ !== 'Escape') {
return false;
}

Expand Down

0 comments on commit a5cc173

Please sign in to comment.