aboutsummaryrefslogtreecommitdiff
path: root/js/tools/ToolBase.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/ToolBase.js')
-rw-r--r--js/tools/ToolBase.js192
1 files changed, 192 insertions, 0 deletions
diff --git a/js/tools/ToolBase.js b/js/tools/ToolBase.js
new file mode 100644
index 00000000..678d03ac
--- /dev/null
+++ b/js/tools/ToolBase.js
@@ -0,0 +1,192 @@
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;
8var Component = require("montage/ui/component").Component;
9
10//var snapManager = ("js/helper-classes/3D/snap-manager").SnapManager;
11
12exports.toolBase = Montage.create(Component, {
13 options: { value: null },
14
15 /**
16 * This property will make the stageManager return null when false
17 * or the Stage / PasteBoard when true
18 */
19 _canOperateOnStage: { value: false },
20
21 _downPoint: { value: { "x": null, "y": null } },
22 _upPoint: { value: { "x": null, "y": null } },
23
24 downPoint: {
25 get: function() { return this._downPoint; },
26 set: function(value) { this._downPoint = value; }
27 },
28
29 upPoint: {
30 get: function() { return this._upPoint; },
31 set: function(value) { this._upPoint = value; }
32 },
33
34 // Need to keep track of current mouse position for KEY modifiers event which do not have mouse coordinates.
35 _currentX: {value: 0, writable: true},
36 _currentY: {value: 0, writable: true},
37
38 /**
39 * This function is for specifying custom feedback routine
40 * upon mouse over.
41 * For example, the drawing tools will add a glow when mousing
42 * over existing canvas elements to signal to the user that
43 * the drawing operation will act on the targeted canvas.
44 */
45 _showFeedbackOnMouseMove : { value: null },
46
47 _canDraw: { value: true },
48 _isDrawing: { value: false },
49 _hasDraw: { value: false },
50 _isSpace: { value: false },
51 _escape: { value: false },
52
53
54 HandleLeftButtonUp: { value : function () {} },
55 HandleRightButtonDown: { value : function () {} },
56 HandleRightButtonUp: { value : function () {} },
57 HandleMouseMove: { value : function () {} },
58
59 HandleKeyPress: { value : function () {} },
60 HandleKeyUp: { value : function () {} },
61 HandleDoubleClick: { value : function () {} },
62 HandleShiftKeyDown: { value : function () {} },
63 HandleShiftKeyUp: { value : function () {} },
64 HandleAltKeyDown: { value : function () {} },
65 HandleAltKeyUp: { value : function () {} },
66
67 HandleSpaceDown: { value: function() { this._isSpace = true; } },
68 HandleSpaceUp: { value: function() { this._isSpace = false; } },
69
70 HandleEscape: { value: function(event) {} },
71
72 /**
73 * If wasSelected, configure the tool by:
74 * 2) adding custom feedback
75 * 3) drawing handles
76 * If wasSelected is false, clean up after the tool by:
77 * 1) removing custom feedback
78 */
79 _configure: {
80 value: function(selected) {
81 this.Configure(selected);
82 }
83 },
84
85 Configure: { value: function (wasSelected) {} },
86
87 doSelection: {
88 value: function(event) {
89
90 if(this._canOperateOnStage) {
91 if(event.shiftKey) {
92 this.application.ninja.selectionController.shiftSelectElement(this.application.ninja.stage.GetElement(event));
93 } else {
94 this.application.ninja.selectionController.selectElement(this.application.ninja.stage.GetElement(event));
95 }
96 }
97
98 // TODO - Code used to know if this is a GL Canvas container --> Move this to the selectionManager?
99 /*
100 if(selectedObject.Ninja && selectedObject.Ninja.GLWorld) {
101 selectedObject.Ninja.GLWorld.getShapeFromPoint(event.layerX - selectedObject.left, event.layerY - selectedObject.top);
102 }
103 */
104
105 }
106 },
107
108 zoomIn:{
109 value:function(event){
110 var upperBoundary ,previousZoomValue;
111
112 previousZoomValue = this.application.Ninja._documentBarRef.zoomFactor ;
113 upperBoundary = previousZoomValue *1.2 ;
114
115 if(upperBoundary > 2000)
116 this.application.Ninja._documentBarRef.zoomFactor = 2000;
117 else
118 this.application.Ninja._documentBarRef.zoomFactor*= 1.2;
119
120 }
121 },
122
123 zoomOut:{
124 value:function(){
125 var lowerBoundary ,previousZoomValue;
126
127 previousZoomValue = this.application.Ninja._documentBarRef.zoomFactor ;
128 lowerBoundary = previousZoomValue/1.2 ;
129
130 if(lowerBoundary < 25)
131 this.application.Ninja._documentBarRef.zoomFactor = 25;
132 else
133 this.application.Ninja._documentBarRef.zoomFactor/= 1.2;
134 }
135 },
136
137 UpdateSelection: {
138 value : function (shouldDispatchEvent) {
139 if(shouldDispatchEvent) {
140// documentControllerModule.DocumentController.DispatchElementChangedEvent(selectionManagerModule.selectionManager.selectedItems, []);
141 } else {
142// if(!selectionManagerModule.selectionManager.isDocument) {
143// stageManagerModule.stageManager.drawSelectionRec(true);
144// drawLayoutModule.drawLayout.redrawDocument();
145// }
146// else
147// {
148// stageManagerModule.stageManager.drawSelectionRec(true);
149// drawLayoutModule.drawLayout.redrawDocument();
150// }
151 }
152
153// if (drawUtils.isDrawingGrid())
154// {
155// snapManager.updateWorkingPlaneFromView();
156// }
157 }
158 },
159
160 // Should be an array of handles for each tool.
161 // The array should contain ToolHandle objects that define
162 // dimensions, cursor, functionality
163 // For example, the Selection Tool holds the 8 resize handles in this order because this
164 // is the order we retrieve a rectangle's points using viewUtils:
165 // 0 7 6
166 // 1 5
167 // 2 3 4
168 _handles: {
169 value:null,
170 writable: true
171 },
172
173// InitHandles: {
174// value: function () {
175// this.DrawHandles();
176// }
177// },
178
179 // Used for figuring what the tool should do.
180 // For example, if the handle mode is 5, the tool should resize the element to the right
181 _handleMode: {
182 value:null,
183 writable: true
184 },
185
186 DrawHandles: {
187 value: function () {
188 // Tool should override this method if it implements handles
189 }
190 }
191
192});