PageRenderTime 48ms CodeModel.GetById 35ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lltoggleablemenu.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 101 lines | 60 code | 15 blank | 26 comment | 6 complexity | e2ce03a036261754643bd53d2d2f05ce MD5 | raw file
  1/** 
  2 * @file lltoggleablemenu.cpp
  3 * @brief Menu toggled by a button press
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27
 28#include "linden_common.h"
 29
 30#include "lltoggleablemenu.h"
 31#include "lluictrlfactory.h"
 32
 33static LLDefaultChildRegistry::Register<LLToggleableMenu> r("toggleable_menu");
 34
 35LLToggleableMenu::LLToggleableMenu(const LLToggleableMenu::Params& p)
 36:	LLMenuGL(p),
 37	mButtonRect(),
 38	mVisibilityChangeSignal(NULL),
 39	mClosedByButtonClick(false)
 40{
 41}
 42
 43LLToggleableMenu::~LLToggleableMenu()
 44{
 45	delete mVisibilityChangeSignal;
 46}
 47
 48boost::signals2::connection LLToggleableMenu::setVisibilityChangeCallback(const commit_signal_t::slot_type& cb)
 49{
 50	if (!mVisibilityChangeSignal) mVisibilityChangeSignal = new commit_signal_t();
 51	return mVisibilityChangeSignal->connect(cb);
 52}
 53
 54// virtual
 55void LLToggleableMenu::handleVisibilityChange (BOOL curVisibilityIn)
 56{
 57	S32 x,y;
 58	LLUI::getMousePositionLocal(LLUI::getRootView(), &x, &y);
 59
 60	if (!curVisibilityIn && mButtonRect.pointInRect(x, y))
 61	{
 62		mClosedByButtonClick = true;
 63	}
 64
 65	if (mVisibilityChangeSignal)
 66	{
 67		(*mVisibilityChangeSignal)(this,
 68				LLSD().with("visibility", curVisibilityIn).with("closed_by_button_click", mClosedByButtonClick));
 69	}
 70}
 71
 72void LLToggleableMenu::setButtonRect(const LLRect& rect, LLView* current_view)
 73{
 74	LLRect screen;
 75	current_view->localRectToScreen(rect, &screen);
 76	mButtonRect = screen;
 77}
 78
 79void LLToggleableMenu::setButtonRect(LLView* current_view)
 80{
 81	LLRect rect = current_view->getLocalRect();
 82	setButtonRect(rect, current_view);
 83}
 84
 85bool LLToggleableMenu::toggleVisibility() 
 86{
 87	if (mClosedByButtonClick)
 88	{
 89		mClosedByButtonClick = false;
 90		return false;
 91	}
 92
 93	if (getVisible())
 94	{
 95		setVisible(FALSE);
 96		mClosedByButtonClick = false;
 97		return false;
 98	}
 99
100	return true;
101}