PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llchatmsgbox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 92 lines | 49 code | 14 blank | 29 comment | 1 complexity | 9f9a31c7866e7d9d2a862bed41193e64 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llchatmsgbox.cpp
  3. * @author Martin Reddy
  4. * @brief chat history text box, able to show array of strings with separator
  5. *
  6. * $LicenseInfo:firstyear=2009&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 "llviewerprecompiledheaders.h"
  28. #include "llchatmsgbox.h"
  29. #include "llwindow.h"
  30. static LLDefaultChildRegistry::Register<LLChatMsgBox> r("text_chat");
  31. class ChatSeparator : public LLTextSegment
  32. {
  33. public:
  34. ChatSeparator(S32 start, S32 end)
  35. : LLTextSegment(start, end),
  36. mEditor(NULL)
  37. {}
  38. /*virtual*/ void linkToDocument(class LLTextBase* editor)
  39. {
  40. mEditor = editor;
  41. }
  42. /*virtual*/ void unlinkFromDocument(class LLTextBase* editor)
  43. {
  44. mEditor = NULL;
  45. }
  46. /*virtual*/ S32 getWidth(S32 first_char, S32 num_chars) const
  47. {
  48. return mEditor->getDocumentView()->getRect().getWidth();
  49. }
  50. /*virtual*/ F32 draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect)
  51. {
  52. gl_line_2d(draw_rect.mLeft + 5, draw_rect.getCenterY(), draw_rect.mRight - 5, draw_rect.getCenterY(), LLColor4::grey);
  53. return draw_rect.getWidth();
  54. }
  55. private:
  56. LLTextBase* mEditor;
  57. };
  58. LLChatMsgBox::Params::Params() :
  59. block_spacing("block_spacing", 10)
  60. {
  61. changeDefault(line_spacing.pixels, 4);
  62. }
  63. LLChatMsgBox::LLChatMsgBox(const Params& p) :
  64. LLTextBox(p),
  65. mBlockSpacing(p.block_spacing)
  66. {}
  67. void LLChatMsgBox::addText( const LLStringExplicit& text , const LLStyle::Params& input_params )
  68. {
  69. S32 length = getLength();
  70. // if there is existing text, add a separator
  71. if (length > 0)
  72. {
  73. // chat separator exists right before the null terminator
  74. insertSegment(new ChatSeparator(length - 1, length - 1));
  75. }
  76. // prepend newline only if there is some existing text
  77. appendText(text, length > 0, input_params);
  78. }