PageRenderTime 28ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llconsole.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 155 lines | 86 code | 24 blank | 45 comment | 0 complexity | 277e9947139534237872abc430547a36 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llconsole.h
  3. * @brief a simple console-style output device
  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. #ifndef LL_LLCONSOLE_H
  27. #define LL_LLCONSOLE_H
  28. #include "llfixedbuffer.h"
  29. #include "lluictrl.h"
  30. #include "v4color.h"
  31. #include <deque>
  32. class LLSD;
  33. class LLConsole : public LLFixedBuffer, public LLUICtrl, public LLInstanceTracker<LLConsole>
  34. {
  35. public:
  36. typedef enum e_font_size
  37. {
  38. MONOSPACE = -1,
  39. SMALL = 0,
  40. BIG = 1
  41. } EFontSize;
  42. struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
  43. {
  44. Optional<U32> max_lines;
  45. Optional<F32> persist_time;
  46. Optional<S32> font_size_index;
  47. Params()
  48. : max_lines("max_lines", LLUI::sSettingGroups["config"]->getS32("ConsoleMaxLines")),
  49. persist_time("persist_time", 0.f), // forever
  50. font_size_index("font_size_index")
  51. {
  52. changeDefault(mouse_opaque, false);
  53. }
  54. };
  55. protected:
  56. LLConsole(const Params&);
  57. friend class LLUICtrlFactory;
  58. public:
  59. // call once per frame to pull data out of LLFixedBuffer
  60. static void updateClass();
  61. //A paragraph color segment defines the color of text in a line
  62. //of text that was received for console display. It has no
  63. //notion of line wraps, screen position, or the text it contains.
  64. //It is only the number of characters that are a color and the
  65. //color.
  66. struct ParagraphColorSegment
  67. {
  68. S32 mNumChars;
  69. LLColor4 mColor;
  70. };
  71. //A line color segment is a chunk of text, the color associated
  72. //with it, and the X Position it was calculated to begin at
  73. //on the screen. X Positions are re-calculated if the
  74. //screen changes size.
  75. class LineColorSegment
  76. {
  77. public:
  78. LineColorSegment(LLWString text, LLColor4 color, F32 xpos) : mText(text), mColor(color), mXPosition(xpos) {}
  79. public:
  80. LLWString mText;
  81. LLColor4 mColor;
  82. F32 mXPosition;
  83. };
  84. typedef std::list<LineColorSegment> line_color_segments_t;
  85. //A line is composed of one or more color segments.
  86. class Line
  87. {
  88. public:
  89. line_color_segments_t mLineColorSegments;
  90. };
  91. typedef std::list<Line> lines_t;
  92. typedef std::list<ParagraphColorSegment> paragraph_color_segments_t;
  93. //A paragraph is a processed element containing the entire text of the
  94. //message (used for recalculating positions on screen resize)
  95. //The time this message was added to the console output
  96. //The visual screen width of the longest line in this block
  97. //And a list of one or more lines which are used to display this message.
  98. class Paragraph
  99. {
  100. public:
  101. Paragraph (LLWString str, const LLColor4 &color, F32 add_time, const LLFontGL* font, F32 screen_width);
  102. void makeParagraphColorSegments ( const LLColor4 &color);
  103. void updateLines ( F32 screen_width, const LLFontGL* font, bool force_resize=false );
  104. public:
  105. LLWString mParagraphText; //The entire text of the paragraph
  106. paragraph_color_segments_t mParagraphColorSegments;
  107. F32 mAddTime; //Time this paragraph was added to the display.
  108. F32 mMaxWidth; //Width of the widest line of text in this paragraph.
  109. lines_t mLines;
  110. };
  111. //The console contains a deque of paragraphs which represent the individual messages.
  112. typedef std::deque<Paragraph> paragraph_t;
  113. paragraph_t mParagraphs;
  114. ~LLConsole(){};
  115. // each line lasts this long after being added
  116. void setLinePersistTime(F32 seconds);
  117. void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
  118. // -1 = monospace, 0 means small, font size = 1 means big
  119. void setFontSize(S32 size_index);
  120. // Overrides
  121. /*virtual*/ void draw();
  122. private:
  123. void update();
  124. F32 mLinePersistTime; // Age at which to stop drawing.
  125. F32 mFadeTime; // Age at which to start fading
  126. const LLFontGL* mFont;
  127. S32 mConsoleWidth;
  128. S32 mConsoleHeight;
  129. };
  130. extern LLConsole* gConsole;
  131. #endif