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