PageRenderTime 43ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llscrolllistitem.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 150 lines | 92 code | 27 blank | 31 comment | 10 complexity | 5bf7cd6ca409c993d12032ee5737a243 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llscrolllistitem.cpp
  3. * @brief Scroll lists are composed of rows (items), each of which
  4. * contains columns (cells).
  5. *
  6. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include "llscrolllistitem.h"
  29. #include "llrect.h"
  30. #include "llui.h"
  31. //---------------------------------------------------------------------------
  32. // LLScrollListItem
  33. //---------------------------------------------------------------------------
  34. LLScrollListItem::LLScrollListItem( const Params& p )
  35. : mSelected(FALSE),
  36. mHighlighted(FALSE),
  37. mEnabled(p.enabled),
  38. mUserdata(p.userdata),
  39. mItemValue(p.value)
  40. {
  41. }
  42. LLScrollListItem::~LLScrollListItem()
  43. {
  44. std::for_each(mColumns.begin(), mColumns.end(), DeletePointer());
  45. }
  46. void LLScrollListItem::addColumn(const LLScrollListCell::Params& p)
  47. {
  48. mColumns.push_back(LLScrollListCell::create(p));
  49. }
  50. void LLScrollListItem::setNumColumns(S32 columns)
  51. {
  52. S32 prev_columns = mColumns.size();
  53. if (columns < prev_columns)
  54. {
  55. std::for_each(mColumns.begin()+columns, mColumns.end(), DeletePointer());
  56. }
  57. mColumns.resize(columns);
  58. for (S32 col = prev_columns; col < columns; ++col)
  59. {
  60. mColumns[col] = NULL;
  61. }
  62. }
  63. void LLScrollListItem::setColumn( S32 column, LLScrollListCell *cell )
  64. {
  65. if (column < (S32)mColumns.size())
  66. {
  67. delete mColumns[column];
  68. mColumns[column] = cell;
  69. }
  70. else
  71. {
  72. llerrs << "LLScrollListItem::setColumn: bad column: " << column << llendl;
  73. }
  74. }
  75. S32 LLScrollListItem::getNumColumns() const
  76. {
  77. return mColumns.size();
  78. }
  79. LLScrollListCell* LLScrollListItem::getColumn(const S32 i) const
  80. {
  81. if (0 <= i && i < (S32)mColumns.size())
  82. {
  83. return mColumns[i];
  84. }
  85. return NULL;
  86. }
  87. std::string LLScrollListItem::getContentsCSV() const
  88. {
  89. std::string ret;
  90. S32 count = getNumColumns();
  91. for (S32 i=0; i<count; ++i)
  92. {
  93. ret += getColumn(i)->getValue().asString();
  94. if (i < count-1)
  95. {
  96. ret += ", ";
  97. }
  98. }
  99. return ret;
  100. }
  101. void LLScrollListItem::draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding)
  102. {
  103. // draw background rect
  104. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  105. LLRect bg_rect = rect;
  106. gl_rect_2d( bg_rect, bg_color );
  107. S32 cur_x = rect.mLeft;
  108. S32 num_cols = getNumColumns();
  109. S32 cur_col = 0;
  110. for (LLScrollListCell* cell = getColumn(0); cur_col < num_cols; cell = getColumn(++cur_col))
  111. {
  112. // Two ways a cell could be hidden
  113. if (cell->getWidth() < 0
  114. || !cell->getVisible()) continue;
  115. LLUI::pushMatrix();
  116. {
  117. LLUI::translate((F32) cur_x, (F32) rect.mBottom, 0.0f);
  118. cell->draw( fg_color, highlight_color );
  119. }
  120. LLUI::popMatrix();
  121. cur_x += cell->getWidth() + column_padding;
  122. }
  123. }