aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/brush-stroke.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 11:38:39 -0800
committerJonathan Duran2012-03-06 11:38:39 -0800
commit342fb451bd251358068a0dcb10e9dc218b79a176 (patch)
treeaa0195d581c3934fb6dc09981506b3c070002806 /js/lib/geom/brush-stroke.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
downloadninja-342fb451bd251358068a0dcb10e9dc218b79a176.tar.gz
Squashed commit of the following:
commit 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f Author: Jose Antonio Marquez <kgq387@motorola.com> Date: Tue Mar 6 11:24:25 2012 -0800 Fixing WebGL not available bug commit 84332ab81c1b445195f1d9be8bbeae0725c8e758 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Mar 6 10:58:25 2012 -0800 Squashed commit of preload-fix into Master - Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 13f52cf0c74f53a919fa864f86669e8155f82961 Merge: dced508 abc04f3 Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:46:11 2012 -0800 Merge pull request #93 from imix23ways/Timeline Timeline: Critical bug fixes commit dced508bb19a7bcd467ff1b86b5df5bbec4be794 Merge: 0aeb400 cc772ef Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:45:35 2012 -0800 Merge pull request #92 from mqg734/WebGLFixes Selection Tool Fixes for elements flying off into space when they overlap commit 0aeb400070762cf01d83cf9f9ee25a5595098b7f Merge: ff0a956 aabb48a Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 14:05:21 2012 -0800 Merge pull request #94 from ericguzman/PresetsPanel Presets Panel - Fix single-click activation, and transition cut-off bug. commit cc772ef3333ed419d269a2bda7aea5b0150a7bd9 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:34:58 2012 -0800 Fixing flying off into space bug for translate tool too. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit abc04f3d50311ed1c21067344bc7e448686f8c5c Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:26:25 2012 -0800 Timeline Fix timing function Signed-off-by: Jonathan Duran <jduran@motorola.com> commit aabb48a1c8d34bc968f4c6b0ffee4e31c1d5d286 Author: Eric Guzman <ericg@motorola.com> Date: Fri Mar 2 11:22:44 2012 -0800 Presets Panel - Fix single-click activation, and transition cut-off bug. Use double-click as the activation event for transition presets. Also fixed the bug when applying a style preset before the transition preset, which disabled transitions after the first one. commit f3207f39ea9d8c1c34246217a23d3a689671903d Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:21:29 2012 -0800 Don't draw transform handles if the stage is the target element. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 5425be91e7125c22955b4459a62412ff574e49a8 Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:11:48 2012 -0800 Timeline: Fix for animation iteration count Add default webkit css properties to allow animations with integer iteration counts. Signed-off-by: Jonathan Duran <jduran@motorola.com> commit 1760bac1da9218315ad1bacdcf3a157495a049e8 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 10:48:41 2012 -0800 Fix for jumping issue when moving items that have any 3d on them. We can't translate 3d moves into 2d space due to perspective, so we must update the matrix3d values instead of the top-left values if items have 3d. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 2c04935f0ccb1cb7c98371fc10b43155f2d956c4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 22:20:06 2012 -0800 Fix for elements flying off into space when moving elements that overlap. This was happening because our hit record's element and the browser's element from point did not match. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 50058746779f714ed9b0287f49e56c9f0d35593e Merge: 500426d ff0a956 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 21:49:44 2012 -0800 Merge branch 'refs/heads/ninja-internal' into WebGLFixes commit 500426dea0ca95a6b45be8ea8d132cfdb4d2c940 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:11:39 2012 -0800 Fixed logic error when resizing with the top-left transform handles. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 7980d9bde2b43aa5a494ddf6f1db5c4959a57b91 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:04:15 2012 -0800 Re-fixing IKNinja-940 - Can't select objects when in side/top view. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit f04cc0146d8f7573628678613a99c270116768e4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Feb 29 16:45:40 2012 -0800 Last-used material (instead of FlatMaterial) is applied to shape when turning on use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/lib/geom/brush-stroke.js')
-rwxr-xr-xjs/lib/geom/brush-stroke.js482
1 files changed, 482 insertions, 0 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
new file mode 100755
index 00000000..9a934928
--- /dev/null
+++ b/js/lib/geom/brush-stroke.js
@@ -0,0 +1,482 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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// Todo: This entire class should be converted to a module
8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
9var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
10
11///////////////////////////////////////////////////////////////////////
12// Class GLBrushStroke
13// representation a sequence points (polyline) created by brush tool.
14// Derived from class GLGeomObj
15///////////////////////////////////////////////////////////////////////
16var BrushStroke = function GLBrushStroke() {
17 ///////////////////////////////////////////////////
18 // Instance variables
19 ///////////////////////////////////////////////////
20 this._Points = [];
21 this._BBoxMin = [0, 0, 0];
22 this._BBoxMax = [0, 0, 0];
23 this._dirty = true;
24
25 //whether or not to use the canvas drawing to stroke/fill
26 this._useCanvasDrawing = true;
27
28 //the X and Y location of this subpath's canvas in stage world space of Ninja
29 this._canvasX = 0;
30 this._canvasY = 0;
31
32 //stroke information
33 this._strokeWidth = 0.0;
34 this._strokeColor = [0.4, 0.4, 0.4, 1.0];
35 this._strokeMaterial = null;
36 this._strokeStyle = "Solid";
37
38 //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely
39 //smaller value means more samples for the path
40 this._WETNESS_FACTOR = 0.25;
41
42 //prevent extremely long paths that can take a long time to render
43 this._MAX_ALLOWED_SAMPLES = 500;
44
45 //drawing context
46 this._world = null;
47
48 //tool that owns this brushstroke
49 this._drawingTool = null;
50 this._planeMat = null;
51 this._planeMatInv = null;
52 this._planeCenter = null;
53
54 /////////////////////////////////////////////////////////
55 // Property Accessors/Setters
56 /////////////////////////////////////////////////////////
57 this.setWorld = function (world) {
58 this._world = world;
59 };
60
61 this.getWorld = function () {
62 return this._world;
63 };
64
65 this.geomType = function () {
66 return this.GEOM_TYPE_CUBIC_BEZIER;
67 };
68
69 this.setDrawingTool = function (tool) {
70 this._drawingTool = tool;
71 };
72
73 this.getDrawingTool = function () {
74 return this._drawingTool;
75 };
76
77 this.setPlaneMatrix = function(planeMat){
78 this._planeMat = planeMat;
79 };
80
81 this.setPlaneMatrixInverse = function(planeMatInv){
82 this._planeMatInv = planeMatInv;
83 };
84
85 this.setPlaneCenter = function(pc){
86 this._planeCenter = pc;
87 };
88
89 this.getCanvasX = function(){
90 return this._canvasX;
91 };
92
93 this.getCanvasY = function(){
94 return this._canvasY;
95 };
96
97 this.setCanvasX = function(cx){
98 this._canvasX=cx;
99 };
100
101 this.setCanvasY = function(cy){
102 this._canvasY=cy;
103 };
104
105 this.getNumPoints = function () {
106 return this._Points.length;
107 };
108
109 this.getPoint = function (index) {
110 return this._Points[index];
111 };
112
113 this.addPoint = function (pt) {
114 //add the point only if it is some epsilon away from the previous point
115 var numPoints = this._Points.length;
116 if (numPoints>0) {
117 var threshold = this._WETNESS_FACTOR*this._strokeWidth;
118 var prevPt = this._Points[numPoints-1];
119 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]];
120 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]);
121 if (diffPtMag>threshold){
122 this._Points.push(pt);
123 this._dirty=true;
124 }
125 } else {
126 this._Points.push(pt);
127 this._dirty=true;
128 }
129 };
130
131 this.insertPoint = function(pt, index){
132 this._Points.splice(index, 0, pt); this._dirty=true;
133 };
134
135 this.isDirty = function(){
136 return this._dirty;
137 };
138
139 this.makeDirty = function(){
140 this._dirty=true;
141 };
142
143 this.getBBoxMin = function () {
144 return this._BBoxMin;
145 };
146
147 this.getBBoxMax = function () {
148 return this._BBoxMax;
149 };
150
151 this.getStrokeWidth = function () {
152 return this._strokeWidth;
153 };
154
155 this.setStrokeWidth = function (w) {
156 this._strokeWidth = w;
157 this._dirty=true;
158 };
159
160 this.getStrokeMaterial = function () {
161 return this._strokeMaterial;
162 };
163
164 this.setStrokeMaterial = function (m) {
165 this._strokeMaterial = m;
166 };
167
168 this.getStrokeColor = function () {
169 return this._strokeColor;
170 };
171
172 this.setStrokeColor = function (c) {
173 this._strokeColor = c;
174 };
175
176 this.getStrokeStyle = function () {
177 return this._strokeStyle;
178 };
179
180 this.setStrokeStyle = function (s) {
181 this._strokeStyle = s;
182 };
183
184 this.setWidth = function () {
185
186 };//NO-OP for now
187
188 this.setHeight = function () {
189
190 };//NO-OP for now
191
192
193 //remove and return anchor at specified index, return null on error
194 this.removePoint = function (index) {
195 var retAnchor = null;
196 if (index < this._Points.length) {
197 retPt = this._Points.splice(index, 1);
198 this._dirty=true;
199 }
200 return retPoint;
201 };
202
203 //remove all the points
204 this.clear = function () {
205 this._Points = [];
206 this._dirty=true;
207 }
208
209 this.translate = function (tx, ty, tz) {
210 for (var i=0;i<this._Points.length;i++){
211 this._Points[i][0]+=tx;
212 this._Points[i][1]+=ty;
213 this._Points[i][2]+=tz;
214 }
215 };
216
217 this.computeMetaGeometry = function() {
218 if (this._dirty) {
219 var numPoints = this._Points.length;
220
221 //**** add samples to the path if needed...linear interpolation for now
222 if (numPoints>1) {
223 var threshold = this._WETNESS_FACTOR*this._strokeWidth;
224 var prevPt = this._Points[0];
225 var prevIndex = 0;