00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "lltoolview.h"
00035
00036 #include "llfontgl.h"
00037 #include "llrect.h"
00038
00039 #include "llagent.h"
00040 #include "llbutton.h"
00041 #include "llpanel.h"
00042 #include "lltool.h"
00043 #include "lltoolmgr.h"
00044 #include "lltextbox.h"
00045 #include "llresmgr.h"
00046
00047
00048 LLToolContainer::LLToolContainer(LLToolView* parent)
00049 : mParent(parent),
00050 mButton(NULL),
00051 mPanel(NULL),
00052 mTool(NULL)
00053 { }
00054
00055
00056 LLToolContainer::~LLToolContainer()
00057 {
00058
00059
00060
00061 delete mTool;
00062 mTool = NULL;
00063 }
00064
00065
00066 LLToolView::LLToolView(const std::string& name, const LLRect& rect)
00067 : LLView(name, rect, MOUSE_OPAQUE),
00068 mButtonCount(0)
00069 {
00070 }
00071
00072
00073 LLToolView::~LLToolView()
00074 {
00075 for_each(mContainList.begin(), mContainList.end(), DeletePointer());
00076 mContainList.clear();
00077 }
00078
00079
00080 void LLToolView::addTool(const LLString& icon_off, const LLString& icon_on, LLPanel* panel, LLTool* tool, LLView* hoverView, const char* label)
00081 {
00082 llassert(tool);
00083
00084 LLToolContainer* contain = new LLToolContainer(this);
00085
00086 LLRect btn_rect = getButtonRect(mButtonCount);
00087
00088 contain->mButton = new LLButton("ToolBtn",
00089 btn_rect,
00090 icon_off,
00091 icon_on,
00092 "",
00093 &LLToolView::onClickToolButton,
00094 contain,
00095 LLFontGL::sSansSerif);
00096
00097 contain->mPanel = panel;
00098 contain->mTool = tool;
00099
00100 addChild(contain->mButton);
00101 mButtonCount++;
00102
00103 const S32 LABEL_TOP_SPACING = 0;
00104 const LLFontGL* font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL );
00105 S32 label_width = font->getWidth( label );
00106 LLRect label_rect;
00107 label_rect.setLeftTopAndSize(
00108 btn_rect.mLeft + btn_rect.getWidth() / 2 - label_width / 2,
00109 btn_rect.mBottom - LABEL_TOP_SPACING,
00110 label_width,
00111 llfloor(font->getLineHeight()));
00112 addChild( new LLTextBox( "tool label", label_rect, label, font ) );
00113
00114
00115 if (contain->mPanel)
00116 {
00117 contain->mPanel->setBackgroundVisible( FALSE );
00118 contain->mPanel->setBorderVisible( FALSE );
00119 addChild(contain->mPanel);
00120 }
00121
00122 mContainList.push_back(contain);
00123 }
00124
00125
00126 LLRect LLToolView::getButtonRect(S32 button_index)
00127 {
00128 const S32 HPAD = 7;
00129 const S32 VPAD = 7;
00130 const S32 TOOL_SIZE = 32;
00131 const S32 HORIZ_SPACING = TOOL_SIZE + 5;
00132 const S32 VERT_SPACING = TOOL_SIZE + 14;
00133
00134 S32 tools_per_row = getRect().getWidth() / HORIZ_SPACING;
00135
00136 S32 row = button_index / tools_per_row;
00137 S32 column = button_index % tools_per_row;
00138
00139
00140
00141 LLRect rect;
00142 rect.setLeftTopAndSize( HPAD + (column * HORIZ_SPACING),
00143 -VPAD + getRect().getHeight() - (row * VERT_SPACING),
00144 TOOL_SIZE,
00145 TOOL_SIZE
00146 );
00147
00148 return rect;
00149 }
00150
00151
00152 void LLToolView::draw()
00153 {
00154
00155
00156 LLTool* selected = LLToolMgr::getInstance()->getCurrentToolset()->getSelectedTool();
00157 for (contain_list_t::iterator iter = mContainList.begin();
00158 iter != mContainList.end(); ++iter)
00159 {
00160 LLToolContainer* contain = *iter;
00161 BOOL state = (contain->mTool == selected);
00162 contain->mButton->setToggleState( state );
00163 if (contain->mPanel)
00164 {
00165 contain->mPanel->setVisible( state );
00166 }
00167 }
00168
00169
00170 LLView::draw();
00171 }
00172
00173
00174 LLToolContainer* LLToolView::findToolContainer( LLTool *tool )
00175 {
00176
00177 llassert( tool );
00178 for (contain_list_t::iterator iter = mContainList.begin();
00179 iter != mContainList.end(); ++iter)
00180 {
00181 LLToolContainer* contain = *iter;
00182 if( contain->mTool == tool )
00183 {
00184 return contain;
00185 }
00186 }
00187 llerrs << "LLToolView::findToolContainer - tool not found" << llendl;
00188 return NULL;
00189 }
00190
00191
00192 void LLToolView::onClickToolButton(void* userdata)
00193 {
00194 LLToolContainer* clicked = (LLToolContainer*) userdata;
00195
00196
00197 LLToolMgr::getInstance()->getCurrentToolset()->selectTool( clicked->mTool );
00198 }
00199
00200
00201