aboutsummaryrefslogtreecommitdiff
path: root/js/tools/OvalTool.js
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/tools/OvalTool.js
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/tools/OvalTool.js')
-rw-r--r--js/tools/OvalTool.js103
1 files changed, 103 insertions, 0 deletions
diff --git a/js/tools/OvalTool.js b/js/tools/OvalTool.js
new file mode 100644
index 00000000..e0f1f03f
--- /dev/null
+++ b/js/tools/OvalTool.js
@@ -0,0 +1,103 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var Montage = require("montage/core/core").Montage,
8 ShapeTool = require("js/tools/ShapeTool").ShapeTool,
9 ShapesController = require("js/controllers/elements/shapes-controller").ShapesController;
10
11exports.OvalTool = Montage.create(ShapeTool, {
12
13 _toolID: { value: "ovalTool" },
14 _imageID: { value: "ovalToolImg" },
15 _toolImageClass: { value: "ovalToolUp" },
16 _selectedToolImageClass: { value: "ovalToolDown" },
17 _toolTipText: { value: "Oval Tool (O)" },
18 _selectedToolClass:{value:"ovalToolSpecificProperties"},
19 _ovalView : { value: null, writable: true},
20
21 RenderShape: {
22 value: function (w, h, planeMat, midPt, canvas)
23 {
24 if( (Math.floor(w) === 0) || (Math.floor(h) === 0) )
25 {
26 return;
27 }
28
29 var left = Math.round(midPt[0] - 0.5*w);
30 var top = Math.round(midPt[1] - 0.5*h);
31
32 var strokeStyleIndex = this.options.strokeStyleIndex;
33 var strokeStyle = this.options.strokeStyle;
34
35 var strokeSize = ShapesController.GetValueInPixels(this.options.strokeSize.value, this.options.strokeSize.units, h);
36
37 var innerRadius = this.options.innerRadius.value / 100;
38
39 var strokeColor = this.application.ninja.colorController.colorToolbar.stroke.webGlColor;
40 var fillColor = this.application.ninja.colorController.colorToolbar.fill.webGlColor;
41
42 // for default stroke and fill/no materials
43 var strokeMaterial = null;
44 var fillMaterial = null;
45
46 var strokeIndex = parseInt(this.options.strokeMaterial);
47 if(strokeIndex > 0)
48 {
49 strokeMaterial = Object.create(MaterialsLibrary.getMaterialAt(strokeIndex-1));
50 }
51
52 var fillIndex = parseInt(this.options.fillMaterial);
53 if(fillIndex > 0)
54 {
55 fillMaterial = Object.create(MaterialsLibrary.getMaterialAt(fillIndex-1));
56 }
57
58
59 var world = this.getGLWorld(canvas, this.options.use3D);
60
61 var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2);
62 var yOffset = (canvas.height/2 - (top - canvas.offsetTop + h/2));
63
64 var oval = new GLCircle();
65 oval.init(world, xOffset, yOffset, w, h, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle);
66
67 world.addObject(oval);
68 world.render();
69
70 canvas.elementModel.shapeModel.shapeCount++;
71 if(canvas.elementModel.shapeModel.shapeCount === 1)
72 {
73 canvas.elementModel.selection = "Oval";
74 canvas.elementModel.pi = "OvalPi";
75 canvas.elementModel.shapeModel.strokeSize = this.options.strokeSize.value + " " + this.options.strokeSize.units;
76 canvas.elementModel.shapeModel.stroke = strokeColor;
77 canvas.elementModel.shapeModel.fill = fillColor;
78
79 canvas.elementModel.shapeModel.innerRadius = this.options.innerRadius.value + " " + this.options.innerRadius.units;
80
81 canvas.elementModel.shapeModel.strokeMaterial = strokeMaterial;
82 canvas.elementModel.shapeModel.fillMaterial = fillMaterial;
83 canvas.elementModel.shapeModel.strokeMaterialIndex = strokeIndex;
84 canvas.elementModel.shapeModel.fillMaterialIndex = fillIndex;
85
86 canvas.elementModel.shapeModel.strokeStyleIndex = strokeStyleIndex;
87 canvas.elementModel.shapeModel.strokeStyle = strokeStyle;
88
89 canvas.elementModel.shapeModel.GLGeomObj = oval;
90 }
91 else
92 {
93 // TODO - update the shape's info only. shapeModel will likely need an array of shapes.
94 }
95
96 if(canvas.elementModel.isShape)
97 {
98 this.application.ninja.selectionController.selectElement(canvas);
99 }
100
101 }
102 }
103}); \ No newline at end of file