From 7df86c159a1c069cd1ffb59f8ec3f4273b84c42a Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 29 Aug 2024 10:55:38 +0200 Subject: Some margin and indentation tweaks in news and NPC dialogs * Apply indentation after wrapping only in NPC dialogs and chat window, since we don't want this in the updater window / news. * Added some margin around the text in the updater window and NPC dialogs, using gcn::Widget::setFrameSize. * Cosmetic changes to BrowserBox implementation. --- src/gui/widgets/browserbox.cpp | 42 ++++++++++++++++-------------------------- src/gui/widgets/browserbox.h | 33 ++++++++++++++++++++------------- src/gui/widgets/chattab.cpp | 1 + 3 files changed, 37 insertions(+), 39 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 7b77721c..a0c361d0 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -66,7 +66,7 @@ LayoutContext::LayoutContext(gcn::Font *font) } -BrowserBox::BrowserBox(unsigned int mode): +BrowserBox::BrowserBox(Mode mode): mMode(mode) { setFocusable(true); @@ -148,15 +148,10 @@ void BrowserBox::addRow(const std::string &row) for (auto &row : mTextRows) { for (auto &part : row.parts) - { part.y -= removedHeight; - } for (auto &link : row.links) - { - link.y1 -= removedHeight; - link.y2 -= removedHeight; - } + link.rect.y -= removedHeight; } } @@ -207,25 +202,21 @@ void BrowserBox::draw(gcn::Graphics *graphics) { auto &link = *mHoveredLink; + const gcn::Rectangle &rect = link.rect; + if (mHighlightMode & BACKGROUND) { graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT)); - graphics->fillRectangle(gcn::Rectangle( - link.x1, - link.y1, - link.x2 - link.x1, - link.y2 - link.y1 - )); + graphics->fillRectangle(rect); } if (mHighlightMode & UNDERLINE) { graphics->setColor(Theme::getThemeColor(Theme::HYPERLINK)); - graphics->drawLine( - link.x1, - link.y2, - link.x2, - link.y2); + graphics->drawLine(rect.x, + rect.y + rect.height, + rect.x + rect.width, + rect.y + rect.height); } } @@ -332,7 +323,7 @@ void BrowserBox::layoutTextRow(TextRow &row, LayoutContext &context) if (wrapped) { context.y += context.lineHeight; - x = 15; + x = mWrapIndent; wrapped = false; } @@ -388,12 +379,11 @@ void BrowserBox::layoutTextRow(TextRow &row, LayoutContext &context) if (c == '<' && linkIndex < row.links.size()) { auto &link = row.links[linkIndex]; - const int size = context.font->getWidth(link.caption) + 1; - link.x1 = x; - link.y1 = context.y; - link.x2 = link.x1 + size; - link.y2 = context.y + context.fontHeight - 1; + link.rect.x = x; + link.rect.y = context.y; + link.rect.width = context.font->getWidth(link.caption) + 1; + link.rect.height = context.fontHeight - 1; linkIndex++; } @@ -416,7 +406,7 @@ void BrowserBox::layoutTextRow(TextRow &row, LayoutContext &context) // Auto wrap mode if (mMode == AUTO_WRAP && getWidth() > 0 && partWidth > 0 - && (x + partWidth + 10) > getWidth()) + && (x + partWidth) > getWidth()) { bool forced = false; @@ -447,7 +437,7 @@ void BrowserBox::layoutTextRow(TextRow &row, LayoutContext &context) partWidth = context.font->getWidth(part); } while (end > start && partWidth > 0 - && (x + partWidth + 10) > getWidth()); + && (x + partWidth) > getWidth()); if (forced) { diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index e869c52c..d7ff0428 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -35,13 +35,13 @@ struct LayoutContext; struct BrowserLink { - int x1 = 0, x2 = 0, y1 = 0, y2 = 0; /**< Where link is placed */ + gcn::Rectangle rect; /**< Where link is placed */ std::string link; std::string caption; bool contains(int x, int y) const { - return x >= x1 && x < x2 && y >= y1 && y < y2; + return rect.isPointInRect(x, y); } }; @@ -71,7 +71,13 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener { public: - BrowserBox(unsigned int mode = AUTO_SIZE); + enum Mode + { + AUTO_SIZE, + AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ + }; + + BrowserBox(Mode mode = AUTO_SIZE); ~BrowserBox() override; /** @@ -84,6 +90,11 @@ class BrowserBox : public gcn::Widget, */ void setHighlightMode(unsigned int mode) { mHighlightMode = mode; } + /** + * Sets the wrap indent for the browser box. + */ + void setWrapIndent(int indent) { mWrapIndent = indent; } + /** * Sets whether the font will use a shadow for text. */ @@ -126,16 +137,10 @@ class BrowserBox : public gcn::Widget, */ void draw(gcn::Graphics *graphics) override; - void maybeRelayoutText(); - /** - * BrowserBox modes. + * Overridden to avoid drawing the default frame. */ - enum - { - AUTO_SIZE, - AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ - }; + void drawFrame(gcn::Graphics *) override {} /** * BrowserBox colors. @@ -164,7 +169,7 @@ class BrowserBox : public gcn::Widget, * Highlight modes for links. * This can be used for a bitmask. */ - enum + enum LinkHighlightMode { UNDERLINE = 1, BACKGROUND = 2 @@ -174,12 +179,14 @@ class BrowserBox : public gcn::Widget, void relayoutText(); void layoutTextRow(TextRow &row, LayoutContext &context); void updateHoveredLink(int x, int y); + void maybeRelayoutText(); std::deque mTextRows; LinkHandler *mLinkHandler = nullptr; - unsigned int mMode; + Mode mMode; unsigned int mHighlightMode = UNDERLINE | BACKGROUND; + int mWrapIndent = 0; bool mShadows = false; bool mOutline = false; bool mUseLinksAndUserColors = true; diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 964c7eaf..5097bffa 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -51,6 +51,7 @@ ChatTab::ChatTab(const std::string &name) setCaption(name); mTextOutput = new BrowserBox(BrowserBox::AUTO_WRAP); + mTextOutput->setWrapIndent(15); mTextOutput->setMaxRows((int) config.getIntValue("ChatLogLength")); mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler); -- cgit v1.2.3-70-g09d2