Integration (with myself) fixes

- Adding default value in empty frames to avoid artifact when paint
bucketing (you may have issues with previously stored model before this
commit, no migration plan for papybrossette :D)
 - Fix issue: Model does not show up when loading a remote GAE model
 - Removing FRAMESHEET_UPDATED events (remains of history manager
implementation)
This commit is contained in:
Vince 2012-09-03 20:45:25 +02:00
parent c6d338507e
commit 2a20cc90ea
9 changed files with 45 additions and 43 deletions

View File

@ -1,6 +1,16 @@
var Constants = { var Constants = {
DEFAULT_PEN_COLOR : '#000000', DEFAULT_PEN_COLOR : '#000000',
TRANSPARENT_COLOR : "TRANSPARENT", TRANSPARENT_COLOR : 'TRANSPARENT',
/*
* Fake semi-transparent color used to highlight transparent
* strokes and rectangles:
*/
SELECTION_TRANSPARENT_COLOR: 'rgba(255, 255, 255, 0.6)',
/*
* Default entry point for piskel web service:
*/
PISKEL_SERVICE_URL: 'http://2.piskel-app.appspot.com' PISKEL_SERVICE_URL: 'http://2.piskel-app.appspot.com'
}; };

View File

@ -21,8 +21,10 @@
context.clearRect(col * dpi, row * dpi, dpi, dpi); context.clearRect(col * dpi, row * dpi, dpi, dpi);
} }
else { else {
// TODO(vincz): Found a better design to update the palette, it's called too frequently. if(color != Constants.SELECTION_TRANSPARENT_COLOR) {
$.publish(Events.COLOR_USED, [color]); // TODO(vincz): Found a better design to update the palette, it's called too frequently.
$.publish(Events.COLOR_USED, [color]);
}
context.fillStyle = color; context.fillStyle = color;
context.fillRect(col * dpi, row * dpi, dpi, dpi); context.fillRect(col * dpi, row * dpi, dpi, dpi);
} }

View File

@ -32,10 +32,4 @@
ns.Eraser.prototype.moveToolAt = function(col, row, frame, color, canvas, dpi) { ns.Eraser.prototype.moveToolAt = function(col, row, frame, color, canvas, dpi) {
this.applyToolAt(col, row, frame, color, canvas, dpi); this.applyToolAt(col, row, frame, color, canvas, dpi);
}; };
ns.Eraser.prototype.releaseToolAt = function(col, row, frame, color, canvas, dpi) {
// TODO: Create a afterRelease event hook or put that deep in the model
$.publish(Events.FRAMESHEET_UPDATED);
};
})(); })();

View File

@ -21,18 +21,12 @@
var targetColor = pskl.utils.normalizeColor(frame[col][row]); var targetColor = pskl.utils.normalizeColor(frame[col][row]);
//this.recursiveFloodFill_(frame, col, row, targetColor, color); //this.recursiveFloodFill_(frame, col, row, targetColor, color);
this.queueLinearFloodFill_(frame, col, row, targetColor, color); this.queueLinearFloodFill_(frame, col, row, targetColor, color);
$.publish(Events.FRAMESHEET_UPDATED);
// Draw in canvas: // Draw in canvas:
// TODO: Remove that when we have the centralized redraw loop // TODO: Remove that when we have the centralized redraw loop
this.drawFrameInCanvas(frame, canvas, dpi); this.drawFrameInCanvas(frame, canvas, dpi);
}; };
ns.PaintBucket.prototype.releaseToolAt = function(col, row, frame, color, canvas, dpi) {
// TODO: Create a afterRelease event hook or put that deep in the model
$.publish(Events.FRAMESHEET_UPDATED);
};
/** /**
* Flood-fill (node, target-color, replacement-color): * Flood-fill (node, target-color, replacement-color):
* 1. Set Q to the empty queue. * 1. Set Q to the empty queue.

View File

@ -49,7 +49,7 @@
for(var i = 0; i< strokePoints.length; i++) { for(var i = 0; i< strokePoints.length; i++) {
if(color == Constants.TRANSPARENT_COLOR) { if(color == Constants.TRANSPARENT_COLOR) {
color = "rgba(255, 255, 255, 0.6)"; color = Constants.SELECTION_TRANSPARENT_COLOR;
} }
this.drawPixelInCanvas(strokePoints[i].col, strokePoints[i].row, this.canvasOverlay, color, dpi); this.drawPixelInCanvas(strokePoints[i].col, strokePoints[i].row, this.canvasOverlay, color, dpi);
} }
@ -84,9 +84,6 @@
// For now, we are done with the stroke tool and don't need an overlay anymore: // For now, we are done with the stroke tool and don't need an overlay anymore:
this.removeCanvasOverlays(); this.removeCanvasOverlays();
// TODO: Create a afterRelease event hook or put that deep in the model
$.publish(Events.FRAMESHEET_UPDATED);
}; };
/** /**

View File

@ -52,9 +52,4 @@
this.previousCol = col; this.previousCol = col;
this.previousRow = row; this.previousRow = row;
}; };
ns.SimplePen.prototype.releaseToolAt = function(col, row, frame, color, canvas, dpi) {
// TODO: Create a afterRelease event hook or out that deep in the model
$.publish(Events.FRAMESHEET_UPDATED);
};
})(); })();

View File

@ -62,7 +62,7 @@
// We set it to a semi-opaque white during the tool mousemove allowing to see colors below the stroke. // We set it to a semi-opaque white during the tool mousemove allowing to see colors below the stroke.
// When the stroke tool will be released, It will draw a transparent stroke, // When the stroke tool will be released, It will draw a transparent stroke,
// eg deleting the equivalent of a stroke. // eg deleting the equivalent of a stroke.
color = "rgba(255, 255, 255, 0.6)"; color = Constants.SELECTION_TRANSPARENT_COLOR;
} }
this.drawPixelInCanvas(strokePoints[i].col, strokePoints[i].row, this.canvasOverlay, color, dpi); this.drawPixelInCanvas(strokePoints[i].col, strokePoints[i].row, this.canvasOverlay, color, dpi);
} }
@ -96,10 +96,7 @@
} }
// For now, we are done with the stroke tool and don't need an overlay anymore: // For now, we are done with the stroke tool and don't need an overlay anymore:
this.removeCanvasOverlays(); this.removeCanvasOverlays();
// TODO: Create a afterRelease event hook or out that deep in the model
$.publish(Events.FRAMESHEET_UPDATED);
}; };
})(); })();

View File

@ -9,14 +9,21 @@ pskl.FrameSheetModel = (function() {
var height; var height;
/** /**
* Create empty frame of dimension [width * height] with Constants.TRANSPARENT_COLOR
* as a default value.
*
* @private * @private
*/ */
var createEmptyFrame_ = function() { var createEmptyFrame_ = function() {
var emptyFrame = new Array(width); var emptyFrame = []; //new Array(width);
for (var columnIndex=0; columnIndex < width; columnIndex++) { for (var columnIndex=0; columnIndex < width; columnIndex++) {
emptyFrame[columnIndex] = new Array(height); var columnArray = [];
for(var heightIndex = 0; heightIndex < height; heightIndex++) {
columnArray.push(Constants.TRANSPARENT_COLOR);
}
emptyFrame[columnIndex] = columnArray;
} }
return emptyFrame; return emptyFrame;
}; };
/** /**

View File

@ -62,15 +62,15 @@ $.namespace("pskl");
frameSheet = pskl.FrameSheetModel.getInstance(framePixelWidth, framePixelHeight); frameSheet = pskl.FrameSheetModel.getInstance(framePixelWidth, framePixelHeight);
frameSheet.addEmptyFrame(); frameSheet.addEmptyFrame();
this.setActiveFrame(0); this.setActiveFrame(0);
pskl.NotificationService.init(); pskl.NotificationService.init();
pskl.LocalStorageService.init(frameSheet); pskl.LocalStorageService.init(frameSheet);
// TODO: Add comments // TODO: Add comments
var frameId = this.getFrameIdFromUrl(); var framesheetId = this.getFramesheetIdFromUrl();
if (frameId) { if (framesheetId) {
$.publish(Events.SHOW_NOTIFICATION, [{"content": "Loading animation with id : [" + frameId + "]"}]); $.publish(Events.SHOW_NOTIFICATION, [{"content": "Loading animation with id : [" + framesheetId + "]"}]);
this.loadFramesheetFromService(frameId); this.loadFramesheetFromService(framesheetId);
} else { } else {
this.finishInit(); this.finishInit();
pskl.LocalStorageService.displayRestoreNotification(); pskl.LocalStorageService.displayRestoreNotification();
@ -102,8 +102,9 @@ $.namespace("pskl");
pskl.ToolSelector.init(); pskl.ToolSelector.init();
}, },
getFrameIdFromUrl : function() { getFramesheetIdFromUrl : function() {
var href = window.location.href; var href = window.location.href;
// TODO: Change frameId to framesheetId on the backend
if (href.indexOf('frameId=') != -1) { if (href.indexOf('frameId=') != -1) {
return href.substring(href.indexOf('frameId=')+8); return href.substring(href.indexOf('frameId=')+8);
} }
@ -111,18 +112,22 @@ $.namespace("pskl");
loadFramesheetFromService : function (frameId) { loadFramesheetFromService : function (frameId) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
// TODO: Change frameId to framesheetId on the backend
xhr.open('GET', Constants.PISKEL_SERVICE_URL + '/get?l=' + frameId, true); xhr.open('GET', Constants.PISKEL_SERVICE_URL + '/get?l=' + frameId, true);
xhr.responseType = 'text'; xhr.responseType = 'text';
xhr.onload = function(e) { xhr.onload = function(e) {
frameSheet.deserialize(this.responseText); frameSheet.deserialize(this.responseText);
piskel.setActiveFrame(0);
$.publish(Events.HIDE_NOTIFICATION); $.publish(Events.HIDE_NOTIFICATION);
piskel.finishInit(); piskel.finishInit();
piskel.setActiveFrameAndRedraw(0);
}; };
xhr.onerror = function () { xhr.onerror = function () {
$.publish(Events.HIDE_NOTIFICATION); $.publish(Events.HIDE_NOTIFICATION);
piskel.finishInit(); piskel.finishInit();
piskel.setActiveFrameAndRedraw(0);
}; };
xhr.send(); xhr.send();
@ -136,12 +141,13 @@ $.namespace("pskl");
setActiveFrameAndRedraw: function(index) { setActiveFrameAndRedraw: function(index) {
this.setActiveFrame(index); this.setActiveFrame(index);
// When redraw engine is refactored, remove the following crap and
// trigger an event instead:
// Update drawing canvas: // Update drawing canvas:
this.drawFrameToCanvas(currentFrame, drawingAreaCanvas, drawingCanvasDpi); this.drawFrameToCanvas(currentFrame, drawingAreaCanvas, drawingCanvasDpi);
// Update slideshow: // Update slideshow:
this.createPreviews(); this.createPreviews();
// Update animation preview: // Update animation preview:
animIndex = 0; animIndex = 0;
}, },