Synchronize LLConsole with V3

Ansariel 2014-07-11 09:32:04 +02:00
parent 5cdd3864a9
commit 0ecd3e16d6
2 changed files with 139 additions and 40 deletions

View File

@ -64,7 +64,7 @@ LLConsole::LLConsole(const LLConsole::Params& p)
mFont(p.font),
mConsoleWidth(0),
mConsoleHeight(0),
mParseUrls(p.parse_urls) // Ansariel: If lines should be parsed for URLs
mParseUrls(p.parse_urls) // <FS:Ansariel> If lines should be parsed for URLs
{
if (p.font_size_index.isProvided())
{
@ -73,6 +73,7 @@ LLConsole::LLConsole(const LLConsole::Params& p)
mFadeTime = mLinePersistTime - FADE_DURATION;
setMaxLines(LLUI::sSettingGroups["config"]->getS32("ConsoleMaxLines"));
// <FS:Ansariel> Configurable background for different console types
mBackgroundImage = LLUI::getUIImage(p.background_image);
}
@ -100,8 +101,10 @@ void LLConsole::reshape(S32 width, S32 height, BOOL called_from_parent)
for(paragraph_t::iterator paragraph_it = mParagraphs.begin(); paragraph_it != mParagraphs.end(); paragraph_it++)
{
// Ansariel: Added styleflags parameter for style customization
// <FS:Ansariel> Added styleflags parameter for style customization
//(*paragraph_it).updateLines((F32)getRect().getWidth(), mFont, true);
(*paragraph_it).updateLines((F32)getRect().getWidth(), mFont, (*paragraph_it).mLines.front().mStyleFlags, true);
// </FS:Ansariel>
}
}
@ -113,16 +116,24 @@ void LLConsole::setFontSize(S32 size_index)
}
else if (0 == size_index)
{
// <FS>
//mFont = LLFontGL::getFontSansSerif();
mFont = LLFontGL::getFontSansSerifSmall();
// </FS>
}
else if (1 == size_index)
{
// <FS>
//mFont = LLFontGL::getFontSansSerifBig();
mFont = LLFontGL::getFontSansSerif();
// </FS>
}
// <FS>
else if (2 == size_index)
{
mFont = LLFontGL::getFontSansSerifBig();
}
// </FS>
else
{
mFont = LLFontGL::getFontSansSerifHuge();
@ -135,16 +146,22 @@ void LLConsole::setFontSize(S32 size_index)
for(paragraph_t::iterator paragraph_it = mParagraphs.begin(); paragraph_it != mParagraphs.end(); paragraph_it++)
{
// Ansariel: Added styleflags parameter for style customization
// <FSAnsariel> Added styleflags parameter for style customization
//(*paragraph_it).updateLines((F32)getRect().getWidth(), mFont, true);
(*paragraph_it).updateLines((F32)getRect().getWidth(), mFont, (*paragraph_it).mLines.front().mStyleFlags, true);
// </FS:Ansariel>
}
}
void LLConsole::draw()
{
// Units in pixels
// <FS>
//static const F32 padding_horizontal = 10;
//static const F32 padding_vertical = 3;
static const F32 padding_horizontal = 15;
static const F32 padding_vertical = 8;
// </FS>
LLGLSUIDefault gls_ui;
// skip lines added more than mLinePersistTime ago
@ -188,9 +205,69 @@ void LLConsole::draw()
// draw remaining lines
//[FIX FIRE-2822 SJ] Start a little bit higher with the Console not to let it blend with the stand button when Avatar is sitting
//F32 y_pos = 0.f;
F32 y_pos = 10.f;
// <FS:CR> FIRE-1332 - Sepeate opacity settings for nametag and console chat
// <FS> Different draw options
//LLUIImagePtr imagep = LLUI::getUIImage("transparent");
//F32 console_opacity = llclamp(LLUI::sSettingGroups["config"]->getF32("ConsoleBackgroundOpacity"), 0.f, 1.f);
//LLColor4 color = LLUIColorTable::instance().getColor("ConsoleBackground");
//color.mV[VALPHA] *= console_opacity;
//F32 line_height = mFont->getLineHeight();
//for(paragraph_it = mParagraphs.rbegin(); paragraph_it != mParagraphs.rend(); paragraph_it++)
//{
// S32 target_height = llfloor( (*paragraph_it).mLines.size() * line_height + padding_vertical);
// S32 target_width = llfloor( (*paragraph_it).mMaxWidth + padding_horizontal);
// y_pos += ((*paragraph_it).mLines.size()) * line_height;
// imagep->drawSolid(-14, (S32)(y_pos + line_height - target_height), target_width, target_height, color);
// F32 y_off=0;
// F32 alpha;
// if ((mLinePersistTime > 0.f) && ((*paragraph_it).mAddTime < fade_time))
// {
// alpha = ((*paragraph_it).mAddTime - skip_time)/(mLinePersistTime - mFadeTime);
// }
// else
// {
// alpha = 1.0f;
// }
// if( alpha > 0.f )
// {
// for (lines_t::iterator line_it=(*paragraph_it).mLines.begin();
// line_it != (*paragraph_it).mLines.end();
// line_it ++)
// {
// for (line_color_segments_t::iterator seg_it = (*line_it).mLineColorSegments.begin();
// seg_it != (*line_it).mLineColorSegments.end();
// seg_it++)
// {
// mFont->render((*seg_it).mText, 0, (*seg_it).mXPosition - 8, y_pos - y_off,
// LLColor4(
// (*seg_it).mColor.mV[VRED],
// (*seg_it).mColor.mV[VGREEN],
// (*seg_it).mColor.mV[VBLUE],
// (*seg_it).mColor.mV[VALPHA]*alpha),
// LLFontGL::LEFT,
// LLFontGL::BASELINE,
// LLFontGL::NORMAL,
// LLFontGL::DROP_SHADOW,
// S32_MAX,
// target_width
// );
// }
// y_off += line_height;
// }
// }
// y_pos += padding_vertical;
//}
static LLCachedControl<F32> consoleBackgroundOpacity(*LLUI::sSettingGroups["config"], "ConsoleBackgroundOpacity");
static LLUIColor cbcolor = LLUIColorTable::instance().getColor("ConsoleBackground");
LLColor4 color = cbcolor.get();
@ -199,7 +276,6 @@ void LLConsole::draw()
F32 line_height = mFont->getLineHeight();
static LLCachedControl<bool> classic_draw_mode(*LLUI::sSettingGroups["config"], "FSConsoleClassicDrawMode");
// Ansariel: Classic draw mode for console (Single block over all lines and with width of the longest line)
if (classic_draw_mode)
{
static const F32 padding_vert = 5;
@ -250,7 +326,7 @@ void LLConsole::draw()
(*seg_it).mColor.mV[VALPHA]*alpha),
LLFontGL::LEFT,
LLFontGL::BASELINE,
(*line_it).mStyleFlags, // Ansariel: Custom style flags for the font
(*line_it).mStyleFlags,
LLFontGL::DROP_SHADOW,
S32_MAX,
target_width
@ -306,7 +382,7 @@ void LLConsole::draw()
(*seg_it).mColor.mV[VALPHA]*alpha),
LLFontGL::LEFT,
LLFontGL::BASELINE,
(*line_it).mStyleFlags, // Ansariel: Custom style flags for the font
(*line_it).mStyleFlags,
LLFontGL::DROP_SHADOW,
S32_MAX,
target_width
@ -318,16 +394,16 @@ void LLConsole::draw()
y_pos += padding_vertical;
}
}
// </FS>
}
// Ansariel: Added styleflags parameter for style customization
// <FS:Ansariel> Chat console
void LLConsole::addConsoleLine(const std::string& utf8line, const LLColor4 &color, LLFontGL::StyleFlags styleflags)
{
LLWString wline = utf8str_to_wstring(utf8line);
addConsoleLine(wline, color, styleflags);
}
// Ansariel: Added styleflags parameter for style customization
void LLConsole::addConsoleLine(const LLWString& wline, const LLColor4 &color, LLFontGL::StyleFlags styleflags)
{
if (wline.empty())
@ -337,7 +413,7 @@ void LLConsole::addConsoleLine(const LLWString& wline, const LLColor4 &color, LL
removeExtraLines();
// <Ansariel> Parse SLURLs
// Parse SLURLs
LLWString newLine = wline;
if (mParseUrls)
{
@ -352,7 +428,6 @@ void LLConsole::addConsoleLine(const LLWString& wline, const LLColor4 &color, LL
workLine = workLine.erase(0, urlMatch.getEnd() + 1);
}
}
// </Ansariel> Parse SLURLs
mMutex.lock();
mLines.push_back(newLine);
@ -377,6 +452,21 @@ void LLConsole::clear()
mTimer.reset();
}
void LLConsole::removeExtraLines()
{
mMutex.lock();
while ((S32)mLines.size() > llmax((S32)0, (S32)(mMaxLines - 1)))
{
mLines.pop_front();
mAddTimes.pop_front();
mLineLengths.pop_front();
mLineColors.pop_front();
mLineStyle.pop_front();
}
mMutex.unlock();
}
// </FS:Ansariel> Chat console
//Generate highlight color segments for this paragraph. Pass in default color of paragraph.
void LLConsole::Paragraph::makeParagraphColorSegments (const LLColor4 &color)
{
@ -402,8 +492,10 @@ void LLConsole::Paragraph::makeParagraphColorSegments (const LLColor4 &color)
}
//Called when a paragraph is added to the console or window is resized.
// Ansariel: Added styleflags parameter for style customization
// <FS:Ansariel> Added styleflags parameter for style customization
//void LLConsole::Paragraph::updateLines(F32 screen_width, const LLFontGL* font, bool force_resize)
void LLConsole::Paragraph::updateLines(F32 screen_width, const LLFontGL* font, LLFontGL::StyleFlags styleflags, bool force_resize)
// </FS:Ansariel>
{
if ( !force_resize )
{
@ -456,7 +548,7 @@ void LLConsole::Paragraph::updateLines(F32 screen_width, const LLFontGL* font, L
mMaxWidth = llmax( mMaxWidth, (F32)font->getWidth( mParagraphText.substr( paragraph_offset, drawable ).c_str() ) );
Line line;
line.mStyleFlags = styleflags; // Ansariel: Add styleflags to every new line
line.mStyleFlags = styleflags; // <FS:Ansariel> Add styleflags to every new line
U32 left_to_draw = drawable;
U32 drawn = 0;
@ -499,12 +591,17 @@ void LLConsole::Paragraph::updateLines(F32 screen_width, const LLFontGL* font, L
}
//Pass in the string and the default color for this block of text.
// Ansariel: Added styleflags parameter for style customization
// <FS:Ansariel> Added styleflags parameter for style customization
//LLConsole::Paragraph::Paragraph (LLWString str, const LLColor4 &color, F32 add_time, const LLFontGL* font, F32 screen_width)
LLConsole::Paragraph::Paragraph (LLWString str, const LLColor4 &color, F32 add_time, const LLFontGL* font, F32 screen_width, LLFontGL::StyleFlags styleflags)
// </FS:Ansariel>
: mParagraphText(str), mAddTime(add_time), mMaxWidth(-1)
{
makeParagraphColorSegments(color);
// <FS:Ansariel> Added styleflags parameter for style customization
//updateLines( screen_width, font );
updateLines( screen_width, font, styleflags );
// </FS:Ansariel>
}
// called once per frame regardless of console visibility
@ -524,6 +621,15 @@ void LLConsole::update()
while (!mLines.empty())
{
// <FS:Ansariel> Chat console
//mParagraphs.push_back(
// Paragraph( mLines.front(),
// LLColor4::white,
// mTimer.getElapsedTimeF32(),
// mFont,
// (F32)getRect().getWidth()));
//mLines.pop_front();
mParagraphs.push_back(
Paragraph( mLines.front(),
(!mLineColors.empty() ? mLineColors.front() : LLColor4::white),
@ -536,6 +642,7 @@ void LLConsole::update()
mLineColors.pop_front();
if (!mLineStyle.empty())
mLineStyle.pop_front();
// </FS:Ansariel>
}
}
@ -546,16 +653,3 @@ void LLConsole::update()
}
}
void LLConsole::removeExtraLines()
{
mMutex.lock();
while ((S32)mLines.size() > llmax((S32)0, (S32)(mMaxLines - 1)))
{
mLines.pop_front();
mAddTimes.pop_front();
mLineLengths.pop_front();
mLineColors.pop_front();
mLineStyle.pop_front();
}
mMutex.unlock();
}

View File

@ -50,15 +50,15 @@ public:
Optional<U32> max_lines;
Optional<F32> persist_time;
Optional<S32> font_size_index;
Optional<bool> parse_urls; // Ansariel: If lines should be parsed for URLs
Optional<std::string> background_image; // Ansariel: Configurable background for different console types
Optional<bool> parse_urls; // <FS:Ansariel> If lines should be parsed for URLs
Optional<std::string> background_image; // <FS:Ansariel> Configurable background for different console types
Params()
: max_lines("max_lines", LLUI::sSettingGroups["config"]->getS32("ConsoleMaxLines")),
persist_time("persist_time", 0.f), // forever
font_size_index("font_size_index"),
parse_urls("parse_urls", false), // Ansariel: If lines should be parsed for URLs
background_image("background_image", "Console_Background") // Ansariel: Configurable background for different console types
parse_urls("parse_urls", false), // <FS:Ansariel> If lines should be parsed for URLs
background_image("background_image", "Console_Background") // <FS:Ansariel> Configurable background for different console types
{
changeDefault(mouse_opaque, false);
}
@ -103,16 +103,13 @@ public:
{
public:
line_color_segments_t mLineColorSegments;
// Ansariel: Added styleflags member for fontstyle customization
// <FS:Ansariel> Added styleflags member for fontstyle customization
LLFontGL::StyleFlags mStyleFlags;
};
typedef std::list<Line> lines_t;
typedef std::list<ParagraphColorSegment> paragraph_color_segments_t;
std::deque<LLColor4> mLineColors;
std::deque<LLFontGL::StyleFlags> mLineStyle;
//A paragraph is a processed element containing the entire text of the
//message (used for recalculating positions on screen resize)
//The time this message was added to the console output
@ -121,11 +118,15 @@ public:
class Paragraph
{
public:
// Ansariel: Added styleflags parameter for style customization
// <FS:Ansariel> Added styleflags parameter for style customization
//Paragraph (LLWString str, const LLColor4 &color, F32 add_time, const LLFontGL* font, F32 screen_width);
Paragraph (LLWString str, const LLColor4 &color, F32 add_time, const LLFontGL* font, F32 screen_width, LLFontGL::StyleFlags styleflags);
// </FS:Ansariel>
void makeParagraphColorSegments ( const LLColor4 &color);
// Ansariel: Added styleflags parameter for style customization
// <FS:Ansariel> Added styleflags parameter for style customization
//void updateLines ( F32 screen_width, const LLFontGL* font, bool force_resize=false );
void updateLines ( F32 screen_width, const LLFontGL* font, LLFontGL::StyleFlags styleflags, bool force_resize=false );
// </FS:Ansariel>
public:
LLWString mParagraphText; //The entire text of the paragraph
paragraph_color_segments_t mParagraphColorSegments;
@ -153,13 +154,17 @@ public:
// Overrides
/*virtual*/ void draw();
// Ansariel: Added styleflags parameter for style customization
// <FS:Ansariel> Chat console
void addConsoleLine(const std::string& utf8line, const LLColor4 &color, LLFontGL::StyleFlags styleflags = LLFontGL::NORMAL);
void addConsoleLine(const LLWString& wline, const LLColor4 &color, LLFontGL::StyleFlags styleflags = LLFontGL::NORMAL);
void clear();
std::deque<LLColor4> mLineColors;
std::deque<LLFontGL::StyleFlags> mLineStyle;
protected:
void removeExtraLines();
// </FS:Ansariel>
private:
void update();
@ -169,8 +174,8 @@ private:
const LLFontGL* mFont;
S32 mConsoleWidth;
S32 mConsoleHeight;
bool mParseUrls; // Ansariel: If lines should be parsed for URLs
LLUIImagePtr mBackgroundImage; // Ansariel: Configurable background for different console types
bool mParseUrls; // <FS:Ansariel> If lines should be parsed for URLs
LLUIImagePtr mBackgroundImage; // <FS:Ansariel> Configurable background for different console types
};
extern LLConsole* gConsole;