PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms 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
 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
28#include "llviewerprecompiledheaders.h"
29
30#include "llchatmsgbox.h"
31#include "llwindow.h"
32
33
34static LLDefaultChildRegistry::Register<LLChatMsgBox> r("text_chat");
35
36class ChatSeparator : public LLTextSegment
37{
38public:
39	ChatSeparator(S32 start, S32 end)
40	:	LLTextSegment(start, end),
41		mEditor(NULL)
42	{}
43
44	/*virtual*/ void linkToDocument(class LLTextBase* editor)
45	{
46		mEditor = editor;
47	}
48
49	/*virtual*/ void unlinkFromDocument(class LLTextBase* editor)
50	{
51		mEditor = NULL;
52	}
53
54	/*virtual*/ S32 getWidth(S32 first_char, S32 num_chars) const
55	{
56		return mEditor->getDocumentView()->getRect().getWidth();
57	}
58
59	/*virtual*/ F32	draw(S32 start, S32 end, S32 selection_start, S32 selection_end, const LLRect& draw_rect)
60	{
61		gl_line_2d(draw_rect.mLeft + 5, draw_rect.getCenterY(), draw_rect.mRight - 5, draw_rect.getCenterY(), LLColor4::grey);
62		return draw_rect.getWidth();
63	}
64
65private:
66	LLTextBase* mEditor;
67};
68
69
70LLChatMsgBox::Params::Params() :
71	block_spacing("block_spacing", 10)
72{
73	changeDefault(line_spacing.pixels, 4);
74}
75
76LLChatMsgBox::LLChatMsgBox(const Params& p) :
77	LLTextBox(p),
78	mBlockSpacing(p.block_spacing)
79{}
80
81void LLChatMsgBox::addText( const LLStringExplicit& text , const LLStyle::Params& input_params )
82{
83	S32 length = getLength();
84	// if there is existing text, add a separator
85	if (length > 0)
86	{
87		// chat separator exists right before the null terminator
88		insertSegment(new ChatSeparator(length - 1, length - 1));
89	}
90	// prepend newline only if there is some existing text
91	appendText(text, length > 0, input_params);
92}