diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-09-30 14:03:48 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-09-30 14:03:48 +0300 |
commit | 25d77892d72d455f8a89372687db45aefbc61cec (patch) | |
tree | de03cb1af09eebf6db853a6585b953884bcca3b2 /src/gui/windows/emotewindow.cpp | |
parent | 05c22dd1a69fe90da67188c74a6995ee3747e937 (diff) | |
download | mv-25d77892d72d455f8a89372687db45aefbc61cec.tar.gz mv-25d77892d72d455f8a89372687db45aefbc61cec.tar.bz2 mv-25d77892d72d455f8a89372687db45aefbc61cec.tar.xz mv-25d77892d72d455f8a89372687db45aefbc61cec.zip |
move windows classes to windows directory.
Diffstat (limited to 'src/gui/windows/emotewindow.cpp')
-rw-r--r-- | src/gui/windows/emotewindow.cpp | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp new file mode 100644 index 000000000..cdff2d31d --- /dev/null +++ b/src/gui/windows/emotewindow.cpp @@ -0,0 +1,229 @@ +/* + * 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/windows/emotewindow.h" + +#include "gui/widgets/colormodel.h" +#include "gui/widgets/colorpage.h" +#include "gui/widgets/emotepage.h" +#include "gui/widgets/namesmodel.h" +#include "gui/widgets/scrollarea.h" +#include "gui/widgets/tabbedarea.h" + +#include "utils/gettext.h" + +#include "resources/image.h" +#include "resources/imageset.h" + +#include "debug.h" + +static const int fontSizeListSize = 2; + +static const char *const fontSizeList[] = +{ + // TRANSLATORS: font size + N_("Normal font"), + // TRANSLATORS: font size + N_("Bold font"), +}; + +EmoteWindow::EmoteWindow() : + // TRANSLATORS: emotes window name + Window(_("Emotes"), false, nullptr, "emotes.xml"), + mTabs(new TabbedArea(this)), + mEmotePage(new EmotePage(this)), + mColorModel(ColorModel::createDefault(this)), + mColorPage(new ColorPage(this, mColorModel, "colorpage.xml")), + mScrollColorPage(new ScrollArea(mColorPage, false, "emotepage.xml")), + mFontModel(new NamesModel), + mFontPage(new ListBox(this, mFontModel, "")), + mScrollFontPage(new ScrollArea(mFontPage, false, "fontpage.xml")), + mImageSet(Theme::getImageSetFromThemeXml("emotetabs.xml", "", 17, 16)) +{ + setShowTitle(false); + setResizable(true); + + addMouseListener(this); + const int pad2 = mPadding * 2; + const int width = 200; + const int height = 150; + setWidth(width + pad2); + setHeight(height + pad2); + add(mTabs); + mTabs->setPosition(mPadding, mPadding); + mTabs->setWidth(width); + mTabs->setHeight(height); + center(); + + setTitleBarHeight(getPadding() + getTitlePadding()); + mScrollColorPage->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS); + mScrollColorPage->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mScrollFontPage->setVerticalScrollPolicy(ScrollArea::SHOW_NEVER); + mScrollFontPage->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + + mFontModel->fillFromArray(&fontSizeList[0], fontSizeListSize); + mFontPage->setCenter(true); + + if (mImageSet && mImageSet->size() >= 3) + { + for (int f = 0; f < 3; f ++) + { + Image *const image = mImageSet->get(f); + if (image) + image->incRef(); + } + + mTabs->addTab(mImageSet->get(0), mEmotePage); + mTabs->addTab(mImageSet->get(2), mScrollColorPage); + mTabs->addTab(mImageSet->get(1), mScrollFontPage); + } + else + { + // TRANSLATORS: emotes tab name + mTabs->addTab(_("Emotes"), mEmotePage); + // TRANSLATORS: emotes tab name + mTabs->addTab(_("Colors"), mScrollColorPage); + // TRANSLATORS: emotes tab name + mTabs->addTab(_("Fonts"), mScrollFontPage); + } + + mEmotePage->setActionEventId("emote"); + mColorPage->setActionEventId("color"); + mFontPage->setActionEventId("font"); +} + +EmoteWindow::~EmoteWindow() +{ + mTabs->removeAll(false); + mTabs->removeTab(mTabs->getTabByIndex(0)); + delete mEmotePage; + mEmotePage = nullptr; + delete mColorPage; + mColorPage = nullptr; + delete mColorModel; + mColorModel = nullptr; + delete mScrollColorPage; + mScrollColorPage = nullptr; + delete mFontPage; + mFontPage = nullptr; + delete mFontModel; + mFontModel = nullptr; + delete mScrollFontPage; + mScrollFontPage = nullptr; + if (mImageSet) + { + mImageSet->decRef(); + mImageSet = nullptr; + } +} + +void EmoteWindow::show() +{ + setVisible(true); +} + +void EmoteWindow::hide() +{ + setVisible(false); +} + +std::string EmoteWindow::getSelectedEmote() const +{ + const int index = mEmotePage->getSelectedIndex(); + if (index < 0) + return std::string(); + + char chr[2]; + chr[0] = '0' + index; + chr[1] = 0; + return std::string("%%").append(&chr[0]); +} + +void EmoteWindow::clearEmote() +{ + const int index = mEmotePage->getSelectedIndex(); + mEmotePage->resetAction(); + if (index >= 0) + setVisible(false); +} + +std::string EmoteWindow::getSelectedColor() const +{ + const int index = mColorPage->getSelected(); + if (index < 0) + return std::string(); + + char chr[2]; + chr[0] = '0' + index; + chr[1] = 0; + return std::string("##").append(&chr[0]); +} + +void EmoteWindow::clearColor() +{ + mColorPage->resetAction(); + setVisible(false); +} + +std::string EmoteWindow::getSelectedFont() const +{ + const int index = mFontPage->getSelected(); + if (index < 0) + return std::string(); + + if (!index) + return "##b"; + else + return "##B"; +} + +void EmoteWindow::clearFont() +{ + mFontPage->setSelected(-1); + setVisible(false); +} + +void EmoteWindow::addListeners(gcn::ActionListener *const listener) +{ + mEmotePage->addActionListener(listener); + mColorPage->addActionListener(listener); + mFontPage->addActionListener(listener); +} + +void EmoteWindow::widgetResized(const gcn::Event &event) +{ + Window::widgetResized(event); + const int pad2 = mPadding * 2; + const int width = mDimension.width; + const int height = mDimension.height; + + mTabs->setSize(width - pad2, height - pad2); + mTabs->adjustWidget(mEmotePage); + mTabs->adjustWidget(mScrollColorPage); + mColorPage->setSize(mScrollColorPage->getWidth(), + mScrollColorPage->getHeight()); + mEmotePage->widgetResized(event); +} + +void EmoteWindow::widgetMoved(const gcn::Event &event) +{ + Window::widgetMoved(event); + mEmotePage->widgetResized(event); +} |