aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/brush-stroke.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/brush-stroke.js')
-rwxr-xr-xjs/lib/geom/brush-stroke.js46
1 files changed, 41 insertions, 5 deletions
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 0278e49c..02a39ccd 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -4,9 +4,11 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7// Todo: This entire class should be converted to a module
8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; 7var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
9var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 8var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
9var CanvasController = require("js/controllers/elements/canvas-controller").CanvasController;
10
11// Todo: This entire class should be converted to a module
10 12
11/////////////////////////////////////////////////////////////////////// 13///////////////////////////////////////////////////////////////////////
12// Class GLBrushStroke 14// Class GLBrushStroke
@@ -28,7 +30,10 @@ var BrushStroke = function GLBrushStroke() {
28 //whether or not to use the canvas drawing to stroke/fill 30 //whether or not to use the canvas drawing to stroke/fill
29 this._useCanvasDrawing = true; 31 this._useCanvasDrawing = true;
30 32
31 //the X and Y location of this subpath's canvas in stage world space of Ninja 33 //the HTML5 canvas that holds this brush stroke
34 this._canvas = null;
35
36 //the X and Y location of this brush stroke canvas in stage world space of Ninja
32 this._canvasX = 0; 37 this._canvasX = 0;
33 this._canvasY = 0; 38 this._canvasY = 0;
34 39
@@ -65,6 +70,10 @@ var BrushStroke = function GLBrushStroke() {
65 ///////////////////////////////////////////////////////// 70 /////////////////////////////////////////////////////////
66 // Property Accessors/Setters 71 // Property Accessors/Setters
67 ///////////////////////////////////////////////////////// 72 /////////////////////////////////////////////////////////
73 this.setCanvas = function(c) {
74 this._canvas = c;
75 }
76
68 this.setWorld = function (world) { 77 this.setWorld = function (world) {
69 this._world = world; 78 this._world = world;
70 }; 79 };
@@ -195,6 +204,9 @@ var BrushStroke = function GLBrushStroke() {
195 this._dirty = true; 204 this._dirty = true;
196 } 205 }
197 } 206 }
207 this.getStrokeHardness = function(){
208 return this._strokeHardness;
209 }
198 210
199 this.setDoSmoothing = function(s){ 211 this.setDoSmoothing = function(s){
200 if (this._strokeDoSmoothing!==s) { 212 if (this._strokeDoSmoothing!==s) {
@@ -203,12 +215,19 @@ var BrushStroke = function GLBrushStroke() {
203 } 215 }
204 } 216 }
205 217
218 this.getDoSmoothing = function(){
219 return this._strokeDoSmoothing;
220 }
221
206 this.setSmoothingAmount = function(a){ 222 this.setSmoothingAmount = function(a){
207 if (this._strokeAmountSmoothing!==a) { 223 if (this._strokeAmountSmoothing!==a) {
208 this._strokeAmountSmoothing = a; 224 this._strokeAmountSmoothing = a;
209 this._dirty = true; 225 this._dirty = true;
210 } 226 }
227 }
211 228
229 this.getSmoothingAmount = function(){
230 return this._strokeAmountSmoothing;
212 } 231 }
213 232
214 this.setStrokeUseCalligraphic = function(c){ 233 this.setStrokeUseCalligraphic = function(c){
@@ -225,6 +244,14 @@ var BrushStroke = function GLBrushStroke() {
225 }; 244 };
226 } 245 }
227 246
247 this.getStrokeUseCalligraphic = function(){
248 return this._strokeUseCalligraphic;
249 }
250
251 this.getStrokeAngle = function(){
252 this._strokeAngle = a;
253 }
254
228 this.getStrokeStyle = function () { 255 this.getStrokeStyle = function () {
229 return this._strokeStyle; 256 return this._strokeStyle;
230 }; 257 };
@@ -301,12 +328,13 @@ var BrushStroke = function GLBrushStroke() {
301 console.log("Inserted "+numInsertedPoints+" additional CatmullRom points"); 328 console.log("Inserted "+numInsertedPoints+" additional CatmullRom points");
302 this._addedSamples = true; 329 this._addedSamples = true;
303 this._dirty=true; 330 this._dirty=true;
304 } 331 } //if we need to add samples to this curve (done only once)
332
305 //build a copy of the original points...this should be done only once 333 //build a copy of the original points...this should be done only once
306 if (this._storedOrigPoints === false) { 334 if (this._storedOrigPoints === false) {
307 this._OrigPoints = this._Points.slice(0); 335 this._OrigPoints = this._Points.slice(0);
308 this._storedOrigPoints = true; 336 this._storedOrigPoints = true;
309 } 337 } //if we need to store a copy of the original points (done only once)
310 338
311 if (this._dirty) { 339 if (this._dirty) {
312 this._Points = this._OrigPoints.slice(0); 340 this._Points = this._OrigPoints.slice(0);
@@ -377,7 +405,7 @@ var BrushStroke = function GLBrushStroke() {
377 405
378 // get the context 406 // get the context
379 var ctx = world.get2DContext(); 407 var ctx = world.get2DContext();
380 if (!ctx) throw ("null context in brushstroke render") 408 if (!ctx) throw ("null context in brushstroke render");
381 409
382 var numPoints = this.getNumPoints(); 410 var numPoints = this.getNumPoints();
383 if (numPoints === 0) { 411 if (numPoints === 0) {
@@ -391,6 +419,14 @@ var BrushStroke = function GLBrushStroke() {
391 var bboxMax = this.getBBoxMax(); 419 var bboxMax = this.getBBoxMax();
392 var bboxWidth = bboxMax[0] - bboxMin[0]; 420 var bboxWidth = bboxMax[0] - bboxMin[0];
393 var bboxHeight = bboxMax[1] - bboxMin[1]; 421 var bboxHeight = bboxMax[1] - bboxMin[1];
422
423 //assign the new width and height as the canvas dimensions through the canvas controller
424 if (this._canvas) {
425 CanvasController.setProperty(this._canvas, "width", bboxWidth+"px");
426 CanvasController.setProperty(this._canvas, "height", bboxHeight+"px");
427 this._canvas.elementModel.shapeModel.GLWorld.setViewportFromCanvas(this._canvas);
428 }
429
394 ctx.clearRect(0, 0, bboxWidth, bboxHeight); 430 ctx.clearRect(0, 0, bboxWidth, bboxHeight);
395 431
396 if (this._strokeUseCalligraphic) { 432 if (this._strokeUseCalligraphic) {