diff options
-rw-r--r-- | src/gui/chatwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/npcdialog.cpp | 2 | ||||
-rw-r--r-- | src/gui/updaterwindow.cpp | 1 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 42 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.h | 33 | ||||
-rw-r--r-- | src/gui/widgets/chattab.cpp | 1 |
6 files changed, 41 insertions, 40 deletions
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 0229bf76..29bf9c1b 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -56,7 +56,7 @@ class ChatInput : public TextField, public gcn::FocusListener { public: ChatInput(): - TextField("", false) + TextField(std::string(), false) { setVisible(false); addFocusListener(this); diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index be076fc5..33b512f0 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -87,6 +87,8 @@ NpcDialog::NpcDialog(int npcId) // Setup output text box mTextBox = new BrowserBox(BrowserBox::AUTO_WRAP); + mTextBox->setWrapIndent(15); + mTextBox->setFrameSize(2); mTextBox->setLinkHandler(mItemLinkHandler.get()); mScrollArea = new ScrollArea(mTextBox); diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 802ce271..387b11ef 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -141,6 +141,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mPlayButton = new Button(_("Play"), "play", this); mBrowserBox->setLinkHandler(mLinkHandler.get()); + mBrowserBox->setFrameSize(4); mProgressBar->setSmoothProgress(false); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mPlayButton->setEnabled(false); 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); |