PageRenderTime 70ms CodeModel.GetById 35ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llinspect.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 149 lines | 95 code | 17 blank | 37 comment | 10 complexity | 0cf16757233335305bbb725cffdb008f MD5 | raw file
  1/** 
  2 * @file llinspect.cpp
  3 *
  4 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  5 * Second Life Viewer Source Code
  6 * Copyright (C) 2010, Linden Research, Inc.
  7 * 
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation;
 11 * version 2.1 of the License only.
 12 * 
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16 * Lesser General Public License for more details.
 17 * 
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 21 * 
 22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 23 * $/LicenseInfo$
 24 */
 25#include "llviewerprecompiledheaders.h"
 26
 27#include "llinspect.h"
 28
 29#include "lltooltip.h"
 30#include "llcontrol.h"	// LLCachedControl
 31#include "llui.h"		// LLUI::sSettingsGroups
 32#include "llviewermenu.h"
 33
 34LLInspect::LLInspect(const LLSD& key)
 35:	LLFloater(key),
 36	mCloseTimer(),
 37	mOpenTimer()
 38{
 39}
 40
 41LLInspect::~LLInspect()
 42{
 43}
 44
 45// virtual
 46void LLInspect::draw()
 47{
 48	static LLCachedControl<F32> FADE_TIME(*LLUI::sSettingGroups["config"], "InspectorFadeTime", 1.f);
 49	static LLCachedControl<F32> STAY_TIME(*LLUI::sSettingGroups["config"], "InspectorShowTime", 1.f);
 50	if (mOpenTimer.getStarted())
 51	{
 52		LLFloater::draw();
 53		if (mOpenTimer.getElapsedTimeF32() > STAY_TIME)
 54		{
 55			mOpenTimer.stop();
 56			mCloseTimer.start();
 57		}
 58
 59	}
 60	else if (mCloseTimer.getStarted())
 61	{
 62		F32 alpha = clamp_rescale(mCloseTimer.getElapsedTimeF32(), 0.f, FADE_TIME, 1.f, 0.f);
 63		LLViewDrawContext context(alpha);
 64		LLFloater::draw();
 65		if (mCloseTimer.getElapsedTimeF32() > FADE_TIME)
 66		{
 67			closeFloater(false);
 68		}
 69	}
 70	else
 71	{
 72		LLFloater::draw();
 73	}
 74}
 75
 76// virtual
 77void LLInspect::onOpen(const LLSD& data)
 78{
 79	LLFloater::onOpen(data);
 80	
 81	mCloseTimer.stop();
 82	mOpenTimer.start();
 83}
 84
 85// virtual
 86void LLInspect::onFocusLost()
 87{
 88	LLFloater::onFocusLost();
 89	
 90	// Start closing when we lose focus
 91	mCloseTimer.start();
 92	mOpenTimer.stop();
 93}
 94
 95// virtual
 96BOOL LLInspect::handleHover(S32 x, S32 y, MASK mask)
 97{
 98	mOpenTimer.pause();
 99	return LLView::handleHover(x, y, mask);
100}
101
102BOOL LLInspect::handleToolTip(S32 x, S32 y, MASK mask)
103{
104	BOOL handled = FALSE;
105
106
107	//delegate handling of tooltip to the hovered child
108	LLView* child_handler = childFromPoint(x,y);
109	if (child_handler && !child_handler->getToolTip().empty())// show tooltip if a view has non-empty tooltip message
110	{
111		//build LLInspector params to get correct tooltip setting, etc. background image
112		LLInspector::Params params;
113		params.fillFrom(LLUICtrlFactory::instance().getDefaultParams<LLInspector>());
114		params.message = child_handler->getToolTip();
115		//set up delay if there is no visible tooltip at this moment
116		params.delay_time =  LLToolTipMgr::instance().toolTipVisible() ? 0.f : LLUI::sSettingGroups["config"]->getF32( "ToolTipDelay" );
117		LLToolTipMgr::instance().show(params);
118		handled = TRUE;
119	}
120	return handled;
121}
122// virtual
123void LLInspect::onMouseLeave(S32 x, S32 y, MASK mask)
124{
125	mOpenTimer.unpause();
126}
127
128bool LLInspect::childHasVisiblePopupMenu()
129{
130	// Child text-box may spawn a pop-up menu, if mouse is over the menu, Inspector 
131	// will hide(which is not expected).
132	// This is an attempt to find out if child control has spawned a menu.
133
134	LLView* child_menu = gMenuHolder->getVisibleMenu();
135	if(child_menu)
136	{
137		LLRect floater_rc = calcScreenRect();
138		LLRect menu_screen_rc = child_menu->calcScreenRect();
139		S32 mx, my;
140		LLUI::getMousePositionScreen(&mx, &my);
141
142		// This works wrong if we spawn a menu near Inspector and menu overlaps Inspector.
143		if(floater_rc.overlaps(menu_screen_rc) && menu_screen_rc.pointInRect(mx, my))
144		{
145			return true;
146		}
147	}
148	return false;
149}