aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorValerio Virgillito2012-03-06 11:05:00 -0800
committerValerio Virgillito2012-03-06 11:05:00 -0800
commit4540b5b4ea2065c3e0d67b46bba8b6764801fbea (patch)
tree4e1561530b1b90ea497bac8e41d193fa605e98b4 /js/tools
parent4e35725e6c9044c37bef28b8c8d36f4b5c89bfd9 (diff)
parent84332ab81c1b445195f1d9be8bbeae0725c8e758 (diff)
downloadninja-4540b5b4ea2065c3e0d67b46bba8b6764801fbea.tar.gz
Merge branch 'refs/heads/master' into panels
Diffstat (limited to 'js/tools')
-rw-r--r--js/tools/BrushTool.js6
-rwxr-xr-xjs/tools/LineTool.js7
-rwxr-xr-xjs/tools/OvalTool.js9
-rwxr-xr-xjs/tools/PenTool.js25
-rwxr-xr-xjs/tools/RectTool.js9
-rwxr-xr-xjs/tools/ShapeTool.js4
-rwxr-xr-xjs/tools/drawing-tool-base.js18
7 files changed, 47 insertions, 31 deletions
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js
index fec89eb2..752aa2a3 100644
--- a/js/tools/BrushTool.js
+++ b/js/tools/BrushTool.js
@@ -13,6 +13,8 @@ var ElementMediator = require("js/mediators/element-mediator").ElementMediator;
13var TagTool = require("js/tools/TagTool").TagTool; 13var TagTool = require("js/tools/TagTool").TagTool;
14var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; 14var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager;
15 15
16var BrushStroke = require("js/lib/geom/brush-stroke").BrushStroke;
17
16exports.BrushTool = Montage.create(ShapeTool, { 18exports.BrushTool = Montage.create(ShapeTool, {
17 hasReel: { value: false }, 19 hasReel: { value: false },
18 _toolID: { value: "brushTool" }, 20 _toolID: { value: "brushTool" },
@@ -63,7 +65,7 @@ exports.BrushTool = Montage.create(ShapeTool, {
63 } 65 }
64 //start a new brush stroke 66 //start a new brush stroke
65 if (this._selectedBrushStroke === null){ 67 if (this._selectedBrushStroke === null){
66 this._selectedBrushStroke = new GLBrushStroke(); 68 this._selectedBrushStroke = new BrushStroke();
67 if (this.application.ninja.colorController.colorToolbar.stroke.webGlColor){ 69 if (this.application.ninja.colorController.colorToolbar.stroke.webGlColor){
68 this._selectedBrushStroke.setStrokeColor(this.application.ninja.colorController.colorToolbar.stroke.webGlColor); 70 this._selectedBrushStroke.setStrokeColor(this.application.ninja.colorController.colorToolbar.stroke.webGlColor);
69 } 71 }
@@ -192,7 +194,7 @@ exports.BrushTool = Montage.create(ShapeTool, {
192 var bboxMax = this._selectedBrushStroke.getBBoxMax(); 194 var bboxMax = this._selectedBrushStroke.getBBoxMax();
193 var bboxWidth = bboxMax[0] - bboxMin[0]; 195 var bboxWidth = bboxMax[0] - bboxMin[0];
194 var bboxHeight = bboxMax[1] - bboxMin[1]; 196 var bboxHeight = bboxMax[1] - bboxMin[1];
195 var bboxMid = Vector.create([0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])]); 197 var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])];
196 198
197 this._selectedBrushStroke.setCanvasX(bboxMid[0]); 199 this._selectedBrushStroke.setCanvasX(bboxMid[0]);
198 this._selectedBrushStroke.setCanvasY(bboxMid[1]); 200 this._selectedBrushStroke.setCanvasY(bboxMid[1]);
diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js
index 32572af1..a61f8f79 100755
--- a/js/tools/LineTool.js
+++ b/js/tools/LineTool.js
@@ -13,6 +13,9 @@ var Montage = require("montage/core/core").Montage,
13 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, 13 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController,
14 ShapeModel = require("js/models/shape-model").ShapeModel; 14 ShapeModel = require("js/models/shape-model").ShapeModel;
15 15
16var Line = require("js/lib/geom/line").Line;
17var MaterialsModel = require("js/models/materials-model").MaterialsModel;
18
16exports.LineTool = Montage.create(ShapeTool, { 19exports.LineTool = Montage.create(ShapeTool, {
17 _toolID: { value: "lineTool" }, 20 _toolID: { value: "lineTool" },
18 _imageID: { value: "lineToolImg" }, 21 _imageID: { value: "lineToolImg" },
@@ -211,7 +214,7 @@ exports.LineTool = Montage.create(ShapeTool, {
211 var strokeM = this.options.strokeMaterial; 214 var strokeM = this.options.strokeMaterial;
212 if(strokeM) 215 if(strokeM)
213 { 216 {
214 strokeMaterial = Object.create(MaterialsLibrary.getMaterial(strokeM)); 217 strokeMaterial = Object.create(MaterialsModel.getMaterial(strokeM));
215 } 218 }
216 } 219 }
217 220
@@ -220,7 +223,7 @@ exports.LineTool = Montage.create(ShapeTool, {
220 var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2); 223 var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2);
221 var yOffset = (canvas.height/2 - (top - canvas.offsetTop + h/2)); 224 var yOffset = (canvas.height/2 - (top - canvas.offsetTop + h/2));
222 225
223 var line = new GLLine(world, xOffset, yOffset, w, h, slope, strokeSize, strokeColor, strokeMaterial, strokeStyle, xAdj, yAdj); 226 var line = new Line(world, xOffset, yOffset, w, h, slope, strokeSize, strokeColor, strokeMaterial, strokeStyle, xAdj, yAdj);
224 227
225 world.addObject(line); 228 world.addObject(line);
226 world.render(); 229 world.render();
diff --git a/js/tools/OvalTool.js b/js/tools/OvalTool.js
index 911059a7..a10e0bb5 100755
--- a/js/tools/OvalTool.js
+++ b/js/tools/OvalTool.js
@@ -8,6 +8,9 @@ var Montage = require("montage/core/core").Montage,
8 ShapeTool = require("js/tools/ShapeTool").ShapeTool, 8 ShapeTool = require("js/tools/ShapeTool").ShapeTool,
9 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; 9 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController;
10 10
11var Circle = require("js/lib/geom/circle").Circle;
12var MaterialsModel = require("js/models/materials-model").MaterialsModel;
13
11exports.OvalTool = Montage.create(ShapeTool, { 14exports.OvalTool = Montage.create(ShapeTool, {
12 15
13 _toolID: { value: "ovalTool" }, 16 _toolID: { value: "ovalTool" },
@@ -48,13 +51,13 @@ exports.OvalTool = Montage.create(ShapeTool, {
48 var strokeM = this.options.strokeMaterial; 51 var strokeM = this.options.strokeMaterial;
49 if(strokeM) 52 if(strokeM)
50 { 53 {
51 strokeMaterial = Object.create(MaterialsLibrary.getMaterial(strokeM)); 54 strokeMaterial = Object.create(MaterialsModel.getMaterial(strokeM));
52 } 55 }
53 56
54 var fillM = this.options.fillMaterial; 57 var fillM = this.options.fillMaterial;
55 if(fillM) 58 if(fillM)
56 { 59 {
57 fillMaterial = Object.create(MaterialsLibrary.getMaterial(fillM)); 60 fillMaterial = Object.create(MaterialsModel.getMaterial(fillM));
58 } 61 }
59 } 62 }
60 63
@@ -63,7 +66,7 @@ exports.OvalTool = Montage.create(ShapeTool, {
63 var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2); 66 var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2);
64 var yOffset = (canvas.height/2 - (top - canvas.offsetTop + h/2)); 67 var yOffset = (canvas.height/2 - (top - canvas.offsetTop + h/2));
65 68
66 var oval = new GLCircle(); 69 var oval = new Circle(); //GLCircle();
67 oval.init(world, xOffset, yOffset, w, h, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle); 70 oval.init(world, xOffset, yOffset, w, h, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle);
68 71
69 world.addObject(oval); 72 world.addObject(oval);
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index ddc8bc04..71a91870 100755
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -15,6 +15,9 @@ var TagTool = require("js/tools/TagTool").TagTool;
15var ElementController = require("js/controllers/elements/element-controller").ElementController; 15var ElementController = require("js/controllers/elements/element-controller").ElementController;
16var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; 16var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager;
17 17
18var AnchorPoint = require("js/lib/geom/anchor-point").AnchorPoint;
19var SubPath = require("js/lib/geom/sub-path").SubPath;
20
18//todo remove this global var 21//todo remove this global var
19var g_DoPenToolMouseMove = true; 22var g_DoPenToolMouseMove = true;
20 23
@@ -146,7 +149,7 @@ exports.PenTool = Montage.create(ShapeTool, {
146 if (mouseDownPos) { 149 if (mouseDownPos) {
147 //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath 150 //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath
148 if (this._selectedSubpath === null) { 151 if (this._selectedSubpath === null) {
149 this._selectedSubpath = new GLSubpath(); 152 this._selectedSubpath = new SubPath();
150 this._isNewPath = true; 153 this._isNewPath = true;
151 if (this._entryEditMode === this.ENTRY_SELECT_PATH){ 154 if (this._entryEditMode === this.ENTRY_SELECT_PATH){
152 //this should not happen, as ENTRY_SELECT_PATH implies there was a selected subpath 155 //this should not happen, as ENTRY_SELECT_PATH implies there was a selected subpath
@@ -212,13 +215,13 @@ exports.PenTool = Montage.create(ShapeTool, {
212 this._penCanvas = null; 215 this._penCanvas = null;
213 this._penPlaneMat = null; 216 this._penPlaneMat = null;
214 this._snapTarget = null; 217 this._snapTarget = null;
215 this._selectedSubpath = new GLSubpath(); 218 this._selectedSubpath = new SubPath();
216 this._isNewPath = true; 219 this._isNewPath = true;
217 } 220 }
218 221
219 //add an anchor point to end of the subpath, and make it the selected anchor point 222 //add an anchor point to end of the subpath, and make it the selected anchor point
220 if (!this._selectedSubpath.getIsClosed() || this._makeMultipleSubpaths) { 223 if (!this._selectedSubpath.getIsClosed() || this._makeMultipleSubpaths) {
221 this._selectedSubpath.addAnchor(new GLAnchorPoint()); 224 this._selectedSubpath.addAnchor(new AnchorPoint());
222 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 225 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
223 newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); 226 newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]);
224 newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); 227 newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]);
@@ -231,7 +234,7 @@ exports.PenTool = Montage.create(ShapeTool, {
231 if (this._isPickedEndPointInSelectPathMode){ 234 if (this._isPickedEndPointInSelectPathMode){
232 //TODO clean up this code...very similar to the code block above 235 //TODO clean up this code...very similar to the code block above
233 if (!this._selectedSubpath.getIsClosed()) { 236 if (!this._selectedSubpath.getIsClosed()) {
234 this._selectedSubpath.addAnchor(new GLAnchorPoint()); 237 this._selectedSubpath.addAnchor(new AnchorPoint());
235 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 238 var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
236 newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); 239 newAnchor.setPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]);
237 newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]); 240 newAnchor.setPrevPos(mouseDownPos[0], mouseDownPos[1], mouseDownPos[2]);
@@ -389,7 +392,7 @@ exports.PenTool = Montage.create(ShapeTool, {
389 var bboxMax = this._selectedSubpath.getBBoxMax(); 392 var bboxMax = this._selectedSubpath.getBBoxMax();
390 var bboxWidth = bboxMax[0] - bboxMin[0]; 393 var bboxWidth = bboxMax[0] - bboxMin[0];
391 var bboxHeight = bboxMax[1] - bboxMin[1]; 394 var bboxHeight = bboxMax[1] - bboxMin[1];
392 var bboxMid = Vector.create([0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])]); 395 var bboxMid = [0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])];
393 396
394 this._selectedSubpath.setCanvasX(bboxMid[0]); 397 this._selectedSubpath.setCanvasX(bboxMid[0]);
395 this._selectedSubpath.setCanvasY(bboxMid[1]); 398 this._selectedSubpath.setCanvasY(bboxMid[1]);
@@ -638,7 +641,7 @@ exports.PenTool = Montage.create(ShapeTool, {
638 var baseline = VecUtils.vecNormalize(3, baselineOrig); 641 var baseline = VecUtils.vecNormalize(3, baselineOrig);
639 var delta = VecUtils.vecSubtract(3, p2, p3); 642 var delta = VecUtils.vecSubtract(3, p2, p3);
640 //component of the delta along baseline 643 //component of the delta along baseline
641 var deltaB = Vector.create(baseline); 644 var deltaB = baseline;
642 VecUtils.vecScale(3, deltaB, VecUtils.vecDot(3, baseline, delta)); 645 VecUtils.vecScale(3, deltaB, VecUtils.vecDot(3, baseline, delta));
643 //component of the delta orthogonal to baseline 646 //component of the delta orthogonal to baseline
644 var deltaO = VecUtils.vecSubtract(3, delta, deltaB); 647 var deltaO = VecUtils.vecSubtract(3, delta, deltaB);
@@ -655,7 +658,7 @@ exports.PenTool = Montage.create(ShapeTool, {
655 //if there is a selected anchor point 658 //if there is a selected anchor point
656 if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) { 659 if (this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex() !== -1) {
657 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); 660 var selAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex());
658 var pos = Vector.create([selAnchor.getPosX(), selAnchor.getPosY(), selAnchor.getPosZ()]); 661 var pos = [selAnchor.getPosX(), selAnchor.getPosY(), selAnchor.getPosZ()];
659 var distToPrev = selAnchor.getPrevDistanceSq(pos[0], pos[1], pos[2]); 662 var distToPrev = selAnchor.getPrevDistanceSq(pos[0], pos[1], pos[2]);
660 var distToNext = selAnchor.getNextDistanceSq(pos[0], pos[1], pos[2]); 663 var distToNext = selAnchor.getNextDistanceSq(pos[0], pos[1], pos[2]);
661 var threshSq = 0; // 4 * this._PICK_POINT_RADIUS * this._PICK_POINT_RADIUS; 664 var threshSq = 0; // 4 * this._PICK_POINT_RADIUS * this._PIC