llconsole.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * @file llconsole.h
  3. * @brief a simple console-style output device
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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. #ifndef LL_LLCONSOLE_H
  33. #define LL_LLCONSOLE_H
  34. #include <deque>
  35. #include "llerrorcontrol.h" // For LLLineBuffer
  36. #include "llmutex.h"
  37. #include "llview.h"
  38. #include "llcolor4.h"
  39. // Let enough room for the Lua side bar
  40. constexpr S32 CONSOLE_PADDING_LEFT = 48;
  41. constexpr S32 CONSOLE_PADDING_RIGHT = 48;
  42. class LLFontGL;
  43. class LLSD;
  44. class LLConsole final : public LLLineBuffer, public LLView
  45. {
  46. public:
  47. // font_size_index: -1 = monospace, 0 small, 1 big
  48. LLConsole(const std::string& name, const LLRect& rect,
  49. S32 font_size_index, U32 max_lines, F32 persist_time);
  50. ~LLConsole() override;
  51. // Overrides
  52. void draw() override;
  53. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  54. // From LLLineBuffer
  55. void clear() override;
  56. void addLine(const std::string& utf8line) override;
  57. // Maximum number of lines displayed in the console
  58. void setMaxLines(U32 lines) { mMaxLines = llmax(lines, 5U); }
  59. // Each line lasts this long after being added
  60. void setLinePersistTime(F32 seconds);
  61. // -1 = monospace, 0 means small, font size = 1 means big
  62. void setFontSize(S32 size_index);
  63. void addConsoleLine(const std::string& utf8line, const LLColor4& color);
  64. void addConsoleLine(const LLWString& wline, const LLColor4& color);
  65. void replaceAllText(const std::string& search_txt,
  66. const std::string& replace_txt,
  67. bool case_insensitive);
  68. // A paragraph color segment defines the color of text in a line of text
  69. // that was received for console display. It has no notion of line wraps,
  70. // screen position, or the text it contains.
  71. // It is only the number of characters that are a color and the color.
  72. struct ParagraphColorSegment
  73. {
  74. ParagraphColorSegment(S32 num_chars, const LLColor4& color)
  75. : mNumChars(num_chars),
  76. mColor(color)
  77. {
  78. }
  79. S32 mNumChars;
  80. LLColor4 mColor;
  81. };
  82. // A line color segment is a chunk of text, the color associated with it,
  83. // and the X Position it was calculated to begin at on the screen. X
  84. // positions are re-calculated if the screen changes size.
  85. class LineColorSegment
  86. {
  87. public:
  88. LineColorSegment(LLWString text, LLColor4 color, F32 xpos)
  89. : mText(text),
  90. mColor(color),
  91. mXPosition(xpos)
  92. {
  93. }
  94. public:
  95. LLWString mText;
  96. LLColor4 mColor;
  97. F32 mXPosition;
  98. };
  99. typedef std::list<LineColorSegment> line_color_segments_t;
  100. typedef std::list<line_color_segments_t> lines_t;
  101. typedef std::list<ParagraphColorSegment> paragraph_color_segments_t;
  102. // A paragraph is a processed element containing the entire text of the
  103. // message (used for recalculating positions on screen resize), the time
  104. // this message was added to the console output, the visual screen width
  105. // of the longest line in this block and a list of one or more lines which
  106. // are used to display this message.
  107. class Paragraph
  108. {
  109. public:
  110. Paragraph(LLWString str, const LLColor4& color, F32 add_time);
  111. void updateLines(F32 screen_width, LLFontGL* font,
  112. bool force_resize = false);
  113. public:
  114. // The entire text of the paragraph:
  115. LLWString mParagraphText;
  116. paragraph_color_segments_t mParagraphColorSegments;
  117. // Time this paragraph was added to the display:
  118. F32 mAddTime;
  119. // Width of the widest line of text in this paragraph:
  120. F32 mMaxWidth;
  121. lines_t mLines;
  122. };
  123. static void setBackground(const LLColor4& color, F32 opacity);
  124. LL_INLINE static const LLColor4& getBackground()
  125. {
  126. return sConsoleBackground;
  127. }
  128. private:
  129. void replaceParaText(Paragraph* para, const LLWString& search_text,
  130. const LLWString& replace_text, bool case_insensitive,
  131. bool new_paragraph = false);
  132. public:
  133. // The console contains a deque of paragraphs which represent the
  134. // individual messages.
  135. typedef std::deque<Paragraph*> paragraph_t;
  136. paragraph_t mParagraphs;
  137. paragraph_t mNewParagraphs;
  138. private:
  139. LLFontGL* mFont;
  140. S32 mFontSize;
  141. F32 mLineHeight;
  142. U32 mMaxLines;
  143. F32 mLinePersistTime; // Age at which to stop drawing.
  144. F32 mFadeTime; // Age at which to start fading
  145. S32 mConsoleWidth;
  146. S32 mConsoleHeight;
  147. LLMutex mQueueMutex;
  148. LLTimer mTimer;
  149. static LLColor4 sConsoleBackground;
  150. };
  151. // To be used for the main (chat) console only !
  152. extern LLConsole* gConsolep;
  153. #endif