diff options
Diffstat (limited to 'js/controllers')
-rwxr-xr-x | js/controllers/elements/shapes-controller.js | 90 |
1 files changed, 51 insertions, 39 deletions
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 51ddea20..14cdc473 100755 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js | |||
@@ -22,53 +22,65 @@ exports.ShapesController = Montage.create(CanvasController, { | |||
22 | case "strokeSize": | 22 | case "strokeSize": |
23 | // TODO - For now, just handling px units. | 23 | // TODO - For now, just handling px units. |
24 | this.setShapeProperty(el, "strokeSize", value); | 24 | this.setShapeProperty(el, "strokeSize", value); |
25 | // Changing stroke size should grow/shrink the shape from the center. | 25 | // TODO - For now, just handle Line, Rectangle and Oval. Eventually, move this into each class's |
26 | var delta = ~~(val - el.elementModel.shapeModel.GLGeomObj.getStrokeWidth()), | 26 | // setStrokeWidth code like SubPath and BrushStroke do. |
27 | l = this.application.ninja.elementMediator.getProperty(el, "left", parseInt), | 27 | var geomType = el.elementModel.shapeModel.GLGeomObj.geomType(); |
28 | t = this.application.ninja.elementMediator.getProperty(el, "top", parseInt), | 28 | if( (geomType > 0) && (geomType < 4) ) |
29 | w = this.application.ninja.elementMediator.getProperty(el, "width", parseInt), | ||
30 | h = this.application.ninja.elementMediator.getProperty(el, "height", parseInt); | ||
31 | |||
32 | if(el.elementModel.selection === "Line") | ||
33 | { | 29 | { |
34 | var slope = el.elementModel.shapeModel.slope; | 30 | // Changing stroke size should grow/shrink the shape from the center. |
35 | // set the dimensions | 31 | var delta = ~~(val - el.elementModel.shapeModel.GLGeomObj.getStrokeWidth()), |
36 | if(slope === "horizontal") | 32 | l = this.application.ninja.elementMediator.getProperty(el, "left", parseInt), |
33 | t = this.application.ninja.elementMediator.getProperty(el, "top", parseInt), | ||
34 | w = this.application.ninja.elementMediator.getProperty(el, "width", parseInt), | ||
35 | h = this.application.ninja.elementMediator.getProperty(el, "height", parseInt); | ||
36 | |||
37 | if(geomType === 3) | ||
37 | { | 38 | { |
38 | h = Math.max(val, 1); | 39 | var slope = el.elementModel.shapeModel.slope; |
39 | } | 40 | // set the dimensions |
40 | else if(slope === "vertical") | 41 | if(slope === "horizontal") |
41 | { | 42 | { |
42 | w = Math.max(val, 1); | 43 | h = Math.max(val, 1); |
43 | } | 44 | t -= ~~(delta/2); |
44 | else | 45 | } |
45 | { | 46 | else if(slope === "vertical") |
46 | var oldXAdj = el.elementModel.shapeModel.GLGeomObj.getXAdj(); | ||
47 | var oldYAdj = el.elementModel.shapeModel.GLGeomObj.getYAdj(); | ||
48 | var theta = Math.atan(el.elementModel.shapeModel.slope); | ||
49 | var xAdj = Math.abs((val/2)*Math.sin(theta)); | ||
50 | var yAdj = Math.abs((val/2)*Math.cos(theta)); | ||
51 | var dX = ~~(xAdj*2 - oldXAdj*2); | ||
52 | var dY = ~~(yAdj*2 - oldYAdj*2); | ||
53 | |||
54 | if(delta > 0) | ||
55 | { | 47 | { |
56 | l -= dX*2; | 48 | w = Math.max(val, 1); |
57 | t -= dY*2; | 49 | l -= ~~(delta/2); |
50 | } | ||
51 | else | ||
52 | { | ||
53 | var oldXAdj = el.elementModel.shapeModel.GLGeomObj.getXAdj(); | ||
54 | var oldYAdj = el.elementModel.shapeModel.GLGeomObj.getYAdj(); | ||
55 | var theta = Math.atan(el.elementModel.shapeModel.slope); | ||
56 | var xAdj = Math.abs((val/2)*Math.sin(theta)); | ||
57 | var yAdj = Math.abs((val/2)*Math.cos(theta)); | ||
58 | var dX = ~~(xAdj*2 - oldXAdj*2); | ||
59 | var dY = ~~(yAdj*2 - oldYAdj*2); | ||
60 | |||
61 | l -= dX; | ||
62 | t -= dY; | ||
58 | w += dX*2; | 63 | w += dX*2; |
59 | h += dY*2; | 64 | h += dY*2; |
60 | } | ||
61 | |||
62 | el.elementModel.shapeModel.GLGeomObj.setXAdj(xAdj); | ||
63 | el.elementModel.shapeModel.GLGeomObj.setYAdj(yAdj); | ||
64 | 65 | ||
66 | el.elementModel.shapeModel.GLGeomObj.setXAdj(xAdj); | ||
67 | el.elementModel.shapeModel.GLGeomObj.setYAdj(yAdj); | ||
68 | } | ||
69 | } | ||
70 | else | ||
71 | { | ||
72 | l -= ~~(delta/2); | ||
73 | t -= ~~(delta/2); | ||
74 | w += delta; | ||
75 | h += delta; | ||
65 | } | 76 | } |
77 | this.application.ninja.elementMediator.setProperties([el], | ||
78 | { "left": [l + "px"], | ||
79 | "top": [t + "px"], | ||
80 | "width": [w + "px"], | ||
81 | "height": [h + "px"] }, | ||
82 | eventType, source ); | ||
66 | } | 83 | } |
67 | this.application.ninja.elementMediator.setProperties([el], | ||
68 | { "left": [l + "px"], | ||
69 | "top": [t + "px"], | ||
70 | "width": [w + "px"], | ||
71 | "height": [h + "px"] }, eventType, source ); | ||
72 | el.elementModel.shapeModel.GLGeomObj.setStrokeWidth(val); | 84 | el.elementModel.shapeModel.GLGeomObj.setStrokeWidth(val); |
73 | el.elementModel.shapeModel.GLGeomObj.buildBuffers(); | 85 | el.elementModel.shapeModel.GLGeomObj.buildBuffers(); |
74 | el.elementModel.shapeModel.GLWorld.render(); | 86 | el.elementModel.shapeModel.GLWorld.render(); |