aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js40
1 files changed, 27 insertions, 13 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 51db0dd0..fc6043d6 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -7,6 +7,7 @@
7var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 7var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
8var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; 8var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
9var MaterialsModel = require("js/models/materials-model").MaterialsModel; 9var MaterialsModel = require("js/models/materials-model").MaterialsModel;
10
10 /////////////////////////////////////////////////////////////////////// 11 ///////////////////////////////////////////////////////////////////////
11// Class GLRectangle 12// Class GLRectangle
12// GL representation of a rectangle. 13// GL representation of a rectangle.
@@ -58,6 +59,10 @@ var Rectangle = function GLRectangle()
58 this.setBRRadius(brRadius); 59 this.setBRRadius(brRadius);
59 60
60 this._strokeStyle = strokeStyle; 61 this._strokeStyle = strokeStyle;
62
63 this._matrix = Matrix.I(4);
64 //this._matrix[12] = xoffset;
65 //this._matrix[13] = yoffset;
61 } 66 }
62 67
63 // the overall radius includes the fill and the stroke. separate the two based onthe stroke width 68 // the overall radius includes the fill and the stroke. separate the two based onthe stroke width
@@ -377,26 +382,36 @@ var Rectangle = function GLRectangle()
377 if (brRad > minDimen) brRad = minDimen; 382 if (brRad > minDimen) brRad = minDimen;
378 if (trRad > minDimen) trRad = minDimen; 383 if (trRad > minDimen) trRad = minDimen;
379 384
385 var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
386 var world = this.getWorld();
387 viewUtils.pushViewportObj( world.getCanvas() );
388 var cop = viewUtils.getCenterOfProjection();
389 viewUtils.popViewportObj();
390 var xCtr = cop[0] + this._xOffset, yCtr = cop[1] - this._yOffset;
391 var xLeft = xCtr - 0.5*this.getWidth(), yTop = yCtr - 0.5*this.getHeight();
392 var xDist = cop[0] - xLeft, yDist = cop[1] - yTop;
393 var xOff = 0.5*world.getViewportWidth() - xDist, yOff = 0.5*world.getViewportHeight() - yDist;
394
380 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { 395 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) {
381 ctx.rect(pt[0], pt[1], width - 2*inset, height - 2*inset); 396 ctx.rect(pt[0]+xOff, pt[1]+yOff, width - 2*inset, height - 2*inset);
382 } else { 397 } else {
383 // get the top left point 398 // get the top left point
384 rad = tlRad - inset; 399 rad = tlRad - inset;
385 if (rad < 0) rad = 0; 400 if (rad < 0) rad = 0;
386 pt[1] += rad; 401 pt[1] += rad;
387 if (MathUtils.fpSign(rad) == 0) pt[1] = inset; 402 if (MathUtils.fpSign(rad) == 0) pt[1] = inset;
388 ctx.moveTo( pt[0], pt[1] ); 403 ctx.moveTo( pt[0]+xOff, pt[1]+yOff );
389 404
390 // get the bottom left point 405 // get the bottom left point
391 pt = [inset, height - inset]; 406 pt = [inset, height - inset];
392 rad = blRad - inset; 407 rad = blRad - inset;
393 if (rad < 0) rad = 0; 408 if (rad < 0) rad = 0;
394 pt[1] -= rad; 409 pt[1] -= rad;
395 ctx.lineTo( pt[0], pt[1] ); 410 ctx.lineTo( pt[0]+xOff, pt[1]+yOff );
396 411
397 // get the bottom left curve 412 // get the bottom left curve
398 if (MathUtils.fpSign(rad) > 0) { 413 if (MathUtils.fpSign(rad) > 0) {
399 ctx.quadraticCurveTo( inset, height-inset, inset+rad, height-inset ); 414 ctx.quadraticCurveTo( inset+xOff, height-inset+yOff, inset+rad+xOff, height-inset+yOff );
400 } 415 }
401 416
402 // do the bottom of the rectangle 417 // do the bottom of the rectangle
@@ -404,11 +419,11 @@ var Rectangle = function GLRectangle()
404 rad = brRad - inset; 419 rad = brRad - inset;
405 if (rad < 0) rad = 0; 420 if (rad < 0) rad = 0;
406 pt[0] -= rad; 421 pt[0] -= rad;
407 ctx.lineTo( pt[0], pt[1] ); 422 ctx.lineTo( pt[0]+xOff, pt[1]+yOff );
408 423
409 // get the bottom right arc 424 // get the bottom right arc
410 if (MathUtils.fpSign(rad) > 0) { 425 if (MathUtils.fpSign(rad) > 0) {
411 ctx.quadraticCurveTo( width-inset, height-inset, width-inset, height-inset-rad ); 426 ctx.quadraticCurveTo( width-inset+xOff, height-inset+yOff, width-inset+xOff, height-inset-rad+yOff );
412 } 427 }
413 428
414 // get the right of the rectangle 429 // get the right of the rectangle
@@ -416,11 +431,11 @@ var Rectangle = function GLRectangle()
416 rad = trRad - inset; 431 rad = trRad - inset;
417 if (rad < 0) rad = 0; 432 if (rad < 0) rad = 0;
418 pt[1] += rad; 433 pt[1] += rad;
419 ctx.lineTo( pt[0], pt[1] ); 434 ctx.lineTo( pt[0]+xOff, pt[1]+yOff );
420 435
421 // do the top right corner 436 // do the top right corner
422 if (MathUtils.fpSign(rad) > 0) { 437 if (MathUtils.fpSign(rad) > 0) {
423 ctx.quadraticCurveTo( width-inset, inset, width-inset-rad, inset ); 438 ctx.quadraticCurveTo( width-inset+xOff, inset+yOff, width-inset-rad+xOff, inset+yOff );
424 } 439 }
425 440
426 // do the top of the rectangle 441 // do the top of the rectangle
@@ -428,13 +443,13 @@ var Rectangle = function GLRectangle()
428 rad = tlRad - inset; 443 rad = tlRad - inset;
429 if (rad < 0) rad = 0; 444 if (rad < 0) rad = 0;
430 pt[0] += rad; 445 pt[0] += rad;
431 ctx.lineTo( pt[0], pt[1] ); 446 ctx.lineTo( pt[0]+xOff, pt[1]+yOff );
432 447
433 // do the top left corner 448 // do the top left corner
434 if (MathUtils.fpSign(rad) > 0) { 449 if (MathUtils.fpSign(rad) > 0) {
435 ctx.quadraticCurveTo( inset, inset, inset, inset+rad ); 450 ctx.quadraticCurveTo( inset+xOff, inset+yOff, inset+xOff, inset+rad+yOff );
436 } else { 451 } else {
437 ctx.lineTo( inset, 2*inset ); 452 ctx.lineTo( inset+xOff, 2*inset+yOff );
438 } 453 }
439 } 454 }
440 }; 455 };
@@ -442,7 +457,7 @@ var Rectangle = function GLRectangle()
442 this.render = function() { 457 this.render = function() {
443 // get the world 458 // get the world
444 var world = this.getWorld(); 459 var world = this.getWorld();
445 if (!world) throw( "null world in rectangle render" ); 460 if (!world) throw( "null world in rectangle render" );
446 461
447 // get the context 462 // get the context
448 var ctx = world.get2DContext(); 463 var ctx = world.get2DContext();
@@ -690,7 +705,6 @@ var Rectangle = function GLRectangle()
690 var projPt = MathUtils.vecIntersectPlane ( pt, dir, plane ); 705 var projPt = MathUtils.vecIntersectPlane ( pt, dir, plane );
691 706
692 // transform the projected point back to the XY plane 707 // transform the projected point back to the XY plane
693 //var invMat = mat.inverse();
694 var invMat = glmat4.inverse(mat, []); 708 var invMat = glmat4.inverse(mat, []);
695 var planePt = MathUtils.transformPoint( projPt, invMat ); 709 var planePt = MathUtils.transformPoint( projPt, invMat );
696 710