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/LineTool.js | 111 ++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 51 deletions(-) (limited to 'js/tools/LineTool.js') 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, -- cgit v1.2.3