diff options
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/colormodel.cpp | 96 | ||||
-rw-r--r-- | src/gui/widgets/colormodel.h | 76 | ||||
-rw-r--r-- | src/gui/widgets/colorpage.cpp | 110 | ||||
-rw-r--r-- | src/gui/widgets/colorpage.h | 54 | ||||
-rw-r--r-- | src/gui/widgets/listbox.cpp | 10 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.cpp | 9 | ||||
-rw-r--r-- | src/gui/widgets/tabbedarea.h | 2 |
7 files changed, 346 insertions, 11 deletions
diff --git a/src/gui/widgets/colormodel.cpp b/src/gui/widgets/colormodel.cpp new file mode 100644 index 000000000..794dfc08e --- /dev/null +++ b/src/gui/widgets/colormodel.cpp @@ -0,0 +1,96 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2013 The ManaPlus Developers + * + * 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/>. + */ + +#include "gui/widgets/colormodel.h" + +#include "gui/widgets/widget2.h" + +#include "utils/gettext.h" + +#include <guichan/font.hpp> + +#include "debug.h" + +ColorModel::ColorModel() : + mNames(), + mColors() +{ +} + +ColorModel::~ColorModel() +{ +} + +int ColorModel::getNumberOfElements() +{ + return static_cast<int>(mNames.size()); +} + +std::string ColorModel::getElementAt(int i) +{ + if (i >= getNumberOfElements() || i < 0) + return "???"; + return mNames[i]; +} + +ColorPair *ColorModel::getColorAt(int i) +{ + if (i >= static_cast<int>(mColors.size()) || i < 0) + return nullptr; + + return &mColors[i]; +} + +void ColorModel::add(const std::string &name, const gcn::Color *color1, + const gcn::Color *color2) +{ + mNames.push_back(name); + mColors.push_back(ColorPair(color1, color2)); +} + +#define addColor(name, color) \ + model->add(name, &widget->getThemeColor(Theme::color), \ + &widget->getThemeColor(Theme::color##_OUTLINE)); + +ColorModel *ColorModel::createDefault(const Widget2 *const widget) +{ + ColorModel *const model = new ColorModel(); + // TRANSLATORS: color name + addColor(_("black"), BLACK); + // TRANSLATORS: color name + addColor(_("red"), RED); + // TRANSLATORS: color name + addColor(_("green"), GREEN); + // TRANSLATORS: color name + addColor(_("blue"), BLUE); + // TRANSLATORS: color name + addColor(_("gold"), ORANGE); + // TRANSLATORS: color name + addColor(_("yellow"), YELLOW); + // TRANSLATORS: color name + addColor(_("pink"), PINK); + // TRANSLATORS: color name + addColor(_("purple"), PURPLE); + // TRANSLATORS: color name + addColor(_("grey"), GRAY); + // TRANSLATORS: color name + addColor(_("brown"), BROWN); + return model; +} diff --git a/src/gui/widgets/colormodel.h b/src/gui/widgets/colormodel.h new file mode 100644 index 000000000..0035da5e6 --- /dev/null +++ b/src/gui/widgets/colormodel.h @@ -0,0 +1,76 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2013 The ManaPlus Developers + * + * 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 GUI_WIDGETS_COLORMODEL_H +#define GUI_WIDGETS_COLORMODEL_H + +#include "utils/stringvector.h" + +#include "resources/image.h" + +#include <guichan/color.hpp> +#include <guichan/listmodel.hpp> + +class Widget2; + +struct ColorPair +{ + ColorPair(const gcn::Color* c1, const gcn::Color* c2) : + color1(c1), + color2(c2) + { + } + + const gcn::Color* color1; + const gcn::Color* color2; +}; + +class ColorModel : public gcn::ListModel +{ + public: + ColorModel(); + + A_DELETE_COPY(ColorModel) + + virtual ~ColorModel(); + + virtual int getNumberOfElements() override A_WARN_UNUSED; + + virtual std::string getElementAt(int i) override A_WARN_UNUSED; + + virtual ColorPair *getColorAt(int i) A_WARN_UNUSED; + + StringVect &getNames() A_WARN_UNUSED + { return mNames; } + + size_t size() A_WARN_UNUSED + { return mNames.size(); } + + void add(const std::string &name, const gcn::Color *color1, + const gcn::Color *color2); + + static ColorModel *createDefault(const Widget2 *const widget); + + protected: + StringVect mNames; + std::vector<ColorPair> mColors; +}; + +#endif // GUI_WIDGETS_COLORMODEL_H diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp new file mode 100644 index 000000000..bd37dbeeb --- /dev/null +++ b/src/gui/widgets/colorpage.cpp @@ -0,0 +1,110 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * 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/>. + */ + +#include "gui/widgets/colorpage.h" + +#include "gui/widgets/colormodel.h" + +#include "resources/resourcemanager.h" + +#include <guichan/font.hpp> + +#include "debug.h" + +ColorPage::ColorPage(const Widget2 *const widget, + gcn::ListModel *const listModel, + const std::string &skin) : + ListBox(widget, listModel, skin), + mItemPadding(mSkin ? mSkin->getOption("itemPadding") : 1) +{ +// addMouseListener(this); + const gcn::Font *const font = getFont(); + if (font) + mRowHeight = font->getHeight() + 2 * mItemPadding; + else + mRowHeight = 13; + adjustSize(); +} + +ColorPage::~ColorPage() +{ +} + +void ColorPage::draw(gcn::Graphics *graphics) +{ + BLOCK_START("ColorPage::draw") + + ColorModel *const model = static_cast<ColorModel* const>( + mListModel); + Graphics *const g = static_cast<Graphics *const>(graphics); + + mHighlightColor.a = static_cast<int>(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); + updateAlpha(); + gcn::Font *const font = getFont(); + + const int rowHeight = getRowHeight(); + const int width = mDimension.width; + + if (mSelected >= 0) + { + graphics->fillRectangle(gcn::Rectangle(mPadding, + rowHeight * mSelected + mPadding, + mDimension.width - 2 * mPadding, rowHeight)); + + const ColorPair *const colors = model->getColorAt(mSelected); + g->setColorAll(*colors->color1, *colors->color2); + const std::string str = mListModel->getElementAt(mSelected); + font->drawString(graphics, str, (width - font->getWidth(str)) / 2, + mSelected * rowHeight + mPadding); + } + + g->setColorAll(mForegroundColor, mForegroundColor2); + const int sz = mListModel->getNumberOfElements(); + for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight) + { + if (i != mSelected) + { + const ColorPair *const colors = model->getColorAt(i); + g->setColorAll(*colors->color1, *colors->color2); + const std::string str = mListModel->getElementAt(i); + font->drawString(graphics, str, (width - font->getWidth(str)) / 2, + y); + } + } + + BLOCK_END("ColorPage::draw") +} + +void ColorPage::resetAction() +{ + setSelected(-1); +} + +void ColorPage::adjustSize() +{ + BLOCK_START("ColorPage::adjustSize") + if (mListModel) + { + setHeight(getRowHeight() * mListModel->getNumberOfElements() + + 2 * mPadding + 20); + } + BLOCK_END("ColorPage::adjustSize") +} diff --git a/src/gui/widgets/colorpage.h b/src/gui/widgets/colorpage.h new file mode 100644 index 000000000..c86ee5a07 --- /dev/null +++ b/src/gui/widgets/colorpage.h @@ -0,0 +1,54 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * 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 GUI_WIDGETS_COLORPAGE_H +#define GUI_WIDGETS_COLORPAGE_H + +#include "gui/widgets/widget2.h" + +#include "gui/widgets/listbox.h" + +#include <guichan/widget.hpp> + +#include "localconsts.h" + +class ColorPage final : public ListBox +{ + public: + ColorPage(const Widget2 *const widget, + gcn::ListModel *const listModel, + const std::string &skin); + + A_DELETE_COPY(ColorPage) + + ~ColorPage(); + + void draw(gcn::Graphics *graphics) override; + + void resetAction(); + + void adjustSize() override; + + private: + int mItemPadding; + unsigned int mRowHeight; +}; + +#endif // GUI_WIDGETS_COLORPAGE_H diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index e5229eca6..4d05e496e 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -103,22 +103,18 @@ void ListBox::draw(gcn::Graphics *graphics) graphics->fillRectangle(gcn::Rectangle(mPadding, rowHeight * mSelected + mPadding, mDimension.width - 2 * mPadding, rowHeight)); - } - const int sel = getSelected(); - if (sel >= 0) - { g->setColorAll(mForegroundSelectedColor, mForegroundSelectedColor2); - font->drawString(graphics, mListModel->getElementAt(sel), - mPadding, sel * rowHeight + mPadding); + font->drawString(graphics, mListModel->getElementAt(mSelected), + mPadding, mSelected * rowHeight + mPadding); } // Draw the list elements g->setColorAll(mForegroundColor, mForegroundColor2); const int sz = mListModel->getNumberOfElements(); for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight) { - if (i != sel) + if (i != mSelected) { font->drawString(graphics, mListModel->getElementAt(i), mPadding, y); diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index 5e3af38d4..25fc3b8f2 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -610,7 +610,7 @@ gcn::Widget *TabbedArea::getWidgetByIndex(const int index) const return mTabs[index].second; } -void TabbedArea::removeAll() +void TabbedArea::removeAll(bool del) { if (getSelectedTabIndex() != -1) { @@ -622,8 +622,11 @@ void TabbedArea::removeAll() Tab *tab = mTabs[idx].first; gcn::Widget *widget = mTabs[idx].second; removeTab(tab); - delete tab; - delete widget; + if (del) + { + delete tab; + delete widget; + } } } diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h index ec0b43b5e..7be1391a5 100644 --- a/src/gui/widgets/tabbedarea.h +++ b/src/gui/widgets/tabbedarea.h @@ -104,7 +104,7 @@ class TabbedArea final : public Widget2, */ void removeTab(Tab *const tab); - void removeAll(); + void removeAll(bool del = true); /** * Overload the logic function since it's broken in guichan 0.8. |