Annotation of /trunk/indra/newview/llfloatergesture.cpp
Parent Directory
|
Revision Log
Revision 135 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llfloatergesture.cpp | ||
| 3 : | * @brief Read-only list of gestures from your inventory. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2002&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2002-2009, Linden Research, Inc. | ||
| 8 : | * | ||
| 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 "llfloatergesture.h" | ||
| 36 : | |||
| 37 : | #include "lldir.h" | ||
| 38 : | #include "llinventory.h" | ||
| 39 : | #include "llmultigesture.h" | ||
| 40 : | |||
| 41 : | #include "llagent.h" | ||
| 42 : | #include "llviewerwindow.h" | ||
| 43 : | #include "llbutton.h" | ||
| 44 : | #include "llcombobox.h" | ||
| 45 : | #include "llgesturemgr.h" | ||
| 46 : | #include "llinventorymodel.h" | ||
| 47 : | #include "llinventoryview.h" | ||
| 48 : | #include "llkeyboard.h" | ||
| 49 : | #include "lllineeditor.h" | ||
| 50 : | #include "llpreviewgesture.h" | ||
| 51 : | #include "llresizehandle.h" | ||
| 52 : | #include "llscrollbar.h" | ||
| 53 : | #include "llscrollcontainer.h" | ||
| 54 : | #include "llscrolllistctrl.h" | ||
| 55 : | #include "lltextbox.h" | ||
| 56 : | #include "lluictrlfactory.h" | ||
| 57 : | #include "llviewergesture.h" | ||
| 58 : | #include "llviewerimagelist.h" | ||
| 59 : | #include "llviewerinventory.h" | ||
| 60 : | #include "llvoavatar.h" | ||
| 61 : | #include "llviewercontrol.h" | ||
| 62 : | |||
| 63 : | // static | ||
| 64 : | LLFloaterGesture* LLFloaterGesture::sInstance = NULL; | ||
| 65 : | LLFloaterGestureObserver* LLFloaterGesture::sObserver = NULL; | ||
| 66 : | |||
| 67 : | BOOL item_name_precedes( LLInventoryItem* a, LLInventoryItem* b ) | ||
| 68 : | { | ||
| 69 : | return LLStringUtil::precedesDict( a->getName(), b->getName() ); | ||
| 70 : | } | ||
| 71 : | |||
| 72 : | class LLFloaterGestureObserver : public LLGestureManagerObserver | ||
| 73 : | { | ||
| 74 : | public: | ||
| 75 : | LLFloaterGestureObserver() {} | ||
| 76 : | virtual ~LLFloaterGestureObserver() {} | ||
| 77 : | virtual void changed() { LLFloaterGesture::refreshAll(); } | ||
| 78 : | }; | ||
| 79 : | |||
| 80 : | //--------------------------------------------------------------------------- | ||
| 81 : | // LLFloaterGesture | ||
| 82 : | //--------------------------------------------------------------------------- | ||
| 83 : | LLFloaterGesture::LLFloaterGesture() | ||
| 84 : | : LLFloater(std::string("Gesture Floater")) | ||
| 85 : | { | ||
| 86 : | sInstance = this; | ||
| 87 : | |||
| 88 : | sObserver = new LLFloaterGestureObserver; | ||
| 89 : | gGestureManager.addObserver(sObserver); | ||
| 90 : | } | ||
| 91 : | |||
| 92 : | // virtual | ||
| 93 : | LLFloaterGesture::~LLFloaterGesture() | ||
| 94 : | { | ||
| 95 : | gGestureManager.removeObserver(sObserver); | ||
| 96 : | delete sObserver; | ||
| 97 : | sObserver = NULL; | ||
| 98 : | |||
| 99 : | sInstance = NULL; | ||
| 100 : | |||
| 101 : | // Custom saving rectangle, since load must be done | ||
| 102 : | // after postBuild. | ||
| 103 : | gSavedSettings.setRect("FloaterGestureRect2", getRect()); | ||
| 104 : | } | ||
| 105 : | |||
| 106 : | // virtual | ||
| 107 : | BOOL LLFloaterGesture::postBuild() | ||
| 108 : | { | ||
| 109 : | std::string label; | ||
| 110 : | |||
| 111 : | // Translate title | ||
| 112 : | label = getTitle(); | ||
| 113 : | |||
| 114 : | setTitle(label); | ||
| 115 : | |||
| 116 : | childSetCommitCallback("gesture_list", onCommitList, this); | ||
| 117 : | childSetDoubleClickCallback("gesture_list", onClickPlay); | ||
| 118 : | |||
| 119 : | childSetAction("inventory_btn", onClickInventory, this); | ||
| 120 : | |||
| 121 : | childSetAction("edit_btn", onClickEdit, this); | ||
| 122 : | |||
| 123 : | childSetAction("play_btn", onClickPlay, this); | ||
| 124 : | childSetAction("stop_btn", onClickPlay, this); | ||
| 125 : | |||
| 126 : | childSetAction("new_gesture_btn", onClickNew, this); | ||
| 127 : | |||
| 128 : | childSetVisible("play_btn", true); | ||
| 129 : | childSetVisible("stop_btn", false); | ||
| 130 : | setDefaultBtn("play_btn"); | ||
| 131 : | |||
| 132 : | return TRUE; | ||
| 133 : | } | ||
| 134 : | |||
| 135 : | |||
| 136 : | // static | ||
| 137 : | void LLFloaterGesture::show() | ||
| 138 : | { | ||
| 139 : | if (sInstance) | ||
| 140 : | { | ||
| 141 : | sInstance->open(); /*Flawfinder: ignore*/ | ||
| 142 : | return; | ||
| 143 : | } | ||
| 144 : | |||
| 145 : | LLFloaterGesture *self = new LLFloaterGesture(); | ||
| 146 : | |||
| 147 : | // Builds and adds to gFloaterView | ||
| 148 : | LLUICtrlFactory::getInstance()->buildFloater(self, "floater_gesture.xml"); | ||
| 149 : | |||
| 150 : | // Fix up rectangle | ||
| 151 : | LLRect rect = gSavedSettings.getRect("FloaterGestureRect2"); | ||
| 152 : | self->reshape(rect.getWidth(), rect.getHeight()); | ||
| 153 : | self->setRect(rect); | ||
| 154 : | |||
| 155 : | self->buildGestureList(); | ||
| 156 : | |||
| 157 : | self->childSetFocus("gesture_list"); | ||
| 158 : | |||
| 159 : | LLCtrlListInterface *list = self->childGetListInterface("gesture_list"); | ||
| 160 : | if (list) | ||
| 161 : | { | ||
| 162 : | const BOOL ascending = TRUE; | ||
| 163 : | list->sortByColumn(std::string("name"), ascending); | ||
| 164 : | list->selectFirstItem(); | ||
| 165 : | } | ||
| 166 : | |||
| 167 : | self->mSelectedID = LLUUID::null; | ||
| 168 : | |||
| 169 : | // Update button labels | ||
| 170 : | onCommitList(NULL, self); | ||
| 171 : | self->open(); /*Flawfinder: ignore*/ | ||
| 172 : | } | ||
| 173 : | |||
| 174 : | // static | ||
| 175 : | void LLFloaterGesture::toggleVisibility() | ||
| 176 : | { | ||
| 177 : | if(sInstance && sInstance->getVisible()) | ||
| 178 : | { | ||
| 179 : | sInstance->close(); | ||
| 180 : | } | ||
| 181 : | else | ||
| 182 : | { | ||
| 183 : | show(); | ||
| 184 : | } | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | // static | ||
| 188 : | void LLFloaterGesture::refreshAll() | ||
| 189 : | { | ||
| 190 : | if (sInstance) | ||
| 191 : | { | ||
| 192 : | sInstance->buildGestureList(); | ||
| 193 : | |||
| 194 : | LLCtrlListInterface *list = sInstance->childGetListInterface("gesture_list"); | ||
| 195 : | if (!list) return; | ||
| 196 : | |||
| 197 : | if (sInstance->mSelectedID.isNull()) | ||
| 198 : | { | ||
| 199 : | list->selectFirstItem(); | ||
| 200 : | } | ||
| 201 : | else | ||
| 202 : | { | ||
| 203 : | if (list->setCurrentByID(sInstance->mSelectedID)) | ||
| 204 : | { | ||
| 205 : | LLCtrlScrollInterface *scroll = sInstance->childGetScrollInterface("gesture_list"); | ||
| 206 : | if (scroll) scroll->scrollToShowSelected(); | ||
| 207 : | } | ||
| 208 : | else | ||
| 209 : | { | ||
| 210 : | list->selectFirstItem(); | ||
| 211 : | } | ||
| 212 : | } | ||
| 213 : | |||
| 214 : | // Update button labels | ||
| 215 : | onCommitList(NULL, sInstance); | ||
| 216 : | } | ||
| 217 : | } | ||
| 218 : | |||
| 219 : | void LLFloaterGesture::buildGestureList() | ||
| 220 : | { | ||
| 221 : | LLCtrlListInterface *list = childGetListInterface("gesture_list"); | ||
| 222 : | if (!list) return; | ||
| 223 : | |||
| 224 : | list->operateOnAll(LLCtrlListInterface::OP_DELETE); | ||
| 225 : | |||
| 226 : | LLGestureManager::item_map_t::iterator it; | ||
| 227 : | for (it = gGestureManager.mActive.begin(); it != gGestureManager.mActive.end(); ++it) | ||
| 228 : | { | ||
| 229 : | const LLUUID& item_id = (*it).first; | ||
| 230 : | LLMultiGesture* gesture = (*it).second; | ||
| 231 : | |||
| 232 : | // Note: Can have NULL item if inventory hasn't arrived yet. | ||
| 233 : | std::string item_name = "Loading..."; | ||
| 234 : | LLInventoryItem* item = gInventory.getItem(item_id); | ||
| 235 : | if (item) | ||
| 236 : | { | ||
| 237 : | item_name = item->getName(); | ||
| 238 : | } | ||
| 239 : | |||
| 240 : | std::string font_style = "NORMAL"; | ||
| 241 : | // If gesture is playing, bold it | ||
| 242 : | |||
| 243 : | LLSD element; | ||
| 244 : | element["id"] = item_id; | ||
| 245 : | |||
| 246 : | if (gesture) | ||
| 247 : | { | ||
| 248 : | if (gesture->mPlaying) | ||
| 249 : | { | ||
| 250 : | font_style = "BOLD"; | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | element["columns"][0]["column"] = "trigger"; | ||
| 254 : | element["columns"][0]["value"] = gesture->mTrigger; | ||
| 255 : | element["columns"][0]["font"] = "SANSSERIF"; | ||
| 256 : | element["columns"][0]["font-style"] = font_style; | ||
| 257 : | |||
| 258 : | std::string key_string = LLKeyboard::stringFromKey(gesture->mKey); | ||
| 259 : | std::string buffer; | ||
| 260 : | |||
| 261 : | { | ||
| 262 : | if (gesture->mKey == KEY_NONE) | ||
| 263 : | { | ||
| 264 : | buffer = "---"; | ||
| 265 : | key_string = "~~~"; // alphabetize to end | ||
| 266 : | } | ||
| 267 : | else | ||
| 268 : | { | ||
| 269 : | if (gesture->mMask & MASK_CONTROL) buffer.append("Ctrl-"); | ||
| 270 : | if (gesture->mMask & MASK_ALT) buffer.append("Alt-"); | ||
| 271 : | if (gesture->mMask & MASK_SHIFT) buffer.append("Shift-"); | ||
| 272 : | if ((gesture->mMask & (MASK_CONTROL|MASK_ALT|MASK_SHIFT)) && | ||
| 273 : | (key_string[0] == '-' || key_string[0] == '=')) | ||
| 274 : | { | ||
| 275 : | buffer.append(" "); | ||
| 276 : | } | ||
| 277 : | buffer.append(key_string); | ||
| 278 : | } | ||
| 279 : | } | ||
| 280 : | element["columns"][1]["column"] = "shortcut"; | ||
| 281 : | element["columns"][1]["value"] = buffer; | ||
| 282 : | element["columns"][1]["font"] = "SANSSERIF"; | ||
| 283 : | element["columns"][1]["font-style"] = font_style; | ||
| 284 : | |||
| 285 : | // hidden column for sorting | ||
| 286 : | element["columns"][2]["column"] = "key"; | ||
| 287 : | element["columns"][2]["value"] = key_string; | ||
| 288 : | element["columns"][2]["font"] = "SANSSERIF"; | ||
| 289 : | element["columns"][2]["font-style"] = font_style; | ||
| 290 : | |||
| 291 : | // Only add "playing" if we've got the name, less confusing. JC | ||
| 292 : | if (item && gesture->mPlaying) | ||
| 293 : | { | ||
| 294 : | item_name += " (Playing)"; | ||
| 295 : | } | ||
| 296 : | element["columns"][3]["column"] = "name"; | ||
| 297 : | element["columns"][3]["value"] = item_name; | ||
| 298 : | element["columns"][3]["font"] = "SANSSERIF"; | ||
| 299 : | element["columns"][3]["font-style"] = font_style; | ||
| 300 : | } | ||
| 301 : | else | ||
| 302 : | { | ||
| 303 : | element["columns"][0]["column"] = "trigger"; | ||
| 304 : | element["columns"][0]["value"] = ""; | ||
| 305 : | element["columns"][0]["font"] = "SANSSERIF"; | ||
| 306 : | element["columns"][0]["font-style"] = font_style; | ||
| 307 : | element["columns"][0]["column"] = "trigger"; | ||
| 308 : | element["columns"][0]["value"] = "---"; | ||
| 309 : | element["columns"][0]["font"] = "SANSSERIF"; | ||
| 310 : | element["columns"][0]["font-style"] = font_style; | ||
| 311 : | element["columns"][2]["column"] = "key"; | ||
| 312 : | element["columns"][2]["value"] = "~~~"; | ||
| 313 : | element["columns"][2]["font"] = "SANSSERIF"; | ||
| 314 : | element["columns"][2]["font-style"] = font_style; | ||
| 315 : | element["columns"][3]["column"] = "name"; | ||
| 316 : | element["columns"][3]["value"] = item_name; | ||
| 317 : | element["columns"][3]["font"] = "SANSSERIF"; | ||
| 318 : | element["columns"][3]["font-style"] = font_style; | ||
| 319 : | } | ||
| 320 : | list->addElement(element, ADD_BOTTOM); | ||
| 321 : | } | ||
| 322 : | } | ||
| 323 : | |||
| 324 : | // static | ||
| 325 : | void LLFloaterGesture::onClickInventory(void* data) | ||
| 326 : | { | ||
| 327 : | LLFloaterGesture* self = (LLFloaterGesture*)data; | ||
| 328 : | |||
| 329 : | LLCtrlListInterface *list = self->childGetListInterface("gesture_list"); | ||
| 330 : | if (!list) return; | ||
| 331 : | const LLUUID& item_id = list->getCurrentID(); | ||
| 332 : | |||
| 333 : | LLInventoryView* inv = LLInventoryView::showAgentInventory(); | ||
| 334 : | if (!inv) return; | ||
| 335 : | inv->getPanel()->setSelection(item_id, TRUE); | ||
| 336 : | } | ||
| 337 : | |||
| 338 : | // static | ||
| 339 : | void LLFloaterGesture::onClickPlay(void* data) | ||
| 340 : | { | ||
| 341 : | LLFloaterGesture* self = (LLFloaterGesture*)data; | ||
| 342 : | |||
| 343 : | LLCtrlListInterface *list = self->childGetListInterface("gesture_list"); | ||
| 344 : | if (!list) return; | ||
| 345 : | const LLUUID& item_id = list->getCurrentID(); | ||
| 346 : | |||
| 347 : | if (gGestureManager.isGesturePlaying(item_id)) | ||
| 348 : | { | ||
| 349 : | gGestureManager.stopGesture(item_id); | ||
| 350 : | } | ||
| 351 : | else | ||
| 352 : | { | ||
| 353 : | gGestureManager.playGesture(item_id); | ||
| 354 : | } | ||
| 355 : | } | ||
| 356 : | |||
| 357 : | class GestureShowCallback : public LLInventoryCallback | ||
| 358 : | { | ||
| 359 : | public: | ||
| 360 : | GestureShowCallback(std::string &title) | ||
| 361 : | { | ||
| 362 : | mTitle = title; | ||
| 363 : | } | ||
| 364 : | void fire(const LLUUID &inv_item) | ||
| 365 : | { | ||
| 366 : | LLPreviewGesture::show(mTitle, inv_item, LLUUID::null); | ||
| 367 : | } | ||
| 368 : | private: | ||
| 369 : | std::string mTitle; | ||
| 370 : | }; | ||
| 371 : | |||
| 372 : | // static | ||
| 373 : | void LLFloaterGesture::onClickNew(void* data) | ||
| 374 : | { | ||
| 375 : | std::string title("Gesture: "); | ||
| 376 : | title.append("New Gesture"); | ||
| 377 : | LLPointer<LLInventoryCallback> cb = new GestureShowCallback(title); | ||
| 378 : | create_inventory_item(gAgent.getID(), gAgent.getSessionID(), | ||
| 379 : | LLUUID::null, LLTransactionID::tnull, "New Gesture", "", LLAssetType::AT_GESTURE, | ||
| 380 : | LLInventoryType::IT_GESTURE, NOT_WEARABLE, PERM_MOVE | PERM_TRANSFER, cb); | ||
| 381 : | } | ||
| 382 : | |||
| 383 : | |||
| 384 : | // static | ||
| 385 : | void LLFloaterGesture::onClickEdit(void* data) | ||
| 386 : | { | ||
| 387 : | LLFloaterGesture* self = (LLFloaterGesture*)data; | ||
| 388 : | |||
| 389 : | LLCtrlListInterface *list = self->childGetListInterface("gesture_list"); | ||
| 390 : | if (!list) return; | ||
| 391 : | const LLUUID& item_id = list->getCurrentID(); | ||
| 392 : | |||
| 393 : | LLInventoryItem* item = gInventory.getItem(item_id); | ||
| 394 : | if (!item) return; | ||
| 395 : | |||
| 396 : | std::string title("Gesture: "); | ||
| 397 : | title.append(item->getName()); | ||
| 398 : | |||
| 399 : | LLPreviewGesture* previewp = LLPreviewGesture::show(title, item_id, LLUUID::null); | ||
| 400 : | if (!previewp->getHost()) | ||
| 401 : | { | ||
| 402 : | previewp->setRect(gFloaterView->findNeighboringPosition(self, previewp)); | ||
| 403 : | } | ||
| 404 : | } | ||
| 405 : | |||
| 406 : | // static | ||
| 407 : | void LLFloaterGesture::onCommitList(LLUICtrl* ctrl, void* data) | ||
| 408 : | { | ||
| 409 : | LLFloaterGesture* self = (LLFloaterGesture*)data; | ||
| 410 : | |||
| 411 : | const LLUUID& item_id = self->childGetValue("gesture_list").asUUID(); | ||
| 412 : | |||
| 413 : | self->mSelectedID = item_id; | ||
| 414 : | if (gGestureManager.isGesturePlaying(item_id)) | ||
| 415 : | { | ||
| 416 : | self->childSetVisible("play_btn", false); | ||
| 417 : | self->childSetVisible("stop_btn", true); | ||
| 418 : | } | ||
| 419 : | else | ||
| 420 : | { | ||
| 421 : | self->childSetVisible("play_btn", true); | ||
| 422 : | self->childSetVisible("stop_btn", false); | ||
| 423 : | } | ||
| 424 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

