diff options
Diffstat (limited to 'js/tools')
-rw-r--r-- | js/tools/BrushTool.js | 288 | ||||
-rw-r--r-- | js/tools/EraserTool.js | 32 | ||||
-rw-r--r-- | js/tools/EyedropperTool.js | 152 | ||||
-rw-r--r-- | js/tools/FillTool.js | 65 | ||||
-rw-r--r-- | js/tools/InkBottleTool.js | 69 | ||||
-rw-r--r-- | js/tools/LineTool.js | 251 | ||||
-rw-r--r-- | js/tools/OvalTool.js | 103 | ||||
-rw-r--r-- | js/tools/PanTool.js | 378 | ||||
-rw-r--r-- | js/tools/PenTool.js | 1245 | ||||
-rw-r--r-- | js/tools/PencilTool.js | 32 | ||||
-rw-r--r-- | js/tools/RectTool.js | 126 | ||||
-rw-r--r-- | js/tools/Rotate3DToolBase.js | 637 | ||||
-rw-r--r-- | js/tools/RotateObject3DTool.js | 64 | ||||
-rw-r--r-- | js/tools/RotateStage3DTool.js | 148 | ||||
-rw-r--r-- | js/tools/SelectionTool.js | 829 | ||||
-rw-r--r-- | js/tools/ShapeTool.js | 217 | ||||
-rw-r--r-- | js/tools/SubSelectTool.js | 32 | ||||
-rw-r--r-- | js/tools/TagTool.js | 273 | ||||
-rw-r--r-- | js/tools/TextTool.js | 87 | ||||
-rw-r--r-- | js/tools/ToolBase.js | 192 | ||||
-rw-r--r-- | js/tools/Translate3DToolBase.js | 357 | ||||
-rw-r--r-- | js/tools/TranslateObject3DTool.js | 132 | ||||
-rw-r--r-- | js/tools/ZoomTool.js | 442 | ||||
-rw-r--r-- | js/tools/drawing-tool-base.js | 673 | ||||
-rw-r--r-- | js/tools/drawing-tool.js | 370 | ||||
-rw-r--r-- | js/tools/modifier-tool-base.js | 1007 |
26 files changed, 8201 insertions, 0 deletions
diff --git a/js/tools/BrushTool.js b/js/tools/BrushTool.js new file mode 100644 index 00000000..ce8ffbb9 --- /dev/null +++ b/js/tools/BrushTool.js | |||
@@ -0,0 +1,288 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var ShapeTool = require("js/tools/ShapeTool").ShapeTool; | ||
8 | var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase; | ||
9 | var defaultEventManager = require("montage/core/event/event-manager").defaultEventManager; | ||
10 | var Montage = require("montage/core/core").Montage; | ||
11 | var NJUtils = require("js/lib/NJUtils").NJUtils; | ||
12 | var ElementMediator = require("js/mediators/element-mediator").ElementMediator; | ||
13 | var TagTool = require("js/tools/TagTool").TagTool; | ||
14 | var snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; | ||
15 | |||
16 | exports.BrushTool = Montage.create(ShapeTool, { | ||
17 | hasReel: { value: false }, | ||
18 | _toolID: { value: "brushTool" }, | ||
19 | _imageID: { value: "brushToolImg" }, | ||
20 | _toolImageClass: { value: "brushToolUp" }, | ||
21 | _selectedToolImageClass: { value: "brushToolDown" }, | ||
22 | _toolTipText: { value: "Brush Tool" }, | ||
23 | _brushView: { value: null, writable: true }, | ||
24 | |||
25 | _selectedToolClass: { value: "brushToolSpecificProperties" }, | ||
26 | _penToolProperties: { enumerable: false, value: null, writable: true }, | ||
27 | _parentNode: { enumerable: false, value: null, writable: true }, | ||
28 | _toolsPropertiesContainer: { enumerable: false, value: null, writable: true }, | ||
29 | |||
30 | //config options | ||
31 | _useWebGL: {value: false, writable: false}, | ||
32 | |||
33 | //view options | ||
34 | _brushStrokeCanvas: {value: null, writable: true}, | ||
35 | _brushStrokePlaneMat: {value: null, writable: true}, | ||
36 | |||
37 | //the current brush stroke | ||
38 | _selectedBrushStroke: {value: null, writable: true}, | ||
39 | |||
40 | ShowToolProperties: { | ||
41 | value: function () { | ||
42 | this._brushView = PenView.create(); | ||
43 | this._brushView.element = document.getElementById('topPanelContainer').children[0]; | ||
44 | this._brushView.needsDraw = true; | ||
45 | this._brushView.addEventListener(ToolEvents.TOOL_OPTION_CHANGE, this, false); | ||
46 | } | ||
47 | }, | ||
48 | |||
49 | HandleLeftButtonDown: { | ||
50 | value: function (event) { | ||
51 | //ignore any right or middle clicks | ||
52 | if (event.button !== 0) { | ||
53 | //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) | ||
54 | return; | ||
55 | } | ||
56 | if (this._canDraw) { | ||
57 | this._isDrawing = true; | ||
58 | } | ||
59 | |||
60 | this.startDraw(event); | ||
61 | if (this._brushStrokePlaneMat === null) { | ||
62 | this._brushStrokePlaneMat = this.mouseDownHitRec.getPlaneMatrix(); | ||
63 | } | ||
64 | //start a new brush stroke | ||
65 | if (this._selectedBrushStroke === null){ | ||
66 | this._selectedBrushStroke = new GLBrushStroke(); | ||
67 | } | ||
68 | console.log("BrushTool Start"); | ||
69 | NJevent("enableStageMove");//stageManagerModule.stageManager.enableMouseMove(); | ||
70 | } //value: function (event) { | ||
71 | }, //HandleLeftButtonDown | ||
72 | |||
73 | |||
74 | //need to override this function because the ShapeTool's definition contains a clearDrawingCanvas call - Pushkar | ||
75 | // might not need to override once we draw using OpenGL instead of SVG | ||
76 | // Also took out all the snapping code for now...need to add that back | ||
77 | HandleMouseMove: | ||
78 | { | ||
79 | value: function (event) { | ||
80 | //ignore any right or middle clicks | ||
81 | if (event.button !== 0) { | ||
82 | //NOTE: this will work on Webkit only...IE has different codes (left: 1, middle: 4, right: 2) | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | if (this._isDrawing) { | ||
87 | snapManager.enableElementSnap(false); | ||
88 | snapManager.enableGridSnap(false); | ||
89 | snapManager.enableSnapAlign(false); | ||
90 | //this.doDraw(event); | ||
91 | //var currMousePos = this.getMouseUpPos(); | ||
92 | //instead of doDraw call own DrawingTool | ||
93 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(event.pageX, event.pageY)); | ||
94 | var hitRecSnapPoint = DrawingToolBase.getUpdatedSnapPointNoAppLevelEnabling(point.x, point.y, true, this.mouseDownHitRec); | ||
95 | var currMousePos = DrawingToolBase.getHitRecPos(hitRecSnapPoint); | ||
96 | |||
97 | if (this._selectedBrushStroke){ | ||
98 | this._selectedBrushStroke.addPoint(currMousePos); | ||
99 | } | ||
100 | |||
101 | this.ShowCurrentBrushStrokeOnStage(); | ||
102 | } //if (this._isDrawing) { | ||
103 | |||
104 | //this.drawLastSnap(); //TODO.. is this line necessary if we're not snapping? // Required cleanup for both Draw/Feedbacks | ||
105 | |||
106 | }//value: function(event) | ||
107 | }, | ||
108 | |||
109 | |||
110 | |||
111 | HandleLeftButtonUp: { | ||
112 | value: function (event) { | ||
113 | /*var drawData = this.getDrawingData(); | ||
114 | if (drawData) { | ||
115 | if (this._brushStrokePlaneMat === null) { | ||
116 | this._brushStrokePlaneMat = drawData.planeMat; | ||
117 | } | ||
118 | } | ||
119 | if (this._isDrawing) { | ||
120 | this.doDraw(event); | ||
121 | }*/ | ||
122 | this.endDraw(event); | ||
123 | |||
124 | this._isDrawing = false; | ||
125 | this._hasDraw = false; | ||
126 | console.log("BrushTool Stop"); | ||
127 | |||
128 | //TODO get these values from the options | ||
129 | if (this._selectedBrushStroke){ | ||
130 | this._selectedBrushStroke.setStrokeWidth(20); | ||
131 | } | ||
132 | //display the previously drawn stroke in a separate canvas | ||
133 | this.RenderCurrentBrushStroke(); | ||
134 | |||
135 | this._selectedBrushStroke = null; | ||
136 | this._brushStrokeCanvas = null; | ||
137 | NJevent("disableStageMove"); | ||
138 | } | ||
139 | }, | ||
140 | |||
141 | ShowCurrentBrushStrokeOnStage:{ | ||
142 | value: function() { | ||
143 | //clear the canvas before we draw anything else | ||
144 | this.application.ninja.stage.clearDrawingCanvas(); | ||
145 | if (this._selectedBrushStroke && this._selectedBrushStroke.getNumPoints()>0){ | ||
146 | this._selectedBrushStroke.computeMetaGeometry(); | ||
147 | var ctx = this.application.ninja.stage.drawingContext;//stageManagerModule.stageManager.drawingContext; | ||
148 | if (ctx === null) | ||
149 | throw ("null drawing context in Brushtool::ShowCurrentBrushStrokeOnStage"); | ||
150 | ctx.save(); | ||
151 | |||
152 | var horizontalOffset = this.application.ninja.stage.userContentLeft; | ||
153 | var verticalOffset = this.application.ninja.stage.userContentTop; | ||
154 | |||
155 | var numPoints = this._selectedBrushStroke.getNumPoints(); | ||
156 | ctx.lineWidth = 1; | ||
157 | ctx.strokeStyle = "black"; | ||
158 | ctx.beginPath(); | ||
159 | var pt = this._selectedBrushStroke.getPoint(0); | ||
160 | ctx.moveTo(pt[0]+ horizontalOffset,pt[1]+ verticalOffset); | ||
161 | for (var i = 1; i < numPoints; i++) { | ||
162 | pt = this._selectedBrushStroke.getPoint(i); | ||
163 | var x = pt[0]+ horizontalOffset; | ||
164 | var y = pt[1]+ verticalOffset; | ||
165 | ctx.lineTo(x,y); | ||
166 | } | ||
167 | ctx.stroke(); | ||
168 | ctx.restore(); | ||
169 | |||
170 | } | ||
171 | } | ||
172 | }, | ||
173 | |||
174 | RenderCurrentBrushStroke:{ | ||
175 | value: function() { | ||
176 | if (this._selectedBrushStroke){ | ||
177 | this._selectedBrushStroke.computeMetaGeometry(); | ||
178 | var bboxMin = this._selectedBrushStroke.getBBoxMin(); | ||
179 | var bboxMax = this._selectedBrushStroke.getBBoxMax(); | ||
180 | var bboxWidth = bboxMax[0] - bboxMin[0]; | ||
181 | var bboxHeight = bboxMax[1] - bboxMin[1]; | ||
182 | var bboxMid = Vector.create([0.5 * (bboxMax[0] + bboxMin[0]), 0.5 * (bboxMax[1] + bboxMin[1]), 0.5 * (bboxMax[2] + bboxMin[2])]); | ||
183 | |||
184 | this._selectedBrushStroke.setCanvasX(bboxMid[0]); | ||
185 | this._selectedBrushStroke.setCanvasY(bboxMid[1]); | ||
186 | |||
187 | //call render shape with the bbox width and height | ||
188 | this.RenderShape(bboxWidth, bboxHeight, this._brushStrokePlaneMat, bboxMid, this._brushStrokeCanvas); | ||
189 | } | ||
190 | } | ||
191 | }, | ||
192 | |||
193 | |||
194 | RenderShape: { | ||
195 | value: function (w, h, planeMat, midPt, canvas) { | ||
196 | if ((Math.floor(w) === 0) || (Math.floor(h) === 0)) { | ||
197 | return; | ||
198 | } | ||
199 | |||