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 mContainList.deleteAllData();
00076 }
00077
00078
00079 void LLToolView::addTool(const LLString& icon_off, const LLString& icon_on, LLPanel* panel, LLTool* tool, LLView* hoverView, const char* label)
00080 {
00081 llassert(tool);
00082
00083 LLToolContainer* contain = new LLToolContainer(this);
00084
00085 LLRect btn_rect = getButtonRect(mButtonCount);
00086
00087 contain->mButton = new LLButton("ToolBtn",
00088 btn_rect,
00089 icon_off,
00090 icon_on,
00091 "",
00092 &LLToolView::onClickToolButton,
00093 contain,
00094 LLFontGL::sSansSerif);
00095
00096 contain->mPanel = panel;
00097 contain->mTool = tool;
00098
00099 addChild(contain->mButton);
00100 mButtonCount++;
00101
00102 const S32 LABEL_TOP_SPACING = 0;
00103 const LLFontGL* font = gResMgr->getRes( LLFONT_SANSSERIF_SMALL );
00104 S32 label_width = font->getWidth( label );
00105 LLRect label_rect;
00106 label_rect.setLeftTopAndSize(
00107 btn_rect.mLeft + btn_rect.getWidth() / 2 - label_width / 2,
00108 btn_rect.mBottom - LABEL_TOP_SPACING,
00109 label_width,
00110 llfloor(font->getLineHeight()));
00111 addChild( new LLTextBox( "tool label", label_rect, label, font ) );
00112
00113
00114 if (contain->mPanel)
00115 {
00116 contain->mPanel->setBackgroundVisible( FALSE );
00117 contain->mPanel->setBorderVisible( FALSE );
00118 addChild(contain->mPanel);
00119 }
00120
00121 mContainList.addData(contain);
00122 }
00123
00124
00125 LLRect LLToolView::getButtonRect(S32 button_index)
00126 {
00127 const S32 HPAD = 7;
00128 const S32 VPAD = 7;
00129 const S32 TOOL_SIZE = 32;
00130 const S32 HORIZ_SPACING = TOOL_SIZE + 5;
00131 const S32 VERT_SPACING = TOOL_SIZE + 14;
00132
00133 S32 tools_per_row = mRect.getWidth() / HORIZ_SPACING;
00134
00135 S32 row = button_index / tools_per_row;
00136 S32 column = button_index % tools_per_row;
00137
00138
00139
00140 LLRect rect;
00141 rect.setLeftTopAndSize( HPAD + (column * HORIZ_SPACING),
00142 -VPAD + getRect().getHeight() - (row * VERT_SPACING),
00143 TOOL_SIZE,
00144 TOOL_SIZE
00145 );
00146
00147 return rect;
00148 }
00149
00150
00151 void LLToolView::draw()
00152 {
00153
00154
00155 LLTool* selected = gToolMgr->getCurrentToolset()->getSelectedTool();
00156 for( LLToolContainer* contain = mContainList.getFirstData();
00157 contain != NULL;
00158 contain = mContainList.getNextData()
00159 )
00160 {
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( LLToolContainer* contain = mContainList.getFirstData(); contain; contain = mContainList.getNextData() )
00179 {
00180 if( contain->mTool == tool )
00181 {
00182 return contain;
00183 }
00184 }
00185 llerrs << "LLToolView::findToolContainer - tool not found" << llendl;
00186 return NULL;
00187 }
00188
00189
00190 void LLToolView::onClickToolButton(void* userdata)
00191 {
00192 LLToolContainer* clicked = (LLToolContainer*) userdata;
00193
00194
00195 gToolMgr->getCurrentToolset()->selectTool( clicked->mTool );
00196 }
00197
00198