diff options
author | Valerio Virgillito | 2012-08-07 16:33:00 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-08-07 16:33:00 -0700 |
commit | 63e45de6eb9c19be9e262ffdda87edc6867ecef3 (patch) | |
tree | 14c7037e86fe0cb5ca88037b6f47988bf781d5d4 /js/lib | |
parent | b6a8ae331cc89f494ace2571ba6719a07b0e1c64 (diff) | |
parent | da71ec8bf450438a4dc904cb348e548d01dfcb3f (diff) | |
download | ninja-63e45de6eb9c19be9e262ffdda87edc6867ecef3.tar.gz |
Merge pull request #426 from mqg734/LineInCanvas
Support line drawing in existing canvas.
Diffstat (limited to 'js/lib')
-rwxr-xr-x | js/lib/geom/line.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js index eec4f6d9..df65ee86 100755 --- a/js/lib/geom/line.js +++ b/js/lib/geom/line.js | |||
@@ -537,6 +537,15 @@ exports.Line = Object.create(GeomObj, { | |||
537 | ctx.strokeStyle = c; | 537 | ctx.strokeStyle = c; |
538 | } | 538 | } |
539 | 539 | ||
540 | var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; | ||
541 | viewUtils.pushViewportObj( world.getCanvas() ); | ||
542 | var cop = viewUtils.getCenterOfProjection(); | ||
543 | viewUtils.popViewportObj(); | ||
544 | var xCtr = cop[0] + this._xOffset, yCtr = cop[1] - this._yOffset; | ||
545 | var xLeft = xCtr - 0.5*this.getWidth(), yTop = yCtr - 0.5*this.getHeight(); | ||
546 | var xDist = cop[0] - xLeft, yDist = cop[1] - yTop; | ||
547 | var xOff = 0.5*world.getViewportWidth() - xDist, yOff = 0.5*world.getViewportHeight() - yDist; | ||
548 | |||
540 | // get the points | 549 | // get the points |
541 | var p0, p1; | 550 | var p0, p1; |
542 | if(this._slope === "vertical") { | 551 | if(this._slope === "vertical") { |
@@ -554,8 +563,8 @@ exports.Line = Object.create(GeomObj, { | |||
554 | } | 563 | } |
555 | 564 | ||
556 | // draw the line | 565 | // draw the line |
557 | ctx.moveTo( p0[0], p0[1] ); | 566 | ctx.moveTo( p0[0]+xOff, p0[1]+yOff ); |
558 | ctx.lineTo( p1[0], p1[1] ); | 567 | ctx.lineTo( p1[0]+xOff, p1[1]+yOff ); |
559 | ctx.stroke(); | 568 | ctx.stroke(); |
560 | } | 569 | } |
561 | } | 570 | } |