summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-06 14:02:19 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-06 14:12:59 +0300
commit73e7be1617217396c5f1eead52af87bc7fef2357 (patch)
treeb985dfd5f1173a6c7e1c741c796a4a61de0cefa8 /src/gui
parent5ffbb0ca66337bd13a21a1875cc5bec5cc9a724d (diff)
downloadmv-73e7be1617217396c5f1eead52af87bc7fef2357.tar.gz
mv-73e7be1617217396c5f1eead52af87bc7fef2357.tar.bz2
mv-73e7be1617217396c5f1eead52af87bc7fef2357.tar.xz
mv-73e7be1617217396c5f1eead52af87bc7fef2357.zip
add colors tab into chat emotes window.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chatwindow.cpp12
-rw-r--r--src/gui/emotewindow.cpp40
-rw-r--r--src/gui/emotewindow.h10
-rw-r--r--src/gui/widgets/colormodel.cpp96
-rw-r--r--src/gui/widgets/colormodel.h76
-rw-r--r--src/gui/widgets/colorpage.cpp110
-rw-r--r--src/gui/widgets/colorpage.h54
-rw-r--r--src/gui/widgets/listbox.cpp10
-rw-r--r--src/gui/widgets/tabbedarea.cpp9
-rw-r--r--src/gui/widgets/tabbedarea.h2
10 files changed, 404 insertions, 15 deletions
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 2017fc4f6..ed8e6a1d3 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -499,6 +499,18 @@ void ChatWindow::action(const gcn::ActionEvent &event)
}
}
}
+ else if (eventId == "color")
+ {
+ if (emoteWindow)
+ {
+ const std::string str = emoteWindow->getSelectedColor();
+ if (!str.empty())
+ {
+ addInputText(str, false);
+ emoteWindow->clearColor();
+ }
+ }
+ }
else if (eventId == ACTION_COLOR_PICKER)
{
if (mColorPicker)
diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp
index a66cecf87..fc76f474b 100644
--- a/src/gui/emotewindow.cpp
+++ b/src/gui/emotewindow.cpp
@@ -23,6 +23,8 @@
#include "gui/chatwindow.h"
#include "gui/gui.h"
+#include "gui/widgets/colormodel.h"
+#include "gui/widgets/colorpage.h"
#include "gui/widgets/emotepage.h"
#include "gui/widgets/layouthelper.h"
#include "gui/widgets/scrollarea.h"
@@ -41,7 +43,9 @@ EmoteWindow::EmoteWindow() :
Window(_("Emotes"), false, nullptr, "emotes.xml"),
mTabs(new TabbedArea(this)),
mEmotePage(new EmotePage(this)),
- mScrollEmotePage(new ScrollArea(mEmotePage, false, "emotepage.xml"))
+ mColorModel(ColorModel::createDefault(this)),
+ mColorPage(new ColorPage(this, mColorModel, "colorpage.xml")),
+ mScrollColorPage(new ScrollArea(mColorPage, false, "emotepage.xml"))
{
setShowTitle(false);
@@ -57,17 +61,28 @@ EmoteWindow::EmoteWindow() :
center();
setTitleBarHeight(getPadding() + getTitlePadding());
+ mScrollColorPage->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
// TRANSLATORS: emotes tab name
mTabs->addTab(_("Emotes"), mEmotePage);
+ // TRANSLATORS: emotes tab name
+ mTabs->addTab(_("Colors"), mScrollColorPage);
mEmotePage->setActionEventId("emote");
+ mColorPage->setActionEventId("color");
}
EmoteWindow::~EmoteWindow()
{
+ mTabs->removeAll(false);
mTabs->removeTab(mTabs->getTabByIndex(0));
- delete mScrollEmotePage;
- mScrollEmotePage = nullptr;
+ delete mEmotePage;
+ mEmotePage = nullptr;
+ delete mColorPage;
+ mColorPage = nullptr;
+ delete mColorModel;
+ mColorModel = nullptr;
+ delete mScrollColorPage;
+ mScrollColorPage = nullptr;
}
void EmoteWindow::show()
@@ -100,7 +115,26 @@ void EmoteWindow::clearEmote()
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);
+}
+
void EmoteWindow::addListeners(gcn::ActionListener *const listener)
{
mEmotePage->addActionListener(listener);
+ mColorPage->addActionListener(listener);
}
diff --git a/src/gui/emotewindow.h b/src/gui/emotewindow.h
index 69a646bd8..140ed4c36 100644
--- a/src/gui/emotewindow.h
+++ b/src/gui/emotewindow.h
@@ -25,6 +25,8 @@
#include <guichan/mouselistener.hpp>
+class ColorModel;
+class ColorPage;
class EmotePage;
class ScrollArea;
class TabbedArea;
@@ -46,12 +48,18 @@ class EmoteWindow final : public Window
void clearEmote();
+ std::string getSelectedColor() const;
+
+ void clearColor();
+
void addListeners(gcn::ActionListener *const listener);
private:
TabbedArea *mTabs;
EmotePage *mEmotePage;
- ScrollArea *mScrollEmotePage;
+ ColorModel *mColorModel;
+ ColorPage *mColorPage;
+ ScrollArea *mScrollColorPage;
};
extern EmoteWindow *emoteWindow;
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.