summaryrefslogtreecommitdiff
path: root/indra/newview/llnavigationbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llnavigationbar.cpp')
-rw-r--r--indra/newview/llnavigationbar.cpp137
1 files changed, 117 insertions, 20 deletions
diff --git a/indra/newview/llnavigationbar.cpp b/indra/newview/llnavigationbar.cpp
index 71dc0f9011..59708fcfb5 100644
--- a/indra/newview/llnavigationbar.cpp
+++ b/indra/newview/llnavigationbar.cpp
@@ -34,6 +34,8 @@
#include "llnavigationbar.h"
+#include "v2math.h"
+
#include "llregionhandle.h"
#include "llfloaterreg.h"
@@ -181,6 +183,77 @@ void LLTeleportHistoryMenuItem::onMouseLeave(S32 x, S32 y, MASK mask)
mArrowIcon->setVisible(FALSE);
}
+static LLDefaultChildRegistry::Register<LLPullButton> menu_button("pull_button");
+
+LLPullButton::LLPullButton(const LLPullButton::Params& params):
+ LLButton(params)
+ , mClickDraggingSignal(NULL)
+{
+ setDirectionFromName(params.direction);
+}
+boost::signals2::connection LLPullButton::setClickDraggingCallback( const commit_signal_t::slot_type& cb )
+{
+ if (!mClickDraggingSignal) mClickDraggingSignal = new commit_signal_t();
+ return mClickDraggingSignal->connect(cb);
+}
+
+/*virtual*/
+void LLPullButton::onMouseLeave(S32 x, S32 y, MASK mask)
+{
+ LLButton::onMouseLeave(x, y, mask);
+
+ if(mMouseDownTimer.getStarted() )
+ {
+ const LLVector2 cursor_direction = LLVector2(F32(x),F32(y)) - mLastMouseDown;
+ if( angle_between(mDraggingDirection, cursor_direction) < 0.5 * F_PI_BY_TWO)//call if angle < pi/4
+ {
+ if(mClickDraggingSignal)
+ {
+ (*mClickDraggingSignal)(this, LLSD());
+ }
+ }
+ }
+
+}
+
+/*virtual*/
+BOOL LLPullButton::handleMouseDown(S32 x, S32 y, MASK mask)
+ {
+ BOOL handled = LLButton::handleMouseDown(x,y, mask);
+ if(handled)
+ {
+ mLastMouseDown.set(F32(x), F32(y));
+ }
+ return handled;
+}
+
+/*virtual*/
+BOOL LLPullButton::handleMouseUp(S32 x, S32 y, MASK mask)
+{
+ mLastMouseDown.clear();
+ return LLButton::handleMouseUp(x, y, mask);
+}
+
+void LLPullButton::setDirectionFromName(const std::string& name)
+{
+ if (name == "left")
+ {
+ mDraggingDirection.set(F32(-1), F32(0));
+ }
+ else if (name == "right")
+ {
+ mDraggingDirection.set(F32(0), F32(1));
+ }
+ else if (name == "down")
+ {
+ mDraggingDirection.set(F32(0), F32(-1));
+ }
+ else if (name == "up")
+ {
+ mDraggingDirection.set(F32(0), F32(1));
+ }
+}
+
//-- LNavigationBar ----------------------------------------------------------
/*
@@ -215,8 +288,8 @@ LLNavigationBar::~LLNavigationBar()
BOOL LLNavigationBar::postBuild()
{
- mBtnBack = getChild<LLButton>("back_btn");
- mBtnForward = getChild<LLButton>("forward_btn");
+ mBtnBack = getChild<LLPullButton>("back_btn");
+ mBtnForward = getChild<LLPullButton>("forward_btn");
mBtnHome = getChild<LLButton>("home_btn");
mCmbLocation= getChild<LLLocationInputCtrl>("location_combo");
@@ -224,20 +297,15 @@ BOOL LLNavigationBar::postBuild()
fillSearchComboBox();
- if (!mBtnBack || !mBtnForward || !mBtnHome ||
- !mCmbLocation || !mSearchComboBox)
- {
- llwarns << "Malformed navigation bar" << llendl;
- return FALSE;
- }
-
mBtnBack->setEnabled(FALSE);
mBtnBack->setClickedCallback(boost::bind(&LLNavigationBar::onBackButtonClicked, this));
- mBtnBack->setHeldDownCallback(boost::bind(&LLNavigationBar::onBackOrForwardButtonHeldDown, this, _2));
-
+ mBtnBack->setHeldDownCallback(boost::bind(&LLNavigationBar::onBackOrForwardButtonHeldDown, this,_1, _2));
+ mBtnBack->setClickDraggingCallback(boost::bind(&LLNavigationBar::showTeleportHistoryMenu, this,_1));
+
mBtnForward->setEnabled(FALSE);
mBtnForward->setClickedCallback(boost::bind(&LLNavigationBar::onForwardButtonClicked, this));
- mBtnForward->setHeldDownCallback(boost::bind(&LLNavigationBar::onBackOrForwardButtonHeldDown, this, _2));
+ mBtnForward->setHeldDownCallback(boost::bind(&LLNavigationBar::onBackOrForwardButtonHeldDown, this, _1, _2));
+ mBtnForward->setClickDraggingCallback(boost::bind(&LLNavigationBar::showTeleportHistoryMenu, this,_1));
mBtnHome->setClickedCallback(boost::bind(&LLNavigationBar::onHomeButtonClicked, this));
@@ -332,10 +400,10 @@ void LLNavigationBar::onBackButtonClicked()
LLTeleportHistory::getInstance()->goBack();
}
-void LLNavigationBar::onBackOrForwardButtonHeldDown(const LLSD& param)
+void LLNavigationBar::onBackOrForwardButtonHeldDown(LLUICtrl* ctrl, const LLSD& param)
{
if (param["count"].asInteger() == 0)
- showTeleportHistoryMenu();
+ showTeleportHistoryMenu(ctrl);
}
void LLNavigationBar::onForwardButtonClicked()
@@ -571,7 +639,7 @@ void LLNavigationBar::onRegionNameResponse(
gAgent.teleportViaLocation(global_pos);
}
-void LLNavigationBar::showTeleportHistoryMenu()
+void LLNavigationBar::showTeleportHistoryMenu(LLUICtrl* btn_ctrl)
{
// Don't show the popup if teleport history is empty.
if (LLTeleportHistory::getInstance()->isEmpty())
@@ -585,14 +653,43 @@ void LLNavigationBar::showTeleportHistoryMenu()
if (mTeleportHistoryMenu == NULL)
return;
- // *TODO: why to draw/update anything before showing the menu?
- mTeleportHistoryMenu->buildDrawLabels();
mTeleportHistoryMenu->updateParent(LLMenuGL::sMenuContainer);
const S32 MENU_SPAWN_PAD = -1;
- LLMenuGL::showPopup(mBtnBack, mTeleportHistoryMenu, 0, MENU_SPAWN_PAD);
-
+ LLMenuGL::showPopup(btn_ctrl, mTeleportHistoryMenu, 0, MENU_SPAWN_PAD);
+ LLButton* nav_button = dynamic_cast<LLButton*>(btn_ctrl);
+ if(nav_button)
+ {
+ if(mHistoryMenuConnection.connected())
+ {
+ LL_WARNS("Navgationbar")<<"mHistoryMenuConnection should be disconnected at this moment."<<LL_ENDL;
+ mHistoryMenuConnection.disconnect();
+ }
+ mHistoryMenuConnection = gMenuHolder->setMouseUpCallback(boost::bind(&LLNavigationBar::onNavigationButtonHeldUp, this, nav_button));
+ // pressed state will be update after mouseUp in onBackOrForwardButtonHeldUp();
+ nav_button->setForcePressedState(true);
+ }
// *HACK pass the mouse capturing to the drop-down menu
- gFocusMgr.setMouseCapture( NULL );
+ // it need to let menu handle mouseup event
+ gFocusMgr.setMouseCapture(gMenuHolder);
+}
+/**
+ * Taking into account the HACK above, this callback-function is responsible for correct handling of mouseUp event in case of holding-down the navigation buttons..
+ * We need to process this case separately to update a pressed state of navigation button.
+ */
+void LLNavigationBar::onNavigationButtonHeldUp(LLButton* nav_button)
+{
+ if(nav_button)
+ {
+ nav_button->setForcePressedState(false);
+ }
+ if(gFocusMgr.getMouseCapture() == gMenuHolder)
+ {
+ // we had passed mouseCapture in showTeleportHistoryMenu()
+ // now we MUST release mouseCapture to continue a proper mouseevent workflow.
+ gFocusMgr.setMouseCapture(NULL);
+ }
+ //gMenuHolder is using to display bunch of menus. Disconnect signal to avoid unnecessary calls.
+ mHistoryMenuConnection.disconnect();
}
void LLNavigationBar::handleLoginComplete()