mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Added simple move tool
This commit is contained in:
parent
17bf7b3807
commit
f06f03a7f7
@ -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/rectangle.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-rectangle .drawing-canvas-move:hover {
|
||||||
|
cursor: url(../img/tools/cursors/rectangle.png) 4 21, pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.tool-icon.selected {
|
.tool-icon.selected {
|
||||||
cursor: auto;
|
cursor: auto;
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
|
@ -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">
|
||||||
@ -102,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 -->
|
||||||
|
@ -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;
|
||||||
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,85 +1,85 @@
|
|||||||
(function () {
|
(function () {
|
||||||
var ns = $.namespace("pskl.model");
|
var ns = $.namespace("pskl.model");
|
||||||
|
|
||||||
ns.Frame = function (pixels) {
|
ns.Frame = function (pixels) {
|
||||||
this.pixels = pixels;
|
this.pixels = pixels;
|
||||||
this.previousStates = [pixels];
|
this.previousStates = [this._clonePixels()];
|
||||||
this.stateIndex = 0;
|
this.stateIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.createEmpty = function (width, height) {
|
ns.Frame.createEmpty = function (width, height) {
|
||||||
var pixels = []; //new Array(width);
|
var pixels = []; //new Array(width);
|
||||||
for (var columnIndex=0; columnIndex < width; columnIndex++) {
|
for (var columnIndex=0; columnIndex < width; columnIndex++) {
|
||||||
var columnArray = [];
|
var columnArray = [];
|
||||||
for(var heightIndex = 0; heightIndex < height; heightIndex++) {
|
for(var heightIndex = 0; heightIndex < height; heightIndex++) {
|
||||||
columnArray.push(Constants.TRANSPARENT_COLOR);
|
columnArray.push(Constants.TRANSPARENT_COLOR);
|
||||||
}
|
}
|
||||||
pixels[columnIndex] = columnArray;
|
pixels[columnIndex] = columnArray;
|
||||||
}
|
}
|
||||||
return new ns.Frame(pixels);
|
return new ns.Frame(pixels);
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.createEmptyFromFrame = function (frame) {
|
ns.Frame.createEmptyFromFrame = function (frame) {
|
||||||
return ns.Frame.createEmpty(frame.getWidth(), frame.getHeight());
|
return ns.Frame.createEmpty(frame.getWidth(), frame.getHeight());
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.clone = function () {
|
ns.Frame.prototype.clone = function () {
|
||||||
return new ns.Frame(this._clonePixels());
|
return new ns.Frame(this._clonePixels());
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype._clonePixels = function () {
|
ns.Frame.prototype._clonePixels = function () {
|
||||||
var pixels = [];
|
var pixels = [];
|
||||||
for (var col = 0 ; col < this.getWidth() ; col++) {
|
for (var col = 0 ; col < this.getWidth() ; col++) {
|
||||||
pixels[col] = this.pixels[col].slice(0 , this.getHeight());
|
pixels[col] = this.pixels[col].slice(0 , this.getHeight());
|
||||||
}
|
}
|
||||||
return pixels;
|
return pixels;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.serialize = function () {
|
ns.Frame.prototype.serialize = function () {
|
||||||
return JSON.stringify(this.pixels);
|
return JSON.stringify(this.pixels);
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.setPixel = function (col, row, color) {
|
ns.Frame.prototype.setPixel = function (col, row, color) {
|
||||||
this.pixels[col][row] = color;
|
this.pixels[col][row] = color;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.getPixel = function (col, row) {
|
ns.Frame.prototype.getPixel = function (col, row) {
|
||||||
return this.pixels[col][row];
|
return this.pixels[col][row];
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.getWidth = function () {
|
ns.Frame.prototype.getWidth = function () {
|
||||||
return this.pixels.length;
|
return this.pixels.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.getHeight = function () {
|
ns.Frame.prototype.getHeight = function () {
|
||||||
return this.pixels[0].length;
|
return this.pixels[0].length;
|
||||||
};
|
};
|
||||||
|
|
||||||
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 () {
|
ns.Frame.prototype.saveState = function () {
|
||||||
// remove all states past current state
|
// remove all states past current state
|
||||||
this.previousStates.length = this.stateIndex + 1;
|
this.previousStates.length = this.stateIndex + 1;
|
||||||
// push new state
|
// push new state
|
||||||
this.previousStates.push(this._clonePixels());
|
this.previousStates.push(this._clonePixels());
|
||||||
// set the stateIndex to latest saved state
|
// set the stateIndex to latest saved state
|
||||||
this.stateIndex = this.previousStates.length - 1;
|
this.stateIndex = this.previousStates.length - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.loadPreviousState = function () {
|
ns.Frame.prototype.loadPreviousState = function () {
|
||||||
if (this.stateIndex >= 0) {
|
if (this.stateIndex > 0) {
|
||||||
this.stateIndex--;
|
this.stateIndex--;
|
||||||
this.pixels = this.previousStates[this.stateIndex];
|
this.pixels = this.previousStates[this.stateIndex];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.Frame.prototype.loadNextState = function () {
|
ns.Frame.prototype.loadNextState = function () {
|
||||||
if (this.stateIndex < this.previousStates.length - 1) {
|
if (this.stateIndex < this.previousStates.length - 1) {
|
||||||
this.stateIndex++;
|
this.stateIndex++;
|
||||||
this.pixels = this.previousStates[this.stateIndex];
|
this.pixels = this.previousStates[this.stateIndex];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
x
Reference in New Issue
Block a user