2013-09-28 23:10:12 +04:00
|
|
|
/**
|
2012-09-14 22:12:21 +04:00
|
|
|
* @provide pskl.drawingtools.RectangleSelect
|
2012-09-12 14:01:47 +04:00
|
|
|
*
|
|
|
|
* @require pskl.utils
|
|
|
|
*/
|
|
|
|
(function() {
|
2013-08-10 14:11:16 +04:00
|
|
|
var ns = $.namespace("pskl.drawingtools");
|
2012-09-12 14:01:47 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
ns.RectangleSelect = function() {
|
|
|
|
this.toolId = "tool-rectangle-select";
|
|
|
|
this.helpText = "Rectangle selection tool";
|
|
|
|
|
|
|
|
ns.BaseSelect.call(this);
|
|
|
|
};
|
2012-09-12 14:01:47 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
pskl.utils.inherit(ns.RectangleSelect, ns.BaseSelect);
|
|
|
|
|
2012-09-15 04:02:02 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
ns.RectangleSelect.prototype.onSelectStart_ = function (col, row, color, frame, overlay) {
|
|
|
|
// Drawing the first point of the rectangle in the fake overlay canvas:
|
|
|
|
overlay.setPixel(col, row, color);
|
|
|
|
};
|
2012-09-12 14:01:47 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* When creating the rectangle selection, we clear the current overlayFrame and
|
|
|
|
* redraw the current rectangle based on the orgin coordinate and
|
|
|
|
* the current mouse coordiinate in sprite.
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
ns.RectangleSelect.prototype.onSelect_ = function (col, row, color, frame, overlay) {
|
|
|
|
overlay.clear();
|
|
|
|
if(this.startCol == col &&this.startRow == row) {
|
|
|
|
$.publish(Events.SELECTION_DISMISSED);
|
|
|
|
} else {
|
|
|
|
var selection = new pskl.selection.RectangularSelection(
|
|
|
|
this.startCol, this.startRow, col, row);
|
|
|
|
$.publish(Events.SELECTION_CREATED, [selection]);
|
2013-08-10 16:28:10 +04:00
|
|
|
this.drawSelectionOnOverlay_(selection, overlay);
|
2013-08-10 14:11:16 +04:00
|
|
|
}
|
|
|
|
};
|
2012-09-14 00:57:32 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
ns.RectangleSelect.prototype.onSelectEnd_ = function (col, row, color, frame, overlay) {
|
|
|
|
this.onSelect_(col, row, color, frame, overlay);
|
|
|
|
};
|
2012-09-15 04:02:02 +04:00
|
|
|
|
2012-09-12 14:01:47 +04:00
|
|
|
})();
|