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/TranslateObject3DTool.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/TranslateObject3DTool.js')
-rw-r--r-- | js/tools/TranslateObject3DTool.js | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/js/tools/TranslateObject3DTool.js b/js/tools/TranslateObject3DTool.js new file mode 100644 index 00000000..bbbbc871 --- /dev/null +++ b/js/tools/TranslateObject3DTool.js | |||
@@ -0,0 +1,132 @@ | |||
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 Translate3DToolBase = require("js/tools/Translate3DToolBase").Translate3DToolBase, | ||
8 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | ||
9 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | ||
10 | snapManager = require("js/helper-classes/3D/snap-manager").SnapManager; | ||
11 | |||
12 | exports.TranslateObject3DTool = Object.create(Translate3DToolBase, { | ||
13 | _toolID: { value: "translateObject3DTool" }, | ||
14 | _canOperateOnStage: { value: true }, | ||
15 | |||
16 | initializeSnapping : { | ||
17 | value : function(event) | ||
18 | { | ||
19 | this._mouseDownHitRec = null; | ||
20 | this._mouseUpHitRec = null; | ||
21 | |||
22 | snapManager.clearAvoidList(); | ||
23 | snapManager.clearDragPlane(); | ||
24 | |||
25 | // the translate tool does snap align to the bounds of the object only. | ||
26 | // turn off snap align to the cursor. This needs to be re-enabled in the mouse up method | ||
27 | snapManager.enableSnapAlign( false ); | ||
28 | |||
29 | // snap to element and snap to grid are conditionally enabled based | ||
30 | // on the snap results of the mouse down. enable everything for the first snap | ||
31 | this._snapToElements = snapManager.elementSnapEnabledAppLevel(); | ||
32 | this._snapToGrid = snapManager.gridSnapEnabledAppLevel(); | ||
33 | |||
34 | this._dragPlane = null; | ||
35 | var do3DSnap = true; | ||
36 | |||
37 | if(this._handleMode === null) | ||
38 | { | ||
39 | // this.doSelection(event); | ||
40 | |||
41 | snapManager.enableElementSnap ( true ); | ||
42 | snapManager.enableGridSnap ( true ); | ||
43 | } | ||
44 | else | ||
45 | { | ||
46 | this._delta = 0; | ||
47 | // special case for z-translation | ||
48 | if( this._handleMode && (this._handleMode === 2) ) | ||
49 | { | ||
50 | this._dragPlane = viewUtils.getNormalToUnprojectedElementPlane(this._target); | ||
51 | snapManager.setupDragPlaneFromPlane(this._dragPlane); | ||
52 | do3DSnap = false; | ||
53 | |||
54 | snapManager.enableElementSnap ( false ); | ||
55 | snapManager.enableGridSnap ( false ); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | if(this._targets) | ||
60 | { | ||
61 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, | ||
62 | new WebKitPoint(event.pageX, event.pageY)); | ||
63 | |||
64 | // do the snap before setting up the avoid list to allow | ||
65 | // a snap on the mouse down | ||
66 | var hitRec = snapManager.snap(point.x, point.y, do3DSnap); | ||
67 | |||
68 | // we don't want to snap to selected objects during the drag | ||
69 | var len = this._targets.length; | ||
70 | for(var i=0; i<len; i++) | ||
71 | { | ||
72 | snapManager.addToAvoidList( this._targets[i].elt ); | ||
73 | } | ||
74 | if (hitRec) | ||
75 | { | ||
76 | // disable snap attributes | ||
77 | if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT) | ||
78 | { | ||
79 | this._snapToElements = false; | ||
80 | this._snapToGrid = false; | ||
81 | } | ||
82 | else if (hitRec.getType() == hitRec.SNAP_TYPE_ELEMENT_CENTER) | ||
83 | { | ||
84 | snapManager.enableSnapAlign( snapManager.snapAlignEnabledAppLevel() ); | ||
85 | } | ||
86 | |||
87 | // parameterize the snap point on the target | ||
88 | this._snapParam = this.parameterizeSnap( hitRec ); | ||
89 | |||
90 | if(!this._dragPlane) | ||
91 | { | ||
92 | if( this._inLocalMode && (this._targets.length === 1) ) | ||
93 | { | ||
94 | this._dragPlane = viewUtils.getUnprojectedElementPlane(this._clickedObject); | ||
95 | snapManager.setupDragPlaneFromPlane(this._dragPlane); | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | this._dragPlane = snapManager.setupDragPlanes( hitRec ); | ||
100 | } | ||
101 | |||
102 | } | ||
103 | |||
104 | var wpHitRec = hitRec.convertToWorkingPlane( this._dragPlane ); | ||
105 | this._mouseDownHitRec = wpHitRec; | ||
106 | this._mouseUpHitRec = null; | ||
107 | |||
108 | var pt = hitRec.getScreenPoint(); | ||
109 | this.downPoint.x = pt[0]; | ||
110 | this.downPoint.y = pt[1]; | ||
111 | |||
112 | // TODO - need to figure out snapManager dependency by drawUtils. | ||
113 | // For now, bypassing by calling snapManager.drawLastHit(); | ||
114 | // drawUtils.refreshDisplay(); | ||
115 | snapManager.drawLastHit(); | ||
116 | } | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | this.target = null; | ||
121 | } | ||
122 | } | ||
123 | }, | ||
124 | |||
125 | _handleToolOptionsChange: { | ||
126 | value: function(event) { | ||
127 | this._inLocalMode = event.detail.mode; | ||
128 | this.DrawHandles(); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | }); \ No newline at end of file | ||