aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llconsole.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llconsole.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llconsole.cpp')
-rw-r--r--linden/indra/newview/llconsole.cpp287
1 files changed, 287 insertions, 0 deletions
diff --git a/linden/indra/newview/llconsole.cpp b/linden/indra/newview/llconsole.cpp
new file mode 100644
index 0000000..1ed0e17
--- /dev/null
+++ b/linden/indra/newview/llconsole.cpp
@@ -0,0 +1,287 @@
1/**
2 * @file llconsole.cpp
3 * @brief a scrolling console output device
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llconsole.h"
31
32// linden library includes
33#include "llmath.h"
34#include "llviewercontrol.h"
35#include "llcriticaldamp.h"
36#include "llfontgl.h"
37#include "llgl.h"
38#include "llui.h"
39#include "llviewerimage.h"
40#include "llviewerimagelist.h"
41#include "llviewerwindow.h"
42#include "llfontgl.h"
43#include "llmath.h"
44
45#include "llstartup.h"
46#include "viewer.h"
47
48LLConsole* gConsole = NULL; // Created and destroyed in LLViewerWindow.
49
50const F32 FADE_DURATION = 2.f;
51const S32 MIN_CONSOLE_WIDTH = 200;
52
53LLConsole::LLConsole(const std::string& name, const U32 max_lines, const LLRect &rect,
54 S32 font_size_index, F32 persist_time )
55 :
56 LLFixedBuffer(max_lines),
57 LLView(name, rect, FALSE),
58 mLastBoxHeight(0),
59 mLastBoxWidth(0)
60{
61 mLinePersistTime = persist_time; // seconds
62 mFadeTime = persist_time - FADE_DURATION;
63
64 setFontSize( font_size_index );
65 setMaxLines(gSavedSettings.getS32("ConsoleMaxLines"));
66}
67
68LLConsole::~LLConsole()
69{
70 mColors.clear();
71}
72
73EWidgetType LLConsole::getWidgetType() const
74{
75 return WIDGET_TYPE_CONSOLE;
76}
77
78LLString LLConsole::getWidgetTag() const
79{
80 return LL_CONSOLE_TAG;
81}
82
83void LLConsole::setLinePersistTime(F32 seconds)
84{
85 mLinePersistTime = seconds;
86 mFadeTime = mLinePersistTime - FADE_DURATION;
87}
88
89void LLConsole::reshape(S32 width, S32 height, BOOL called_from_parent)
90{
91 S32 new_width = llmax(50, llmin(mRect.getWidth(), gViewerWindow->getWindowWidth()));
92 S32 new_height = llmax(llfloor(mFont->getLineHeight()) + 15, llmin(mRect.getHeight(), gViewerWindow->getWindowHeight()));
93
94 LLView::reshape(new_width, new_height, called_from_parent);
95}
96
97void LLConsole::setFontSize(S32 size_index)
98{
99 if (-1 == size_index)
100 {
101 mFont = LLFontGL::sMonospace;
102 }
103 else if (0 == size_index)
104 {
105 mFont = LLFontGL::sSansSerif;
106 }
107 else if (1 == size_index)
108 {
109 mFont = LLFontGL::sSansSerifBig;
110 }
111 else
112 {
113 mFont = LLFontGL::sSansSerifHuge;
114 }
115}
116
117void LLConsole::draw()
118{
119 LLGLSUIDefault gls_ui;
120
121 // skip lines added more than mLinePersistTime ago
122 F32 cur_time = mTimer.getElapsedTimeF32();
123
124 if( gStartupState != STATE_STARTED )
125 {
126 S32 count = mLines.size();
127 S32 i = 0;
128 while( count-- )
129 {
130 mAddTimes[i] = cur_time;
131 i = (i+1) % mMaxLines;
132 }
133 }
134
135 F32 skip_time = cur_time - mLinePersistTime;
136 F32 fade_time = cur_time - mFadeTime;
137
138 // draw remaining lines
139 F32 x_pos = 0.f;
140 F32 y_pos = 0.f;
141
142 S32 line_count = mLines.size();
143
144 // remove stale lines
145 for (S32 line_num = 0; line_num < line_count; line_num++)
146 {
147 if((mLinePersistTime > 0.f) && (mAddTimes[0] - skip_time)/(mLinePersistTime - mFadeTime) <= 0.f)
148 {
149 mLines.pop_front();
150 mAddTimes.pop_front();
151 mLineLengths.pop_front();
152 mColors.pop_front();
153 }
154 }
155
156 line_count = mLines.size();
157
158 S32 i;
159 if (line_count == 0)
160 {
161 mLastBoxHeight = 0;
162 mLastBoxWidth = 0;
163 return;
164 }
165 else
166 {
167 LLUUID image_id;
168 image_id.set(gViewerArt.getString("rounded_square.tga"));
169 LLViewerImage* imagep = gImageList.getImage(image_id, MIPMAP_FALSE, TRUE);
170
171 F32 console_opacity = llclamp(gSavedSettings.getF32("ConsoleBackgroundOpacity"), 0.f, 1.f);
172 LLColor4 color(0.f, 0.f, 0.f, console_opacity);
173
174 S32 max_width = 0;
175 for (i = 0; i < line_count; i++)
176 {
177 max_width = llmax(max_width, mFont->getWidth(mLines[i].c_str()) + 30);
178 }
179 max_width = llmin(max_width, gViewerWindow->getWindowWidth());
180
181 F32 u = 1.f;//LLCriticalDamp::getInterpolant(0.1f);
182 S32 target_height = llfloor(line_count * mFont->getLineHeight() + 15);
183 S32 target_width = max_width;
184 mLastBoxHeight = llmax(target_height, (S32)lerp((F32)mLastBoxHeight, (F32)target_height, u));
185 mLastBoxWidth = llmax(MIN_CONSOLE_WIDTH, llmax(target_width, (S32)lerp((F32)mLastBoxWidth, (F32)target_width, u)));
186 gl_draw_scaled_image_with_border(-15, -10, 16, 16, mLastBoxWidth + 15, mLastBoxHeight,
187 imagep, color, TRUE );
188 }
189
190 y_pos += (line_count-1) * mFont->getLineHeight();
191
192
193 for (i = 0; i < line_count; i++)
194 {
195 F32 alpha;
196
197 if ((mLinePersistTime > 0.f) && (mAddTimes[i] < fade_time))
198 {
199 alpha = (mAddTimes[i] - skip_time)/(mLinePersistTime - mFadeTime);
200 }
201 else
202 {
203 alpha = 1.0f;
204 }
205
206 if( alpha > 0.f )
207 {
208 // text line itself
209 mFont->render(mLines[i], 0, x_pos, y_pos,
210 LLColor4(
211 mColors[i].mV[VRED],
212 mColors[i].mV[VGREEN],
213 mColors[i].mV[VBLUE],
214 mColors[i].mV[VALPHA]*alpha),
215 LLFontGL::LEFT,
216 LLFontGL::BASELINE,
217 LLFontGL::DROP_SHADOW,
218 S32_MAX,
219 mLastBoxWidth
220 );
221 }
222
223 y_pos -= mFont->getLineHeight();
224 }
225}
226
227void LLConsole::addLine(const LLString& utf8line)
228{
229 LLWString wline = utf8str_to_wstring(utf8line);
230 addLine(wline, 0.f, LLColor4(1.f, 1.f, 1.f, 1.f));
231}
232
233void LLConsole::addLine(const LLWString& wline)
234{
235 addLine(wline, 0.f, LLColor4(1.f, 1.f, 1.f, 1.f));
236}
237
238void LLConsole::addLine(const LLString& utf8line, F32 size, const LLColor4 &color)
239{
240 LLWString wline = utf8str_to_wstring(utf8line);
241 addLine(wline, size, color);
242}
243
244void LLConsole::addLine(const LLWString& wline, F32 size, const LLColor4 &color)
245{
246 if (!wline.empty() && mFont != NULL)
247 {
248 // Wrap lines that are longer than the view is wide.
249 S32 offset = 0;
250 while( offset < (S32)wline.length() )
251 {
252 S32 skip_chars; // skip '\n'
253 // Figure out if a word-wrapped line fits here.
254 LLWString::size_type line_end = wline.find_first_of(llwchar('\n'), offset);
255 if (line_end != LLWString::npos)
256 {
257 skip_chars = 1; // skip '\n'
258 }
259 else
260 {
261 line_end = wline.size();
262 skip_chars = 0;
263 }
264 U32 drawable = mFont->maxDrawableChars(wline.c_str()+offset, (F32)mRect.getWidth(), line_end-offset, TRUE);
265 if (drawable != 0)
266 {
267 LLFixedBuffer::addLine(wline.substr(offset, drawable));
268 }
269 else
270 {
271 // force a blank line
272 LLFixedBuffer::addLine(" ");
273 }
274 mColors.push_back(color);
275 offset += (drawable + skip_chars);
276 }
277 }
278}
279
280void LLConsole::removeExtraLines()
281{
282 while((S32)mColors.size() > llmax(0, (S32)(mMaxLines - 1)))
283 {
284 mColors.pop_front();
285 }
286 LLFixedBuffer::removeExtraLines();
287}