PageRenderTime 374ms CodeModel.GetById 92ms app.highlight 9ms RepoModel.GetById 203ms app.codeStats 0ms

/indra/newview/lltoolpipette.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 136 lines | 79 code | 20 blank | 37 comment | 7 complexity | 292ddd728f2915a52879b56517a60d18 MD5 | raw file
  1/** 
  2 * @file lltoolpipette.cpp
  3 * @brief LLToolPipette class implementation
  4 *
  5 * $LicenseInfo:firstyear=2006&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 * A tool to pick texture entry infro from objects in world (color/texture)
 29 */
 30
 31#include "llviewerprecompiledheaders.h"
 32
 33// File includes
 34#include "lltoolpipette.h" 
 35
 36// Library includes
 37#include "lltooltip.h"
 38
 39// Viewer includes
 40#include "llviewerobjectlist.h"
 41#include "llviewerwindow.h"
 42#include "llselectmgr.h"
 43#include "lltoolmgr.h"
 44
 45//
 46// Member functions
 47//
 48
 49LLToolPipette::LLToolPipette()
 50:	LLTool(std::string("Pipette")),
 51	mSuccess(TRUE)
 52{ 
 53}
 54
 55
 56LLToolPipette::~LLToolPipette()
 57{ }
 58
 59
 60BOOL LLToolPipette::handleMouseDown(S32 x, S32 y, MASK mask)
 61{
 62	mSuccess = TRUE;
 63	mTooltipMsg.clear();
 64	setMouseCapture(TRUE);
 65	gViewerWindow->pickAsync(x, y, mask, pickCallback);
 66	return TRUE;
 67}
 68
 69BOOL LLToolPipette::handleMouseUp(S32 x, S32 y, MASK mask)
 70{
 71	mSuccess = TRUE;
 72	LLSelectMgr::getInstance()->unhighlightAll();
 73	// *NOTE: This assumes the pipette tool is a transient tool.
 74	LLToolMgr::getInstance()->clearTransientTool();
 75	setMouseCapture(FALSE);
 76	return TRUE;
 77}
 78
 79BOOL LLToolPipette::handleHover(S32 x, S32 y, MASK mask)
 80{
 81	gViewerWindow->setCursor(mSuccess ? UI_CURSOR_PIPETTE : UI_CURSOR_NO);
 82	if (hasMouseCapture()) // mouse button is down
 83	{
 84		gViewerWindow->pickAsync(x, y, mask, pickCallback);
 85		return TRUE;
 86	}
 87	return FALSE;
 88}
 89
 90BOOL LLToolPipette::handleToolTip(S32 x, S32 y, MASK mask)
 91{
 92	if (mTooltipMsg.empty())
 93	{
 94		return FALSE;
 95	}
 96
 97	LLRect sticky_rect;
 98	sticky_rect.setCenterAndSize(x, y, 20, 20);
 99	LLToolTipMgr::instance().show(LLToolTip::Params()
100		.message(mTooltipMsg)
101		.sticky_rect(sticky_rect));
102
103	return TRUE;
104}
105
106void LLToolPipette::setTextureEntry(const LLTextureEntry* entry)
107{
108	if (entry)
109	{
110		mTextureEntry = *entry;
111		mSignal(mTextureEntry);
112	}
113}
114
115void LLToolPipette::pickCallback(const LLPickInfo& pick_info)
116{
117	LLViewerObject* hit_obj	= pick_info.getObject();
118	LLSelectMgr::getInstance()->unhighlightAll();
119
120	// if we clicked on a face of a valid prim, save off texture entry data
121	if (hit_obj && 
122		hit_obj->getPCode() == LL_PCODE_VOLUME &&
123		pick_info.mObjectFace != -1)
124	{
125		//TODO: this should highlight the selected face only
126		LLSelectMgr::getInstance()->highlightObjectOnly(hit_obj);
127		const LLTextureEntry* entry = hit_obj->getTE(pick_info.mObjectFace);
128		LLToolPipette::getInstance()->setTextureEntry(entry);
129	}
130}
131
132void LLToolPipette::setResult(BOOL success, const std::string& msg)
133{
134	mTooltipMsg = msg;
135	mSuccess = success;
136}