00001
00033 #include "llviewerprecompiledheaders.h"
00034
00035 #include "lltoolbar.h"
00036
00037 #include "imageids.h"
00038 #include "llfontgl.h"
00039 #include "llrect.h"
00040 #include "llparcel.h"
00041
00042 #include "llagent.h"
00043 #include "llbutton.h"
00044 #include "llfocusmgr.h"
00045 #include "llviewercontrol.h"
00046 #include "llmenucommands.h"
00047 #include "llimview.h"
00048 #include "lluiconstants.h"
00049 #include "llvoavatar.h"
00050 #include "lltooldraganddrop.h"
00051 #include "llinventoryview.h"
00052 #include "llfloateravatarlist.h"
00053 #include "llfloaterchatterbox.h"
00054 #include "llfloaterfriends.h"
00055 #include "llfloatersnapshot.h"
00056 #include "lltoolmgr.h"
00057 #include "llfloatereventlog.h"
00058 #include "llui.h"
00059 #include "llviewermenu.h"
00060 #include "llfirstuse.h"
00061 #include "llviewerparcelmgr.h"
00062 #include "llvieweruictrlfactory.h"
00063 #include "llviewerwindow.h"
00064 #include "viewer.h"
00065 #include "lltoolgrab.h"
00066
00067 #if LL_DARWIN
00068
00069 #include "llresizehandle.h"
00070
00071
00072
00073 class LLFakeResizeHandle : public LLResizeHandle
00074 {
00075 public:
00076 LLFakeResizeHandle(const LLString& name, const LLRect& rect, S32 min_width, S32 min_height, ECorner corner = RIGHT_BOTTOM )
00077 : LLResizeHandle(name, rect, min_width, min_height, corner )
00078 {
00079
00080 }
00081
00082 virtual BOOL handleHover(S32 x, S32 y, MASK mask) { return FALSE; };
00083 virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask) { return FALSE; };
00084 virtual BOOL handleMouseUp(S32 x, S32 y, MASK mask) { return FALSE; };
00085
00086 };
00087
00088 #endif // LL_DARWIN
00089
00090
00091
00092
00093
00094 LLToolBar *gToolBar = NULL;
00095 S32 TOOL_BAR_HEIGHT = 20;
00096
00097
00098
00099
00100 F32 LLToolBar::sInventoryAutoOpenTime = 1.f;
00101
00102
00103
00104
00105
00106 LLToolBar::LLToolBar(const std::string& name, const LLRect& r)
00107 : LLPanel(name, r, BORDER_NO)
00108 #if LL_DARWIN
00109 , mResizeHandle(NULL)
00110 #endif
00111 {
00112 setIsChrome(TRUE);
00113 setFollows( FOLLOWS_LEFT | FOLLOWS_RIGHT | FOLLOWS_BOTTOM );
00114
00115 gUICtrlFactory->buildPanel(this, "panel_toolbar.xml");
00116 mIsFocusRoot = TRUE;
00117
00118 }
00119
00120
00121 BOOL LLToolBar::postBuild()
00122 {
00123 childSetAction("communicate_btn", onClickCommunicate, this);
00124 childSetControlName("communicate_btn", "ShowCommunicate");
00125
00126 childSetAction("chat_btn", onClickChat, this);
00127 childSetControlName("chat_btn", "ChatVisible");
00128
00129 childSetAction("appearance_btn", onClickAppearance, this);
00130 childSetControlName("appearance_btn", "");
00131
00132 childSetAction("clothing_btn", onClickClothing, this);
00133 childSetControlName("clothing_btn", "ClothingBtnState");
00134
00135 childSetAction("fly_btn", onClickFly, this);
00136 childSetControlName("fly_btn", "FlyBtnState");
00137
00138 childSetAction("sit_btn", onClickSit, this);
00139 childSetControlName("sit_btn", "SitBtnState");
00140
00141 childSetAction("snapshot_btn", onClickSnapshot, this);
00142 childSetControlName("snapshot_btn", "");
00143
00144 childSetAction("directory_btn", onClickDirectory, this);
00145 childSetControlName("directory_btn", "ShowDirectory");
00146
00147 childSetAction("build_btn", onClickBuild, this);
00148 childSetControlName("build_btn", "BuildBtnState");
00149
00150 childSetAction("radar_btn", onClickRadar, this);
00151 childSetControlName("radar_btn", "ShowMiniMap");
00152
00153 childSetAction("map_btn", onClickMap, this);
00154 childSetControlName("map_btn", "ShowWorldMap");
00155
00156 childSetAction("event_log_btn", onClickEventLog, this);
00157 childSetControlName("event_log_btn", "ShowEventLog");
00158
00159 childSetAction("inventory_btn", onClickInventory, this);
00160 childSetControlName("inventory_btn", "ShowInventory");
00161
00162 childSetAction("avatar_list_btn", onClickAvatarList, this);
00163 childSetControlName("inventory_btn", "ShowAvatarList");
00164
00165 for (child_list_const_iter_t child_iter = getChildList()->begin();
00166 child_iter != getChildList()->end(); ++child_iter)
00167 {
00168 LLView *view = *child_iter;
00169 if(view->getWidgetType() == WIDGET_TYPE_BUTTON)
00170 {
00171 LLButton* btn = (LLButton*)view;
00172 btn->setSoundFlags(LLView::SILENT);
00173 }
00174 }
00175
00176 #if LL_DARWIN
00177 if(mResizeHandle == NULL)
00178 {
00179 LLRect rect(0, 0, RESIZE_HANDLE_WIDTH, RESIZE_HANDLE_HEIGHT);
00180 mResizeHandle = new LLFakeResizeHandle(LLString(""), rect, RESIZE_HANDLE_WIDTH, RESIZE_HANDLE_HEIGHT);
00181 this->addChildAtEnd(mResizeHandle);
00182 }
00183 #endif // LL_DARWIN
00184
00185 layoutButtons();
00186
00187 return TRUE;
00188 }
00189
00190 LLToolBar::~LLToolBar()
00191 {
00192
00193 }
00194
00195
00196 BOOL LLToolBar::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
00197 EDragAndDropType cargo_type,
00198 void* cargo_data,
00199 EAcceptance* accept,
00200 LLString& tooltip_msg)
00201 {
00202 LLButton* inventory_btn = LLUICtrlFactory::getButtonByName(this, "inventory_btn");
00203 if (!inventory_btn) return FALSE;
00204
00205 LLInventoryView* active_inventory = LLInventoryView::getActiveInventory();
00206
00207 if(active_inventory && active_inventory->getVisible())
00208 {
00209 mInventoryAutoOpen = FALSE;
00210 }
00211 else if (inventory_btn->getRect().pointInRect(x, y))
00212 {
00213 if (mInventoryAutoOpen)
00214 {
00215 if (!(active_inventory && active_inventory->getVisible()) &&
00216 mInventoryAutoOpenTimer.getElapsedTimeF32() > sInventoryAutoOpenTime)
00217 {
00218 LLInventoryView::showAgentInventory();
00219 }
00220 }
00221 else
00222 {
00223 mInventoryAutoOpen = TRUE;
00224 mInventoryAutoOpenTimer.reset();
00225 }
00226 }
00227
00228 return LLPanel::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
00229 }
00230
00231
00232 void LLToolBar::toggle(void*)
00233 {
00234 BOOL show = gSavedSettings.getBOOL("ShowToolBar");
00235 gSavedSettings.setBOOL("ShowToolBar", !show);
00236 gToolBar->setVisible(!show);
00237 }
00238
00239
00240
00241 BOOL LLToolBar::visible(void*)
00242 {
00243 return gToolBar->getVisible();
00244 }
00245
00246
00247 void LLToolBar::layoutButtons()
00248 {
00249
00250 const S32 FUDGE_WIDTH_OF_SCREEN = 4;
00251 S32 width = gViewerWindow->getWindowWidth() + FUDGE_WIDTH_OF_SCREEN;
00252 S32 count = getChildCount();
00253 S32 pad = 2;
00254
00255 #if LL_DARWIN
00256
00257 if(mResizeHandle != NULL)
00258 {
00259
00260 count--;
00261
00262 if(!gViewerWindow->getWindow()->getFullscreen())
00263 {
00264
00265 width -= RESIZE_HANDLE_WIDTH;
00266
00267 LLRect r;
00268 r.mLeft = width - pad;
00269 r.mBottom = 0;
00270 r.mRight = r.mLeft + RESIZE_HANDLE_WIDTH;
00271 r.mTop = r.mBottom + RESIZE_HANDLE_HEIGHT;
00272 mResizeHandle->setRect(r);
00273 mResizeHandle->setVisible(TRUE);
00274 }
00275 else
00276 {
00277 mResizeHandle->setVisible(FALSE);
00278 }
00279 }
00280 #endif // LL_DARWIN
00281
00282
00283
00284 F32 segment_width = (F32)(width + pad) / (F32)count;
00285 S32 btn_width = lltrunc(segment_width - pad);
00286
00287
00288 S32 height = -1;
00289 S32 i = count - 1;
00290 for (child_list_const_iter_t child_iter = getChildList()->begin();
00291 child_iter != getChildList()->end(); ++child_iter)
00292 {
00293 LLView *btn_view = *child_iter;
00294 if(btn_view->getWidgetType() == WIDGET_TYPE_BUTTON)
00295 {
00296 if (height < 0)
00297 {
00298 height = btn_view->getRect().getHeight();
00299 }
00300 S32 x = llround(i*segment_width);
00301 S32 y = 0;
00302 LLRect r;
00303 r.setOriginAndSize(x, y, btn_width, height);
00304 btn_view->setRect(r);
00305 i--;
00306 }
00307 }
00308 }
00309
00310
00311
00312 void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent)
00313 {
00314 LLPanel::reshape(width, height, called_from_parent);
00315
00316 layoutButtons();
00317 }
00318
00319
00320
00321 void LLToolBar::refresh()
00322 {
00323 BOOL show = gSavedSettings.getBOOL("ShowToolBar");
00324 BOOL mouselook = gAgent.cameraMouselook();
00325 setVisible(show && !mouselook);
00326
00327
00328
00329 childSetEnabled("fly_btn", gAgent.canFly() || gAgent.getFlying() );
00330
00331 childSetEnabled("build_btn", gParcelMgr->agentCanBuild() );
00332
00333
00334 BOOL build_mode = gToolMgr->inEdit();
00335
00336 if (gToolGrab->getHideBuildHighlight())
00337 {
00338 build_mode = FALSE;
00339 }
00340 gSavedSettings.setBOOL("BuildBtnState", build_mode);
00341 }
00342
00343
00344
00345 void LLToolBar::onClickCommunicate(void* user_data)
00346 {
00347 LLFloaterChatterBox::toggleInstance(LLSD());
00348 }
00349
00350
00351
00352 void LLToolBar::onClickChat(void* user_data)
00353 {
00354 handle_chat(NULL);
00355 }
00356
00357
00358 void LLToolBar::onClickAppearance(void*)
00359 {
00360 if (gAgent.getWearablesLoaded())
00361 {
00362 gAgent.changeCameraToCustomizeAvatar();
00363 }
00364 }
00365
00366
00367
00368 void LLToolBar::onClickClothing(void*)
00369 {
00370 handle_clothing(NULL);
00371 }
00372
00373
00374
00375 void LLToolBar::onClickFly(void*)
00376 {
00377 gAgent.toggleFlying();
00378 }
00379
00380
00381
00382 void LLToolBar::onClickSit(void*)
00383 {
00384 if (!(gAgent.getControlFlags() & AGENT_CONTROL_SIT_ON_GROUND))
00385 {
00386
00387 gAgent.setFlying(FALSE);
00388 gAgent.setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
00389
00390
00391 LLFirstUse::useSit();
00392 }
00393 else
00394 {
00395
00396 gAgent.setFlying(FALSE);
00397 gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
00398 }
00399 }
00400
00401
00402
00403 void LLToolBar::onClickSnapshot(void*)
00404 {
00405 LLFloaterSnapshot::show (0);
00406 }
00407
00408
00409
00410 void LLToolBar::onClickDirectory(void*)
00411 {
00412 handle_find(NULL);
00413 }
00414
00415
00416
00417 void LLToolBar::onClickBuild(void*)
00418 {
00419 toggle_build_mode();
00420 }
00421
00422
00423
00424 void LLToolBar::onClickRadar(void*)
00425 {
00426 handle_mini_map(NULL);
00427 }
00428
00429
00430
00431 void LLToolBar::onClickMap(void*)
00432 {
00433 handle_map(NULL);
00434 }
00435
00436
00437 void LLToolBar::onClickEventLog(void*)
00438 {
00439 LLFloaterEventLog::toggle(NULL);
00440 }
00441
00442
00443 void LLToolBar::onClickInventory(void*)
00444 {
00445 handle_inventory(NULL);
00446 }
00447
00448
00449 void LLToolBar::onClickAvatarList(void*)
00450 {
00451 LLFloaterAvatarList::toggle(NULL);
00452 }