aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/lib/geom/brush-stroke.js1406
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 ///////////////////////////////////////////////////////// 70BrushStroke.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/////////////////////////////////////////////////////////
75BrushStroke.prototype.setCanvas = function(c) {
76 this._canvas = c;
77};
78
79BrushStroke.prototype.setWorld = function (world) {
80 this._world = world;
81};
82
83BrushStroke.prototype.getWorld = function () {
84 return this._world;
85};
86
87BrushStroke.prototype.geomType = function () {
88 return this.GEOM_TYPE_BRUSH_STROKE;
89};
90
91BrushStroke.prototype.setDrawingTool = function (tool) {
92 this._drawingTool = tool;
93};
94
95BrushStroke.prototype.getDrawingTool = function () {
96 return this._drawingTool;
97};
98
99BrushStroke.prototype.setPlaneMatrix = function(planeMat){
100 this._planeMat = planeMat;
101};
102
103BrushStroke.prototype.setPlaneMatrixInverse = function(planeMatInv){
104 this._planeMatInv = planeMatInv;
105};
106
107BrushStroke.prototype.setPlaneCenter = function(pc){
108 this._planeCenter = pc;
109};
110
111BrushStroke.prototype.setDragPlane = function(p){
112 this._dragPlane = p;
113};
114
115BrushStroke.prototype.getNumPoints = function () {
116 if (this._LocalPoints.length)
117 return this._LocalPoints.length;
118 else
119 return this._Points.length;
120};
121
122BrushStroke.prototype.getPoint = function (index) {
123 return this._Points[index].slice(0);
124};
125
126BrushStroke.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) { 146BrushStroke.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 () { 152BrushStroke.prototype.isDirty = function(){
81 return this._world; 153 return this._isDirty;
82 }; 154};
83 155
84 this.geomType = function () { 156BrushStroke.prototype.makeDirty = function(){
85 return this.GEOM_TYPE_BRUSH_STROKE; 157 this._isDirty=true;
86 }; 158};
87 159
88 this.setDrawingTool = function (tool) { 160BrushStroke.prototype.getStageWorldCenter = function() {
89 this._drawingTool = tool; 161 return this._stageWorldCenter;
90 }; 162};
91 163
92 this.getDrawingTool = function () { 164BrushStroke.prototype.getBBoxMin = function () {
93 return this._drawingTool; 165 return this._BBoxMin;
94 }; 166};
95 167
96 this.setPlaneMatrix = function(planeMat){ 168BrushStroke.prototype.getBBoxMax = function () {
97 this._planeMat = planeMat; 169 return this._BBoxMax;
98 }; 170};
99 171
100 this.setPlaneMatrixInverse = function(planeMatInv){ 172BrushStroke.prototype.getStrokeWidth = function () {
101 this._planeMatInv = planeMatInv; 173 return this._strokeWidth;
102 }; 174};
103 175
104 this.setPlaneCenter = function(pc){ 176BrushStroke.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){ 184BrushStroke.prototype.getStrokeMaterial = function () {
109 this._dragPlane = p; 185 return this._strokeMaterial;
110 }; 186};
111 187
112 this.getNumPoints = function () { 188BrushStroke.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) { 192BrushStroke.prototype.getStrokeColor = function () {
120 return this._Points[index].slice(0); 193 return this._strokeColor;
121 }; 194};
122 195
123 this.addPoint = function (pt) { 196BrushStroke.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(){ 200BrushStroke.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(){ 204BrushStroke.prototype.setSecondStrokeColor = function(c){
154 this._isDirty=true; 205 this._secondStrokeColor=c; this._isDirty = true;
155 }; 206};
156 207
157 this.getStageWorldCenter = function() { 208BrushStroke.prototype.setStrokeHardness = function(h){
158 return this._stageWorldCenter; 209 if (this._strokeHardness!==h){
159 }; 210 this._strokeHardness=h;
211 this._isDirty = true;
212 }
213};
214BrushStroke.prototype.getStrokeHardness = function(){
215 return this._strokeHardness;
216};
217
218BrushStroke.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 () { 225BrushStroke.prototype.getDoSmoothing = function(){
162 return this