llscrollingpanellist.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * @file llscrollingpanellist.cpp
  3. * @brief
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewergpl$
  6. *
  7. * Copyright (c) 2006-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llstl.h"
  34. #include "llscrollingpanellist.h"
  35. static const std::string LL_SCROLLING_PANEL_LIST_TAG = "scrolling_panel_list";
  36. static LLRegisterWidget<LLScrollingPanelList> r19(LL_SCROLLING_PANEL_LIST_TAG);
  37. /////////////////////////////////////////////////////////////////////
  38. // LLScrollingPanelList
  39. // This could probably be integrated with LLScrollContainer -SJB
  40. void LLScrollingPanelList::clearPanels()
  41. {
  42. deleteAllChildren();
  43. mPanelList.clear();
  44. reshape(1, 1, false);
  45. }
  46. void LLScrollingPanelList::addPanel(LLScrollingPanel* panel)
  47. {
  48. addChildAtEnd(panel);
  49. mPanelList.push_front(panel);
  50. constexpr S32 GAP_BETWEEN_PANELS = 6;
  51. // Resize this view
  52. S32 total_height = 0;
  53. S32 max_width = 0;
  54. S32 cur_gap = 0;
  55. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin(),
  56. end = mPanelList.end();
  57. iter != end; ++iter)
  58. {
  59. LLScrollingPanel* childp = *iter;
  60. total_height += childp->getRect().getHeight() + cur_gap;
  61. max_width = llmax(max_width, childp->getRect().getWidth());
  62. cur_gap = GAP_BETWEEN_PANELS;
  63. }
  64. reshape(max_width, total_height, false);
  65. // Reposition each of the child views
  66. S32 cur_y = total_height;
  67. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin(),
  68. end = mPanelList.end();
  69. iter != end; ++iter)
  70. {
  71. LLScrollingPanel* childp = *iter;
  72. cur_y -= childp->getRect().getHeight();
  73. childp->translate(-childp->getRect().mLeft,
  74. cur_y - childp->getRect().mBottom);
  75. cur_y -= GAP_BETWEEN_PANELS;
  76. }
  77. }
  78. void LLScrollingPanelList::updatePanels(bool allow_modify)
  79. {
  80. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin(),
  81. end = mPanelList.end();
  82. iter != end; ++iter)
  83. {
  84. LLScrollingPanel* childp = *iter;
  85. childp->updatePanel(allow_modify);
  86. }
  87. }
  88. void LLScrollingPanelList::updatePanelVisiblilty()
  89. {
  90. // Determine visibility of children.
  91. S32 BORDER_WIDTH = 2; // HACK
  92. LLRect parent_local_rect = getParent()->getRect();
  93. parent_local_rect.stretch(-BORDER_WIDTH);
  94. LLRect parent_screen_rect;
  95. getParent()->localPointToScreen(BORDER_WIDTH, 0, &parent_screen_rect.mLeft,
  96. &parent_screen_rect.mBottom);
  97. getParent()->localPointToScreen(parent_local_rect.getWidth() - BORDER_WIDTH,
  98. parent_local_rect.getHeight() - BORDER_WIDTH,
  99. &parent_screen_rect.mRight,
  100. &parent_screen_rect.mTop);
  101. for (std::deque<LLScrollingPanel*>::iterator iter = mPanelList.begin(),
  102. end = mPanelList.end();
  103. iter != end; ++iter)
  104. {
  105. LLScrollingPanel* childp = *iter;
  106. const LLRect& local_rect = childp->getRect();
  107. LLRect screen_rect;
  108. childp->localPointToScreen(0, 0, &screen_rect.mLeft,
  109. &screen_rect.mBottom);
  110. childp->localPointToScreen(local_rect.getWidth(),
  111. local_rect.getHeight(),
  112. &screen_rect.mRight, &screen_rect.mTop);
  113. bool intersects = screen_rect.mRight > parent_screen_rect.mLeft &&
  114. screen_rect.mLeft < parent_screen_rect.mRight &&
  115. screen_rect.mTop > parent_screen_rect.mBottom &&
  116. screen_rect.mBottom < parent_screen_rect.mTop;
  117. childp->setVisible(intersects);
  118. }
  119. }
  120. void LLScrollingPanelList::draw()
  121. {
  122. updatePanelVisiblilty();
  123. LLUICtrl::draw();
  124. }
  125. //virtual
  126. const std::string& LLScrollingPanelList::getTag() const
  127. {
  128. return LL_SCROLLING_PANEL_LIST_TAG;
  129. }
  130. //virtual
  131. LLXMLNodePtr LLScrollingPanelList::getXML(bool save_children) const
  132. {
  133. LLXMLNodePtr node = LLUICtrl::getXML();
  134. node->setName(LL_SCROLLING_PANEL_LIST_TAG);
  135. return node;
  136. }
  137. //static
  138. LLView* LLScrollingPanelList::fromXML(LLXMLNodePtr node, LLView* parent,
  139. LLUICtrlFactory* factory)
  140. {
  141. std::string name = LL_SCROLLING_PANEL_LIST_TAG;
  142. node->getAttributeString("name", name);
  143. LLRect rect;
  144. createRect(node, rect, parent, LLRect());
  145. LLScrollingPanelList* scrolling_panel_list = new LLScrollingPanelList(name,
  146. rect);
  147. scrolling_panel_list->initFromXML(node, parent);
  148. return scrolling_panel_list;
  149. }