aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLRectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rw-r--r--js/helper-classes/RDGE/GLRectangle.js295
1 files changed, 227 insertions, 68 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
index 2899e476..e34532d2 100644
--- a/js/helper-classes/RDGE/GLRectangle.js
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -210,8 +210,11 @@ function GLRectangle()
210 // get the world 210 // get the world
211 var world = this.getWorld(); 211 var world = this.getWorld();
212 if (!world) throw( "null world in buildBuffers" ); 212 if (!world) throw( "null world in buildBuffers" );
213 213 //console.log( "GLRectangle.buildBuffers " + world._worldCount );
214 if (!world._useWebGL) return; 214 if (!world._useWebGL) return;
215
216 // make sure RDGE has the correct context
217 g_Engine.setContext( world.getCanvas().uuid );
215 218
216 // create the gl buffer 219 // create the gl buffer
217 var gl = world.getGLContext(); 220 var gl = world.getGLContext();
@@ -284,6 +287,7 @@ function GLRectangle()
284 xFill -= strokeSize; 287 xFill -= strokeSize;
285 yFill -= strokeSize; 288 yFill -= strokeSize;
286 var fillMaterial = this.makeFillMaterial(); 289 var fillMaterial = this.makeFillMaterial();
290 //console.log( "fillMaterial: " + fillMaterial.getName() );
287 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 291 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
288 this._primArray.push( fillPrim ); 292 this._primArray.push( fillPrim );
289 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 293 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
@@ -313,71 +317,72 @@ function GLRectangle()
313 var width = Math.round(this.getWidth()), 317 var width = Math.round(this.getWidth()),
314 height = Math.round(this.getHeight()); 318 height = Math.round(this.getHeight());
315 319
320 // get the top left point
316 pt = [inset, inset]; // top left corner 321 pt = [inset, inset]; // top left corner
322 rad = this.getTLRadius() - inset;
323 if (rad < 0) rad = 0;
324 pt[1] += rad;
325 if (MathUtils.fpSign(rad) == 0) pt[1] = 0;
326 ctx.moveTo( pt[0], pt[1] );
327
328 // get the bottom left point
329 pt = [inset, height - inset];
330 rad = this.getBLRadius() - inset;
331 if (rad < 0) rad = 0;
332 pt[1] -= rad;
333 ctx.lineTo( pt[0], pt[1] );
334
335 // get the bottom left arc
336 if (MathUtils.fpSign(rad) > 0)
337 {
338 ctr = [ this.getBLRadius(), height - this.getBLRadius() ];
339 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx );
340 ctx.arc( ctr[0], ctr[1], rad, Math.PI, 0.5*Math.PI, true );
341 }
317 342
318 var tlRad = this._tlRadius; //top-left radius 343 // do the bottom of the rectangle
319 var trRad = this._trRadius; 344 pt = [width - inset, height - inset];
320 var blRad = this._blRadius; 345 rad = this.getBRRadius() - inset;
321 var brRad = this._brRadius; 346 if (rad < 0) rad = 0;
347 pt[0] -= rad;
348 ctx.lineTo( pt[0], pt[1] );
322 349
323 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) 350 // get the bottom right arc
351 if (MathUtils.fpSign(rad) > 0)
324 { 352 {
325 ctx.rect(pt[0], pt[1], width - 2*inset, height - 2*inset); 353 ctr = [width - this.getBRRadius(), height - this.getBRRadius()];
354 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx );
355 ctx.arc( ctr[0], ctr[1], rad, 0.5*Math.PI, 0.0, true );
326 } 356 }
327 else 357
358 // get the right of the rectangle
359 pt = [width - inset, inset];
360 rad = this.getTRRadius() - inset;
361 if (rad < 0) rad = 0;
362 pt[1] += rad;
363 ctx.lineTo( pt[0], pt[1] );
364
365 // do the top right corner
366 if (MathUtils.fpSign(rad) > 0)
367 {
368 ctr = [width - this.getTRRadius(), this.getTRRadius()];
369 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx );
370 ctx.arc( ctr[0], ctr[1], rad, 0.0, -0.5*Math.PI, true );
371 }
372
373 // do the top of the rectangle
374 pt = [inset, inset]
375 rad = this.getTLRadius() - inset;
376 if (rad < 0) rad = 0;
377 pt[0] += rad;
378 ctx.lineTo( pt[0], pt[1] );
379
380 // do the top left corner
381 if (MathUtils.fpSign(rad) > 0)
328 { 382 {
329 // get the top left point 383 ctr = [this.getTLRadius(), this.getTLRadius()];
330 rad = tlRad - inset; 384 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx );
331 if (rad < 0) rad = 0; 385 ctx.arc( ctr[0], ctr[1], rad, -0.5*Math.PI, Math.PI, true );
332 pt[1] += rad;
333 if (MathUtils.fpSign(rad) == 0) pt[1] = inset;
334 ctx.moveTo( pt[0], pt[1] );
335
336 // get the bottom left point
337 pt = [inset, height - inset];
338 rad = blRad - inset;
339 if (rad < 0) rad = 0;
340 pt[1] -= rad;
341 ctx.lineTo( pt[0], pt[1] );
342
343 // get the bottom left curve
344 if (MathUtils.fpSign(rad) > 0)
345 ctx.quadraticCurveTo( inset, height-inset, inset+rad, height-inset );
346
347 // do the bottom of the rectangle
348 pt = [width - inset, height - inset];
349 rad = brRad - inset;
350 if (rad < 0) rad = 0;
351 pt[0] -= rad;
352 ctx.lineTo( pt[0], pt[1] );
353
354 // get the bottom right arc
355 if (MathUtils.fpSign(rad) > 0)
356 ctx.quadraticCurveTo( width-inset, height-inset, width-inset, height-inset-rad );
357
358 // get the right of the rectangle
359 pt = [width - inset, inset];
360 rad = trRad - inset;
361 if (rad < 0) rad = 0;
362 pt[1] += rad;
363 ctx.lineTo( pt[0], pt[1] );
364
365 // do the top right corner
366 if (MathUtils.fpSign(rad) > 0)
367 ctx.quadraticCurveTo( width-inset, inset, width-inset-rad, inset );
368
369 // do the top of the rectangle
370 pt = [inset, inset]
371 rad = tlRad - inset;
372 if (rad < 0) rad = 0;
373 pt[0] += rad;
374 ctx.lineTo( pt[0], pt[1] );
375
376 // do the top left corner
377 if (MathUtils.fpSign(rad) > 0)
378 ctx.quadraticCurveTo( inset, inset, inset, inset+rad );
379 else
380 ctx.lineTo( inset, 2*inset );
381 } 386 }
382 } 387 }
383 388
@@ -396,20 +401,32 @@ function GLRectangle()
396 var w = world.getViewportWidth(), 401 var w = world.getViewportWidth(),
397 h = world.getViewportHeight(); 402 h = world.getViewportHeight();
398 403
399 // set the fill 404 // draw the fill
400 ctx.beginPath(); 405 ctx.beginPath();
401 ctx.fillStyle = "#990000"; 406 ctx.fillStyle = "#990000";
407 //ctx.strokeStyle = "#0000ff";
402 if (this._fillColor) 408 if (this._fillColor)
403 ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); 409 ctx.fillStyle = MathUtils.colorToHex( this._fillColor );
404 410
405 // set the stroke 411 //ctx.lineWidth = 0;
412 //ctx.rect( lw, lw, w - 2*lw, h- 2*lw );
413 //this.renderPath( lw, ctx )
414 //ctx.fill();
415 //ctx.closePath();
416
417 // draw the stroke
418 //ctx.beginPath();
419 //ctx.fillStyle = "#990000";
406 ctx.strokeStyle = "#0000ff"; 420 ctx.strokeStyle = "#0000ff";
407 if (this._strokeColor) 421 if (this._strokeColor)
408 ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); 422 ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor );
409 423
410 ctx.lineWidth = lw; 424 ctx.lineWidth = lw;
425 //ctx.rect( 0.5*lw, 0.5*lw, w-lw, h-lw );
411 var inset = Math.ceil( 0.5*lw ) + 0.5; 426 var inset = Math.ceil( 0.5*lw ) + 0.5;
427// console.log( "linewidth: " + lw + ", inset: " + inset+ ", width: " + Math.round(this.getWidth()) + ", height: " + Math.round(this.getHeight()) );
412 this.renderPath( inset, ctx ); 428 this.renderPath( inset, ctx );
429 //this.renderPath( lw, ctx );
413 ctx.fill(); 430 ctx.fill();
414 ctx.stroke(); 431 ctx.stroke();
415 ctx.closePath(); 432 ctx.closePath();
@@ -418,7 +435,7 @@ function GLRectangle()
418 this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) 435 this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
419 { 436 {
420 // create the geometry 437 // create the geometry
421 var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) 438 var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material)
422 return prim; 439 return prim;
423 } 440 }
424 441
@@ -428,9 +445,9 @@ function GLRectangle()
428 // special the (common) case of no rounded corners 445