From a11ef2eed7049835c8bdfa50a2b893632c46eaa0 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 4 Apr 2012 11:11:58 -0700 Subject: Squashed commit of Preparing for the montage undo-manager: Architecture changes Reworked the add and remove elements into 1 function which can take 1 or more elements. Removed the _element from the selection array Many other changes related to those 2 changes Undo/Redo shortcuts are now using montage undo/redo manager. Signed-off-by: Valerio Virgillito --- js/tools/BrushTool.js | 2 +- js/tools/LineTool.js | 111 ++++++++++++++++++++++------------------ js/tools/PenTool.js | 12 ++--- js/tools/Rotate3DToolBase.js | 4 +- js/tools/SelectionTool.js | 34 +++++------- js/tools/ShapeTool.js | 37 ++++++++------ js/tools/TagTool.js | 6 +-- js/tools/TextTool.js | 4 +- js/tools/Translate3DToolBase.js | 2 +- js/tools/modifier-tool-base.js | 2 +- 10 files changed, 110 insertions(+), 104 deletions(-) (limited to 'js/tools') diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js index f7f0e4bf..2171d2c6 100644 --- a/js/tools/BrushTool.js +++ b/js/tools/BrushTool.js @@ -306,7 +306,7 @@ exports.BrushTool = Montage.create(ShapeTool, { if (!canvas) { var newCanvas = NJUtils.makeNJElement("canvas", "Brushstroke", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); var elementModel = TagTool.makeElement(w, h, planeMat, midPt, newCanvas); - ElementMediator.addElement(newCanvas, elementModel.data, true); + ElementMediator.addElements(newCanvas, elementModel.data, false); // create all the GL stuff var world = this.getGLWorld(newCanvas, this._useWebGL); diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js index a61f8f79..455f519e 100755 --- a/js/tools/LineTool.js +++ b/js/tools/LineTool.js @@ -7,7 +7,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot var Montage = require("montage/core/core").Montage, ShapeTool = require("js/tools/ShapeTool").ShapeTool, DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase, - ElementMediator = require("js/mediators/element-mediator").ElementMediator, NJUtils = require("js/lib/NJUtils").NJUtils, TagTool = require("js/tools/TagTool").TagTool, ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, @@ -53,59 +52,43 @@ exports.LineTool = Montage.create(ShapeTool, { } }, - HandleLeftButtonUp: - { - value: function (event) - { - var slope = this._getSlope(), - drawData = this.getDrawingData(); + HandleLeftButtonUp: { + value: function (event) { + var slope = this._getSlope(), drawData = this.getDrawingData(); if(drawData) { - var canvas, - xAdj = 0, - yAdj = 0, - w = ~~drawData.width, - h = ~~drawData.height; - if(!this._useExistingCanvas()) - { - // set the dimensions - if(slope === "horizontal") - { - h = Math.max(this._strokeSize, 1); - } - else if(slope === "vertical") - { - w = Math.max(this._strokeSize, 1); - } - else - { - // else make the line's stroke fit inside the canvas by growing the canvas - var theta = Math.atan(slope); - xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); - yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); - - w += ~~(xAdj*2); - h += ~~(yAdj*2); - } - - canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); - var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas); - - ElementMediator.addElement(canvas, elementModel.data, true); - canvas.elementModel.isShape = true; - } - else - { - canvas = this._targetedElement; - canvas.elementModel.controller = ShapesController; - if(!canvas.elementModel.shapeModel) - { - canvas.elementModel.shapeModel = Montage.create(ShapeModel); + var canvas, xAdj = 0, yAdj = 0, w, h; + if(!this._useExistingCanvas()) { + if(drawData = this.getDrawingData()) { + // set the dimensions + w = ~~drawData.width; + h = ~~drawData.height; + if(slope === "horizontal") { + h = Math.max(this._strokeSize, 1); + } else if(slope === "vertical") { + w = Math.max(this._strokeSize, 1); + } else { + // else make the line's stroke fit inside the canvas by growing the canvas + var theta = Math.atan(slope); + xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); + yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); + + w += ~~(xAdj*2); + h += ~~(yAdj*2); + } + + canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); + var elementModel = TagTool.makeElement(w, h, drawData.planeMat, drawData.midPt, canvas); + canvas.elementModel.isShape = true; + this.application.ninja.elementMediator.addElements(canvas, elementModel.data); + } else { + canvas = this._targetedElement; + canvas.elementModel.controller = ShapesController; + if(!canvas.elementModel.shapeModel) { + canvas.elementModel.shapeModel = Montage.create(ShapeModel); + } } } - this.RenderShape(w, h, drawData.planeMat, drawData.midPt, - canvas, slope, xAdj, yAdj); - NJevent("elementAdded", canvas); } this.endDraw(event); @@ -113,11 +96,37 @@ exports.LineTool = Montage.create(ShapeTool, { this._isDrawing = false; this._hasDraw=false; - this.DrawHandles(); } }, + onAddElements: { + value: function(el) { + var drawData, xAdj = 0, yAdj = 0, w, h, slope = this._getSlope(); + + if(drawData = this.getDrawingData()) { + // set the dimensions + w = ~~drawData.width; + h = ~~drawData.height; + if(slope === "horizontal") { + h = Math.max(this._strokeSize, 1); + } else if(slope === "vertical") { + w = Math.max(this._strokeSize, 1); + } else { + // else make the line's stroke fit inside the canvas by growing the canvas + var theta = Math.atan(slope); + xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); + yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); + + w += ~~(xAdj*2); + h += ~~(yAdj*2); + } + + this.RenderShape(w, h, drawData.planeMat, drawData.midPt, el, slope, xAdj, yAdj); + } + } + }, + _getSlope: { value: function() { var hitRec0 = this._mouseDownHitRec, diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 779b7f16..4a16a491 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -585,7 +585,7 @@ exports.PenTool = Montage.create(ShapeTool, { var newCanvas = null; newCanvas = NJUtils.makeNJElement("canvas", "Subpath", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); var elementModel = TagTool.makeElement(parseInt(w), parseInt(h), planeMat, midPt, newCanvas); - ElementMediator.addElement(newCanvas, elementModel.data, true); + ElementMediator.addElements(newCanvas, elementModel.data, false); // create all the GL stuff var world = this.getGLWorld(newCanvas, this._useWebGL);//this.options.use3D);//this.CreateGLWorld(planeMat, midPt, newCanvas, this._useWebGL);//fillMaterial, strokeMaterial); @@ -978,11 +978,11 @@ exports.PenTool = Montage.create(ShapeTool, { } else{ for (var i=0;i 0) { - this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]._element; + this.application.ninja.currentSelectedContainer = this.application.ninja.selectedElements[0]; } else { this.application.ninja.currentSelectedContainer = this.application.ninja.currentDocument.documentRoot; } @@ -242,8 +242,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { case Keyboard.LEFT: var newLeft = []; var leftArr = this.application.ninja.selectedElements.map(function(item) { - newLeft.push( (parseInt(ElementsMediator.getProperty(item._element, "left")) - inc) + "px" ); - return ElementsMediator.getProperty(item._element, "left"); + newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) - inc) + "px" ); + return ElementsMediator.getProperty(item, "left"); }); ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); @@ -251,8 +251,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { case Keyboard.UP: var newTop = []; var topArr = this.application.ninja.selectedElements.map(function(item) { - newTop.push( (parseInt(ElementsMediator.getProperty(item._element, "top")) - inc) + "px" ); - return ElementsMediator.getProperty(item._element, "top"); + newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) - inc) + "px" ); + return ElementsMediator.getProperty(item, "top"); }); ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); @@ -260,8 +260,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { case Keyboard.RIGHT: var newLeft = []; var leftArr = this.application.ninja.selectedElements.map(function(item) { - newLeft.push( (parseInt(ElementsMediator.getProperty(item._element, "left")) + inc) + "px" ); - return ElementsMediator.getProperty(item._element, "left"); + newLeft.push( (parseInt(ElementsMediator.getProperty(item, "left")) + inc) + "px" ); + return ElementsMediator.getProperty(item, "left"); }); ElementsMediator.setProperty(this.application.ninja.selectedElements, "left", newLeft , "Change", "selectionTool", leftArr); @@ -269,8 +269,8 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { case Keyboard.DOWN: var newTop = []; var topArr = this.application.ninja.selectedElements.map(function(item) { - newTop.push( (parseInt(ElementsMediator.getProperty(item._element, "top")) + inc) + "px" ); - return ElementsMediator.getProperty(item._element, "top"); + newTop.push( (parseInt(ElementsMediator.getProperty(item, "top")) + inc) + "px" ); + return ElementsMediator.getProperty(item, "top"); }); ElementsMediator.setProperty(this.application.ninja.selectedElements, "top", newTop , "Change", "selectionTool", topArr); @@ -308,19 +308,15 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { previousStyles = []; var len = this.application.ninja.selectedElements.length; this._targets = []; - for(var i = 0; i < len; i++) - { - var elt = this.application.ninja.selectedElements[i]._element; + for(var i = 0; i < len; i++) { + var elt = this.application.ninja.selectedElements[i]; var curMat = viewUtils.getMatrixFromElement(elt); var curMatInv = glmat4.inverse(curMat, []); this._targets.push({elt:elt, mat:curMat, matInv:curMatInv}); - if(addToUndoStack) - { - - if(!this._use3DMode) - { + if(addToUndoStack) { + if(!this._use3DMode) { var previousMat = this._undoArray[i].mat.slice(0); var prevX = this._undoArray[i]._x; var prevY = this._undoArray[i]._y; @@ -344,9 +340,7 @@ var SelectionTool = exports.SelectionTool = Montage.create(ModifierToolBase, { this._targets[i].mat = previousMat; this._targets[i].matInv = glmat4.inverse(previousMat, []); - } - else - { + } else { var previousMat = this._undoArray[i].mat.slice(0); var prevW = this._undoArray[i]._w; var prevH = this._undoArray[i]._h; diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index d3a36163..34b3615b 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js @@ -9,7 +9,6 @@ var Montage = require("montage/core/core").Montage, viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, NJUtils = require("js/lib/NJUtils").NJUtils, - ElementMediator = require("js/mediators/element-mediator").ElementMediator, ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, ShapeModel = require("js/models/shape-model").ShapeModel, TagTool = require("js/tools/TagTool").TagTool; @@ -62,30 +61,23 @@ exports.ShapeTool = Montage.create(DrawingTool, { { var drawData; - drawData = this.getDrawingData(); + drawData = this.getDrawingData(); if(drawData) { var canvas; - if(!this._useExistingCanvas()) - { + if(!this._useExistingCanvas()) { canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); - var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, - drawData.planeMat, drawData.midPt, canvas); + var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, drawData.planeMat, drawData.midPt, canvas); - ElementMediator.addElement(canvas, elementModel.data, true); canvas.elementModel.isShape = true; - } - else - { + this.application.ninja.elementMediator.addElements(canvas, elementModel.data); + } else { canvas = this._targetedElement; canvas.elementModel.controller = ShapesController; - if(!canvas.elementModel.shapeModel) - { + if(!canvas.elementModel.shapeModel) { canvas.elementModel.shapeModel = Montage.create(ShapeModel); } } - this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, canvas); - NJevent("elementAdded", canvas); } this.endDraw(event); @@ -93,17 +85,28 @@ exports.ShapeTool = Montage.create(DrawingTool, { this._isDrawing = false; this._hasDraw=false; - this.DrawHandles(); } }, + onAddElements: { + value: function(el) { + var drawData; + + if(drawData = this.getDrawingData()) { + this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, el); + } + } + }, + Configure: { value: function(wasSelected) { if(wasSelected) { this.AddCustomFeedback(); + this.application.ninja.elementMediator.addDelegate = this; } else { this.RemoveCustomFeedback(); + this.application.ninja.elementMediator.addDelegate = null; } } }, @@ -174,12 +177,12 @@ exports.ShapeTool = Montage.create(DrawingTool, { getGLWorld: { value: function (canvas, use3D) { - var world = ElementMediator.getShapeProperty(canvas, "GLWorld"); + var world = this.application.ninja.elementMediator.getShapeProperty(canvas, "GLWorld"); if(!world) { // create all the GL stuff var world = new World(canvas, use3D); - ElementMediator.setShapeProperty(canvas, "GLWorld", world); + this.application.ninja.elementMediator.setShapeProperty(canvas, "GLWorld", world); } return world; diff --git a/js/tools/TagTool.js b/js/tools/TagTool.js index e3f49bbe..5512165e 100755 --- a/js/tools/TagTool.js +++ b/js/tools/TagTool.js @@ -90,7 +90,7 @@ exports.TagTool = Montage.create(DrawingTool, { if(selectionManagerModule.selectionManager.isDocument) { this.editSymbol = documentManagerModule.DocumentManager.activeDocument.documentRoot; } else { - this.editSymbol = selectionManagerModule.selectionManager._selectedItems[0]._element; + this.editSymbol = selectionManagerModule.selectionManager._selectedItems[0]; } */ } @@ -104,7 +104,7 @@ exports.TagTool = Montage.create(DrawingTool, { if(selectionManagerModule.selectionManager.isDocument) { this.editSymbol = documentManagerModule.DocumentManager.activeDocument.documentRoot; } else { - this.editSymbol = selectionManagerModule.selectionManager._selectedItems[0]._element; + this.editSymbol = selectionManagerModule.selectionManager._selectedItems[0]; } } @@ -142,7 +142,7 @@ exports.TagTool = Montage.create(DrawingTool, { element = this.makeElement(~~data.width, ~~data.height, data.planeMat, data.midPt, this.makeTag()); // Insert Element - NJevent("elementAdding", element); + this.application.ninja.elementMediator.addElements(element.el, element.data); } else { element = this.makeStaticElement(this.makeTag()); this._insertStatic(this.editSymbol, element.el, element.style); diff --git a/js/tools/TextTool.js b/js/tools/TextTool.js index d27a32bb..a58aacc6 100755 --- a/js/tools/TextTool.js +++ b/js/tools/TextTool.js @@ -95,7 +95,7 @@ exports.TextTool = Montage.create(DrawingTool, { } else { this.doSelection(event); if (this.application.ninja.selectedElements.length !== 0 ) { - this.selectedElement = this.application.ninja.selectedElements[0]._element; + this.selectedElement = this.application.ninja.selectedElements[0]; } this._isDrawing = false; } @@ -144,7 +144,7 @@ exports.TextTool = Montage.create(DrawingTool, { HandleDoubleClick: { value: function(e) { - //this.application.ninja.selectedElements[0]._element.setAttribute("contenteditable", true); + //this.application.ninja.selectedElements[0].setAttribute("contenteditable", true); //if (!this.application.ninja.textTool) { diff --git a/js/tools/Translate3DToolBase.js b/js/tools/Translate3DToolBase.js index 07b6d04d..4dca6313 100755 --- a/js/tools/Translate3DToolBase.js +++ b/js/tools/Translate3DToolBase.js @@ -195,7 +195,7 @@ exports.Translate3DToolBase = Montage.create(ModifierToolBase, this._targets = []; for(var i = 0; i < len; i++) { - var elt = this.application.ninja.selectedElements[i]._element; + var elt = this.application.ninja.selectedElements[i]; var curMat = viewUtils.getMatrixFromElement(elt); var curMatInv = glmat4.inverse(curMat, []); diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js index 94b806fd..46bb2e87 100755 --- a/js/tools/modifier-tool-base.js +++ b/js/tools/modifier-tool-base.js @@ -778,7 +778,7 @@ exports.ModifierToolBase = Montage.create(DrawingTool, { { if(len === 1) { - this.target = this.application.ninja.selectedElements[0]._element; + this.target = this.application.ninja.selectedElements[0]; drawUtils.addElement(this.target); } else -- cgit v1.2.3