aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltoolmgr.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lltoolmgr.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/lltoolmgr.cpp')
-rw-r--r--linden/indra/newview/lltoolmgr.cpp563
1 files changed, 563 insertions, 0 deletions
diff --git a/linden/indra/newview/lltoolmgr.cpp b/linden/indra/newview/lltoolmgr.cpp
new file mode 100644
index 0000000..68a3e77
--- /dev/null
+++ b/linden/indra/newview/lltoolmgr.cpp
@@ -0,0 +1,563 @@
1/**
2 * @file lltoolmgr.cpp
3 * @brief LLToolMgr class implementation
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "lltoolmgr.h"
31
32#include "lltool.h"
33// tools and manipulators
34#include "llmanipscale.h"
35#include "lltoolbrush.h"
36#include "lltoolcomp.h"
37#include "lltooldraganddrop.h"
38#include "lltoolface.h"
39#include "lltoolfocus.h"
40#include "lltoolgrab.h"
41#include "lltoolindividual.h"
42#include "lltoolmorph.h"
43#include "lltoolpie.h"
44#include "lltoolplacer.h"
45#include "lltoolselect.h"
46#include "lltoolselectland.h"
47#include "lltoolobjpicker.h"
48#include "lltoolpipette.h"
49
50// Globals (created and destroyed by LLAgent)
51LLToolMgr* gToolMgr = NULL;
52
53// Used when app not active to avoid processing hover.
54LLTool* gToolNull = NULL;
55
56LLToolset* gCurrentToolset = NULL;
57LLToolset* gBasicToolset = NULL;
58LLToolset* gCameraToolset = NULL;
59//LLToolset* gLandToolset = NULL;
60LLToolset* gMouselookToolset = NULL;
61LLToolset* gFaceEditToolset = NULL;
62
63/////////////////////////////////////////////////////
64// LLToolMgr
65
66LLToolMgr::LLToolMgr()
67 :
68 mCurrentTool(NULL),
69 mSavedTool(NULL),
70 mTransientTool( NULL ),
71 mOverrideTool( NULL )
72{
73 gToolNull = new LLTool(NULL); // Does nothing
74 setCurrentTool(gToolNull);
75
76 gBasicToolset = new LLToolset();
77 gCameraToolset = new LLToolset();
78// gLandToolset = new LLToolset();
79 gMouselookToolset = new LLToolset();
80 gFaceEditToolset = new LLToolset();
81
82 gCurrentToolset = gBasicToolset;
83}
84
85void LLToolMgr::initTools()
86{
87 // Initialize all the tools
88 // Variables that are reused for each tool
89 LLTool* tool = NULL;
90
91 //
92 // Pie tool (not visible in UI, implicit)
93 //
94 gToolPie = new LLToolPie();
95
96 gBasicToolset->addTool( gToolPie );
97// gCameraToolset->addTool( gToolPie );
98// gLandToolset->addTool( gToolPie );
99
100 // Camera tool
101 gToolCamera = new LLToolCamera();
102 gBasicToolset ->addTool( gToolCamera );
103 gCameraToolset->addTool( gToolCamera );
104
105 //
106 // Grab tool
107 //
108 gToolGrab = new LLToolGrab();
109 tool = gToolGrab;
110
111 gBasicToolset->addTool( tool );
112
113 //
114 // Translation tool
115 //
116 gToolTranslate = new LLToolCompTranslate();
117 tool = gToolTranslate;
118
119 gBasicToolset->addTool( tool );
120
121 //
122 // Scale ("Stretch") tool
123 //
124 gToolStretch = new LLToolCompScale();
125 tool = gToolStretch;
126
127
128 //
129 // Rotation tool
130 //
131 gToolRotate = new LLToolCompRotate();
132 tool = gToolRotate;
133
134
135 //
136 // Face tool
137 //
138 gToolFace = new LLToolFace();
139 tool = gToolFace;
140
141 //
142 // Pipette tool
143 //
144 gToolPipette = new LLToolPipette();
145
146 //
147 // Individual object selector
148 //
149 gToolIndividual = new LLToolIndividual();
150
151
152 //
153 // Create object tool
154 //
155 gToolCreate = new LLToolCompCreate();
156 tool = gToolCreate;
157
158 gBasicToolset->addTool( tool );
159
160 //
161 // Land brush tool
162 //
163 gToolLand = new LLToolBrushLand();
164 tool = gToolLand;
165
166 gBasicToolset->addTool( tool );
167
168
169 //
170 // Land select tool
171 //
172 gToolParcel = new LLToolSelectLand();
173 tool = gToolParcel;
174
175 //
176 // Gun tool
177 //
178 gToolGun = new LLToolCompGun();
179 gMouselookToolset->addTool( gToolGun );
180
181 //
182 // Inspect tool
183 //
184 gToolInspect = new LLToolCompInspect();
185 gBasicToolset->addTool( gToolInspect );
186
187 //
188 // Face edit tool
189 //
190// gToolMorph = new LLToolMorph();
191// gFaceEditToolset->addTool( gToolMorph );
192 gFaceEditToolset->addTool( gToolCamera );
193
194 // Drag and drop tool
195 gToolDragAndDrop = new LLToolDragAndDrop();
196
197 gToolObjPicker = new LLToolObjPicker();
198
199 // On startup, use "select" tool
200 gBasicToolset->selectTool( gToolPie );
201 useSelectedTool( gBasicToolset );
202}
203
204LLToolMgr::~LLToolMgr()
205{
206 delete gToolPie;
207 gToolPie = NULL;
208
209 delete gToolGun;
210 gToolGun = NULL;
211
212 delete gToolCamera;
213 gToolCamera = NULL;
214
215// delete gToolMorph;
216// gToolMorph = NULL;
217
218 delete gToolDragAndDrop;
219 gToolDragAndDrop = NULL;
220
221 delete gBasicToolset;
222 gBasicToolset = NULL;
223
224 delete gToolGrab;
225 gToolGrab = NULL;
226
227 delete gToolRotate;
228 gToolRotate = NULL;
229
230 delete gToolTranslate;
231 gToolTranslate = NULL;
232
233 delete gToolStretch;
234 gToolStretch = NULL;
235
236 delete gToolIndividual;
237 gToolIndividual = NULL;
238
239 delete gToolPipette;
240 gToolPipette = NULL;
241
242 delete gToolCreate;
243 gToolCreate = NULL;
244
245 delete gToolFace;
246 gToolFace = NULL;
247
248 delete gToolLand;
249 gToolLand = NULL;
250
251 delete gToolParcel;
252 gToolParcel = NULL;
253
254 delete gToolObjPicker;
255 gToolObjPicker = NULL;
256
257 delete gMouselookToolset;
258 gMouselookToolset = NULL;
259
260 delete gFaceEditToolset;
261 gFaceEditToolset = NULL;
262
263 delete gCameraToolset;
264 gCameraToolset = NULL;
265
266 delete gToolNull;
267 gToolNull = NULL;
268}
269
270
271void LLToolMgr::useSelectedTool( LLToolset* vp )
272{
273 setCurrentTool( vp->getSelectedTool() );
274}
275
276BOOL LLToolMgr::usingTransientTool()
277{
278 return mTransientTool ? TRUE : FALSE;
279}
280
281void LLToolMgr::setCurrentTool( LLTool* tool )
282{
283 if (tool == mCurrentTool)
284 {
285 // didn't change tool, so don't mess with
286 // handleSelect or handleDeselect
287 return;
288 }
289
290 if (mTransientTool)
291 {
292 mTransientTool->handleDeselect();
293 mTransientTool = NULL;
294 }
295 else if( mCurrentTool )
296 {
297 mCurrentTool->handleDeselect();
298 }
299
300 mCurrentTool = tool;
301 if (mCurrentTool)
302 {
303 mCurrentTool->handleSelect();
304 }
305}
306
307LLTool* LLToolMgr::getCurrentTool(MASK override_mask)
308{
309 // In mid-drag, always keep the current tool
310 if (gToolTranslate->hasMouseCapture()
311 || gToolRotate->hasMouseCapture()
312 || gToolStretch->hasMouseCapture())
313 {
314 // might have gotten here by overriding another tool
315 if (mOverrideTool)
316 {
317 return mOverrideTool;
318 }
319 else
320 {
321 return mCurrentTool;
322 }
323 }
324
325 if (mTransientTool)
326 {
327 mOverrideTool = NULL;
328 return mTransientTool;
329 }
330
331 if (mCurrentTool == gToolGun)
332 {
333 mOverrideTool = NULL;
334 return mCurrentTool;
335 }
336
337 // ALT always gets you the camera tool
338 if (override_mask & MASK_ALT)
339 {
340 mOverrideTool = gToolCamera;
341 return mOverrideTool;
342 }
343
344 if (mCurrentTool == gToolCamera)
345 {
346 // ...can't switch out of camera
347 mOverrideTool = NULL;
348 return mCurrentTool;
349 }
350 else if (mCurrentTool == gToolGrab)
351 {
352 // ...can't switch out of grab
353 mOverrideTool = NULL;
354 return mCurrentTool;
355 }
356 else if (mCurrentTool == gToolInspect)
357 {
358 // ...can't switch out of grab
359 mOverrideTool = NULL;
360 return mCurrentTool;
361 }
362 else
363 {
364 // ...can switch between editing tools
365 if (override_mask == MASK_CONTROL)
366 {
367 // Control lifts when in the pie tool, otherwise switches to rotate
368 if (mCurrentTool == gToolPie)
369 {
370 mOverrideTool = gToolGrab;
371 }
372 else
373 {
374 mOverrideTool = gToolRotate;
375 }
376 return mOverrideTool;
377 }
378 else if (override_mask == (MASK_CONTROL | MASK_SHIFT))
379 {
380 // Shift-Control spins when in the pie tool, otherwise switches to scale
381 if (mCurrentTool == gToolPie)
382 {
383 mOverrideTool = gToolGrab;
384 }
385 else
386 {
387 mOverrideTool = gToolStretch;
388 }
389 return mOverrideTool;
390 }
391 else
392 {
393 mOverrideTool = NULL;
394 return mCurrentTool;
395 }
396 }
397}
398
399BOOL LLToolMgr::inEdit()
400{
401 return mCurrentTool != gToolPie && mCurrentTool != gToolNull;
402}
403
404void LLToolMgr::setTransientTool(LLTool* tool)
405{
406 if (!tool)
407 {
408 clearTransientTool();
409 }
410 else
411 {
412 if (mTransientTool)
413 {
414 mTransientTool->handleDeselect();
415 mTransientTool = NULL;
416 }
417 else if (mCurrentTool)
418 {
419 mCurrentTool->handleDeselect();
420 }
421
422 mTransientTool = tool;
423 mTransientTool->handleSelect();
424 }
425}
426
427void LLToolMgr::clearTransientTool()
428{
429 if (mTransientTool)
430 {
431 mTransientTool->handleDeselect();
432 mTransientTool = NULL;
433 if (mCurrentTool)
434 {
435 mCurrentTool->handleSelect();
436 }
437 else
438 {
439 llwarns << "mCurrentTool is NULL" << llendl;
440 }
441 }
442}
443
444
445// The "gun tool", used for handling mouselook, captures the mouse and
446// locks it within the window. When the app loses focus we need to
447// release this locking.
448void LLToolMgr::onAppFocusLost()
449{
450 if (mCurrentTool
451 && mCurrentTool == gToolGun)
452 {
453 mCurrentTool->handleDeselect();
454 }
455 mSavedTool = mCurrentTool;
456 mCurrentTool = gToolNull;
457}
458
459void LLToolMgr::onAppFocusGained()
460{
461 if (mSavedTool)
462 {
463 if (mSavedTool == gToolGun)
464 {
465 mCurrentTool->handleSelect();
466 }
467 mCurrentTool = mSavedTool;
468 mSavedTool = NULL;
469 }
470}
471
472/////////////////////////////////////////////////////
473// LLToolset
474
475void LLToolset::addTool(LLTool* tool)
476{
477 llassert( !mToolList.checkData( tool ) ); // check for duplicates
478
479 mToolList.addDataAtEnd( tool );
480 if( !mSelectedTool )
481 {
482 mSelectedTool = tool;
483 }
484}
485
486
487void LLToolset::selectTool(LLTool* tool)
488{
489 mSelectedTool = tool;
490 gToolMgr->setCurrentTool( mSelectedTool );
491}
492
493
494void LLToolset::selectToolByIndex( S32 index )
495{
496 LLTool *tool = mToolList.getNthData( index );
497 if (tool)
498 {
499 mSelectedTool = tool;
500 gToolMgr->setCurrentTool( tool );
501 }
502}
503
504BOOL LLToolset::isToolSelected( S32 index )
505{
506 return (mToolList.getNthData( index ) == mSelectedTool);
507}
508
509
510void LLToolset::selectFirstTool()
511{
512 mSelectedTool = mToolList.getFirstData();
513 gToolMgr->setCurrentTool( mSelectedTool );
514}
515
516
517void LLToolset::selectNextTool()
518{
519 LLTool* next = NULL;
520 for( LLTool* cur = mToolList.getFirstData(); cur; cur = mToolList.getNextData() )
521 {
522 if( cur == mSelectedTool )
523 {
524 next = mToolList.getNextData();
525 break;
526 }
527 }
528
529 if( !next )
530 {
531 next = mToolList.getFirstData();
532 }
533
534 mSelectedTool = next;
535 gToolMgr->setCurrentTool( mSelectedTool );
536}
537
538void LLToolset::selectPrevTool()
539{
540 LLTool* prev = NULL;
541 for( LLTool* cur = mToolList.getLastData(); cur; cur = mToolList.getPreviousData() )
542 {
543 if( cur == mSelectedTool )
544 {
545 prev = mToolList.getPreviousData();
546 break;
547 }
548 }
549
550 if( !prev )
551 {
552 prev = mToolList.getLastData();
553 }
554
555 mSelectedTool = prev;
556 gToolMgr->setCurrentTool( mSelectedTool );
557}
558
559void select_tool( void *tool_pointer )
560{
561 LLTool *tool = (LLTool *)tool_pointer;
562 gCurrentToolset->selectTool( tool );
563}