PageRenderTime 27ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

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