diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/tools/RectTool.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/tools/RectTool.js')
-rw-r--r-- | js/tools/RectTool.js | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/js/tools/RectTool.js b/js/tools/RectTool.js new file mode 100644 index 00000000..fbf1693e --- /dev/null +++ b/js/tools/RectTool.js | |||
@@ -0,0 +1,126 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | ShapeTool = require("js/tools/ShapeTool").ShapeTool, | ||
9 | ShapesController = require("js/controllers/elements/shapes-controller").ShapesController; | ||
10 | |||
11 | exports.RectTool = Montage.create(ShapeTool, { | ||
12 | |||
13 | _toolID: { value: "rectTool" }, | ||
14 | _imageID: { value: "rectToolImg" }, | ||
15 | _toolImageClass: { value: "rectToolUp" }, | ||
16 | _selectedToolImageClass: { value: "rectToolDown" }, | ||
17 | _toolTipText : { value : "Rectangle Tool (R)" }, | ||
18 | _selectedSubTool :{value :"rect"}, | ||
19 | _ovalTool:{value:null,writable:true}, | ||
20 | _rectTool:{value:null,writable:true}, | ||
21 | _rectView:{value:null,writable:true}, | ||
22 | _ovalView:{value:null,writable:true}, | ||
23 | |||
24 | _selectedToolClass:{value:"rectToolSpecificProperties"}, | ||
25 | _rectToolProperties:{enumerable:false , value:null,writable:true}, | ||
26 | _parentNode:{enumerable:false , value:null,writable:true}, | ||
27 | _toolsPropertiesContainer:{enumerable:false , value:null,writable:true}, | ||
28 | |||
29 | _lockRadiusButton : { value: null, writable: true, enumerable: true, configurable: true }, | ||
30 | _tlRadiusHotText : { value: null, writable: true, enumerable: true, configurable: true }, | ||
31 | _trRadiusHotText : { value: null, writable: true, enumerable: true, configurable: true }, | ||
32 | _blRadiusHotText : { value: null, writable: true, enumerable: true, configurable: true }, | ||
33 | _brRadiusHotText : { value: null, writable: true, enumerable: true, configurable: true }, | ||
34 | |||
35 | _lockRadius : { value: false, writable: true, enumerable: true, configurable: true }, | ||
36 | _buttons: {enumerable: false,value: { hexinput: [] , lockbutton: []}}, | ||
37 | |||
38 | RenderShape: { | ||
39 | value: function (w, h, planeMat, midPt, canvas) | ||
40 | { | ||
41 | if( (Math.floor(w) === 0) || (Math.floor(h) === 0) ) | ||
42 | { | ||
43 | return; | ||
44 | } | ||
45 | |||
46 | var left = Math.round(midPt[0] - 0.5*w); | ||
47 | var top = Math.round(midPt[1] - 0.5*h); | ||
48 | |||
49 | var strokeStyleIndex = this.options.strokeStyleIndex; | ||
50 | var strokeStyle = this.options.strokeStyle; | ||
51 | |||
52 | var strokeSize = ShapesController.GetValueInPixels(this.options.strokeSize.value, this.options.strokeSize.units, h); | ||
53 | |||
54 | var tlRadius = ShapesController.GetValueInPixels(this.options.TLRadiusControl.value, this.options.TLRadiusControl.units, h); | ||
55 | var trRadius = ShapesController.GetValueInPixels(this.options.TRRadiusControl.value, this.options.TRRadiusControl.units, h); | ||
56 | var blRadius = ShapesController.GetValueInPixels(this.options.BLRadiusControl.value, this.options.BLRadiusControl.units, h); | ||
57 | var brRadius = ShapesController.GetValueInPixels(this.options.BRRadiusControl.value, this.options.BRRadiusControl.units, h); | ||
58 | |||
59 | var strokeColor = this.application.ninja.colorController.colorToolbar.stroke.webGlColor; | ||
60 | var fillColor = this.application.ninja.colorController.colorToolbar.fill.webGlColor; | ||
61 | // for default stroke and fill/no materials | ||
62 | var strokeMaterial = null; | ||
63 | var fillMaterial = null; | ||
64 | |||
65 | var strokeIndex = parseInt(this.options.strokeMaterial); | ||
66 | if(strokeIndex > 0) | ||
67 | { | ||
68 | strokeMaterial = Object.create(MaterialsLibrary.getMaterialAt(strokeIndex-1)); | ||
69 | } | ||
70 | |||
71 | var fillIndex = parseInt(this.options.fillMaterial); | ||
72 | if(fillIndex > 0) | ||
73 | { | ||
74 | fillMaterial = Object.create(MaterialsLibrary.getMaterialAt(fillIndex-1)); | ||
75 | } | ||
76 | |||
77 | var world = this.getGLWorld(canvas, this.options.use3D); | ||
78 | |||
79 | var xOffset = ((left - canvas.offsetLeft + w/2) - canvas.width/2); | ||
80 | var yOffset = (canvas.height/2 - (top - canvas.offsetTop + h/2)); | ||
81 | |||
82 | var rect = new GLRectangle(); | ||
83 | rect.init(world, xOffset, yOffset, w, h, strokeSize, strokeColor, fillColor, | ||
84 | tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle); | ||
85 | |||
86 | world.addObject(rect); | ||
87 | world.render(); | ||
88 | |||
89 | canvas.elementModel.shapeModel.shapeCount++; | ||
90 | if(canvas.elementModel.shapeModel.shapeCount === 1) | ||
91 | { | ||
92 | canvas.elementModel.selection = "Rectangle"; | ||
93 | canvas.elementModel.pi = "RectanglePi"; | ||
94 | canvas.elementModel.shapeModel.strokeSize = this.options.strokeSize.value + " " + this.options.strokeSize.units; | ||
95 | canvas.elementModel.shapeModel.stroke = strokeColor; | ||
96 | canvas.elementModel.shapeModel.fill = fillColor; | ||
97 | |||
98 | canvas.elementModel.shapeModel.tlRadius = this.options.TLRadiusControl.value + " " + this.options.TLRadiusControl.units; | ||
99 | canvas.elementModel.shapeModel.trRadius = this.options.TRRadiusControl.value + " " + this.options.TRRadiusControl.units; | ||
100 | canvas.elementModel.shapeModel.blRadius = this.options.BLRadiusControl.value + " " + this.options.BLRadiusControl.units; | ||
101 | canvas.elementModel.shapeModel.brRadius = this.options.BRRadiusControl.value + " " + this.options.BRRadiusControl.units; | ||
102 | |||
103 | canvas.elementModel.shapeModel.strokeMaterial = strokeMaterial; | ||
104 | canvas.elementModel.shapeModel.fillMaterial = fillMaterial; | ||
105 | canvas.elementModel.shapeModel.strokeMaterialIndex = strokeIndex; | ||
106 | canvas.elementModel.shapeModel.fillMaterialIndex = fillIndex; | ||
107 | |||
108 | canvas.elementModel.shapeModel.strokeStyleIndex = strokeStyleIndex; | ||
109 | canvas.elementModel.shapeModel.strokeStyle = strokeStyle; | ||
110 | |||
111 | canvas.elementModel.shapeModel.GLGeomObj = rect; | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | // TODO - update the shape's info only. shapeModel will likely need an array of shapes. | ||
116 | } | ||
117 | |||
118 | if(canvas.elementModel.isShape) | ||
119 | { | ||
120 | this.application.ninja.selectionController.selectElement(canvas); | ||
121 | } | ||
122 | |||
123 | |||
124 | } | ||
125 | } | ||
126 | }); \ No newline at end of file | ||