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