|
@@ -1,4 +1,8 @@
|
|
|
-var selector = (function() {
|
|
|
+import { APP_STATE } from "../enums/app-state-enum";
|
|
|
+import { stages as Stages } from "../components/stages";
|
|
|
+import { state as State } from "../components/state";
|
|
|
+import { objects as Objects } from "../components/objects";
|
|
|
+export const selector = (function() {
|
|
|
let _objects = [];
|
|
|
let _selectorPosStart;
|
|
|
let _selectorPosNow;
|
|
@@ -12,15 +16,17 @@ var selector = (function() {
|
|
|
dash: [2, 2]
|
|
|
});
|
|
|
|
|
|
+ let _stage = Stages.getCurrentStage();
|
|
|
+ let _layer = Stages.getCurrentLayer();
|
|
|
+
|
|
|
function _bootstrap() {
|
|
|
_configureSelectorEvents();
|
|
|
_addToLayer();
|
|
|
}
|
|
|
|
|
|
function _addToLayer() {
|
|
|
- let layer = app.currentLayer();
|
|
|
_selectorRect.listening(false);
|
|
|
- layer.add(_selectorRect);
|
|
|
+ _layer.add(_selectorRect);
|
|
|
}
|
|
|
|
|
|
function _getSelectedObjects() {
|
|
@@ -28,21 +34,21 @@ var selector = (function() {
|
|
|
}
|
|
|
|
|
|
function _configureSelectorEvents() {
|
|
|
- app.stage.on("mousedown", function(e) {
|
|
|
+ _stage.on("mousedown", function(e) {
|
|
|
_mode = "drawing";
|
|
|
_startDragSelector({ x: e.evt.layerX, y: e.evt.layerY });
|
|
|
});
|
|
|
|
|
|
- app.stage.on("mousemove", function(e) {
|
|
|
+ _stage.on("mousemove", function(e) {
|
|
|
if (_mode === "drawing") {
|
|
|
_updateDragSelector({ x: e.evt.layerX, y: e.evt.layerY });
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- app.stage.on("mouseup", function(e) {
|
|
|
+ _stage.on("mouseup", function(e) {
|
|
|
_mode = "";
|
|
|
_selectorRect.visible(false);
|
|
|
- app.stage.draw();
|
|
|
+ _stage.draw();
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -52,8 +58,8 @@ var selector = (function() {
|
|
|
}
|
|
|
|
|
|
function _updateDragSelector(posIn) {
|
|
|
- if (app.getState() != APP_STATE.NONE) return;
|
|
|
- let objects = app.getObjects();
|
|
|
+ if (State.getCurrentState() != APP_STATE.NONE) return;
|
|
|
+ let currentObjects = Objects.get();
|
|
|
let posRect = _reverse(_selectorPosStart, _selectorPosNow);
|
|
|
_selectorPosNow = { x: posIn.x, y: posIn.y };
|
|
|
_selectorRect.x(posRect.x1);
|
|
@@ -62,17 +68,17 @@ var selector = (function() {
|
|
|
_selectorRect.height(posRect.y2 - posRect.y1);
|
|
|
_selectorRect.visible(true);
|
|
|
|
|
|
- for (i = 0; i < objects.length; i = i + 1) {
|
|
|
- let object = objects[i];
|
|
|
+ for (let i = 0; i < currentObjects.length; i = i + 1) {
|
|
|
+ let object = currentObjects[i];
|
|
|
if (object.children != undefined && object.children.length > 0) {
|
|
|
- for (j = 0; j < object.children.length; j++) {
|
|
|
+ for (let j = 0; j < object.children.length; j++) {
|
|
|
_style(object.children[j], _selectorRect);
|
|
|
}
|
|
|
} else {
|
|
|
_style(object, _selectorRect);
|
|
|
}
|
|
|
}
|
|
|
- app.stage.draw();
|
|
|
+ _stage.draw();
|
|
|
}
|
|
|
|
|
|
function _style(object, selectorRect) {
|
|
@@ -131,6 +137,7 @@ var selector = (function() {
|
|
|
}
|
|
|
return { x1: r1x, y1: r1y, x2: r2x, y2: r2y };
|
|
|
}
|
|
|
+
|
|
|
return {
|
|
|
selctedObjects: _getSelectedObjects(),
|
|
|
bootstrap: _bootstrap
|