aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltoolview.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lltoolview.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/lltoolview.cpp194
1 files changed, 194 insertions, 0 deletions
diff --git a/linden/indra/newview/lltoolview.cpp b/linden/indra/newview/lltoolview.cpp
new file mode 100644
index 0000000..5b80339
--- /dev/null
+++ b/linden/indra/newview/lltoolview.cpp
@@ -0,0 +1,194 @@
1/**
2 * @file lltoolview.cpp
3 * @brief A UI contains for tool palette tools
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "lltoolview.h"
31
32#include "llfontgl.h"
33#include "llrect.h"
34
35#include "llagent.h"
36#include "llbutton.h"
37#include "llpanel.h"
38#include "lltool.h"
39#include "lltoolmgr.h"
40#include "lltextbox.h"
41#include "llresmgr.h"
42
43
44LLToolContainer::LLToolContainer(LLToolView* parent)
45: mParent(parent),
46 mButton(NULL),
47 mPanel(NULL),
48 mTool(NULL)
49{ }
50
51
52LLToolContainer::~LLToolContainer()
53{
54 // mParent is a pointer to the tool view
55 // mButton is owned by the tool view
56 // mPanel is owned by the tool view
57 delete mTool;
58 mTool = NULL;
59}
60
61
62LLToolView::LLToolView(const std::string& name, const LLRect& rect)
63: LLView(name, rect, MOUSE_OPAQUE),
64 mButtonCount(0)
65{
66}
67
68
69LLToolView::~LLToolView()
70{
71 mContainList.deleteAllData();
72}
73
74//XUI: translate
75void LLToolView::addTool(const LLString& icon_off, const LLString& 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::sSansSerif);
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 = gResMgr->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.addData(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 = mRect.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 = gCurrentToolset->getSelectedTool();
152 for( LLToolContainer* contain = mContainList.getFirstData();
153 contain != NULL;
154 contain = mContainList.getNextData()
155 )
156 {
157 BOOL state = (contain->mTool == selected);
158 contain->mButton->setToggleState( state );
159 if (contain->mPanel)
160 {
161 contain->mPanel->setVisible( state );
162 }
163 }
164
165 // Draw children normally
166 LLView::draw();
167}
168
169// protected
170LLToolContainer* LLToolView::findToolContainer( LLTool *tool )
171{
172 // Find the container for this tool
173 llassert( tool );
174 for( LLToolContainer* contain = mContainList.getFirstData(); contain; contain = mContainList.getNextData() )
175 {
176 if( contain->mTool == tool )
177 {
178 return contain;
179 }
180 }
181 llerrs << "LLToolView::findToolContainer - tool not found" << llendl;
182 return NULL;
183}
184
185// static
186void LLToolView::onClickToolButton(void* userdata)
187{
188 LLToolContainer* clicked = (LLToolContainer*) userdata;
189
190 // Switch to this one
191 gCurrentToolset->selectTool( clicked->mTool );
192 gToolMgr->useSelectedTool( gCurrentToolset );
193}
194