PageRenderTime 31ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llscrollingpanellist.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 218 lines | 151 code | 33 blank | 34 comment | 24 complexity | c7097b76bd503093937f2c3cd687635b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llscrollingpanellist.cpp
  3. * @brief
  4. *
  5. * $LicenseInfo:firstyear=2006&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 "linden_common.h"
  27. #include "llstl.h"
  28. #include "llscrollingpanellist.h"
  29. static LLDefaultChildRegistry::Register<LLScrollingPanelList> r("scrolling_panel_list");
  30. /////////////////////////////////////////////////////////////////////
  31. // LLScrollingPanelList
  32. // This could probably be integrated with LLScrollContainer -SJB
  33. void LLScrollingPanelList::clearPanels()
  34. {
  35. deleteAllChildren();
  36. mPanelList.clear();
  37. LLRect rc = getRect();
  38. rc.setLeftTopAndSize(rc.mLeft, rc.mTop, 1, 1);
  39. setRect(rc);
  40. notifySizeChanged(rc.getHeight());
  41. }
  42. S32 LLScrollingPanelList::addPanel( LLScrollingPanel* panel )
  43. {
  44. addChildInBack( panel );
  45. mPanelList.push_front( panel );
  46. // Resize this view
  47. S32 total_height = 0;
  48. S32 max_width = 0;
  49. S32 cur_gap = 0;
  50. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
  51. iter != mPanelList.end(); ++iter)
  52. {
  53. LLScrollingPanel *childp = *iter;
  54. total_height += childp->getRect().getHeight() + cur_gap;
  55. max_width = llmax( max_width, childp->getRect().getWidth() );
  56. cur_gap = GAP_BETWEEN_PANELS;
  57. }
  58. LLRect rc = getRect();
  59. rc.setLeftTopAndSize(rc.mLeft, rc.mTop, max_width, total_height);
  60. setRect(rc);
  61. notifySizeChanged(rc.getHeight());
  62. // Reposition each of the child views
  63. S32 cur_y = total_height;
  64. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
  65. iter != mPanelList.end(); ++iter)
  66. {
  67. LLScrollingPanel *childp = *iter;
  68. cur_y -= childp->getRect().getHeight();
  69. childp->translate( -childp->getRect().mLeft, cur_y - childp->getRect().mBottom);
  70. cur_y -= GAP_BETWEEN_PANELS;
  71. }
  72. return total_height;
  73. }
  74. void LLScrollingPanelList::removePanel(LLScrollingPanel* panel)
  75. {
  76. U32 index = 0;
  77. LLScrollingPanelList::panel_list_t::const_iterator iter;
  78. if (!mPanelList.empty())
  79. {
  80. for (iter = mPanelList.begin(); iter != mPanelList.end(); ++iter, ++index)
  81. {
  82. if (*iter == panel)
  83. {
  84. break;
  85. }
  86. }
  87. if(iter != mPanelList.end())
  88. {
  89. removePanel(index);
  90. }
  91. }
  92. }
  93. void LLScrollingPanelList::removePanel( U32 panel_index )
  94. {
  95. if ( mPanelList.empty() || panel_index >= mPanelList.size() )
  96. {
  97. llwarns << "Panel index " << panel_index << " is out of range!" << llendl;
  98. return;
  99. }
  100. else
  101. {
  102. removeChild( mPanelList.at(panel_index) );
  103. mPanelList.erase( mPanelList.begin() + panel_index );
  104. }
  105. const S32 GAP_BETWEEN_PANELS = 6;
  106. // Resize this view
  107. S32 total_height = 0;
  108. S32 max_width = 0;
  109. S32 cur_gap = 0;
  110. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
  111. iter != mPanelList.end(); ++iter)
  112. {
  113. LLScrollingPanel *childp = *iter;
  114. total_height += childp->getRect().getHeight() + cur_gap;
  115. max_width = llmax( max_width, childp->getRect().getWidth() );
  116. cur_gap = GAP_BETWEEN_PANELS;
  117. }
  118. LLRect rc = getRect();
  119. rc.setLeftTopAndSize(rc.mLeft, rc.mTop, max_width, total_height);
  120. setRect(rc);
  121. notifySizeChanged(rc.getHeight());
  122. // Reposition each of the child views
  123. S32 cur_y = total_height;
  124. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
  125. iter != mPanelList.end(); ++iter)
  126. {
  127. LLScrollingPanel *childp = *iter;
  128. cur_y -= childp->getRect().getHeight();
  129. childp->translate( -childp->getRect().mLeft, cur_y - childp->getRect().mBottom);
  130. cur_y -= GAP_BETWEEN_PANELS;
  131. }
  132. }
  133. void LLScrollingPanelList::updatePanels(BOOL allow_modify)
  134. {
  135. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
  136. iter != mPanelList.end(); ++iter)
  137. {
  138. LLScrollingPanel *childp = *iter;
  139. childp->updatePanel(allow_modify);
  140. }
  141. }
  142. void LLScrollingPanelList::updatePanelVisiblilty()
  143. {
  144. // Determine visibility of children.
  145. S32 BORDER_WIDTH = 2; // HACK
  146. LLRect parent_local_rect = getParent()->getRect();
  147. parent_local_rect.stretch( -BORDER_WIDTH );
  148. LLRect parent_screen_rect;
  149. getParent()->localPointToScreen(
  150. BORDER_WIDTH, 0,
  151. &parent_screen_rect.mLeft, &parent_screen_rect.mBottom );
  152. getParent()->localPointToScreen(
  153. parent_local_rect.getWidth() - BORDER_WIDTH, parent_local_rect.getHeight() - BORDER_WIDTH,
  154. &parent_screen_rect.mRight, &parent_screen_rect.mTop );
  155. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin();
  156. iter != mPanelList.end(); ++iter)
  157. {
  158. LLScrollingPanel *childp = *iter;
  159. const LLRect& local_rect = childp->getRect();
  160. LLRect screen_rect;
  161. childp->localPointToScreen(
  162. 0, 0,
  163. &screen_rect.mLeft, &screen_rect.mBottom );
  164. childp->localPointToScreen(
  165. local_rect.getWidth(), local_rect.getHeight(),
  166. &screen_rect.mRight, &screen_rect.mTop );
  167. BOOL intersects =
  168. ( (screen_rect.mRight > parent_screen_rect.mLeft) && (screen_rect.mLeft < parent_screen_rect.mRight) ) &&
  169. ( (screen_rect.mTop > parent_screen_rect.mBottom) && (screen_rect.mBottom < parent_screen_rect.mTop) );
  170. childp->setVisible( intersects );
  171. }
  172. }
  173. void LLScrollingPanelList::draw()
  174. {
  175. updatePanelVisiblilty();
  176. LLUICtrl::draw();
  177. }
  178. void LLScrollingPanelList::notifySizeChanged(S32 height)
  179. {
  180. LLSD info;
  181. info["action"] = "size_changes";
  182. info["height"] = height;
  183. notifyParent(info);
  184. }
  185. // EOF