aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/lib/geom/line.js13
-rwxr-xr-xjs/tools/LineTool.js56
2 files changed, 41 insertions, 28 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 }
diff --git a/js/tools/LineTool.js b/js/tools/LineTool.js
index f0d96c3c..4ec327b5 100755
--- a/js/tools/LineTool.js
+++ b/js/tools/LineTool.js
@@ -97,34 +97,38 @@ exports.LineTool = Montage.create(ShapeTool, {
97 if(this.drawData) { 97 if(this.drawData) {
98 w = Math.floor(this.drawData.width); 98 w = Math.floor(this.drawData.width);
99 h = Math.floor(this.drawData.height); 99 h = Math.floor(this.drawData.height);
100 // set the dimensions
101 if(slope === "horizontal") {
102 h = Math.max(this._strokeSize, 1);
103 w = Math.max(w, 1);
104 } else if(slope === "vertical") {
105 w = Math.max(this._strokeSize, 1);
106 h = Math.max(h, 1);
107 } else {
108 // else make the line's stroke fit inside the canvas by growing the canvas
109 var theta = Math.atan(slope);
110 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta));
111 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta));
112
113 w += ~~(xAdj*2);
114 h += ~~(yAdj*2);
115 }
116
100 if(!this._useExistingCanvas()) { 117 if(!this._useExistingCanvas()) {
101 // set the dimensions 118
102 if(slope === "horizontal") { 119 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
103 h = Math.max(this._strokeSize, 1); 120
104 w = Math.max(w, 1); 121 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData);
105 } else if(slope === "vertical") { 122 this.application.ninja.elementMediator.addElements(canvas, styles);
106 w = Math.max(this._strokeSize, 1); 123 } else {
107 h = Math.max(h, 1); 124 canvas = this._targetedElement;
108 } else { 125 if (!canvas.getAttribute( "data-RDGE-id" ))
109 // else make the line's stroke fit inside the canvas by growing the canvas 126 canvas.setAttribute( "data-RDGE-id", NJUtils.generateRandom() );
110 var theta = Math.atan(slope); 127 canvas.elementModel.controller = ShapesController;
111 xAdj = Math.abs((this._strokeSize/2)*Math.sin(theta)); 128 if(!canvas.elementModel.shapeModel) {
112 yAdj = Math.abs((this._strokeSize/2)*Math.cos(theta)); 129 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
113
114 w += ~~(xAdj*2);
115 h += ~~(yAdj*2);
116 }
117
118 canvas = document.application.njUtils.make("canvas", {"data-RDGE-id": NJUtils.generateRandom()}, this.application.ninja.currentDocument);
119
120 var styles = document.application.njUtils.stylesFromDraw(canvas, w, h, this.drawData);
121 this.application.ninja.elementMediator.addElements(canvas, styles);
122 } else {
123 canvas = this._targetedElement;
124 canvas.elementModel.controller = ShapesController;
125 if(!canvas.elementModel.shapeModel) {
126 canvas.elementModel.shapeModel = Montage.create(ShapeModel);
127 } 130 }
131 this.RenderShape(w, h, this.drawData.planeMat, this.drawData.midPt, canvas, slope, xAdj, yAdj);
128 } 132 }
129 } 133 }
130 } 134 }