|
@@ -1,130 +1,147 @@
|
|
var app = (function() {
|
|
var app = (function() {
|
|
- var width = $("#content").width();
|
|
|
|
- var height =
|
|
|
|
|
|
+ let _width = $("#content").width();
|
|
|
|
+ let _height =
|
|
$("#sidebar").height() - $("#header").height() - $("#files").height() - 2;
|
|
$("#sidebar").height() - $("#header").height() - $("#files").height() - 2;
|
|
- var layers = [];
|
|
|
|
- var _layer = [];
|
|
|
|
- var tools = [];
|
|
|
|
- var menu = [];
|
|
|
|
- var layer = undefined;
|
|
|
|
- var _selectedTool = [];
|
|
|
|
-
|
|
|
|
- var stage = new Konva.Stage({
|
|
|
|
|
|
+ let _screen = {
|
|
|
|
+ width: _width,
|
|
|
|
+ height: _height
|
|
|
|
+ };
|
|
|
|
+ let _layers = [];
|
|
|
|
+ let _currentLayers = [];
|
|
|
|
+ let _tools = [];
|
|
|
|
+ let _menu = [];
|
|
|
|
+ let _layer = undefined;
|
|
|
|
+ let _selectedTool = [];
|
|
|
|
+ let _objects = [];
|
|
|
|
+ let _stage = new Konva.Stage({
|
|
container: "container",
|
|
container: "container",
|
|
- width: width,
|
|
|
|
- height: height
|
|
|
|
|
|
+ width: _width,
|
|
|
|
+ height: _height
|
|
});
|
|
});
|
|
|
|
+ let _state = APP_STATE.NONE;
|
|
|
|
|
|
- var screen = {
|
|
|
|
- width: width,
|
|
|
|
- height: height
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- function createLayer() {
|
|
|
|
- var sequence = 0;
|
|
|
|
- if (layers == null || layers.length == 0) {
|
|
|
|
|
|
+ function _createLayer() {
|
|
|
|
+ let sequence = 0;
|
|
|
|
+ if (_layers == null || _layers.length == 0) {
|
|
sequence++;
|
|
sequence++;
|
|
} else {
|
|
} else {
|
|
- sequence = layers.length + 1;
|
|
|
|
|
|
+ sequence = _layers.length + 1;
|
|
}
|
|
}
|
|
- var layer = { sequence: sequence, layer: new Konva.Layer() };
|
|
|
|
- layers.push(layer);
|
|
|
|
- if (currentLayer() == undefined && _layer.length == 0) {
|
|
|
|
- _layer = [];
|
|
|
|
- _layer.push(layer);
|
|
|
|
|
|
+ let layer = { sequence: sequence, layer: new Konva.Layer() };
|
|
|
|
+ _layers.push(layer);
|
|
|
|
+ if (_currentLayer() == undefined && _currentLayers.length == 0) {
|
|
|
|
+ _currentLayers = [];
|
|
|
|
+ _currentLayers.push(layer);
|
|
}
|
|
}
|
|
- stage.add(layer.layer);
|
|
|
|
|
|
+ _stage.add(layer.layer);
|
|
return layer;
|
|
return layer;
|
|
}
|
|
}
|
|
|
|
|
|
- function bootstrap() {
|
|
|
|
- createLayer();
|
|
|
|
|
|
+ function _bootstrap() {
|
|
|
|
+ _createLayer();
|
|
configureStageEvents();
|
|
configureStageEvents();
|
|
- layer = currentLayer();
|
|
|
|
|
|
+ _layer = _currentLayer();
|
|
|
|
+ selector.bootstrap();
|
|
}
|
|
}
|
|
|
|
|
|
- function currentLayer() {
|
|
|
|
- if (_layer[0] == undefined) return undefined;
|
|
|
|
- return _layer[0].layer;
|
|
|
|
|
|
+ function _currentLayer() {
|
|
|
|
+ if (_currentLayers[0] == undefined) return undefined;
|
|
|
|
+ return _currentLayers[0].layer;
|
|
}
|
|
}
|
|
|
|
|
|
function configureStageEvents() {
|
|
function configureStageEvents() {
|
|
- stage.on("click tap", function(e) {
|
|
|
|
- var tool = getSelectedTool();
|
|
|
|
|
|
+ _stage.on("mousedown ", function(e) {
|
|
|
|
+ if (e.target === _stage) {
|
|
|
|
+ _setState(APP_STATE.NONE);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (e.target.id != undefined) {
|
|
|
|
+ _setState(APP_STATE.OBJECT_SELECTED);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ _stage.on("click tap", function(e) {
|
|
|
|
+ let tool = _getSelectedTool();
|
|
if (tool != undefined) {
|
|
if (tool != undefined) {
|
|
tool.draw();
|
|
tool.draw();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- var transformEnabled = true;
|
|
|
|
-
|
|
|
|
- if (
|
|
|
|
- e.target.attrs.transformEnabled != undefined &&
|
|
|
|
- e.target.attrs.transformEnabled == false
|
|
|
|
- ) {
|
|
|
|
- transformEnabled = false;
|
|
|
|
- }
|
|
|
|
- if (e.target === stage || !transformEnabled) {
|
|
|
|
- stage.find("Transformer").destroy();
|
|
|
|
- layer.draw();
|
|
|
|
|
|
+ if (e.target === _stage) {
|
|
|
|
+ _setState(APP_STATE.NONE);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- stage.find("Transformer").destroy();
|
|
|
|
-
|
|
|
|
- var tr = new Konva.Transformer({
|
|
|
|
- anchorStrokeWidth: 2
|
|
|
|
- });
|
|
|
|
- layer.add(tr);
|
|
|
|
- tr.attachTo(e.target);
|
|
|
|
- layer.draw();
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- function setSelectedTool(tool) {
|
|
|
|
- clearSelectedTool();
|
|
|
|
|
|
+ function _setSelectedTool(tool) {
|
|
|
|
+ _clearSelectedTool();
|
|
|
|
+ _setState(APP_STATE.TOOL_SELECTED);
|
|
if (tool.id != undefined) {
|
|
if (tool.id != undefined) {
|
|
document.getElementById("btn-" + tool.id).disabled = true;
|
|
document.getElementById("btn-" + tool.id).disabled = true;
|
|
}
|
|
}
|
|
_selectedTool.push(tool);
|
|
_selectedTool.push(tool);
|
|
}
|
|
}
|
|
|
|
|
|
- function clearSelectedTool() {
|
|
|
|
- var tool = getSelectedTool();
|
|
|
|
|
|
+ function _clearSelectedTool() {
|
|
|
|
+ let tool = _getSelectedTool();
|
|
if (tool != undefined) {
|
|
if (tool != undefined) {
|
|
if (tool.id != undefined) {
|
|
if (tool.id != undefined) {
|
|
document.getElementById("btn-" + tool.id).disabled = false;
|
|
document.getElementById("btn-" + tool.id).disabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_selectedTool = [];
|
|
_selectedTool = [];
|
|
- setStatus("");
|
|
|
|
|
|
+ _setStatus("");
|
|
|
|
+ _setState(APP_STATE.NONE);
|
|
}
|
|
}
|
|
|
|
|
|
- function getSelectedTool() {
|
|
|
|
|
|
+ function _getSelectedTool() {
|
|
if (_selectedTool.length > 0) return _selectedTool[0];
|
|
if (_selectedTool.length > 0) return _selectedTool[0];
|
|
return undefined;
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
|
|
- function getRelativePointerPosition() {
|
|
|
|
- return stage.getPointerPosition();
|
|
|
|
|
|
+ function _getRelativePointerPosition() {
|
|
|
|
+ return _stage.getPointerPosition();
|
|
}
|
|
}
|
|
|
|
|
|
- function setStatus(status) {
|
|
|
|
|
|
+ function _setStatus(status) {
|
|
document.getElementById("status").innerHTML = status;
|
|
document.getElementById("status").innerHTML = status;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function _pushObject(object) {
|
|
|
|
+ _objects.push(object);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function _getObjects() {
|
|
|
|
+ return _objects;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function _setState(state) {
|
|
|
|
+ _state = state;
|
|
|
|
+ }
|
|
|
|
+ function _getState() {
|
|
|
|
+ return _state;
|
|
|
|
+ }
|
|
|
|
+ function _menuClick(e) {
|
|
|
|
+ _setState(APP_STATE.TOOL_SELECTED);
|
|
|
|
+ if (e.click());
|
|
|
|
+ }
|
|
return {
|
|
return {
|
|
- stage: stage,
|
|
|
|
- currentLayer: currentLayer,
|
|
|
|
- createLayer: createLayer,
|
|
|
|
- screen: screen,
|
|
|
|
- bootstrap: bootstrap,
|
|
|
|
- layers: layers,
|
|
|
|
- tools: tools,
|
|
|
|
- setSelectedTool: setSelectedTool,
|
|
|
|
- clearSelectedTool: clearSelectedTool,
|
|
|
|
- getSelectedTool: getSelectedTool,
|
|
|
|
- pos: getRelativePointerPosition,
|
|
|
|
- setStatus: setStatus
|
|
|
|
|
|
+ stage: _stage,
|
|
|
|
+ currentLayer: _currentLayer,
|
|
|
|
+ createLayer: _createLayer,
|
|
|
|
+ screen: _screen,
|
|
|
|
+ bootstrap: _bootstrap,
|
|
|
|
+ layers: _layers,
|
|
|
|
+ tools: _tools,
|
|
|
|
+ setSelectedTool: _setSelectedTool,
|
|
|
|
+ clearSelectedTool: _clearSelectedTool,
|
|
|
|
+ getSelectedTool: _getSelectedTool,
|
|
|
|
+ pos: _getRelativePointerPosition,
|
|
|
|
+ setStatus: _setStatus,
|
|
|
|
+ pushObject: _pushObject,
|
|
|
|
+ getObjects: _getObjects,
|
|
|
|
+ setState: _setState,
|
|
|
|
+ getState: _getState,
|
|
|
|
+ menuClick: _menuClick
|
|
};
|
|
};
|
|
})();
|
|
})();
|