PageRenderTime 118ms CodeModel.GetById 82ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/lltoolview.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 196 lines | 86 code | 36 blank | 74 comment | 8 complexity | 59c357dff9ce6610b770f6e26d757e83 MD5 | raw file
  1/** 
  2 * @file lltoolview.cpp
  3 * @brief A UI contains for tool palette tools
  4 *
  5 * $LicenseInfo:firstyear=2001&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#include "llviewerprecompiledheaders.h"
 28
 29#include "lltoolview.h"
 30
 31#include "llfontgl.h"
 32#include "llrect.h"
 33
 34#include "llagent.h"
 35#include "llbutton.h"
 36#include "llpanel.h"
 37#include "lltool.h"
 38#include "lltoolmgr.h"
 39#include "lltextbox.h"
 40#include "llresmgr.h"
 41
 42
 43LLToolContainer::LLToolContainer(LLToolView* parent)
 44:	mParent(parent),
 45	mButton(NULL),
 46	mPanel(NULL),
 47	mTool(NULL)
 48{ }
 49
 50
 51LLToolContainer::~LLToolContainer()
 52{
 53	// mParent is a pointer to the tool view
 54	// mButton is owned by the tool view
 55	// mPanel is owned by the tool view
 56	delete mTool;
 57	mTool = NULL;
 58}
 59
 60
 61LLToolView::LLToolView(const std::string& name, const LLRect& rect)
 62:	mButtonCount(0)
 63{
 64	LLView::init(LLView::Params().name(name).rect(rect).mouse_opaque(true));
 65}
 66
 67
 68LLToolView::~LLToolView()
 69{
 70	for_each(mContainList.begin(), mContainList.end(), DeletePointer());
 71	mContainList.clear();
 72}
 73
 74//*TODO:translate?
 75// void LLToolView::addTool(const std::string& icon_off, const std::string& icon_on, LLPanel* panel, LLTool* tool, LLView* hoverView, const char* label)
 76// {
 77// 	llassert(tool);
 78
 79// 	LLToolContainer* contain = new LLToolContainer(this);
 80
 81// 	LLRect btn_rect = getButtonRect(mButtonCount);
 82
 83// 	contain->mButton = new LLButton("ToolBtn",
 84// 		btn_rect, 
 85// 		icon_off,
 86// 		icon_on, 
 87// 		"",
 88// 		&LLToolView::onClickToolButton,
 89// 		contain,
 90// 		LLFontGL::getFontSansSerif());
 91
 92// 	contain->mPanel = panel;
 93// 	contain->mTool = tool;
 94
 95// 	addChild(contain->mButton);
 96// 	mButtonCount++;
 97
 98// 	const S32 LABEL_TOP_SPACING = 0;
 99// 	const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL );
100// 	S32 label_width = font->getWidth( label );
101// 	LLRect label_rect;
102// 	label_rect.setLeftTopAndSize( 
103// 		btn_rect.mLeft + btn_rect.getWidth() / 2 - label_width / 2,
104// 		btn_rect.mBottom - LABEL_TOP_SPACING,
105// 		label_width, 
106// 		llfloor(font->getLineHeight()));
107// 	addChild( new LLTextBox( "tool label", label_rect, label, font ) );
108
109// 	// Can optionally ignore panel
110// 	if (contain->mPanel)
111// 	{
112// 		contain->mPanel->setBackgroundVisible( FALSE );
113// 		contain->mPanel->setBorderVisible( FALSE );
114// 		addChild(contain->mPanel);
115// 	}
116
117// 	mContainList.push_back(contain);
118// }
119
120
121LLRect LLToolView::getButtonRect(S32 button_index)
122{
123	const S32 HPAD = 7;
124	const S32 VPAD = 7;
125	const S32 TOOL_SIZE = 32;
126	const S32 HORIZ_SPACING = TOOL_SIZE + 5;
127	const S32 VERT_SPACING = TOOL_SIZE + 14;
128
129	S32 tools_per_row = getRect().getWidth() / HORIZ_SPACING;
130
131	S32 row = button_index / tools_per_row;
132	S32 column = button_index % tools_per_row; 
133
134	// Build the rectangle, recalling the origin is at lower left
135	// and we want the icons to build down from the top.
136	LLRect rect;
137	rect.setLeftTopAndSize( HPAD + (column * HORIZ_SPACING),
138							-VPAD + getRect().getHeight() - (row * VERT_SPACING),
139							TOOL_SIZE,
140							TOOL_SIZE
141							);
142
143	return rect;
144}
145
146
147void LLToolView::draw()
148{
149	// turn off highlighting for all containers 
150	// and hide all option panels except for the selected one.
151	LLTool* selected = LLToolMgr::getInstance()->getCurrentToolset()->getSelectedTool();
152	for (contain_list_t::iterator iter = mContainList.begin();
153		 iter != mContainList.end(); ++iter)
154	{
155		LLToolContainer* contain = *iter;
156		BOOL state = (contain->mTool == selected);
157		contain->mButton->setToggleState( state );
158		if (contain->mPanel)
159		{
160			contain->mPanel->setVisible( state );
161		}
162	}
163
164	// Draw children normally
165	LLView::draw();
166}
167
168// protected
169LLToolContainer* LLToolView::findToolContainer( LLTool *tool )
170{
171	// Find the container for this tool
172	llassert( tool );
173	for (contain_list_t::iterator iter = mContainList.begin();
174		 iter != mContainList.end(); ++iter)
175	{
176		LLToolContainer* contain = *iter;
177		if( contain->mTool == tool )
178		{
179			return contain;
180		}
181	}
182	llerrs << "LLToolView::findToolContainer - tool not found" << llendl;
183	return NULL;
184}
185
186// static
187void LLToolView::onClickToolButton(void* userdata)
188{
189	LLToolContainer* clicked = (LLToolContainer*) userdata;
190
191	// Switch to this one
192	LLToolMgr::getInstance()->getCurrentToolset()->selectTool( clicked->mTool );
193}
194
195
196