ManaPlus
widget2.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2018 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef GUI_WIDGETS_WIDGET2_H
22 #define GUI_WIDGETS_WIDGET2_H
23 
24 #include "const/gui/theme.h"
25 
27 
29 #include "gui/theme.h"
30 
31 #include "localconsts.h"
32 
33 class Widget;
34 
36 {
37  public:
39 
40  virtual ~Widget2()
41  {
42  }
43 
44  inline const Color &getThemeColor(const ThemeColorIdT type,
45  const unsigned int alpha)
46  const A_WARN_UNUSED A_INLINE
47  {
48  return theme->getColor(type + mPaletteOffset, alpha);
49  }
50 
51  inline const Color &getThemeCharColor(const signed char c,
52  bool &valid)
53  const A_WARN_UNUSED A_INLINE
54  {
55  if (theme == nullptr)
56  return Palette::BLACK;
57  const ThemeColorIdT colorId = theme->getIdByChar(c, valid);
58  if (valid)
59  return theme->getColor(colorId + mPaletteOffset, 255U);
60  return Palette::BLACK;
61  }
62 
63  virtual void setWidget2(const Widget2 *const widget)
64  {
65  mPaletteOffset = widget != nullptr ? widget->mPaletteOffset : 0;
66  }
67 
68  void setPalette(int palette)
69  {
70  mPaletteOffset = palette * CAST_S32(
72  checkPalette();
73  setWidget2(this);
74  }
75 
76  void checkPalette()
77  {
78  if (mPaletteOffset < 0 ||
81  {
82  mPaletteOffset = 0;
83  }
84  }
85 
86  void setForegroundColor2(const Color &color) noexcept2
87  {
88  mForegroundColor2 = color;
89  }
90 
92  {
93  return mWindow;
94  }
95 
96  virtual void setWindow(Widget *const window)
97  {
98  mWindow = window;
99  }
100 
101  protected:
102  explicit Widget2(const Widget2 *const widget) :
103  mPaletteOffset(widget != nullptr ? widget->mPaletteOffset : 0),
104  mWindow(widget != nullptr ? widget->getWindow() : nullptr),
106  {
107  checkPalette();
108  }
109 
113 };
114 
115 extern RenderType openGLMode;
116 
117 #endif // GUI_WIDGETS_WIDGET2_H
void checkPalette()
Definition: widget2.h:76
virtual void setWidget2(const Widget2 *const widget)
Definition: widget2.h:63
#define A_WARN_UNUSED
Definition: localconsts.h:160
ThemeColorIdT getIdByChar(const signed char c, bool &valid) const
Definition: theme.cpp:1074
static const Color BLACK
Definition: palette.h:47
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:40
ThemeColorId ::T ThemeColorIdT
Definition: themecolorid.h:34
const Color & getThemeCharColor(const signed char c, bool &valid) const A_INLINE
Definition: widget2.h:51
virtual void setWindow(Widget *const window)
Definition: widget2.h:96
#define CAST_S32
Definition: cast.h:29
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:135
Widget * getWindow() const
Definition: widget2.h:91
Widget * mWindow
Definition: widget2.h:111
#define notfinal
Definition: localconsts.h:260
#define nullptr
Definition: localconsts.h:44
int mPaletteOffset
Definition: widget2.h:110
Theme * theme
Definition: theme.cpp:61
Color mForegroundColor2
Definition: widget2.h:112
Definition: widget.h:97
RenderType openGLMode
Definition: color.h:74
const int THEME_PALETTES
Definition: theme.h:30
Widget2(const Widget2 *const widget)
Definition: widget2.h:102
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
void setForegroundColor2(const Color &color)
Definition: widget2.h:86
#define noexcept2
Definition: localconsts.h:49
RenderType
Definition: rendertype.h:24
void setPalette(int palette)
Definition: widget2.h:68