summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-08-29 10:55:38 +0200
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-08-31 11:30:20 +0200
commit7df86c159a1c069cd1ffb59f8ec3f4273b84c42a (patch)
treea92fbd123e94d4d97584344eb598661b7302305f /src/gui/widgets
parente2fb719501c41356f632e6f8838c91d888239037 (diff)
downloadmana-7df86c159a1c069cd1ffb59f8ec3f4273b84c42a.tar.gz
mana-7df86c159a1c069cd1ffb59f8ec3f4273b84c42a.tar.bz2
mana-7df86c159a1c069cd1ffb59f8ec3f4273b84c42a.tar.xz
mana-7df86c159a1c069cd1ffb59f8ec3f4273b84c42a.zip
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.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/browserbox.cpp42
-rw-r--r--src/gui/widgets/browserbox.h33
-rw-r--r--src/gui/widgets/chattab.cpp1
3 files changed, 37 insertions, 39 deletions
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;
/**
@@ -85,6 +91,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.
*/
void setShadowedText(bool shadows) { mShadows = shadows; }
@@ -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<TextRow> 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);