2013-09-28 23:10:12 +04:00
|
|
|
/**
|
2012-09-14 22:12:21 +04:00
|
|
|
* @provide pskl.drawingtools.ShapeSelect
|
|
|
|
*
|
|
|
|
* @require pskl.utils
|
|
|
|
*/
|
|
|
|
(function() {
|
2013-08-10 14:11:16 +04:00
|
|
|
var ns = $.namespace("pskl.drawingtools");
|
2012-09-14 22:12:21 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
ns.ShapeSelect = function() {
|
|
|
|
this.toolId = "tool-shape-select";
|
|
|
|
this.helpText = "Shape selection tool";
|
|
|
|
|
|
|
|
ns.BaseSelect.call(this);
|
|
|
|
};
|
2012-09-14 22:12:21 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
pskl.utils.inherit(ns.ShapeSelect, ns.BaseSelect);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the shape select tool, you just need to click one time to create a selection.
|
|
|
|
* So we jsut need to implement onSelectStart_ (no need for onSelect_ & onSelectEnd_)
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
ns.ShapeSelect.prototype.onSelectStart_ = function (col, row, color, frame, overlay) {
|
|
|
|
// Clean previous selection:
|
|
|
|
$.publish(Events.SELECTION_DISMISSED);
|
2013-08-10 16:28:10 +04:00
|
|
|
overlay.clear();
|
2013-08-10 14:11:16 +04:00
|
|
|
|
|
|
|
// From the pixel cliked, get shape using an algorithm similar to the paintbucket one:
|
|
|
|
var pixels = pskl.PixelUtils.getSimilarConnectedPixelsFromFrame(frame, col, row);
|
|
|
|
var selection = new pskl.selection.ShapeSelection(pixels);
|
2012-09-15 04:02:02 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
$.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 22:12:21 +04:00
|
|
|
|
|
|
|
})();
|