From 409b9eebe12b864280ead8e3c537a73e40548b97 Mon Sep 17 00:00:00 2001 From: Rye Mutt Date: Sun, 4 Aug 2024 20:02:53 -0400 Subject: Fix chat text segments not dynamically updating when colors changed in preferences --- indra/llui/lllineeditor.h | 2 +- indra/llui/llstyle.cpp | 6 ++-- indra/llui/llstyle.h | 18 +++++++---- indra/llui/lltextbase.cpp | 12 +++---- indra/llui/lltextparser.cpp | 78 ++++++++++++++++++++++----------------------- indra/llui/lltextparser.h | 5 ++- 6 files changed, 64 insertions(+), 57 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index 22ec9ecc8a..cdd22413e7 100644 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -204,7 +204,7 @@ public: void setText(const LLStringExplicit &new_text); const std::string& getText() const override { return mText.getString(); } - LLWString getWText() const { return mText.getWString(); } + const LLWString& getWText() const { return mText.getWString(); } LLWString getConvertedText() const; // trimmed text with paragraphs converted to newlines S32 getLength() const { return mText.length(); } diff --git a/indra/llui/llstyle.cpp b/indra/llui/llstyle.cpp index abf6e1284b..df4b0ef6a0 100644 --- a/indra/llui/llstyle.cpp +++ b/indra/llui/llstyle.cpp @@ -33,11 +33,12 @@ #include "llui.h" LLStyle::Params::Params() -: visible("visible", true), + : visible("visible", true), drop_shadow("drop_shadow", LLFontGL::NO_SHADOW), color("color", LLColor4::black), readonly_color("readonly_color", LLColor4::black), selected_color("selected_color", LLColor4::black), + alpha("alpha", 1.f), font("font", LLFontGL::getFontMonospace()), image("image"), link_href("href"), @@ -54,7 +55,8 @@ LLStyle::LLStyle(const LLStyle::Params& p) mLink(p.link_href), mIsLink(p.is_link.isProvided() ? p.is_link : !p.link_href().empty()), mDropShadow(p.drop_shadow), - mImagep(p.image()) + mImagep(p.image()), + mAlpha(p.alpha) {} void LLStyle::setFont(const LLFontGL* font) diff --git a/indra/llui/llstyle.h b/indra/llui/llstyle.h index 7dbccfff87..e506895de5 100644 --- a/indra/llui/llstyle.h +++ b/indra/llui/llstyle.h @@ -44,6 +44,7 @@ public: Optional color, readonly_color, selected_color; + Optional alpha; Optional font; Optional image; Optional link_href; @@ -61,6 +62,9 @@ public: const LLUIColor& getSelectedColor() const { return mSelectedColor; } void setSelectedColor(const LLUIColor& color) { mSelectedColor = color; } + F32 getAlpha() const { return mAlpha; } + void setAlpha(F32 alpha) { mAlpha = alpha; } + bool isVisible() const; void setVisible(bool is_visible); @@ -89,7 +93,8 @@ public: && mFont == rhs.mFont && mLink == rhs.mLink && mImagep == rhs.mImagep - && mDropShadow == rhs.mDropShadow; + && mDropShadow == rhs.mDropShadow + && mAlpha == rhs.mAlpha; } bool operator!=(const LLStyle& rhs) const { return !(*this == rhs); } @@ -98,18 +103,19 @@ public: LLFontGL::ShadowType mDropShadow; protected: - ~LLStyle() { } + ~LLStyle() = default; private: - bool mVisible; + std::string mFontName; + std::string mLink; LLUIColor mColor; LLUIColor mReadOnlyColor; LLUIColor mSelectedColor; - std::string mFontName; const LLFontGL* mFont; - std::string mLink; - bool mIsLink; LLPointer mImagep; + F32 mAlpha; + bool mVisible; + bool mIsLink; }; typedef LLPointer LLStyleSP; diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index e09fef40df..0aebf7543c 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -2417,16 +2417,14 @@ void LLTextBase::appendAndHighlightTextImpl(const std::string &new_text, S32 hig { LLStyle::Params highlight_params(style_params); - LLSD pieces = LLTextParser::instance().parsePartialLineHighlights(new_text, highlight_params.color(), (LLTextParser::EHighlightPosition)highlight_part); + auto pieces = LLTextParser::instance().parsePartialLineHighlights(new_text, highlight_params.color, (LLTextParser::EHighlightPosition)highlight_part); for (S32 i = 0; i < pieces.size(); i++) { - LLSD color_llsd = pieces[i]["color"]; - LLColor4 lcolor; - lcolor.setValue(color_llsd); - highlight_params.color = lcolor; + const auto& piece_pair = pieces[i]; + highlight_params.color = piece_pair.second; LLWString wide_text; - wide_text = utf8str_to_wstring(pieces[i]["text"].asString()); + wide_text = utf8str_to_wstring(piece_pair.first); S32 cur_length = getLength(); LLStyleConstSP sp(new LLStyle(highlight_params)); @@ -3333,7 +3331,7 @@ F32 LLNormalTextSegment::drawClippedSegment(S32 seg_start, S32 seg_end, S32 sele const LLFontGL* font = mStyle->getFont(); - LLColor4 color = (mEditor.getReadOnly() ? mStyle->getReadOnlyColor() : mStyle->getColor()) % alpha; + LLColor4 color = (mEditor.getReadOnly() ? mStyle->getReadOnlyColor() : mStyle->getColor()) % (alpha * mStyle->getAlpha()); if( selection_start > seg_start ) { diff --git a/indra/llui/lltextparser.cpp b/indra/llui/lltextparser.cpp index 097b168106..d4ef77664e 100644 --- a/indra/llui/lltextparser.cpp +++ b/indra/llui/lltextparser.cpp @@ -36,6 +36,7 @@ #include "llmath.h" #include "v4color.h" #include "lldir.h" +#include "lluicolor.h" // // Member Functions @@ -80,14 +81,14 @@ S32 LLTextParser::findPattern(const std::string &text, LLSD highlight) return static_cast(found); } -LLSD LLTextParser::parsePartialLineHighlights(const std::string &text, const LLColor4 &color, EHighlightPosition part, S32 index) +LLTextParser::parser_out_vec_t LLTextParser::parsePartialLineHighlights(const std::string &text, const LLUIColor& color, EHighlightPosition part, S32 index) { loadKeywords(); //evil recursive string atomizer. - LLSD ret_llsd, start_llsd, middle_llsd, end_llsd; + parser_out_vec_t ret_vec, start_vec, middle_vec, end_vec; - for (S32 i=index;i>; + + parser_out_vec_t parsePartialLineHighlights(const std::string &text,const LLUIColor &color, EHighlightPosition part=WHOLE, S32 index=0); bool parseFullLineHighlights(const std::string &text, LLColor4 *color); private: -- cgit v1.2.3