diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-06-21 02:23:37 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-06-21 02:23:37 +0300 |
commit | b5c71a87d2a0c2c6981331d5958b474162934532 (patch) | |
tree | 7856fc9f506476f302755ba185a08dadd2d35516 | |
parent | ce2eb9e56d8c54fd26023e073cb29b3bb3b60de2 (diff) | |
download | manaverse-b5c71a87d2a0c2c6981331d5958b474162934532.tar.gz manaverse-b5c71a87d2a0c2c6981331d5958b474162934532.tar.bz2 manaverse-b5c71a87d2a0c2c6981331d5958b474162934532.tar.xz manaverse-b5c71a87d2a0c2c6981331d5958b474162934532.zip |
Remove browserboxmode.
-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/widgets/browserbox.cpp | 121 | ||||
-rw-r--r-- | src/gui/widgets/browserbox.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/browserbox_unittest.cc | 1 | ||||
-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/npcdialog.cpp | 3 |
9 files changed, 46 insertions, 124 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd48f24cb..a93145830 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1382,7 +1382,6 @@ SET(SRCS gui/buttontext.h const/gui/chat.h gui/chatlog.h - enums/gui/browserboxmode.h enums/gui/chatmsgtype.h enums/gui/chattabtype.h enums/gui/colorname.h diff --git a/src/Makefile.am b/src/Makefile.am index 0b5a34bd8..7009c0b0c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -177,7 +177,6 @@ BASE_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 \ enums/gui/colorname.h \ diff --git a/src/enums/gui/browserboxmode.h b/src/enums/gui/browserboxmode.h deleted file mode 100644 index f7a0e7667..000000000 --- a/src/enums/gui/browserboxmode.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 486ad9ebd..592283910 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -60,7 +60,6 @@ int BrowserBox::mInstances = 0; mColors[1][ColorName::color] = getThemeColor(ThemeColorId::color##_OUTLINE) BrowserBox::BrowserBox(const Widget2 *const widget, - const BrowserBoxModeT mode, const Opaque opaque, const std::string &skin) : Widget(widget), @@ -72,7 +71,6 @@ BrowserBox::BrowserBox(const Widget2 *const widget, mLinks(), mLinkHandler(nullptr), mSkin(nullptr), - mMode(mode), mHighlightMode(0), mSelectedLink(-1), mMaxRows(0), @@ -283,87 +281,58 @@ void BrowserBox::addRow(const std::string &row, const bool atTop) } } - // Auto size mode - if (mMode == BrowserBoxMode::AUTO_SIZE) - { - std::string plain = newRow; - // workaround if used only one string started from bold - // width for this string can be calculated wrong - // this workaround fix width if string start from bold sign - const bool startBold = (plain.find("##B") == 0); - for (idx1 = plain.find("##"); - idx1 != std::string::npos; - idx1 = plain.find("##")) - { - plain.erase(idx1, 3); - } - - // Adjust the BrowserBox size - const int w = startBold ? - boldFont->getWidth(plain) : font->getWidth(plain) + 2 * mPadding; - if (w > getWidth()) - setWidth(w); - } - const int fontHeight = font->getHeight(); - if (mMode == BrowserBoxMode::AUTO_WRAP) + unsigned int y = 0; + unsigned int nextChar; + const char *const hyphen = "~"; + const unsigned int hyphenWidth = CAST_U32( + font->getWidth(hyphen)); + unsigned int x = 0; + + FOR_EACH (TextRowCIter, i, mTextRows) { - unsigned int y = 0; - unsigned int nextChar; - const char *const hyphen = "~"; - const unsigned int hyphenWidth = CAST_U32( - font->getWidth(hyphen)); - unsigned int x = 0; - - FOR_EACH (TextRowCIter, i, mTextRows) + std::string tempRow = *i; + for (uint32_t j = 0, sz = CAST_U32(tempRow.size()); + j < sz; + j++) { - std::string tempRow = *i; - for (uint32_t j = 0, sz = CAST_U32(tempRow.size()); - j < sz; - j++) - { - const std::string character = tempRow.substr(j, 1); - x += CAST_U32(font->getWidth(character)); - nextChar = j + 1; + const std::string character = tempRow.substr(j, 1); + x += CAST_U32(font->getWidth(character)); + nextChar = j + 1; - // Wraping between words (at blank spaces) - if (nextChar < sz && tempRow.at(nextChar) == ' ') - { - int nextSpacePos = CAST_U32( - tempRow.find(' ', (nextChar + 1))); - if (nextSpacePos <= 0) - nextSpacePos = CAST_U32(sz) - 1U; - - const unsigned int nextWordWidth = - CAST_U32(font->getWidth( - tempRow.substr(nextChar, - (CAST_U32(nextSpacePos) - nextChar)))); - - if ((x + nextWordWidth + 10) - > CAST_U32(getWidth())) - { - x = mNewLinePadding; // Ident in new line - y += 1; - j ++; - } - } - // Wrapping looong lines (brutal force) - else if ((x + 2 * hyphenWidth) - > CAST_U32(getWidth())) + // Wraping between words (at blank spaces) + if (nextChar < sz && tempRow.at(nextChar) == ' ') + { + int nextSpacePos = CAST_U32( + tempRow.find(' ', (nextChar + 1))); + if (nextSpacePos <= 0) + nextSpacePos = CAST_U32(sz) - 1U; + + const unsigned int nextWordWidth = + CAST_U32(font->getWidth( + tempRow.substr(nextChar, + (CAST_U32(nextSpacePos) - nextChar)))); + + if ((x + nextWordWidth + 10) + > CAST_U32(getWidth())) { x = mNewLinePadding; // Ident in new line y += 1; + j ++; } } + // Wrapping looong lines (brutal force) + else if ((x + 2 * hyphenWidth) + > CAST_U32(getWidth())) + { + x = mNewLinePadding; // Ident in new line + y += 1; + } } - - setHeight(fontHeight * (CAST_S32( - CAST_U32(mTextRows.size()) + y))); - } - else - { - setHeight(fontHeight * CAST_S32(mTextRows.size())); } + + setHeight(fontHeight * (CAST_S32( + CAST_U32(mTextRows.size()) + y))); mUpdateTime = 0; updateHeight(); } @@ -789,8 +758,7 @@ int BrowserBox::calcHeight() width = font->getWidth(part); // Auto wrap mode - if (mMode == BrowserBoxMode::AUTO_WRAP && - wWidth > 0 && + if (wWidth > 0 && width > 0 && (x + CAST_U32(width) + 10) > wWidth) { @@ -856,11 +824,8 @@ int BrowserBox::calcHeight() else width = font->getWidth(part); - if (mMode == BrowserBoxMode::AUTO_WRAP && - (width == 0 && !processed)) - { + if (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 60635c8de..04cff5aff 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -26,7 +26,6 @@ #include "enums/simpletypes/opaque.h" -#include "enums/gui/browserboxmode.h" #include "enums/gui/colorname.h" #include "gui/browserlink.h" @@ -54,7 +53,6 @@ class BrowserBox final : public Widget, * Constructor. */ BrowserBox(const Widget2 *const widget, - const BrowserBoxModeT mode, const Opaque opaque, const std::string &skin); @@ -180,7 +178,6 @@ class BrowserBox final : public Widget, LinkHandler *mLinkHandler; Skin *mSkin; - BrowserBoxModeT mMode; unsigned int mHighlightMode; int mSelectedLink; unsigned int mMaxRows; diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc index f151e1524..e32eaa68a 100644 --- a/src/gui/widgets/browserbox_unittest.cc +++ b/src/gui/widgets/browserbox_unittest.cc @@ -93,7 +93,6 @@ 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, - BrowserBoxMode::AUTO_WRAP, Opaque_true, ""); box->setWidth(100); diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp index 91df77ded..358fd8c44 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, BrowserBoxMode::AUTO_WRAP, Opaque_true, + mTextOutput(new BrowserBox(this, 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 f4efb2832..4f2b35113 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, BrowserBoxMode::AUTO_WRAP, Opaque_true, + mPreview(new BrowserBox(this, Opaque_true, "browserbox.xml")), mTextPreview(new TextPreview(this, gettext(rawmsg))), mPreviewBox(new ScrollArea(this, mPreview, Opaque_true, diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 7b1cedfd2..3e1240c2c 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, BrowserBoxMode::AUTO_WRAP, Opaque_true, + mTextBox(new BrowserBox(this, Opaque_true, "browserbox.xml")), mScrollArea(new ScrollArea(this, mTextBox, fromBool(getOptionBool("showtextbackground"), Opaque), @@ -1293,7 +1293,6 @@ void NpcDialog::createSkinControls() { const NpcTextInfo *const info = *it; BrowserBox *box = new BrowserBox(this, - BrowserBoxMode::AUTO_WRAP, Opaque_true, "browserbox.xml"); box->setOpaque(Opaque_false); |