Annotation of /trunk/indra/newview/lltoolmgr.cpp
Parent Directory
|
Revision Log
Revision 137 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file lltoolmgr.cpp | ||
| 3 : | * @brief LLToolMgr class implementation | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2001&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | mjm | 137 | * Copyright (c) 2001-2010, Linden Research, Inc. |
| 8 : | mjm | 135 | * |
| 9 : | * Second Life Viewer Source Code | ||
| 10 : | * The source code in this file ("Source Code") is provided by Linden Lab | ||
| 11 : | * to you under the terms of the GNU General Public License, version 2.0 | ||
| 12 : | * ("GPL"), unless you have obtained a separate licensing agreement | ||
| 13 : | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
| 14 : | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
| 15 : | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
| 16 : | * | ||
| 17 : | * There are special exceptions to the terms and conditions of the GPL as | ||
| 18 : | * it is applied to this Source Code. View the full text of the exception | ||
| 19 : | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
| 20 : | * online at | ||
| 21 : | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 22 : | * | ||
| 23 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 24 : | * that you have read and understood your obligations described above, | ||
| 25 : | * and agree to abide by those obligations. | ||
| 26 : | * | ||
| 27 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 28 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 29 : | * COMPLETENESS OR PERFORMANCE. | ||
| 30 : | * $/LicenseInfo$ | ||
| 31 : | */ | ||
| 32 : | |||
| 33 : | #include "llviewerprecompiledheaders.h" | ||
| 34 : | |||
| 35 : | #include "lltoolmgr.h" | ||
| 36 : | |||
| 37 : | #include "lltool.h" | ||
| 38 : | // tools and manipulators | ||
| 39 : | #include "llmanipscale.h" | ||
| 40 : | #include "llselectmgr.h" | ||
| 41 : | #include "lltoolbrush.h" | ||
| 42 : | #include "lltoolcomp.h" | ||
| 43 : | #include "lltooldraganddrop.h" | ||
| 44 : | #include "lltoolface.h" | ||
| 45 : | #include "lltoolfocus.h" | ||
| 46 : | #include "lltoolgrab.h" | ||
| 47 : | #include "lltoolindividual.h" | ||
| 48 : | #include "lltoolmorph.h" | ||
| 49 : | #include "lltoolpie.h" | ||
| 50 : | #include "lltoolplacer.h" | ||
| 51 : | #include "lltoolselectland.h" | ||
| 52 : | #include "lltoolobjpicker.h" | ||
| 53 : | #include "lltoolpipette.h" | ||
| 54 : | #include "llagent.h" | ||
| 55 : | #include "llviewercontrol.h" | ||
| 56 : | |||
| 57 : | |||
| 58 : | // Used when app not active to avoid processing hover. | ||
| 59 : | LLTool* gToolNull = NULL; | ||
| 60 : | |||
| 61 : | LLToolset* gBasicToolset = NULL; | ||
| 62 : | LLToolset* gCameraToolset = NULL; | ||
| 63 : | //LLToolset* gLandToolset = NULL; | ||
| 64 : | LLToolset* gMouselookToolset = NULL; | ||
| 65 : | LLToolset* gFaceEditToolset = NULL; | ||
| 66 : | |||
| 67 : | ///////////////////////////////////////////////////// | ||
| 68 : | // LLToolMgr | ||
| 69 : | |||
| 70 : | LLToolMgr::LLToolMgr() | ||
| 71 : | : | ||
| 72 : | mBaseTool(NULL), | ||
| 73 : | mSavedTool(NULL), | ||
| 74 : | mTransientTool( NULL ), | ||
| 75 : | mOverrideTool( NULL ), | ||
| 76 : | mSelectedTool( NULL ), | ||
| 77 : | mCurrentToolset( NULL ) | ||
| 78 : | { | ||
| 79 : | gToolNull = new LLTool(LLStringUtil::null); // Does nothing | ||
| 80 : | setCurrentTool(gToolNull); | ||
| 81 : | |||
| 82 : | gBasicToolset = new LLToolset(); | ||
| 83 : | gCameraToolset = new LLToolset(); | ||
| 84 : | // gLandToolset = new LLToolset(); | ||
| 85 : | gMouselookToolset = new LLToolset(); | ||
| 86 : | gFaceEditToolset = new LLToolset(); | ||
| 87 : | } | ||
| 88 : | |||
| 89 : | void LLToolMgr::initTools() | ||
| 90 : | { | ||
| 91 : | static BOOL initialized = FALSE; | ||
| 92 : | if(initialized) | ||
| 93 : | { | ||
| 94 : | return; | ||
| 95 : | } | ||
| 96 : | initialized = TRUE; | ||
| 97 : | gBasicToolset->addTool( LLToolPie::getInstance() ); | ||
| 98 : | gBasicToolset->addTool( LLToolCamera::getInstance() ); | ||
| 99 : | gCameraToolset->addTool( LLToolCamera::getInstance() ); | ||
| 100 : | gBasicToolset->addTool( LLToolGrab::getInstance() ); | ||
| 101 : | gBasicToolset->addTool( LLToolCompTranslate::getInstance() ); | ||
| 102 : | gBasicToolset->addTool( LLToolCompCreate::getInstance() ); | ||
| 103 : | gBasicToolset->addTool( LLToolBrushLand::getInstance() ); | ||
| 104 : | gMouselookToolset->addTool( LLToolCompGun::getInstance() ); | ||
| 105 : | gBasicToolset->addTool( LLToolCompInspect::getInstance() ); | ||
| 106 : | gFaceEditToolset->addTool( LLToolCamera::getInstance() ); | ||
| 107 : | |||
| 108 : | // On startup, use "select" tool | ||
| 109 : | setCurrentToolset(gBasicToolset); | ||
| 110 : | |||
| 111 : | gBasicToolset->selectTool( LLToolPie::getInstance() ); | ||
| 112 : | } | ||
| 113 : | |||
| 114 : | LLToolMgr::~LLToolMgr() | ||
| 115 : | { | ||
| 116 : | delete gBasicToolset; | ||
| 117 : | gBasicToolset = NULL; | ||
| 118 : | |||
| 119 : | delete gMouselookToolset; | ||
| 120 : | gMouselookToolset = NULL; | ||
| 121 : | |||
| 122 : | delete gFaceEditToolset; | ||
| 123 : | gFaceEditToolset = NULL; | ||
| 124 : | |||
| 125 : | delete gCameraToolset; | ||
| 126 : | gCameraToolset = NULL; | ||
| 127 : | |||
| 128 : | delete gToolNull; | ||
| 129 : | gToolNull = NULL; | ||
| 130 : | } | ||
| 131 : | |||
| 132 : | BOOL LLToolMgr::usingTransientTool() | ||
| 133 : | { | ||
| 134 : | return mTransientTool ? TRUE : FALSE; | ||
| 135 : | } | ||
| 136 : | |||
| 137 : | void LLToolMgr::setCurrentToolset(LLToolset* current) | ||
| 138 : | { | ||
| 139 : | if (!current) return; | ||
| 140 : | |||
| 141 : | // switching toolsets? | ||
| 142 : | if (current != mCurrentToolset) | ||
| 143 : | { | ||
| 144 : | // deselect current tool | ||
| 145 : | if (mSelectedTool) | ||
| 146 : | { | ||
| 147 : | mSelectedTool->handleDeselect(); | ||
| 148 : | } | ||
| 149 : | mCurrentToolset = current; | ||
| 150 : | // select first tool of new toolset only if toolset changed | ||
| 151 : | mCurrentToolset->selectFirstTool(); | ||
| 152 : | } | ||
| 153 : | // update current tool based on new toolset | ||
| 154 : | setCurrentTool( mCurrentToolset->getSelectedTool() ); | ||
| 155 : | } | ||
| 156 : | |||
| 157 : | LLToolset* LLToolMgr::getCurrentToolset() | ||
| 158 : | { | ||
| 159 : | return mCurrentToolset; | ||
| 160 : | } | ||
| 161 : | |||
| 162 : | void LLToolMgr::setCurrentTool( LLTool* tool ) | ||
| 163 : | { | ||
| 164 : | if (mTransientTool) | ||
| 165 : | { | ||
| 166 : | mTransientTool = NULL; | ||
| 167 : | } | ||
| 168 : | |||
| 169 : | mBaseTool = tool; | ||
| 170 : | updateToolStatus(); | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | LLTool* LLToolMgr::getCurrentTool() | ||
| 174 : | { | ||
| 175 : | MASK override_mask = gKeyboard->currentMask(TRUE); | ||
| 176 : | |||
| 177 : | LLTool* cur_tool = NULL; | ||
| 178 : | // always use transient tools if available | ||
| 179 : | if (mTransientTool) | ||
| 180 : | { | ||
| 181 : | mOverrideTool = NULL; | ||
| 182 : | cur_tool = mTransientTool; | ||
| 183 : | } | ||
| 184 : | // tools currently grabbing mouse input will stay active | ||
| 185 : | else if (mSelectedTool && mSelectedTool->hasMouseCapture()) | ||
| 186 : | { | ||
| 187 : | cur_tool = mSelectedTool; | ||
| 188 : | } | ||
| 189 : | else | ||
| 190 : | { | ||
| 191 : | mOverrideTool = mBaseTool ? mBaseTool->getOverrideTool(override_mask) : NULL; | ||
| 192 : | |||
| 193 : | // use override tool if available otherwise drop back to base tool | ||
| 194 : | cur_tool = mOverrideTool ? mOverrideTool : mBaseTool; | ||
| 195 : | } | ||
| 196 : | |||
| 197 : | LLTool* prev_tool = mSelectedTool; | ||
| 198 : | // Set the selected tool to avoid infinite recursion | ||
| 199 : | mSelectedTool = cur_tool; | ||
| 200 : | |||
| 201 : | //update tool selection status | ||
| 202 : | if (prev_tool != cur_tool) | ||
| 203 : | { | ||
| 204 : | if (prev_tool) | ||
| 205 : | { | ||
| 206 : | prev_tool->handleDeselect(); | ||
| 207 : | } | ||
| 208 : | if (cur_tool) | ||
| 209 : | { | ||
| 210 : | cur_tool->handleSelect(); | ||
| 211 : | } | ||
| 212 : | } | ||
| 213 : | |||
| 214 : | return mSelectedTool; | ||
| 215 : | } | ||
| 216 : | |||
| 217 : | LLTool* LLToolMgr::getBaseTool() | ||
| 218 : | { | ||
| 219 : | return mBaseTool; | ||
| 220 : | } | ||
| 221 : | |||
| 222 : | void LLToolMgr::updateToolStatus() | ||
| 223 : | { | ||
| 224 : | // call getcurrenttool() to calculate active tool and call handleSelect() and handleDeselect() immediately | ||
| 225 : | // when active tool changes | ||
| 226 : | getCurrentTool(); | ||
| 227 : | } | ||
| 228 : | |||
| 229 : | BOOL LLToolMgr::inEdit() | ||
| 230 : | { | ||
| 231 : | return mBaseTool != LLToolPie::getInstance() && mBaseTool != gToolNull; | ||
| 232 : | } | ||
| 233 : | |||
| 234 : | bool LLToolMgr::inBuildMode() | ||
| 235 : | { | ||
| 236 : | // when entering mouselook inEdit() immediately returns true before | ||
| 237 : | // cameraMouselook() actually starts returning true. Also, appearance edit | ||
| 238 : | // sets build mode to true, so let's exclude that. | ||
| 239 : | bool b=(inEdit() | ||
| 240 : | && gSavedSettings.getBOOL("BuildBtnState") | ||
| 241 : | && !gAgent.cameraMouselook() | ||
| 242 : | && mCurrentToolset != gFaceEditToolset); | ||
| 243 : | |||
| 244 : | return b; | ||
| 245 : | } | ||
| 246 : | |||
| 247 : | void LLToolMgr::setTransientTool(LLTool* tool) | ||
| 248 : | { | ||
| 249 : | if (!tool) | ||
| 250 : | { | ||
| 251 : | clearTransientTool(); | ||
| 252 : | } | ||
| 253 : | else | ||
| 254 : | { | ||
| 255 : | if (mTransientTool) | ||
| 256 : | { | ||
| 257 : | mTransientTool = NULL; | ||
| 258 : | } | ||
| 259 : | |||
| 260 : | mTransientTool = tool; | ||
| 261 : | } | ||
| 262 : | |||
| 263 : | updateToolStatus(); | ||
| 264 : | } | ||
| 265 : | |||
| 266 : | void LLToolMgr::clearTransientTool() | ||
| 267 : | { | ||
| 268 : | if (mTransientTool) | ||
| 269 : | { | ||
| 270 : | mTransientTool = NULL; | ||
| 271 : | if (!mBaseTool) | ||
| 272 : | { | ||
| 273 : | llwarns << "mBaseTool is NULL" << llendl; | ||
| 274 : | } | ||
| 275 : | } | ||
| 276 : | updateToolStatus(); | ||
| 277 : | } | ||
| 278 : | |||
| 279 : | |||
| 280 : | // The "gun tool", used for handling mouselook, captures the mouse and | ||
| 281 : | // locks it within the window. When the app loses focus we need to | ||
| 282 : | // release this locking. | ||
| 283 : | void LLToolMgr::onAppFocusLost() | ||
| 284 : | { | ||
| 285 : | mSavedTool = mBaseTool; | ||
| 286 : | mBaseTool = gToolNull; | ||
| 287 : | updateToolStatus(); | ||
| 288 : | } | ||
| 289 : | |||
| 290 : | void LLToolMgr::onAppFocusGained() | ||
| 291 : | { | ||
| 292 : | if (mSavedTool) | ||
| 293 : | { | ||
| 294 : | mBaseTool = mSavedTool; | ||
| 295 : | mSavedTool = NULL; | ||
| 296 : | } | ||
| 297 : | updateToolStatus(); | ||
| 298 : | } | ||
| 299 : | |||
| 300 : | void LLToolMgr::clearSavedTool() | ||
| 301 : | { | ||
| 302 : | mSavedTool = NULL; | ||
| 303 : | } | ||
| 304 : | |||
| 305 : | ///////////////////////////////////////////////////// | ||
| 306 : | // LLToolset | ||
| 307 : | |||
| 308 : | void LLToolset::addTool(LLTool* tool) | ||
| 309 : | { | ||
| 310 : | mToolList.push_back( tool ); | ||
| 311 : | if( !mSelectedTool ) | ||
| 312 : | { | ||
| 313 : | mSelectedTool = tool; | ||
| 314 : | } | ||
| 315 : | } | ||
| 316 : | |||
| 317 : | |||
| 318 : | void LLToolset::selectTool(LLTool* tool) | ||
| 319 : | { | ||
| 320 : | mSelectedTool = tool; | ||
| 321 : | LLToolMgr::getInstance()->setCurrentTool( mSelectedTool ); | ||
| 322 : | } | ||
| 323 : | |||
| 324 : | |||
| 325 : | void LLToolset::selectToolByIndex( S32 index ) | ||
| 326 : | { | ||
| 327 : | LLTool *tool = (index >= 0 && index < (S32)mToolList.size()) ? mToolList[index] : NULL; | ||
| 328 : | if (tool) | ||
| 329 : | { | ||
| 330 : | mSelectedTool = tool; | ||
| 331 : | LLToolMgr::getInstance()->setCurrentTool( tool ); | ||
| 332 : | } | ||
| 333 : | } | ||
| 334 : | |||
| 335 : | BOOL LLToolset::isToolSelected( S32 index ) | ||
| 336 : | { | ||
| 337 : | LLTool *tool = (index >= 0 && index < (S32)mToolList.size()) ? mToolList[index] : NULL; | ||
| 338 : | return (tool == mSelectedTool); | ||
| 339 : | } | ||
| 340 : | |||
| 341 : | |||
| 342 : | void LLToolset::selectFirstTool() | ||
| 343 : | { | ||
| 344 : | mSelectedTool = (0 < mToolList.size()) ? mToolList[0] : NULL; | ||
| 345 : | LLToolMgr::getInstance()->setCurrentTool( mSelectedTool ); | ||
| 346 : | } | ||
| 347 : | |||
| 348 : | |||
| 349 : | void LLToolset::selectNextTool() | ||
| 350 : | { | ||
| 351 : | LLTool* next = NULL; | ||
| 352 : | for( tool_list_t::iterator iter = mToolList.begin(); | ||
| 353 : | iter != mToolList.end(); ) | ||
| 354 : | { | ||
| 355 : | LLTool* cur = *iter++; | ||
| 356 : | if( cur == mSelectedTool && iter != mToolList.end() ) | ||
| 357 : | { | ||
| 358 : | next = *iter; | ||
| 359 : | break; | ||
| 360 : | } | ||
| 361 : | } | ||
| 362 : | |||
| 363 : | if( next ) | ||
| 364 : | { | ||
| 365 : | mSelectedTool = next; | ||
| 366 : | LLToolMgr::getInstance()->setCurrentTool( mSelectedTool ); | ||
| 367 : | } | ||
| 368 : | else | ||
| 369 : | { | ||
| 370 : | selectFirstTool(); | ||
| 371 : | } | ||
| 372 : | } | ||
| 373 : | |||
| 374 : | void LLToolset::selectPrevTool() | ||
| 375 : | { | ||
| 376 : | LLTool* prev = NULL; | ||
| 377 : | for( tool_list_t::reverse_iterator iter = mToolList.rbegin(); | ||
| 378 : | iter != mToolList.rend(); ) | ||
| 379 : | { | ||
| 380 : | LLTool* cur = *iter++; | ||
| 381 : | if( cur == mSelectedTool && iter != mToolList.rend() ) | ||
| 382 : | { | ||
| 383 : | prev = *iter; | ||
| 384 : | break; | ||
| 385 : | } | ||
| 386 : | } | ||
| 387 : | |||
| 388 : | if( prev ) | ||
| 389 : | { | ||
| 390 : | mSelectedTool = prev; | ||
| 391 : | LLToolMgr::getInstance()->setCurrentTool( mSelectedTool ); | ||
| 392 : | } | ||
| 393 : | else if (mToolList.size() > 0) | ||
| 394 : | { | ||
| 395 : | selectToolByIndex((S32)mToolList.size()-1); | ||
| 396 : | } | ||
| 397 : | } | ||
| 398 : | |||
| 399 : | void select_tool( void *tool_pointer ) | ||
| 400 : | { | ||
| 401 : | LLTool *tool = (LLTool *)tool_pointer; | ||
| 402 : | LLToolMgr::getInstance()->getCurrentToolset()->selectTool( tool ); | ||
| 403 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

