aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltoolbar.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/lltoolbar.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/lltoolbar.cpp')
-rw-r--r--linden/indra/newview/lltoolbar.cpp455
1 files changed, 455 insertions, 0 deletions
diff --git a/linden/indra/newview/lltoolbar.cpp b/linden/indra/newview/lltoolbar.cpp
new file mode 100644
index 0000000..c7bc49e
--- /dev/null
+++ b/linden/indra/newview/lltoolbar.cpp
@@ -0,0 +1,455 @@
1/**
2 * @file lltoolbar.cpp
3 * @author James Cook, Richard Nelson
4 * @brief Large friendly buttons at bottom of screen.
5 *
6 * Copyright (c) 2002-2007, Linden Research, Inc.
7 *
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#include "llviewerprecompiledheaders.h"
30
31#include "lltoolbar.h"
32
33#include "imageids.h"
34#include "llfontgl.h"
35#include "llrect.h"
36#include "llparcel.h"
37
38#include "llagent.h"
39#include "llbutton.h"
40#include "llfocusmgr.h"
41#include "llviewercontrol.h"
42#include "llmenucommands.h"
43#include "llimview.h"
44#include "lluiconstants.h"
45#include "llvoavatar.h"
46#include "lltooldraganddrop.h"
47#include "llinventoryview.h"
48#include "llfloaterfriends.h"
49#include "llfloatersnapshot.h"
50#include "lltoolmgr.h"
51#include "llui.h"
52#include "llviewermenu.h"
53#include "llfirstuse.h"
54#include "llviewerparcelmgr.h"
55#include "llvieweruictrlfactory.h"
56#include "llviewerwindow.h"
57#include "viewer.h"
58#include "lltoolgrab.h"
59
60#if LL_DARWIN
61
62 #include "llresizehandle.h"
63
64 // This class draws like an LLResizeHandle but has no interactivity.
65 // It's just there to provide a cue to the user that the lower right corner of the window functions as a resize handle.
66 class LLFakeResizeHandle : public LLResizeHandle
67 {
68 public:
69 LLFakeResizeHandle(const LLString& name, const LLRect& rect, S32 min_width, S32 min_height, ECorner corner = RIGHT_BOTTOM )
70 : LLResizeHandle(name, rect, min_width, min_height, corner )
71 {
72
73 }
74
75 virtual BOOL handleHover(S32 x, S32 y, MASK mask) { return FALSE; };
76 virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask) { return FALSE; };
77 virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask) { return FALSE; };
78
79 };
80
81#endif // LL_DARWIN
82
83//
84// Globals
85//
86
87LLToolBar *gToolBar = NULL;
88S32 TOOL_BAR_HEIGHT = 20;
89
90//
91// Statics
92//
93F32 LLToolBar::sInventoryAutoOpenTime = 1.f;
94
95//
96// Functions
97//
98
99LLToolBar::LLToolBar(const std::string& name, const LLRect& r)
100: LLPanel(name, r, BORDER_NO)
101#if LL_DARWIN
102 , mResizeHandle(NULL)
103#endif // LL_DARWIN
104{
105 setIsChrome(TRUE);
106 setFollows( FOLLOWS_LEFT | FOLLOWS_RIGHT | FOLLOWS_BOTTOM );
107
108 gUICtrlFactory->buildPanel(this, "panel_toolbar.xml");
109 mIsFocusRoot = TRUE;
110
111}
112
113
114BOOL LLToolBar::postBuild()
115{
116 childSetAction("im_btn", onClickIM, this);
117 childSetControlName("im_btn", "ShowIM");
118
119 childSetAction("chat_btn", onClickChat, this);
120 childSetControlName("chat_btn", "ChatVisible");
121
122 childSetAction("friends_btn", onClickFriends, this);
123 childSetControlName("friends_btn", "ShowFriends");
124
125 childSetAction("appearance_btn", onClickAppearance, this);
126 childSetControlName("appearance_btn", "");
127
128 childSetAction("clothing_btn", onClickClothing, this);
129 childSetControlName("clothing_btn", "ClothingBtnState");
130
131 childSetAction("fly_btn", onClickFly, this);
132 childSetControlName("fly_btn", "FlyBtnState");
133
134 childSetAction("sit_btn", onClickSit, this);
135 childSetControlName("sit_btn", "SitBtnState");
136
137 childSetAction("snapshot_btn", onClickSnapshot, this);
138 childSetControlName("snapshot_btn", "");
139
140 childSetAction("directory_btn", onClickDirectory, this);
141 childSetControlName("directory_btn", "ShowDirectory");
142
143 childSetAction("build_btn", onClickBuild, this);
144 childSetControlName("build_btn", "BuildBtnState");
145
146 childSetAction("radar_btn", onClickRadar, this);
147 childSetControlName("radar_btn", "ShowMiniMap");
148
149 childSetAction("map_btn", onClickMap, this);
150 childSetControlName("map_btn", "ShowWorldMap");
151
152 childSetAction("inventory_btn", onClickInventory, this);
153 childSetControlName("inventory_btn", "ShowInventory");
154
155 for (child_list_const_iter_t child_iter = getChildList()->begin();
156 child_iter != getChildList()->end(); ++child_iter)
157 {
158 LLView *view = *child_iter;
159 if(view->getWidgetType() == WIDGET_TYPE_BUTTON)
160 {
161 LLButton* btn = (LLButton*)view;
162 btn->setSoundFlags(LLView::SILENT);
163 }
164 }
165
166#if LL_DARWIN
167 if(mResizeHandle == NULL)
168 {
169 LLRect rect(0, 0, RESIZE_HANDLE_WIDTH, RESIZE_HANDLE_HEIGHT);
170 mResizeHandle = new LLFakeResizeHandle(LLString(""), rect, RESIZE_HANDLE_WIDTH, RESIZE_HANDLE_HEIGHT);
171 this->addChildAtEnd(mResizeHandle);
172 }
173#endif // LL_DARWIN
174
175 layoutButtons();
176
177 return TRUE;
178}
179
180LLToolBar::~LLToolBar()
181{
182 // LLView destructor cleans up children
183}
184
185
186BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
187 EDragAndDropType cargo_type,
188 void* cargo_data,
189 EAcceptance* accept,
190 LLString& tooltip_msg)
191{
192 LLButton* inventory_btn = LLUICtrlFactory::getButtonByName(this, "inventory_btn");
193 if (!inventory_btn) return FALSE;
194
195 LLInventoryView* active_inventory = LLInventoryView::getActiveInventory();
196
197 if(active_inventory && active_inventory->getVisible())
198 {
199 mInventoryAutoOpen = FALSE;
200 }
201 else if (inventory_btn->getRect().pointInRect(x, y))
202 {
203 if (mInventoryAutoOpen)
204 {
205 if (!(active_inventory && active_inventory->getVisible()) &&
206 mInventoryAutoOpenTimer.getElapsedTimeF32() > sInventoryAutoOpenTime)
207 {
208 LLInventoryView::showAgentInventory();
209 }
210 }
211 else
212 {
213 mInventoryAutoOpen = TRUE;
214 mInventoryAutoOpenTimer.reset();
215 }
216 }
217
218 return LLPanel::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
219}
220
221// static
222void LLToolBar::toggle(void*)
223{
224 BOOL show = gSavedSettings.getBOOL("ShowToolBar");
225 gSavedSettings.setBOOL("ShowToolBar", !show);
226 gToolBar->setVisible(!show);
227}
228
229
230// static
231BOOL LLToolBar::visible(void*)
232{
233 return gToolBar->getVisible();
234}
235
236
237void LLToolBar::layoutButtons()
238{
239 // Always spans whole window. JC
240 const S32 FUDGE_WIDTH_OF_SCREEN = 4;
241 S32 width = gViewerWindow->getWindowWidth() + FUDGE_WIDTH_OF_SCREEN;
242 S32 count = getChildCount();
243 S32 pad = 2;
244
245#if LL_DARWIN
246 // this function may be called before postBuild(), in which case mResizeHandle won't have been set up yet.
247 if(mResizeHandle != NULL)
248 {
249 // a resize handle has been added as a child, increasing the count by one.
250 count--;
251
252 if(!gViewerWindow->getWindow()->getFullscreen())
253 {
254 // Only when running in windowed mode on the Mac, leave room for a resize widget on the right edge of the bar.
255 width -= RESIZE_HANDLE_WIDTH;
256
257 LLRect r;
258 r.mLeft = width - pad;
259 r.mBottom = 0;
260 r.mRight = r.mLeft + RESIZE_HANDLE_WIDTH;
261 r.mTop = r.mBottom + RESIZE_HANDLE_HEIGHT;
262 mResizeHandle->setRect(r);
263 mResizeHandle->setVisible(TRUE);
264 }
265 else
266 {
267 mResizeHandle->setVisible(FALSE);
268 }
269 }
270#endif // LL_DARWIN
271
272 // We actually want to extend "pad" pixels off the right edge of the
273 // screen, such that the rightmost button is aligned.
274 F32 segment_width = (F32)(width + pad) / (F32)count;
275 S32 btn_width = lltrunc(segment_width - pad);
276
277 // Evenly space all views
278 S32 height = -1;
279 S32 i = count - 1;
280 for (child_list_const_iter_t child_iter = getChildList()->begin();
281 child_iter != getChildList()->end(); ++child_iter)
282 {
283 LLView *btn_view = *child_iter;
284 if(btn_view->getWidgetType() == WIDGET_TYPE_BUTTON)
285 {
286 if (height < 0)
287 {
288 height = btn_view->getRect().getHeight();
289 }
290 S32 x = llround(i*segment_width);
291 S32 y = 0;
292 LLRect r;
293 r.setOriginAndSize(x, y, btn_width, height);
294 btn_view->setRect(r);
295 i--;
296 }
297 }
298}
299
300
301// virtual
302void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent)
303{
304 LLPanel::reshape(width, height, called_from_parent);
305
306 layoutButtons();
307}
308
309
310// Per-frame updates of visibility
311void LLToolBar::refresh()
312{
313 BOOL show = gSavedSettings.getBOOL("ShowToolBar");
314 BOOL mouselook = gAgent.cameraMouselook();
315 setVisible(show && !mouselook);
316
317 // Clothing button updated inside LLFloaterClothing
318
319 childSetEnabled("fly_btn", gAgent.canFly() || gAgent.getFlying() );
320
321 childSetEnabled("build_btn", gParcelMgr->agentCanBuild() );
322
323 // Check to see if we're in build mode
324 BOOL build_mode = gToolMgr->inEdit();
325 // And not just clicking on a scripted object
326 if (gToolGrab->getHideBuildHighlight())
327 {
328 build_mode = FALSE;
329 }
330 gSavedSettings.setBOOL("BuildBtnState", build_mode);
331}
332
333
334// static
335void LLToolBar::onClickIM(void* user_data)
336{
337 if(gIMView->getFloaterOpen())
338 {
339 // this is if we want Ctrl-T to be simply a toggle
340 // gIMView->setFloaterOpen( FALSE );
341 // three-state behavior follows
342 if(gFocusMgr.childHasKeyboardFocus(gIMView->getFloater()))
343 {
344 gIMView->setFloaterOpen( FALSE );
345 } else {
346 gIMView->getFloater()->setFocus( TRUE );
347 }
348 }
349 else
350 {
351 gIMView->setFloaterOpen( TRUE );
352 }
353}
354
355
356// static
357void LLToolBar::onClickChat(void* user_data)
358{
359 handle_chat(NULL);
360}
361
362
363// static
364void LLToolBar::onClickFriends(void*)
365{
366 LLFloaterFriends::toggle();
367}
368
369
370// static
371void LLToolBar::onClickAppearance(void*)
372{
373 if (gAgent.getWearablesLoaded())
374 {
375 gAgent.changeCameraToCustomizeAvatar();
376 }
377}
378
379
380// static
381void LLToolBar::onClickClothing(void*)
382{
383 handle_clothing(NULL);
384}
385
386
387// static
388void LLToolBar::onClickFly(void*)
389{
390 gAgent.toggleFlying();
391}
392
393
394// static
395void LLToolBar::onClickSit(void*)
396{
397 if (!(gAgent.getControlFlags() & AGENT_CONTROL_SIT_ON_GROUND))
398 {
399 // sit down
400 gAgent.setFlying(FALSE);
401 gAgent.setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
402
403 // Might be first sit
404 LLFirstUse::useSit();
405 }
406 else
407 {
408 // stand up
409 gAgent.setFlying(FALSE);
410 gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
411 }
412}
413
414
415// static
416void LLToolBar::onClickSnapshot(void*)
417{
418 LLFloaterSnapshot::show (0);
419}
420
421
422// static
423void LLToolBar::onClickDirectory(void*)
424{
425 handle_find(NULL);
426}
427
428
429// static
430void LLToolBar::onClickBuild(void*)
431{
432 toggle_build_mode();
433}
434
435
436// static
437void LLToolBar::onClickRadar(void*)
438{
439 handle_mini_map(NULL);
440}
441
442
443// static
444void LLToolBar::onClickMap(void*)
445{
446 handle_map(NULL);
447}
448
449
450// static
451void LLToolBar::onClickInventory(void*)
452{
453 handle_inventory(NULL);
454}
455