Merge branch 'master' into gh-pages

This commit is contained in:
juliandescottes 2012-09-07 01:19:48 +02:00
commit c6e6fdc935
8 changed files with 149 additions and 63 deletions

View File

@ -45,6 +45,10 @@
background-image: url(../img/tools/icons/rectangle.png); background-image: url(../img/tools/icons/rectangle.png);
} }
.tool-icon.tool-move {
background-image: url(../img/tools/icons/hand.png);
}
/*.tool-icon.tool-palette { /*.tool-icon.tool-palette {
background-image: url(../img/tools/icons/color-palette.png); background-image: url(../img/tools/icons/color-palette.png);
}*/ }*/
@ -69,6 +73,10 @@
cursor: url(../img/tools/cursors/rectangle.png) 4 21, pointer; cursor: url(../img/tools/cursors/rectangle.png) 4 21, pointer;
} }
.tool-move .drawing-canvas-container:hover {
cursor: url(../img/tools/cursors/hand.png) 14 12, pointer;
}
.tool-icon.selected { .tool-icon.selected {
cursor: auto; cursor: auto;
background-color: #eee; background-color: #eee;

View File

@ -30,6 +30,7 @@
<li class="tool-icon tool-paint-bucket" data-tool-id="tool-paint-bucket" title="Bucket tool"></li> <li class="tool-icon tool-paint-bucket" data-tool-id="tool-paint-bucket" title="Bucket tool"></li>
<li class="tool-icon tool-stroke" data-tool-id="tool-stroke" title="Stroke tool"></li> <li class="tool-icon tool-stroke" data-tool-id="tool-stroke" title="Stroke tool"></li>
<li class="tool-icon tool-rectangle" data-tool-id="tool-rectangle" title="Rectangle tool"></li> <li class="tool-icon tool-rectangle" data-tool-id="tool-rectangle" title="Rectangle tool"></li>
<li class="tool-icon tool-move" data-tool-id="tool-move" title="Move tool"></li>
</ul> </ul>
<ul class="tools-group"> <ul class="tools-group">
@ -93,6 +94,7 @@
<script src="js/controller/AnimatedPreviewController.js"></script> <script src="js/controller/AnimatedPreviewController.js"></script>
<script src="js/rendering/FrameRenderer.js"></script> <script src="js/rendering/FrameRenderer.js"></script>
<script src="js/LocalStorageService.js"></script> <script src="js/LocalStorageService.js"></script>
<script src="js/HistoryManager.js"></script>
<script src="js/Palette.js"></script> <script src="js/Palette.js"></script>
<script src="js/Notification.js"></script> <script src="js/Notification.js"></script>
<script src="js/drawingtools/BaseTool.js"></script> <script src="js/drawingtools/BaseTool.js"></script>
@ -101,6 +103,7 @@
<script src="js/drawingtools/Stroke.js"></script> <script src="js/drawingtools/Stroke.js"></script>
<script src="js/drawingtools/PaintBucket.js"></script> <script src="js/drawingtools/PaintBucket.js"></script>
<script src="js/drawingtools/Rectangle.js"></script> <script src="js/drawingtools/Rectangle.js"></script>
<script src="js/drawingtools/Move.js"></script>
<script src="js/ToolSelector.js"></script> <script src="js/ToolSelector.js"></script>
<!-- Application controller and initialization --> <!-- Application controller and initialization -->

View File

@ -1,6 +1,7 @@
Events = { Events = {
TOOL_SELECTED : "TOOL_SELECTED", TOOL_SELECTED : "TOOL_SELECTED",
TOOL_RELEASED : "TOOL_RELEASED",
COLOR_SELECTED: "COLOR_SELECTED", COLOR_SELECTED: "COLOR_SELECTED",
COLOR_USED: "COLOR_USED", COLOR_USED: "COLOR_USED",

40
js/HistoryManager.js Normal file
View File

@ -0,0 +1,40 @@
(function () {
var ns = $.namespace("pskl");
ns.HistoryManager = function () {};
ns.HistoryManager.prototype.init = function () {
document.body.addEventListener('keyup', this.onKeyup.bind(this));
$.subscribe(Events.TOOL_RELEASED, this.saveState.bind(this));
};
ns.HistoryManager.prototype.saveState = function () {
piskel.getCurrentFrame().saveState();
};
ns.HistoryManager.prototype.onKeyup = function (evt) {
if (evt.ctrlKey && evt.keyCode == 90) { // CTRL + Z
this.undo();
}
if (evt.ctrlKey && evt.keyCode == 89) { // CTRL+ Y
this.redo();
}
};
ns.HistoryManager.prototype.undo = function () {
piskel.getCurrentFrame().loadPreviousState();
this.redraw();
};
ns.HistoryManager.prototype.redo = function () {
piskel.getCurrentFrame().loadNextState();
this.redraw();
};
ns.HistoryManager.prototype.redraw = function () {
piskel.drawingController.renderFrame();
piskel.previewsController.createPreviews();
};
ns.HistoryManager = new ns.HistoryManager();
})();

View File

@ -14,7 +14,8 @@ pskl.ToolSelector = (function() {
"eraser" : new pskl.drawingtools.Eraser(), "eraser" : new pskl.drawingtools.Eraser(),
"paintBucket" : new pskl.drawingtools.PaintBucket(), "paintBucket" : new pskl.drawingtools.PaintBucket(),
"stroke" : new pskl.drawingtools.Stroke(), "stroke" : new pskl.drawingtools.Stroke(),
"rectangle" : new pskl.drawingtools.Rectangle() "rectangle" : new pskl.drawingtools.Rectangle(),
"move" : new pskl.drawingtools.Move()
}; };
var currentSelectedTool = toolInstances.simplePen; var currentSelectedTool = toolInstances.simplePen;
var previousSelectedTool = toolInstances.simplePen; var previousSelectedTool = toolInstances.simplePen;

View File

@ -34,7 +34,7 @@
// The fake canvas where we will draw the preview of the stroke: // The fake canvas where we will draw the preview of the stroke:
// Drawing the first point of the stroke in the fake overlay canvas: // Drawing the first point of the stroke in the fake overlay canvas:
drawer.updateOverlay(col, row, color); drawer.overlay.setPixel(col, row, color);
drawer.renderOverlay(); drawer.renderOverlay();
}; };

View File

@ -3,6 +3,8 @@
ns.Frame = function (pixels) { ns.Frame = function (pixels) {
this.pixels = pixels; this.pixels = pixels;
this.previousStates = [this._clonePixels()];
this.stateIndex = 0;
}; };
ns.Frame.createEmpty = function (width, height) { ns.Frame.createEmpty = function (width, height) {
@ -22,13 +24,15 @@
}; };
ns.Frame.prototype.clone = function () { ns.Frame.prototype.clone = function () {
var clone = ns.Frame.createEmptyFromFrame(this); return new ns.Frame(this._clonePixels());
for (var col = 0 ; col < clone.getWidth() ; col++) { };
for (var row = 0 ; row < clone.getHeight() ; row++) {
clone.setPixel(col, row, this.getPixel(col, row)); ns.Frame.prototype._clonePixels = function () {
var pixels = [];
for (var col = 0 ; col < this.getWidth() ; col++) {
pixels[col] = this.pixels[col].slice(0 , this.getHeight());
} }
} return pixels;
return clone;
}; };
ns.Frame.prototype.serialize = function () { ns.Frame.prototype.serialize = function () {
@ -52,7 +56,29 @@
}; };
ns.Frame.prototype.containsPixel = function (col, row) { ns.Frame.prototype.containsPixel = function (col, row) {
return col >= 0 && row >= 0 && col <= this.pixels.length && row <= this.pixels[0].length; return col >= 0 && row >= 0 && col < this.pixels.length && row < this.pixels[0].length;
}; };
ns.Frame.prototype.saveState = function () {
// remove all states past current state
this.previousStates.length = this.stateIndex + 1;
// push new state
this.previousStates.push(this._clonePixels());
// set the stateIndex to latest saved state
this.stateIndex = this.previousStates.length - 1;
};
ns.Frame.prototype.loadPreviousState = function () {
if (this.stateIndex > 0) {
this.stateIndex--;
this.pixels = this.previousStates[this.stateIndex];
}
};
ns.Frame.prototype.loadNextState = function () {
if (this.stateIndex < this.previousStates.length - 1) {
this.stateIndex++;
this.pixels = this.previousStates[this.stateIndex];
}
};
})(); })();

View File

@ -80,6 +80,7 @@ $.namespace("pskl");
this.animationController.init(); this.animationController.init();
this.previewsController.init(); this.previewsController.init();
pskl.HistoryManager.init();
pskl.NotificationService.init(); pskl.NotificationService.init();
pskl.LocalStorageService.init(frameSheet); pskl.LocalStorageService.init(frameSheet);
@ -154,7 +155,7 @@ $.namespace("pskl");
setActiveFrame: function(index) { setActiveFrame: function(index) {
activeFrameIndex = index; activeFrameIndex = index;
this.drawingController.frame = frameSheet.getFrameByIndex(index); this.drawingController.frame = this.getCurrentFrame();
}, },
setActiveFrameAndRedraw: function(index) { setActiveFrameAndRedraw: function(index) {
@ -176,6 +177,10 @@ $.namespace("pskl");
return activeFrameIndex; return activeFrameIndex;
}, },
getCurrentFrame : function () {
return frameSheet.getFrameByIndex(activeFrameIndex);
},
initDrawingArea : function() { initDrawingArea : function() {
drawingAreaContainer = $('#drawing-canvas-container')[0]; drawingAreaContainer = $('#drawing-canvas-container')[0];
document.body.addEventListener('mouseup', this.onMouseup.bind(this)); document.body.addEventListener('mouseup', this.onMouseup.bind(this));
@ -261,6 +266,8 @@ $.namespace("pskl");
if(isRightClicked) { if(isRightClicked) {
$.publish(Events.CANVAS_RIGHT_CLICK_RELEASED); $.publish(Events.CANVAS_RIGHT_CLICK_RELEASED);
} }
isClicked = false; isClicked = false;
isRightClicked = false; isRightClicked = false;
var spriteCoordinate = this.getSpriteCoordinate(event); var spriteCoordinate = this.getSpriteCoordinate(event);
@ -271,11 +278,11 @@ $.namespace("pskl");
this.drawingController this.drawingController
); );
$.publish(Events.TOOL_RELEASED);
// TODO: Remove that when we have the centralized redraw loop // TODO: Remove that when we have the centralized redraw loop
this.previewsController.createPreviews(); this.previewsController.createPreviews();
} }
}, },
onCanvasContextMenu : function (event) { onCanvasContextMenu : function (event) {