aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/line.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/line.js')
-rwxr-xr-xjs/lib/geom/line.js101
1 files changed, 92 insertions, 9 deletions
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
index e8d967f0..1af02bcd 100755
--- a/js/lib/geom/line.js
+++ b/js/lib/geom/line.js
@@ -99,9 +99,47 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
99 99
100 this.geomType = function() { return this.GEOM_TYPE_LINE; } 100 this.geomType = function() { return this.GEOM_TYPE_LINE; }
101 101
102 /////////////////////////////////////////////////////////////////////// 102 ///////////////////////////////////////////////////////////////////////
103 // Methods 103 // Methods
104 /////////////////////////////////////////////////////////////////////// 104 ///////////////////////////////////////////////////////////////////////
105 this.exportJSON = function()
106 {
107 var jObj =
108 {
109 'type' : this.geomType(),
110 'xoff' : this._xOffset,
111 'yoff' : this._yOffset,
112 'width' : this._width,
113 'height' : this._height,
114 'xAdj' : this._xAdj,
115 'yAdj' : this._yAdj,
116 'slope' : this._slope,
117 'strokeWidth' : this._strokeWidth,
118 'strokeColor' : this._strokeColor,
119 'strokeStyle' : this._strokeStyle,
120 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
121 'materials' : this.exportMaterialsJSON()
122 };
123
124 return jObj;
125 };
126
127 this.importJSON = function( jObj )
128 {
129 this._xOffset = jObj.xoff;
130 this._yOffset = jObj.yoff;
131 this._width = jObj.width;
132 this._height = jObj.height;
133 this._xAdj = jObj.xAdj;
134 this._yAdj = jObj.yAdj;
135 this._strokeWidth = jObj.strokeWidth;
136 this._slope = jObj.slope;
137 this._strokeStyle = jObj.strokeStyle;
138 this._strokeColor = jObj.strokeColor;
139 var strokeMaterialName = jObj.strokeMat;
140 this.importMaterialsJSON( jObj.materials );
141 };
142
105 this.export = function() { 143 this.export = function() {
106 var rtnStr = "type: " + this.geomType() + "\n"; 144 var rtnStr = "type: " + this.geomType() + "\n";
107 145
@@ -112,7 +150,14 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
112 rtnStr += "xAdj: " + this._xAdj + "\n"; 150 rtnStr += "xAdj: " + this._xAdj + "\n";
113 rtnStr += "yAdj: " + this._yAdj + "\n"; 151 rtnStr += "yAdj: " + this._yAdj + "\n";
114 rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; 152 rtnStr += "strokeWidth: " + this._strokeWidth + "\n";
115 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; 153
154 if(this._strokeColor.gradientMode) {
155 rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n";
156 rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n";
157 } else {
158 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n";
159 }
160
116 rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; 161 rtnStr += "strokeStyle: " + this._strokeStyle + "\n";
117 rtnStr += "slope: " + String(this._slope) + "\n"; 162 rtnStr += "slope: " + String(this._slope) + "\n";
118 163
@@ -120,7 +165,7 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
120 if (this._strokeMaterial) { 165 if (this._strokeMaterial) {
121 rtnStr += this._strokeMaterial.getName(); 166 rtnStr += this._strokeMaterial.getName();
122 } else { 167 } else {
123 rtnStr += "flatMaterial"; 168 rtnStr += MaterialsModel.getDefaultMaterialName();
124 } 169 }
125 170
126 rtnStr += "\n"; 171 rtnStr += "\n";
@@ -145,12 +190,20 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
145 190
146 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); 191 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
147 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); 192 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
148 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); 193
194 if(importStr.indexOf("strokeGradientMode: ") < 0)
195 {
196 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
197 } else {
198 this._strokeColor = {};
199 this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr );
200 this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr ));
201 }
149 202
150 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 203 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
151 if (!strokeMat) { 204 if (!strokeMat) {
152 console.log( "object material not found in library: " + strokeMaterialName ); 205 console.log( "object material not found in library: " + strokeMaterialName );
153 strokeMat = MaterialsModel.exportFlatMaterial(); 206 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
154 } 207 }
155 208
156 this._strokeMaterial = strokeMat; 209 this._strokeMaterial = strokeMat;
@@ -348,16 +401,46 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
348 if (!ctx) return; 401 if (!ctx) return;
349 402
350 // set up the stroke style 403 // set up the stroke style
351 var lineWidth = this._strokeWidth; 404 var lineWidth = this._strokeWidth,
405 w = this._width,
406 h = this._height;
407
408 var c,
409 gradient,
410 colors,
411 len,
412 n,
413 position,
414 cs;
415
352 ctx.beginPath(); 416 ctx.beginPath();
353 ctx.lineWidth = lineWidth; 417 ctx.lineWidth = lineWidth;
354 if (this._strokeColor) { 418 if (this._strokeColor) {
355 var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; 419 if(this._strokeColor.gradientMode) {
356 ctx.strokeStyle = c; 420 if(this._strokeColor.gradientMode === "radial") {
421 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w/2, h/2));
422 } else {
423 gradient = ctx.createLinearGradient(0, h/2, w, h/2);
424 }
425 colors = this._strokeColor.color;
426
427 len = colors.length;
428
429 for(n=0; n<len; n++) {
430 position = colors[n].position/100;
431 cs = colors[n].value;
432 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")");
433 }
434
435 ctx.strokeStyle = gradient;
436
437 } else {
438 c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")";
439 ctx.strokeStyle = c;
440 }
357 441
358 // get the points 442 // get the points
359 var p0, p1; 443 var p0, p1;
360 var w = this._width, h = this._height;
361 if(this._slope === "vertical") { 444 if(this._slope === "vertical") {
362 p0 = [0.5*w, 0]; 445 p0 = [0.5*w, 0];
363 p1 = [0.5*w, h]; 446 p1 = [0.5*w, h];