aboutsummaryrefslogtreecommitdiff
path: root/js/tools
diff options
context:
space:
mode:
authorPushkar Joshi2012-06-07 09:53:44 -0700
committerPushkar Joshi2012-06-07 09:53:44 -0700
commit1a40c4a3e1817004d1ce1c600ae4857fdd94a97a (patch)
tree25836d69f77472f60bab9a14c23865a3899a60d8 /js/tools
parent763baf19f032c6fbae18963402b79d5d5510d923 (diff)
parent47e0e1f047e83b71c3f86812a45d33904201cc7a (diff)
downloadninja-1a40c4a3e1817004d1ce1c600ae4857fdd94a97a.tar.gz
Merge branch 'master' into brushtool
Diffstat (limited to 'js/tools')
-rwxr-xr-xjs/tools/FillTool.js33
-rwxr-xr-xjs/tools/InkBottleTool.js50
-rwxr-xr-xjs/tools/LineTool.js110
-rwxr-xr-xjs/tools/SelectionTool.js114
-rwxr-xr-xjs/tools/ShapeTool.js46
-rwxr-xr-xjs/tools/TagTool.js12
-rwxr-xr-xjs/tools/drawing-tool.js3
-rwxr-xr-xjs/tools/modifier-tool-base.js2
8 files changed, 227 insertions, 143 deletions
diff --git a/js/tools/FillTool.js b/js/tools/FillTool.js
index 66dd9305..e08ec1da 100755
--- a/js/tools/FillTool.js
+++ b/js/tools/FillTool.js
@@ -70,25 +70,32 @@ exports.FillTool = Montage.create(ModifierToolBase, {
70 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed) 70 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed)
71 startDraw: { 71 startDraw: {
72 value: function(event) { 72 value: function(event) {
73 this.drawData = null;
73 this.isDrawing = true; 74 this.isDrawing = true;
74 75
75 if(this._canColor && this.application.ninja.selectedElements.length) { 76 if(this._canColor && this.application.ninja.selectedElements.length) {
77 var fillInfo = {},
78 color;
79 if(this.options.useFillColor.checked) {
80 fillInfo.colorInfo = {};
81 color = this.options.fill;
82 if(color && color.color)
83 {
84 fillInfo.colorInfo.mode = color.colorMode;
85 fillInfo.colorInfo.color = color.color;
86 } else {
87 fillInfo.colorInfo.mode = "nocolor";
88 fillInfo.colorInfo.color = null;
89 }
90 }
76 91
77 var color = this.options.fill, 92 if(this.options.useWebGL.checked) {
78 colorInfo; 93 fillInfo.webGLInfo = {};
79 if(color && color.color) 94 fillInfo.webGLInfo.material = this.options.fillMaterial.value;
80 {
81 colorInfo = { mode:color.colorMode,
82 color:color.color
83 };
84 } 95 }
85 else 96 if(fillInfo.colorInfo || fillInfo.webGLInfo) {
86 { 97 ElementsMediator.setFill(this.application.ninja.selectedElements, fillInfo, "Change", "fillTool");
87 colorInfo = { mode:"nocolor",
88 color:color.color
89 };
90 } 98 }
91 ElementsMediator.setColor(this.application.ninja.selectedElements, colorInfo, true, "Change", "fillTool");
92 } 99 }
93 } 100 }
94 } 101 }
diff --git a/js/tools/InkBottleTool.js b/js/tools/InkBottleTool.js
index 2c03d133..c5640b10 100755
--- a/js/tools/InkBottleTool.js
+++ b/js/tools/InkBottleTool.js
@@ -65,43 +65,51 @@ exports.InkBottleTool = Montage.create(ModifierToolBase, {
65 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed) 65 // Called by modifier tool base's HandleLeftButtonDown after updating selection (if needed)
66 startDraw: { 66 startDraw: {
67 value: function(event) { 67 value: function(event) {
68 this.drawData = null;
68 this.isDrawing = true; 69 this.isDrawing = true;
69 70
70 if(this._canColor && this.application.ninja.selectedElements.length) 71 if(this._canColor && this.application.ninja.selectedElements.length)
71 { 72 {
72 var color = this.options.stroke, 73 var strokeInfo = {},
73 colorInfo; 74 color;
74 if(color && color.color) 75 if(this.options.useStrokeColor.checked) {
75 { 76 strokeInfo.colorInfo = {};
76 colorInfo = { mode:color.colorMode, 77 color = this.options.stroke;
77 color:color.color 78 if(color && color.color)
78 }; 79 {
79 } 80 strokeInfo.colorInfo.mode = color.colorMode;
80 else 81 strokeInfo.colorInfo.color = color.color;
81 { 82 } else {
82 colorInfo = { mode:"nocolor", 83 strokeInfo.colorInfo.mode = "nocolor";
83 color:color.color 84 strokeInfo.colorInfo.color = null;
84 }; 85 }
85 } 86 }
86 87
87 if(this.options.useBorderWidth.checked || this.options.useBorderStyle.checked) { 88 if(this.options.useBorderWidth.checked || this.options.useBorderStyle.checked) {
88 colorInfo.borderInfo = {}; 89 strokeInfo.borderInfo = {};
89 if(this.options.useBorderWidth.checked) { 90 if(this.options.useBorderWidth.checked) {
90 colorInfo.borderInfo.borderWidth = this.options._borderWidth.value; 91 strokeInfo.borderInfo.borderWidth = this.options.borderWidth.value;
91 colorInfo.borderInfo.borderUnits = this.options._borderWidth.units; 92 strokeInfo.borderInfo.borderUnits = this.options.borderWidth.units;
92 } 93 }
93 if(this.options.useBorderStyle.checked) { 94 if(this.options.useBorderStyle.checked) {
94 colorInfo.borderInfo.borderStyle = this.options._borderStyle.value; 95 strokeInfo.borderInfo.borderStyle = this.options.borderStyle.value;
95 } 96 }
96 } 97 }
97 98
98 if(this.options.useStrokeSize.checked) { 99 if(this.options.useStrokeSize.checked) {
99 colorInfo.strokeInfo = {}; 100 strokeInfo.shapeInfo = {};
100 colorInfo.strokeInfo.strokeSize = this.options._strokeSize.value; 101 strokeInfo.shapeInfo.strokeSize = this.options.strokeSize.value;
101 colorInfo.strokeInfo.strokeUnits = this.options._strokeSize.units; 102 strokeInfo.shapeInfo.strokeUnits = this.options.strokeSize.units;
103 }
104
105 if(this.options.useWebGL.checked) {
106 strokeInfo.webGLInfo = {};
107 strokeInfo.webGLInfo.material = this.options.strokeMaterial.value;
102 } 108 }
103 109
104 ElementsMediator.setColor(this.application.ninja.selectedElements, colorInfo, false, "Change", "inkBottleTool"); 110 if(strokeInfo.colorInfo || strokeInfo.borderInfo || strokeInfo.shapeInfo || strokeInfo.webGLInfo) {
111 ElementsMediator.setStroke(this.application.ninja.selectedElements, strokeInfo, "Change", "inkBottleTool");
112 }
105 } 113 }
106 } 114 }
107 } 115 }
diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js
index b2b48383..327d0054 100755
--- a/js/tools/LineTool.js
+++ b/js/tools/LineTool.js
@@ -54,39 +54,46 @@ exports.LineTool = Montage.create(ShapeTool, {
54 54
55 HandleLeftButtonUp: { 55 HandleLeftButtonUp: {
56 value: function (event) { 56 value: function (event) {
57 var slope = this._getSlope(), drawData = this.getDrawingData(); 57 var slope = this._getSlope(),
58 58 canvas,
59 if(drawData) { 59 xAdj = 0,
60 var canvas, xAdj = 0, yAdj = 0, w, h; 60 yAdj = 0,
61 if(!this._useExistingCanvas()) { 61 w,
62 if(drawData = this.getDrawingData()) { 62 h;
63 // set the dimensions 63
64 w = ~~drawData.width; 64 if(slope) {
65 h = ~~drawData.height; 65 this.drawData = this.getDrawingData();
66 if(slope === "horizontal") { 66 if(this.drawData) {
67 h = Math.max(this._strokeSize, 1); 67 w = Math.floor(this.drawData.width);
68 } else if(slope === "vertical") { 68 h = Math.floor(this.drawData.height);
69 w = Math.max(this._strokeSize, 1); 69 if(!this._useExistingCanvas()) {
70 // set the dimensions
71 if(slope === "horizontal") {
72 h = Math.max(this._strokeSize, 1);
73 w = Math.max(w, 1);
74 } else if(slope === "vertical") {
75 w = Math.max(this._strokeSize, 1);
76 h = Math.max(h, 1);
77 } else {
78 // else make the line's stroke fit inside the canvas by growing the canvas
79 var theta = Math.atan(slope);
80 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
81 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
82
83 w += ~~(xAdj*2);
84 h += ~~(yAdj*2);
85 }
86
87 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
88 document.application.njUtils.createModelWithShape(canvas, "Line");
89
90 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData);
91 this.application.ninja.elementMediator.addElements(canvas, styles);
70 } else { 92 } else {
71 // else make the line's stroke fit inside the canvas by growing the canvas 93 canvas = this._targetedElement;
72 var theta = Math.atan(slope); 94 canvas.elementModel.controller = ShapesController;
73 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); 95 if(!canvas.elementModel.shapeModel) {
74 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); 96 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
75
76 w += ~~(xAdj*2);
77 h += ~~(yAdj*2);
78 }
79
80 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
81 document.application.njUtils.createModelWithShape(canvas, "Line");
82
83 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, drawData);
84 this.application.ninja.elementMediator.addElements(canvas, styles);
85 } else {
86 canvas = this._targetedElement;
87 canvas.elementModel.controller = ShapesController;
88 if(!canvas.elementModel.shapeModel) {
89 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
90 } 97 }
91 } 98 }
92 } 99 }
@@ -103,16 +110,18 @@ exports.LineTool = Montage.create(ShapeTool, {
103 110
104 onAddElements: { 111 onAddElements: {
105 value: function(el) { 112 value: function(el) {
106 var drawData, xAdj = 0, yAdj = 0, w, h, slope = this._getSlope(); 113 var xAdj = 0, yAdj = 0, w, h, slope = this._getSlope();