diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-01-27 17:54:12 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-01-27 17:54:12 +0300 |
commit | f3cec08689d531cf6fe2c9edc733fa8b00032631 (patch) | |
tree | 0426309dc747b7e2aa4b95b0832e1e4e0835d3df /src | |
parent | 3a0d18fa8b8f6a78479fad7785491feff4f4f468 (diff) | |
download | plus-f3cec08689d531cf6fe2c9edc733fa8b00032631.tar.gz plus-f3cec08689d531cf6fe2c9edc733fa8b00032631.tar.bz2 plus-f3cec08689d531cf6fe2c9edc733fa8b00032631.tar.xz plus-f3cec08689d531cf6fe2c9edc733fa8b00032631.zip |
Move browserboxmode into separate file.
Also convert it to strong typed enum.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/enums/gui/browserboxmode.h | 36 | ||||
-rw-r--r-- | src/gui/popups/popupmenu.cpp | 2 | ||||
-rw-r--r-- | src/gui/popups/speechbubble.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 17 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.h | 15 | ||||
-rw-r--r-- | src/gui/widgets/browserbox_unittest.cc | 2 | ||||
-rw-r--r-- | src/gui/widgets/desktop.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/tabs/chat/chattab.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/tabs/setup_colors.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/didyouknowwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/helpwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 4 | ||||
-rw-r--r-- | src/gui/windows/questswindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/updaterwindow.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/whoisonline.cpp | 2 |
17 files changed, 66 insertions, 30 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61ce1a50b..8c5c0b1f4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1347,6 +1347,7 @@ SET(SRCS gui/buttontext.h const/gui/chat.h gui/chatlog.h + enums/gui/browserboxmode.h enums/gui/chatmsgtype.h enums/gui/chattabtype.h gui/cliprect.h diff --git a/src/Makefile.am b/src/Makefile.am index 911bf05d8..14c136d09 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -120,6 +120,7 @@ SRC += events/actionevent.h \ const/gui/chat.h \ const/gui/pages.h \ gui/chatlog.h \ + enums/gui/browserboxmode.h \ enums/gui/chatmsgtype.h \ enums/gui/chattabtype.h \ gui/cliprect.h \ diff --git a/src/enums/gui/browserboxmode.h b/src/enums/gui/browserboxmode.h new file mode 100644 index 000000000..f7a0e7667 --- /dev/null +++ b/src/enums/gui/browserboxmode.h @@ -0,0 +1,36 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2017 The ManaPlus Developers + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ENUMS_GUI_BROWSERBOXMODE_H +#define ENUMS_GUI_BROWSERBOXMODE_H + +#include "enums/simpletypes/enumdefines.h" + +enumStart(BrowserBoxMode) +{ + AUTO_SIZE = 0, + AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ +} +enumEnd(BrowserBoxMode); + +#endif // ENUMS_GUI_BROWSERBOXMODE_H diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 7e05e3f1f..846c29174 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -104,7 +104,7 @@ PopupMenu *popupMenu = nullptr; PopupMenu::PopupMenu() : Popup("PopupMenu", "popupmenu.xml"), - mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, Opaque_true, + mBrowserBox(new BrowserBox(this, BrowserBoxMode::AUTO_SIZE, Opaque_true, "popupbrowserbox.xml")), mScrollArea(nullptr), mBeingId(BeingId_zero), diff --git a/src/gui/popups/speechbubble.cpp b/src/gui/popups/speechbubble.cpp index c02802095..a76f8694c 100644 --- a/src/gui/popups/speechbubble.cpp +++ b/src/gui/popups/speechbubble.cpp @@ -39,7 +39,7 @@ SpeechBubble::SpeechBubble() : mText(), mSpacing(mSkin ? mSkin->getOption("spacing") : 2), mCaption(new Label(this)), - mSpeechBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, Opaque_true, + mSpeechBox(new BrowserBox(this, BrowserBoxMode::AUTO_SIZE, Opaque_true, "speechbrowserbox.xml")) { setContentSize(140, 46); diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 916ce76d7..c443bf07d 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -98,7 +98,7 @@ int BrowserBox::mInstances = 0; mColors[1][color] = getThemeColor(ThemeColorId::color##_OUTLINE) BrowserBox::BrowserBox(const Widget2 *const widget, - const unsigned int mode, + const BrowserBoxModeT mode, const Opaque opaque, const std::string &skin) : Widget(widget), @@ -409,7 +409,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) } // Auto size mode - if (mMode == AUTO_SIZE) + if (mMode == BrowserBoxMode::AUTO_SIZE) { std::string plain = newRow; for (idx1 = plain.find("##"); @@ -426,7 +426,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) } const int fontHeight = font->getHeight(); - if (mMode == AUTO_WRAP) + if (mMode == BrowserBoxMode::AUTO_WRAP) { unsigned int y = 0; unsigned int nextChar; @@ -911,8 +911,10 @@ int BrowserBox::calcHeight() width = font->getWidth(part); // Auto wrap mode - if (mMode == AUTO_WRAP && wWidth > 0 && width > 0 - && (x + CAST_U32(width) + 10) > wWidth) + if (mMode == BrowserBoxMode::AUTO_WRAP && + wWidth > 0 && + width > 0 && + (x + CAST_U32(width) + 10) > wWidth) { bool forced = false; @@ -976,8 +978,11 @@ int BrowserBox::calcHeight() else width = font->getWidth(part); - if (mMode == AUTO_WRAP && (width == 0 && !processed)) + if (mMode == BrowserBoxMode::AUTO_WRAP && + (width == 0 && !processed)) + { break; + } x += CAST_U32(width); if (x > mDataWidth) diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 7eff1f1ea..77f103d83 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -28,6 +28,8 @@ #include "enums/simpletypes/opaque.h" +#include "enums/gui/browserboxmode.h" + #include "gui/browserlink.h" #include "gui/widgets/linepart.h" @@ -49,7 +51,7 @@ class BrowserBox final : public Widget, * Constructor. */ BrowserBox(const Widget2 *const widget, - const unsigned int mode, + const BrowserBoxModeT mode, const Opaque opaque, const std::string &skin); @@ -112,15 +114,6 @@ class BrowserBox final : public Widget, void updateHeight(); - /** - * BrowserBox modes. - */ - enum - { - AUTO_SIZE = 0, - AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ - }; - enum { RED = 0, @@ -205,7 +198,7 @@ class BrowserBox final : public Widget, LinkHandler *mLinkHandler; Skin *mSkin; - unsigned int mMode; + BrowserBoxModeT mMode; unsigned int mHighMode; int mSelectedLink; unsigned int mMaxRows; diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc index c2316eaa3..b31758cbd 100644 --- a/src/gui/widgets/browserbox_unittest.cc +++ b/src/gui/widgets/browserbox_unittest.cc @@ -70,7 +70,7 @@ TEST_CASE("BrowserBox tests", "browserbox") Widget::setGlobalFont(new Font("/usr/share/fonts/truetype/" "ttf-dejavu/DejaVuSans-Oblique.ttf", 18)); BrowserBox *const box = new BrowserBox(nullptr, - BrowserBox::AUTO_WRAP, + BrowserBoxMode::AUTO_WRAP, Opaque_true, ""); box->setWidth(100); diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 05a31f4ec..46bb3cba3 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -52,7 +52,7 @@ Desktop::Desktop(const Widget2 *const widget) : LinkHandler(), WidgetListener(), mWallpaper(nullptr), - mVersionLabel(new BrowserBox(this, BrowserBox::AUTO_WRAP, Opaque_false, + mVersionLabel(new BrowserBox(this, BrowserBoxMode::AUTO_WRAP, Opaque_false, "browserbox.xml")), mSkin(nullptr), mBackgroundColor(getThemeColor(ThemeColorId::BACKGROUND, 128)), diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp index 5691f063a..0a8d38355 100644 --- a/src/gui/widgets/tabs/chat/chattab.cpp +++ b/src/gui/widgets/tabs/chat/chattab.cpp @@ -69,7 +69,7 @@ ChatTab::ChatTab(const Widget2 *const widget, const std::string &logName, const ChatTabTypeT &type) : Tab(widget), - mTextOutput(new BrowserBox(this, BrowserBox::AUTO_WRAP, Opaque_true, + mTextOutput(new BrowserBox(this, BrowserBoxMode::AUTO_WRAP, Opaque_true, "browserbox.xml")), mScrollArea(new ScrollArea(this, mTextOutput, Opaque_false)), mChannelName(channel), diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp index e0fc0b21e..9f7ad0154 100644 --- a/src/gui/widgets/tabs/setup_colors.cpp +++ b/src/gui/widgets/tabs/setup_colors.cpp @@ -55,7 +55,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) : mColorBox(CREATEWIDGETR(ListBox, this, userPalette, "")), mScroll(new ScrollArea(this, mColorBox, Opaque_true, "setup_colors_background.xml")), - mPreview(new BrowserBox(this, BrowserBox::AUTO_WRAP, Opaque_true, + mPreview(new BrowserBox(this, BrowserBoxMode::AUTO_WRAP, Opaque_true, "browserbox.xml")), mTextPreview(new TextPreview(this, gettext(rawmsg))), mPreviewBox(new ScrollArea(this, mPreview, Opaque_true, diff --git a/src/gui/windows/didyouknowwindow.cpp b/src/gui/windows/didyouknowwindow.cpp index 1b66acf05..43251f2dd 100644 --- a/src/gui/windows/didyouknowwindow.cpp +++ b/src/gui/windows/didyouknowwindow.cpp @@ -55,7 +55,7 @@ DidYouKnowWindow::DidYouKnowWindow() : Window(_("Did You Know?"), Modal_false, nullptr, "didyouknow.xml"), ActionListener(), mItemLinkHandler(new ItemLinkHandler), - mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, Opaque_true, + mBrowserBox(new BrowserBox(this, BrowserBoxMode::AUTO_SIZE, Opaque_true, "browserbox.xml")), mScrollArea(new ScrollArea(this, mBrowserBox, Opaque_true, "didyouknow_background.xml")), diff --git a/src/gui/windows/helpwindow.cpp b/src/gui/windows/helpwindow.cpp index 14be15074..62c341ac3 100644 --- a/src/gui/windows/helpwindow.cpp +++ b/src/gui/windows/helpwindow.cpp @@ -56,7 +56,7 @@ HelpWindow::HelpWindow() : ActionListener(), // TRANSLATORS: help window. button. mDYKButton(new Button(this, _("Did you know..."), "DYK", this)), - mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, Opaque_true, + mBrowserBox(new BrowserBox(this, BrowserBoxMode::AUTO_SIZE, Opaque_true, "browserbox.xml")), mScrollArea(new ScrollArea(this, mBrowserBox, Opaque_true, "help_background.xml")), diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index c4f8c6b9c..1c7fca17e 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -100,7 +100,7 @@ NpcDialog::NpcDialog(const BeingId npcId) : mNpcId(npcId), mDefaultInt(0), mDefaultString(), - mTextBox(new BrowserBox(this, BrowserBox::AUTO_WRAP, Opaque_true, + mTextBox(new BrowserBox(this, BrowserBoxMode::AUTO_WRAP, Opaque_true, "browserbox.xml")), mScrollArea(new ScrollArea(this, mTextBox, fromBool(getOptionBool("showtextbackground"), Opaque), @@ -1293,7 +1293,7 @@ void NpcDialog::createSkinControls() { const NpcTextInfo *const info = *it; BrowserBox *box = new BrowserBox(this, - BrowserBox::AUTO_WRAP, + BrowserBoxMode::AUTO_WRAP, Opaque_true, "browserbox.xml"); box->setOpaque(Opaque_false); diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp index f8288c976..e0bb3305d 100644 --- a/src/gui/windows/questswindow.cpp +++ b/src/gui/windows/questswindow.cpp @@ -72,7 +72,7 @@ QuestsWindow::QuestsWindow() : fromBool(getOptionBool("showlistbackground"), Opaque), "quests_list_background.xml")), mItemLinkHandler(new ItemLinkHandler), - mText(new BrowserBox(this, BrowserBox::AUTO_WRAP, Opaque_true, + mText(new BrowserBox(this, BrowserBoxMode::AUTO_WRAP, Opaque_true, "browserbox.xml")), mTextScrollArea(new ScrollArea(this, mText, fromBool(getOptionBool("showtextbackground"), Opaque), diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index 918f44c99..941788723 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -195,7 +195,7 @@ UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost, mProgressBar(new ProgressBar(this, 0.0, 310, 0, ProgressColorId::PROG_UPDATE, "updateprogressbar.xml", "updateprogressbar_fill.xml")), - mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, Opaque_true, + mBrowserBox(new BrowserBox(this, BrowserBoxMode::AUTO_SIZE, Opaque_true, "browserbox.xml")), mScrollArea(new ScrollArea(this, mBrowserBox, Opaque_true, "update_background.xml")), diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp index bfc72ca3b..b11b957c5 100644 --- a/src/gui/windows/whoisonline.cpp +++ b/src/gui/windows/whoisonline.cpp @@ -100,7 +100,7 @@ WhoIsOnline::WhoIsOnline() : mThread(nullptr), mMemoryBuffer(nullptr), mCurlError(new char[CURL_ERROR_SIZE]), - mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, Opaque_true, + mBrowserBox(new BrowserBox(this, BrowserBoxMode::AUTO_SIZE, Opaque_true, "onlinebrowserbox.xml")), mScrollArea(new ScrollArea(this, mBrowserBox, Opaque_false)), // TRANSLATORS: who is online. button. |