diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llconsole.cpp | 166 |
1 files changed, 86 insertions, 80 deletions
diff --git a/linden/indra/newview/llconsole.cpp b/linden/indra/newview/llconsole.cpp index a8554a0..2379da3 100644 --- a/linden/indra/newview/llconsole.cpp +++ b/linden/indra/newview/llconsole.cpp | |||
@@ -63,25 +63,17 @@ const S32 CONSOLE_GUTTER_LEFT = 14; | |||
63 | const S32 CONSOLE_GUTTER_RIGHT = 15; | 63 | const S32 CONSOLE_GUTTER_RIGHT = 15; |
64 | 64 | ||
65 | 65 | ||
66 | LLConsole::LLConsole(const std::string& name, const LLRect &rect, | 66 | LLConsole::LLConsole(const std::string& name, const U32 max_lines, const LLRect &rect, |
67 | S32 font_size_index, F32 persist_time ) | 67 | S32 font_size_index, F32 persist_time ) |
68 | : LLFixedBuffer(), | 68 | : |
69 | LLView(name, rect, FALSE), | 69 | LLFixedBuffer(max_lines), |
70 | mLinePersistTime(persist_time), | 70 | LLView(name, rect, FALSE) |
71 | mFadeTime(persist_time - FADE_DURATION), | ||
72 | mFont(LLFontGL::getFontSansSerif()), | ||
73 | mConsoleWidth(0), | ||
74 | mConsoleHeight(0), | ||
75 | mQueueMutex(NULL) | ||
76 | { | 71 | { |
77 | mTimer.reset(); | 72 | mLinePersistTime = persist_time; // seconds |
73 | mFadeTime = persist_time - FADE_DURATION; | ||
78 | 74 | ||
79 | setFontSize( font_size_index ); | 75 | setFontSize( font_size_index ); |
80 | } | 76 | setMaxLines(gSavedSettings.getS32("ConsoleMaxLines")); |
81 | |||
82 | LLConsole::~LLConsole() | ||
83 | { | ||
84 | clear(); | ||
85 | } | 77 | } |
86 | 78 | ||
87 | void LLConsole::setLinePersistTime(F32 seconds) | 79 | void LLConsole::setLinePersistTime(F32 seconds) |
@@ -106,10 +98,10 @@ void LLConsole::reshape(S32 width, S32 height, BOOL called_from_parent) | |||
106 | mConsoleHeight= new_height; | 98 | mConsoleHeight= new_height; |
107 | 99 | ||
108 | LLView::reshape(new_width, new_height, called_from_parent); | 100 | LLView::reshape(new_width, new_height, called_from_parent); |
109 | 101 | ||
110 | for(paragraph_t::iterator paragraph_it = mParagraphs.begin(); paragraph_it != mParagraphs.end(); paragraph_it++) | 102 | for(paragraph_t::iterator paragraph_it = mParagraphs.begin(); paragraph_it != mParagraphs.end(); paragraph_it++) |
111 | { | 103 | { |
112 | (*paragraph_it)->updateLines((F32)getRect().getWidth(), mFont, true); | 104 | (*paragraph_it).updateLines((F32)getRect().getWidth(), mFont, true); |
113 | } | 105 | } |
114 | } | 106 | } |
115 | 107 | ||
@@ -134,7 +126,7 @@ void LLConsole::setFontSize(S32 size_index) | |||
134 | 126 | ||
135 | for(paragraph_t::iterator paragraph_it = mParagraphs.begin(); paragraph_it != mParagraphs.end(); paragraph_it++) | 127 | for(paragraph_t::iterator paragraph_it = mParagraphs.begin(); paragraph_it != mParagraphs.end(); paragraph_it++) |
136 | { | 128 | { |
137 | (*paragraph_it)->updateLines((F32)getRect().getWidth(), mFont, true); | 129 | (*paragraph_it).updateLines((F32)getRect().getWidth(), mFont, true); |
138 | } | 130 | } |
139 | } | 131 | } |
140 | 132 | ||
@@ -142,49 +134,35 @@ void LLConsole::draw() | |||
142 | { | 134 | { |
143 | LLGLSUIDefault gls_ui; | 135 | LLGLSUIDefault gls_ui; |
144 | 136 | ||
145 | { | ||
146 | LLMutexLock lock(&mQueueMutex); | ||
147 | for(paragraph_t::iterator paragraph_it = mNewParagraphs.begin(); paragraph_it != mNewParagraphs.end(); paragraph_it++) | ||
148 | { | ||
149 | Paragraph* paragraph = *paragraph_it; | ||
150 | mParagraphs.push_back(paragraph); | ||
151 | paragraph->updateLines((F32)getRect().getWidth(), mFont); | ||
152 | } | ||
153 | mNewParagraphs.clear(); | ||
154 | } | ||
155 | |||
156 | if (mParagraphs.empty()) //No text to draw. | ||
157 | { | ||
158 | return; | ||
159 | } | ||
160 | |||
161 | // skip lines added more than mLinePersistTime ago | 137 | // skip lines added more than mLinePersistTime ago |
162 | F32 cur_time = mTimer.getElapsedTimeF32(); | 138 | F32 cur_time = mTimer.getElapsedTimeF32(); |
163 | 139 | ||
164 | F32 skip_time = cur_time - mLinePersistTime; | 140 | F32 skip_time = cur_time - mLinePersistTime; |
165 | F32 fade_time = cur_time - mFadeTime; | 141 | F32 fade_time = cur_time - mFadeTime; |
166 | 142 | ||
167 | U32 max_lines = gSavedSettings.getS32("ConsoleMaxLines"); | 143 | updateBuffer() ; |
144 | |||
145 | if (mParagraphs.empty()) //No text to draw. | ||
146 | { | ||
147 | return; | ||
148 | } | ||
149 | |||
168 | U32 num_lines=0; | 150 | U32 num_lines=0; |
169 | 151 | ||
170 | paragraph_t::reverse_iterator paragraph_it; | 152 | paragraph_t::reverse_iterator paragraph_it; |
171 | paragraph_it = mParagraphs.rbegin(); | 153 | paragraph_it = mParagraphs.rbegin(); |
172 | U32 paragraph_num=mParagraphs.size(); | 154 | U32 paragraph_num=mParagraphs.size(); |
173 | 155 | ||
174 | while (!mParagraphs.empty() && paragraph_it != mParagraphs.rend()) | 156 | while (!mParagraphs.empty() && paragraph_it != mParagraphs.rend()) |
175 | { | 157 | { |
176 | num_lines += (*paragraph_it)->mLines.size(); | 158 | num_lines += (*paragraph_it).mLines.size(); |
177 | if(num_lines > max_lines | 159 | if(num_lines > mMaxLines |
178 | || ( (mLinePersistTime > (F32)0.f) && ((*paragraph_it)->mAddTime - skip_time)/(mLinePersistTime - mFadeTime) <= (F32)0.f)) | 160 | || ( (mLinePersistTime > (F32)0.f) && ((*paragraph_it).mAddTime - skip_time)/(mLinePersistTime - mFadeTime) <= (F32)0.f)) |
179 | { //All lines above here are done. Lose them. | 161 | { //All lines above here are done. Lose them. |
180 | for (U32 i=0;i<paragraph_num;i++) | 162 | for (U32 i=0;i<paragraph_num;i++) |
181 | { | 163 | { |
182 | if (!mParagraphs.empty()) | 164 | if (!mParagraphs.empty()) |
183 | { | ||
184 | Paragraph* paragraph = mParagraphs.front(); | ||
185 | mParagraphs.pop_front(); | 165 | mParagraphs.pop_front(); |
186 | delete paragraph; | ||
187 | } | ||
188 | } | 166 | } |
189 | break; | 167 | break; |
190 | } | 168 | } |
@@ -215,8 +193,8 @@ void LLConsole::draw() | |||
215 | S32 bkg_width=0; | 193 | S32 bkg_width=0; |
216 | for(paragraph_it = mParagraphs.rbegin(); paragraph_it != mParagraphs.rend(); paragraph_it++) | 194 | for(paragraph_it = mParagraphs.rbegin(); paragraph_it != mParagraphs.rend(); paragraph_it++) |
217 | { | 195 | { |
218 | S32 target_height = llfloor( (*paragraph_it)->mLines.size() * line_height + message_spacing); | 196 | S32 target_height = llfloor( (*paragraph_it).mLines.size() * line_height + message_spacing); |
219 | S32 target_width = llfloor( (*paragraph_it)->mMaxWidth + CONSOLE_GUTTER_RIGHT); | 197 | S32 target_width = llfloor( (*paragraph_it).mMaxWidth + CONSOLE_GUTTER_RIGHT); |
220 | 198 | ||
221 | bkg_height+= target_height; | 199 | bkg_height+= target_height; |
222 | if (target_width > bkg_width) | 200 | if (target_width > bkg_width) |
@@ -225,7 +203,7 @@ void LLConsole::draw() | |||
225 | } | 203 | } |
226 | 204 | ||
227 | // Why is this not using llfloor as above? | 205 | // Why is this not using llfloor as above? |
228 | y_pos += ((*paragraph_it)->mLines.size()) * line_height; | 206 | y_pos += ((*paragraph_it).mLines.size()) * line_height; |
229 | y_pos += message_spacing; //Extra spacing between messages. | 207 | y_pos += message_spacing; //Extra spacing between messages. |
230 | } | 208 | } |
231 | imagep->drawSolid(-CONSOLE_GUTTER_LEFT, (S32)(y_pos + line_height - bkg_height - message_spacing), bkg_width, bkg_height, color); | 209 | imagep->drawSolid(-CONSOLE_GUTTER_LEFT, (S32)(y_pos + line_height - bkg_height - message_spacing), bkg_width, bkg_height, color); |
@@ -235,10 +213,10 @@ void LLConsole::draw() | |||
235 | for(paragraph_it = mParagraphs.rbegin(); paragraph_it != mParagraphs.rend(); paragraph_it++) | 213 | for(paragraph_it = mParagraphs.rbegin(); paragraph_it != mParagraphs.rend(); paragraph_it++) |
236 | { | 214 | { |
237 | //080813 Spatters: Dainty per-message block boxes | 215 | //080813 Spatters: Dainty per-message block boxes |
238 | // S32 target_height = llfloor( (*paragraph_it)->mLines.size() * line_height + 8); | 216 | // S32 target_height = llfloor( (*paragraph_it).mLines.size() * line_height + 8); |
239 | S32 target_width = llfloor( (*paragraph_it)->mMaxWidth + CONSOLE_GUTTER_RIGHT); | 217 | S32 target_width = llfloor( (*paragraph_it).mMaxWidth + CONSOLE_GUTTER_RIGHT); |
240 | 218 | ||
241 | y_pos += ((*paragraph_it)->mLines.size()) * line_height; | 219 | y_pos += ((*paragraph_it).mLines.size()) * line_height; |
242 | //080813 Spatters: Dainty per-message block boxes | 220 | //080813 Spatters: Dainty per-message block boxes |
243 | // imagep->drawSolid(-14, (S32)(y_pos + line_height - target_height), target_width, target_height, color); | 221 | // imagep->drawSolid(-14, (S32)(y_pos + line_height - target_height), target_width, target_height, color); |
244 | 222 | ||
@@ -246,9 +224,9 @@ void LLConsole::draw() | |||
246 | 224 | ||
247 | F32 alpha; | 225 | F32 alpha; |
248 | 226 | ||
249 | if ((mLinePersistTime > 0.f) && ((*paragraph_it)->mAddTime < fade_time)) | 227 | if ((mLinePersistTime > 0.f) && ((*paragraph_it).mAddTime < fade_time)) |
250 | { | 228 | { |
251 | alpha = ((*paragraph_it)->mAddTime - skip_time)/(mLinePersistTime - mFadeTime); | 229 | alpha = ((*paragraph_it).mAddTime - skip_time)/(mLinePersistTime - mFadeTime); |
252 | } | 230 | } |
253 | else | 231 | else |
254 | { | 232 | { |
@@ -257,12 +235,12 @@ void LLConsole::draw() | |||
257 | 235 | ||
258 | if( alpha > 0.f ) | 236 | if( alpha > 0.f ) |
259 | { | 237 | { |
260 | for (lines_t::iterator line_it=(*paragraph_it)->mLines.begin(); | 238 | for (lines_t::iterator line_it=(*paragraph_it).mLines.begin(); |
261 | line_it != (*paragraph_it)->mLines.end(); | 239 | line_it != (*paragraph_it).mLines.end(); |
262 | line_it ++) | 240 | line_it ++) |
263 | { | 241 | { |
264 | for (line_color_segments_t::iterator seg_it = (*line_it).begin(); | 242 | for (line_color_segments_t::iterator seg_it = (*line_it).mLineColorSegments.begin(); |
265 | seg_it != (*line_it).end(); | 243 | seg_it != (*line_it).mLineColorSegments.end(); |
266 | seg_it++) | 244 | seg_it++) |
267 | { | 245 | { |
268 | mFont->render((*seg_it).mText, 0, (*seg_it).mXPosition - 8, y_pos - y_off, | 246 | mFont->render((*seg_it).mText, 0, (*seg_it).mXPosition - 8, y_pos - y_off, |
@@ -285,34 +263,21 @@ void LLConsole::draw() | |||
285 | } | 263 | } |
286 | } | 264 | } |
287 | 265 | ||
288 | //virtual | 266 | void LLConsole::addLine(const std::string& utf8line) |
289 | void LLConsole::clear() | ||
290 | { | 267 | { |
291 | mTimer.reset(); | 268 | LLWString wline = utf8str_to_wstring(utf8line); |
292 | LLMutexLock lock(&mQueueMutex); | 269 | addLine(wline, 0.f, LLColor4(1.f, 1.f, 1.f, 1.f)); |
293 | std::for_each(mParagraphs.begin(), mParagraphs.end(), DeletePointer()); | ||
294 | mParagraphs.clear(); | ||
295 | std::for_each(mNewParagraphs.begin(), mNewParagraphs.end(), DeletePointer()); | ||
296 | mNewParagraphs.clear(); | ||
297 | } | 270 | } |
298 | 271 | ||
299 | //virtual | 272 | void LLConsole::addLine(const LLWString& wline) |
300 | void LLConsole::addLine(const std::string& utf8line) | ||
301 | { | 273 | { |
302 | addConsoleLine(utf8line, LLColor4(1.f, 1.f, 1.f, 1.f)); | 274 | addLine(wline, 0.f, LLColor4(1.f, 1.f, 1.f, 1.f)); |
303 | } | 275 | } |
304 | 276 | ||
305 | void LLConsole::addConsoleLine(const std::string& utf8line, const LLColor4 &color) | 277 | void LLConsole::addLine(const std::string& utf8line, F32 size, const LLColor4 &color) |
306 | { | 278 | { |
307 | LLWString wline = utf8str_to_wstring(utf8line); | 279 | LLWString wline = utf8str_to_wstring(utf8line); |
308 | addConsoleLine(wline, color); | 280 | addLine(wline, size, color); |
309 | } | ||
310 | |||
311 | void LLConsole::addConsoleLine(const LLWString& wline, const LLColor4 &color) | ||
312 | { | ||
313 | Paragraph* paragraph = new Paragraph(wline, color, mTimer.getElapsedTimeF32()); | ||
314 | LLMutexLock lock(&mQueueMutex); | ||
315 | mNewParagraphs.push_back ( paragraph ); | ||
316 | } | 281 | } |
317 | 282 | ||
318 | //Generate highlight color segments for this paragraph. Pass in default color of paragraph. | 283 | //Generate highlight color segments for this paragraph. Pass in default color of paragraph. |
@@ -394,7 +359,7 @@ void LLConsole::Paragraph::updateLines(F32 screen_width, LLFontGL* font, bool fo | |||
394 | F32 x_position = 0; //Screen X position of text. | 359 | F32 x_position = 0; //Screen X position of text. |
395 | 360 | ||
396 | mMaxWidth = llmax( mMaxWidth, (F32)font->getWidth( mParagraphText.substr( paragraph_offset, drawable ).c_str() ) ); | 361 | mMaxWidth = llmax( mMaxWidth, (F32)font->getWidth( mParagraphText.substr( paragraph_offset, drawable ).c_str() ) ); |
397 | line_color_segments_t line; | 362 | Line line; |
398 | 363 | ||
399 | U32 left_to_draw = drawable; | 364 | U32 left_to_draw = drawable; |
400 | U32 drawn = 0; | 365 | U32 drawn = 0; |
@@ -403,7 +368,7 @@ void LLConsole::Paragraph::updateLines(F32 screen_width, LLFontGL* font, bool fo | |||
403 | && current_color != mParagraphColorSegments.end() ) | 368 | && current_color != mParagraphColorSegments.end() ) |
404 | { | 369 | { |
405 | LLWString color_text = mParagraphText.substr( paragraph_offset + drawn, current_color_length ); | 370 | LLWString color_text = mParagraphText.substr( paragraph_offset + drawn, current_color_length ); |
406 | line.push_back( LineColorSegment( color_text, //Append segment to line. | 371 | line.mLineColorSegments.push_back( LineColorSegment( color_text, //Append segment to line. |
407 | (*current_color).mColor, | 372 | (*current_color).mColor, |
408 | x_position ) ); | 373 | x_position ) ); |
409 | 374 | ||
@@ -424,7 +389,7 @@ void LLConsole::Paragraph::updateLines(F32 screen_width, LLFontGL* font, bool fo | |||
424 | { | 389 | { |
425 | LLWString color_text = mParagraphText.substr( paragraph_offset + drawn, left_to_draw ); | 390 | LLWString color_text = mParagraphText.substr( paragraph_offset + drawn, left_to_draw ); |
426 | 391 | ||
427 | line.push_back( LineColorSegment( color_text, //Append segment to line. | 392 | line.mLineColorSegments.push_back( LineColorSegment( color_text, //Append segment to line. |
428 | (*current_color).mColor, | 393 | (*current_color).mColor, |
429 | x_position ) ); | 394 | x_position ) ); |
430 | 395 | ||
@@ -442,9 +407,50 @@ void LLConsole::Paragraph::updateLines(F32 screen_width, LLFontGL* font, bool fo | |||
442 | } | 407 | } |
443 | 408 | ||
444 | //Pass in the string and the default color for this block of text. | 409 | //Pass in the string and the default color for this block of text. |
445 | LLConsole::Paragraph::Paragraph (LLWString str, const LLColor4 &color, F32 add_time) | 410 | LLConsole::Paragraph::Paragraph (LLWString str, const LLColor4 &color, F32 add_time, LLFontGL* font, F32 screen_width) |
446 | : mParagraphText(str), mAddTime(add_time), mMaxWidth(-1) | 411 | : mParagraphText(str), mAddTime(add_time), mMaxWidth(-1) |
447 | { | 412 | { |
448 | makeParagraphColorSegments(color); | 413 | makeParagraphColorSegments(color); |
414 | updateLines( screen_width, font ); | ||
449 | } | 415 | } |
450 | 416 | ||
417 | void LLConsole::addLine(const LLWString& wline, F32 size, const LLColor4 &color) | ||
418 | { | ||
419 | Paragraph paragraph(wline, color, mTimer.getElapsedTimeF32(), mFont, (F32)getRect().getWidth() ); | ||
420 | |||
421 | mParagraphs.push_back ( paragraph ); | ||
422 | |||
423 | #if LL_WINDOWS && LL_LCD_COMPILE | ||
424 | // add to LCD screen | ||
425 | AddNewDebugConsoleToLCD(wline); | ||
426 | #endif | ||
427 | } | ||
428 | |||
429 | // | ||
430 | //check if there are some messages stored in the buffer | ||
431 | //if yes, output them. | ||
432 | // | ||
433 | void LLConsole::updateBuffer() | ||
434 | { | ||
435 | BOOL need_clear = FALSE ; | ||
436 | |||
437 | mMutex.lock() ; | ||
438 | if(!mLines.empty()) | ||
439 | { | ||
440 | S32 end = mLines.size() ; | ||
441 | LLColor4 color(1.f, 1.f, 1.f, 1.f) ; | ||
442 | for(S32 i = 0 ; i < end ; i++) | ||
443 | { | ||
444 | Paragraph paragraph(mLines[i], color, mAddTimes[i], mFont, (F32)getRect().getWidth() ); | ||
445 | mParagraphs.push_back ( paragraph ); | ||
446 | } | ||
447 | |||
448 | need_clear = TRUE ; | ||
449 | } | ||
450 | mMutex.unlock() ; | ||
451 | |||
452 | if(need_clear) | ||
453 | { | ||
454 | clear() ; | ||
455 | } | ||
456 | } | ||