2013-09-28 23:10:12 +04:00
|
|
|
/**
|
2012-09-02 15:19:20 +04:00
|
|
|
* @provide pskl.drawingtools.Rectangle
|
|
|
|
*
|
|
|
|
* @require pskl.utils
|
|
|
|
*/
|
|
|
|
(function() {
|
2013-08-10 14:11:16 +04:00
|
|
|
var ns = $.namespace("pskl.drawingtools");
|
2012-09-02 15:19:20 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
ns.Rectangle = function() {
|
|
|
|
this.toolId = "tool-rectangle";
|
|
|
|
this.helpText = "Rectangle tool";
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
// Rectangle's first point coordinates (set in applyToolAt)
|
|
|
|
this.startCol = null;
|
|
|
|
this.startRow = null;
|
|
|
|
};
|
2012-09-02 15:19:20 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
pskl.utils.inherit(ns.Rectangle, ns.BaseTool);
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2013-12-06 01:12:48 +04:00
|
|
|
ns.Rectangle.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
|
2013-08-10 14:11:16 +04:00
|
|
|
this.startCol = col;
|
|
|
|
this.startRow = row;
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
// Drawing the first point of the rectangle in the fake overlay canvas:
|
|
|
|
overlay.setPixel(col, row, color);
|
|
|
|
};
|
2012-09-02 15:19:20 +04:00
|
|
|
|
2013-12-06 01:12:48 +04:00
|
|
|
ns.Rectangle.prototype.moveToolAt = function(col, row, color, frame, overlay, event) {
|
2013-08-10 14:11:16 +04:00
|
|
|
overlay.clear();
|
|
|
|
if(color == Constants.TRANSPARENT_COLOR) {
|
|
|
|
color = Constants.SELECTION_TRANSPARENT_COLOR;
|
|
|
|
}
|
2012-09-12 14:01:47 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
// draw in overlay
|
|
|
|
this.drawRectangle_(col, row, color, overlay);
|
|
|
|
};
|
2012-09-02 15:19:20 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2013-12-06 01:12:48 +04:00
|
|
|
ns.Rectangle.prototype.releaseToolAt = function(col, row, color, frame, overlay, event) {
|
2013-08-10 14:11:16 +04:00
|
|
|
overlay.clear();
|
|
|
|
if(frame.containsPixel(col, row)) { // cancel if outside of canvas
|
|
|
|
// draw in frame to finalize
|
|
|
|
this.drawRectangle_(col, row, color, frame);
|
|
|
|
}
|
|
|
|
};
|
2012-09-02 15:19:20 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
ns.Rectangle.prototype.drawRectangle_ = function (col, row, color, targetFrame) {
|
|
|
|
var strokePoints = pskl.PixelUtils.getBoundRectanglePixels(this.startCol, this.startRow, col, row);
|
|
|
|
for(var i = 0; i< strokePoints.length; i++) {
|
|
|
|
// Change model:
|
|
|
|
targetFrame.setPixel(strokePoints[i].col, strokePoints[i].row, color);
|
|
|
|
}
|
|
|
|
};
|
2012-09-02 15:19:20 +04:00
|
|
|
})();
|