ManaPlus
emotewindow.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2013-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
23 
24 #include "gui/models/colormodel.h"
25 #include "gui/models/namesmodel.h"
26 
28 
29 #include "gui/widgets/colorpage.h"
31 #include "gui/widgets/emotepage.h"
32 #include "gui/widgets/scrollarea.h"
33 #include "gui/widgets/tabbedarea.h"
34 
35 #include "utils/delete2.h"
36 #include "utils/foreach.h"
37 #include "utils/gettext.h"
38 
40 
41 #include "resources/imageset.h"
42 
43 #include "resources/db/textdb.h"
44 
45 #include "resources/image/image.h"
46 
47 #include "debug.h"
48 
50 static const int fontSizeListSize = 2;
51 
52 static const char *const fontSizeList[] =
53 {
54  // TRANSLATORS: font size
55  N_("Normal font"),
56  // TRANSLATORS: font size
57  N_("Bold font"),
58 };
59 
61  // TRANSLATORS: emotes window name
62  Window(_("Emotes"), Modal_false, nullptr, "emotes.xml"),
63  mTabs(CREATEWIDGETR(TabbedArea, this)),
64  mEmotePage(new EmotePage(this)),
65  mColorModel(ColorModel::createDefault(this)),
66  mColorPage(CREATEWIDGETR(ColorPage, this, mColorModel, "colorpage.xml")),
67  mScrollColorPage(new ScrollArea(this, mColorPage, Opaque_false,
68  "emotepage.xml")),
69  mFontModel(new NamesModel),
70  mFontPage(CREATEWIDGETR(ListBox, this, mFontModel, "")),
71  mScrollFontPage(new ScrollArea(this, mFontPage, Opaque_false,
72  "fontpage.xml")),
73  mTextModel(new NamesModel),
74  mTextPage(CREATEWIDGETR(ListBox, this, mTextModel, "")),
75  mScrollTextPage(new ScrollArea(this, mTextPage, Opaque_false,
76  "textpage.xml")),
77  mImageSet(Theme::getImageSetFromThemeXml("emotetabs.xml", "", 17, 16))
78 {
79  setShowTitle(false);
80  setResizable(true);
81 
82  if (setupWindow != nullptr)
84 
85  addMouseListener(this);
86 }
87 
89 {
91  const int pad2 = mPadding * 2;
92  const int width = 200;
93  const int height = 150;
94  setWidth(width + pad2);
95  setHeight(height + pad2);
96  add(mTabs);
98  mTabs->setWidth(width);
99  mTabs->setHeight(height);
100  center();
101 
109 
111 
112  mFontPage->setCenter(true);
113  mTextPage->setCenter(true);
114 
115  if ((mImageSet != nullptr) && mImageSet->size() >= 3)
116  {
117  for (int f = 0; f < 3; f ++)
118  {
119  Image *const image = mImageSet->get(f);
120  if (image != nullptr)
121  image->incRef();
122  }
123 
127  }
128  else
129  {
130  // TRANSLATORS: emotes tab name
131  mTabs->addTab(_("Emotes"), mEmotePage);
132  // TRANSLATORS: emotes tab name
133  mTabs->addTab(_("Colors"), mScrollColorPage);
134  // TRANSLATORS: emotes tab name
135  mTabs->addTab(_("Fonts"), mScrollFontPage);
136  }
137  // TRANSLATORS: emotes tab name
138  mTabs->addTab(_("T"), mScrollTextPage);
139 
140  mEmotePage->setActionEventId("emote");
141  mColorPage->setActionEventId("color");
142  mFontPage->setActionEventId("font");
143  mTextPage->setActionEventId("text");
144 }
145 
147 {
148  mTabs->removeAll(false);
160  if (mImageSet != nullptr)
161  {
162  mImageSet->decRef();
163  mImageSet = nullptr;
164  }
165 }
166 
168 {
170  if (dictionary != nullptr)
171  {
172  mTextModel->clear();
173  const STD_VECTOR<std::string> &texts = TextDb::getTexts();
174  FOR_EACH (StringVectCIter, it, texts)
175  {
177  }
178  }
179 }
180 
182 {
184 }
185 
186 std::string EmoteWindow::getSelectedEmote() const
187 {
188  const int index = mEmotePage->getSelectedIndex();
189  if (index < 0)
190  return std::string();
191 
192  char chr[2];
193  chr[0] = CAST_8('0' + index);
194  chr[1] = 0;
195  return std::string("%%").append(&chr[0]);
196 }
197 
199 {
200  const int index = mEmotePage->getSelectedIndex();
202  if (index >= 0)
204 }
205 
206 std::string EmoteWindow::getSelectedColor() const
207 {
208  const int index = mColorPage->getSelected();
209  if (index < 0)
210  return std::string();
211 
212  char chr[2];
213  chr[0] = CAST_8('0' + index);
214  chr[1] = 0;
215  return std::string("##").append(&chr[0]);
216 }
217 
219 {
220  return mTextPage->getSelected();
221 }
222 
224 {
227 }
228 
229 std::string EmoteWindow::getSelectedFont() const
230 {
231  const int index = mFontPage->getSelected();
232  if (index < 0)
233  return std::string();
234 
235  if (index == 0)
236  return "##b";
237  return "##B";
238 }
239 
241 {
242  mFontPage->setSelected(-1);
244 }
245 
247 {
248  mTextPage->setSelected(-1);
250 }
251 
253 {
258 }
259 
261 {
262  Window::widgetResized(event);
263  const int pad2 = mPadding * 2;
264  const int width = mDimension.width;
265  const int height = mDimension.height;
266 
267  mTabs->setSize(width - pad2, height - pad2);
272  mEmotePage->widgetResized(event);
273 }
274 
275 void EmoteWindow::widgetMoved(const Event &event)
276 {
277  Window::widgetMoved(event);
278  mEmotePage->widgetResized(event);
279 }
#define CAST_8
Definition: cast.h:25
virtual void add(Widget *const widget)
void resetAction()
Definition: colorpage.cpp:110
void resetAction()
Definition: emotepage.cpp:155
void widgetResized(const Event &event)
Definition: emotepage.cpp:160
int getSelectedIndex() const
Definition: emotepage.h:59
TabbedArea * mTabs
Definition: emotewindow.h:74
ScrollArea * mScrollColorPage
Definition: emotewindow.h:78
NamesModel * mFontModel
Definition: emotewindow.h:79
void addListeners(ActionListener *const listener)
void widgetResized(const Event &event)
void postInit()
Definition: emotewindow.cpp:88
NamesModel * mTextModel
Definition: emotewindow.h:82
std::string getSelectedEmote() const
EmotePage * mEmotePage
Definition: emotewindow.h:75
ColorModel * mColorModel
Definition: emotewindow.h:76
ListBox * mTextPage
Definition: emotewindow.h:83
ScrollArea * mScrollTextPage
Definition: emotewindow.h:84
ImageSet * mImageSet
Definition: emotewindow.h:85
void clearFont()
std::string getSelectedFont() const
void clearEmote()
std::string getSelectedColor() const
void widgetMoved(const Event &event)
void clearText()
ColorPage * mColorPage
Definition: emotewindow.h:77
ScrollArea * mScrollFontPage
Definition: emotewindow.h:81
ListBox * mFontPage
Definition: emotewindow.h:80
void clearColor()
int getSelectedTextIndex() const
Definition: event.h:79
Image * get(const size_type i) const
Definition: imageset.cpp:67
size_type size() const
Definition: imageset.h:73
int getSelected() const
Definition: listbox.h:168
void setSelected(const int selected)
Definition: listbox.cpp:399
void setCenter(const bool b)
Definition: listbox.h:150
void add(const std::string &str)
Definition: namesmodel.h:53
void clear()
Definition: namesmodel.h:50
void fillFromArray(const char *const *const arr, const std::size_t size)
Definition: namesmodel.cpp:52
const std::string getStr(const std::string &str)
Definition: podict.cpp:45
int width
Definition: rect.h:219
int height
Definition: rect.h:224
virtual void decRef()
Definition: resource.cpp:50
void setVerticalScrollPolicy(const ScrollPolicy vPolicy)
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
void registerWindowForReset(Window *const window)
void setWidth(int width)
Definition: tabbedarea.cpp:750
void removeTab(Tab *const tab)
Definition: tabbedarea.cpp:323
void setHeight(int height)
Definition: tabbedarea.cpp:757
void adjustWidget(Widget *const widget) const
Definition: tabbedarea.cpp:265
void removeAll(const bool del)
Definition: tabbedarea.cpp:730
void setSize(int width, int height)
Definition: tabbedarea.cpp:764
void addTab(Tab *const tab, Widget *const widget)
Definition: tabbedarea.cpp:238
Tab * getTabByIndex(const int index) const
Definition: tabbedarea.cpp:716
Definition: theme.h:55
void setWidth(const int width)
Definition: widget.cpp:133
void setSize(const int width, const int height)
Definition: widget.cpp:367
Rect mDimension
Definition: widget.h:1101
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void setHeight(const int height)
Definition: widget.cpp:140
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
void setPosition(const int x, const int y)
Definition: widget.cpp:161
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
Definition: window.h:102
void center()
Definition: window.cpp:1417
void setResizable(const bool resize)
Definition: window.cpp:627
virtual void setVisible(Visible visible)
Definition: window.cpp:778
int getTitlePadding() const
Definition: window.h:602
void postInit()
Definition: window.cpp:249
int getPadding() const
Definition: window.h:504
void widgetResized(const Event &event)
Definition: window.cpp:655
void widgetMoved(const Event &event)
Definition: window.cpp:720
void setShowTitle(bool flag)
Definition: window.h:235
int mPadding
Definition: window.h:618
void setTitleBarHeight(unsigned int height)
Definition: window.h:513
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
#define new
Definition: debug_new.h:147
#define delete2(var)
Definition: delete2.h:25
static const int fontSizeListSize
Definition: emotewindow.cpp:50
EmoteWindow * emoteWindow
Definition: emotewindow.cpp:49
static const char *const fontSizeList[]
Definition: emotewindow.cpp:52
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
#define N_(s)
Definition: gettext.h:36
#define _(s)
Definition: gettext.h:35
#define nullptr
Definition: localconsts.h:45
const bool Modal_false
Definition: modal.h:30
const StringVect & getTexts()
Definition: textdb.cpp:92
const bool Opaque_false
Definition: opaque.h:30
PoDict * dictionary
Definition: podict.cpp:29
SetupWindow * setupWindow
Definition: setupwindow.cpp:64
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
const bool Visible_false
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30