diff options
Diffstat (limited to 'js/lib')
-rwxr-xr-x | js/lib/geom/brush-stroke.js | 1406 |
1 files changed, 732 insertions, 674 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index 09a7023c..b2e56149 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js | |||
@@ -65,777 +65,835 @@ var BrushStroke = function GLBrushStroke() { | |||
65 | this._planeMatInv = null; | 65 | this._planeMatInv = null; |
66 | this._planeCenter = null; | 66 | this._planeCenter = null; |
67 | this._dragPlane = null; | 67 | this._dragPlane = null; |
68 | }; //BrushStroke class defition | ||
68 | 69 | ||
69 | ///////////////////////////////////////////////////////// | 70 | BrushStroke.prototype = Object.create(GeomObj, {}); |
70 | // Property Accessors/Setters | 71 | |
71 | ///////////////////////////////////////////////////////// | 72 | ///////////////////////////////////////////////////////// |
72 | this.setCanvas = function(c) { | 73 | // Property Accessors/Setters |
73 | this._canvas = c; | 74 | ///////////////////////////////////////////////////////// |
75 | BrushStroke.prototype.setCanvas = function(c) { | ||
76 | this._canvas = c; | ||
77 | }; | ||
78 | |||
79 | BrushStroke.prototype.setWorld = function (world) { | ||
80 | this._world = world; | ||
81 | }; | ||
82 | |||
83 | BrushStroke.prototype.getWorld = function () { | ||
84 | return this._world; | ||
85 | }; | ||
86 | |||
87 | BrushStroke.prototype.geomType = function () { | ||
88 | return this.GEOM_TYPE_BRUSH_STROKE; | ||
89 | }; | ||
90 | |||
91 | BrushStroke.prototype.setDrawingTool = function (tool) { | ||
92 | this._drawingTool = tool; | ||
93 | }; | ||
94 | |||
95 | BrushStroke.prototype.getDrawingTool = function () { | ||
96 | return this._drawingTool; | ||
97 | }; | ||
98 | |||
99 | BrushStroke.prototype.setPlaneMatrix = function(planeMat){ | ||
100 | this._planeMat = planeMat; | ||
101 | }; | ||
102 | |||
103 | BrushStroke.prototype.setPlaneMatrixInverse = function(planeMatInv){ | ||
104 | this._planeMatInv = planeMatInv; | ||
105 | }; | ||
106 | |||
107 | BrushStroke.prototype.setPlaneCenter = function(pc){ | ||
108 | this._planeCenter = pc; | ||
109 | }; | ||
110 | |||
111 | BrushStroke.prototype.setDragPlane = function(p){ | ||
112 | this._dragPlane = p; | ||
113 | }; | ||
114 | |||
115 | BrushStroke.prototype.getNumPoints = function () { | ||
116 | if (this._LocalPoints.length) | ||
117 | return this._LocalPoints.length; | ||
118 | else | ||
119 | return this._Points.length; | ||
120 | }; | ||
121 | |||
122 | BrushStroke.prototype.getPoint = function (index) { | ||
123 | return this._Points[index].slice(0); | ||
124 | }; | ||
125 | |||
126 | BrushStroke.prototype.addPoint = function (pt) { | ||
127 | //add the point only if it is some epsilon away from the previous point | ||
128 | var numPoints = this._Points.length; | ||
129 | if (numPoints>0) { | ||
130 | var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD; | ||
131 | var prevPt = this._Points[numPoints-1]; | ||
132 | var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; | ||
133 | var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); | ||
134 | if (diffPtMag>threshold){ | ||
135 | this._Points.push(pt); | ||
136 | this._isDirty=true; | ||
137 | this._isInit = false; | ||
138 | } | ||
139 | } else { | ||
140 | this._Points.push(pt); | ||
141 | this._isDirty=true; | ||
142 | this._isInit = false; | ||
74 | } | 143 | } |
144 | }; | ||
75 | 145 | ||
76 | this.setWorld = function (world) { | 146 | BrushStroke.prototype.insertPoint = function(pt, index){ |
77 | this._world = world; | 147 | this._Points.splice(index, 0, pt); |
78 | }; | 148 | this._isDirty=true; |
149 | this._isInit = false; | ||
150 | }; | ||
79 | 151 | ||
80 | this.getWorld = function () { | 152 | BrushStroke.prototype.isDirty = function(){ |
81 | return this._world; | 153 | return this._isDirty; |
82 | }; | 154 | }; |
83 | 155 | ||
84 | this.geomType = function () { | 156 | BrushStroke.prototype.makeDirty = function(){ |
85 | return this.GEOM_TYPE_BRUSH_STROKE; | 157 | this._isDirty=true; |
86 | }; | 158 | }; |
87 | 159 | ||
88 | this.setDrawingTool = function (tool) { | 160 | BrushStroke.prototype.getStageWorldCenter = function() { |
89 | this._drawingTool = tool; | 161 | return this._stageWorldCenter; |
90 | }; | 162 | }; |
91 | 163 | ||
92 | this.getDrawingTool = function () { | 164 | BrushStroke.prototype.getBBoxMin = function () { |
93 | return this._drawingTool; | 165 | return this._BBoxMin; |
94 | }; | 166 | }; |
95 | 167 | ||
96 | this.setPlaneMatrix = function(planeMat){ | 168 | BrushStroke.prototype.getBBoxMax = function () { |
97 | this._planeMat = planeMat; | 169 | return this._BBoxMax; |
98 | }; | 170 | }; |
99 | 171 | ||
100 | this.setPlaneMatrixInverse = function(planeMatInv){ | 172 | BrushStroke.prototype.getStrokeWidth = function () { |
101 | this._planeMatInv = planeMatInv; | 173 | return this._strokeWidth; |
102 | }; | 174 | }; |
103 | 175 | ||
104 | this.setPlaneCenter = function(pc){ | 176 | BrushStroke.prototype.setStrokeWidth = function (w) { |
105 | this._planeCenter = pc; | 177 | this._strokeWidth = w; |
106 | }; | 178 | if (this._strokeWidth<1) { |
179 | this._strokeWidth = 1; | ||
180 | } | ||
181 | this._isDirty=true; | ||
182 | }; | ||
107 | 183 | ||
108 | this.setDragPlane = function(p){ | 184 | BrushStroke.prototype.getStrokeMaterial = function () { |
109 | this._dragPlane = p; | 185 | return this._strokeMaterial; |
110 | }; | 186 | }; |
111 | 187 | ||
112 | this.getNumPoints = function () { | 188 | BrushStroke.prototype.setStrokeMaterial = function (m) { |
113 | if (this._LocalPoints.length) | 189 | this._strokeMaterial = m; this._isDirty = true; |
114 | return this._LocalPoints.length; | 190 | }; |
115 | else | ||
116 | return this._Points.length; | ||
117 | }; | ||
118 | 191 | ||
119 | this.getPoint = function (index) { | 192 | BrushStroke.prototype.getStrokeColor = function () { |
120 | return this._Points[index].slice(0); | 193 | return this._strokeColor; |
121 | }; | 194 | }; |
122 | 195 | ||
123 | this.addPoint = function (pt) { | 196 | BrushStroke.prototype.setStrokeColor = function (c) { |
124 | //add the point only if it is some epsilon away from the previous point | 197 | this._strokeColor = c; this._isDirty = true; |
125 | var numPoints = this._Points.length; | 198 | }; |
126 | if (numPoints>0) { | ||
127 | var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD; | ||
128 | var prevPt = this._Points[numPoints-1]; | ||
129 | var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; | ||
130 | var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); | ||
131 | if (diffPtMag>threshold){ | ||
132 | this._Points.push(pt); | ||
133 | this._isDirty=true; | ||
134 | this._isInit = false; | ||
135 | } | ||
136 | } else { | ||
137 | this._Points.push(pt); | ||
138 | this._isDirty=true; | ||
139 | this._isInit = false; | ||
140 | } | ||
141 | }; | ||
142 | |||
143 | this.insertPoint = function(pt, index){ | ||
144 | this._Points.splice(index, 0, pt); | ||
145 | this._isDirty=true; | ||
146 | this._isInit = false; | ||
147 | }; | ||
148 | 199 | ||
149 | this.isDirty = function(){ | 200 | BrushStroke.prototype.setFillColor = function(c){ |
150 | return this._isDirty; | 201 | return; |
151 | }; | 202 | }; //NO-OP for now as we have no fill region |
152 | 203 | ||
153 | this.makeDirty = function(){ | 204 | BrushStroke.prototype.setSecondStrokeColor = function(c){ |
154 | this._isDirty=true; | 205 | this._secondStrokeColor=c; this._isDirty = true; |
155 | }; | 206 | }; |
156 | 207 | ||
157 | this.getStageWorldCenter = function() { | 208 | BrushStroke.prototype.setStrokeHardness = function(h){ |
158 | return this._stageWorldCenter; | 209 | if (this._strokeHardness!==h){ |
159 | }; | 210 | this._strokeHardness=h; |
211 | this._isDirty = true; | ||
212 | } | ||
213 | }; | ||
214 | BrushStroke.prototype.getStrokeHardness = function(){ | ||
215 | return this._strokeHardness; | ||
216 | }; | ||
217 | |||
218 | BrushStroke.prototype.setDoSmoothing = function(s){ | ||
219 | if (this._strokeDoSmoothing!==s) { | ||
220 | this._strokeDoSmoothing = s; | ||
221 | this._isDirty = true; | ||
222 | } | ||
223 | }; | ||
160 | 224 | ||
161 | this.getBBoxMin = function () { | 225 | BrushStroke.prototype.getDoSmoothing = function(){ |
162 | return this._BBoxMin; | 226 | return this._strokeDoSmoothing; |
163 | }; |