ManaPlus
widget2.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-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 
22 #ifndef GUI_WIDGETS_WIDGET2_H
23 #define GUI_WIDGETS_WIDGET2_H
24 
25 #include "const/gui/theme.h"
26 
28 
30 #include "gui/theme.h"
31 
32 #include "localconsts.h"
33 
34 class Widget;
35 
37 {
38  public:
40 
41  virtual ~Widget2()
42  {
43  }
44 
45  inline const Color &getThemeColor(const ThemeColorIdT type,
46  const unsigned int alpha)
47  const A_WARN_UNUSED A_INLINE
48  {
49  return theme->getColor(type + mPaletteOffset, alpha);
50  }
51 
52  inline const Color &getThemeCharColor(const signed char c,
53  bool &valid)
54  const A_WARN_UNUSED A_INLINE
55  {
56  if (theme == nullptr)
57  return Palette::BLACK;
58  const ThemeColorIdT colorId = theme->getIdByChar(c, valid);
59  if (valid)
60  return theme->getColor(colorId + mPaletteOffset, 255U);
61  return Palette::BLACK;
62  }
63 
64  virtual void setWidget2(const Widget2 *const widget)
65  {
66  mPaletteOffset = widget != nullptr ? widget->mPaletteOffset : 0;
67  }
68 
69  void setPalette(int palette)
70  {
71  mPaletteOffset = palette * CAST_S32(
72  ThemeColorId::THEME_COLORS_END);
73  checkPalette();
74  setWidget2(this);
75  }
76 
77  void checkPalette()
78  {
79  if (mPaletteOffset < 0 ||
81  ThemeColorId::THEME_COLORS_END))
82  {
83  mPaletteOffset = 0;
84  }
85  }
86 
87  void setForegroundColor2(const Color &color) noexcept2
88  {
89  mForegroundColor2 = color;
90  }
91 
93  {
94  return mWindow;
95  }
96 
97  virtual void setWindow(Widget *const window)
98  {
99  mWindow = window;
100  }
101 
102  protected:
103  explicit Widget2(const Widget2 *const widget) :
104  mPaletteOffset(widget != nullptr ? widget->mPaletteOffset : 0),
105  mWindow(widget != nullptr ? widget->getWindow() : nullptr),
107  {
108  checkPalette();
109  }
110 
114 };
115 
116 extern RenderType openGLMode;
117 
118 #endif // GUI_WIDGETS_WIDGET2_H
#define CAST_S32
Definition: cast.h:30
Definition: color.h:76
static const Color BLACK
Definition: palette.h:48
const Color & getColor(const ThemeColorIdT type, const unsigned int alpha)
Definition: theme.h:136
ThemeColorIdT getIdByChar(const signed char c, bool &valid) const
Definition: theme.cpp:1075
virtual void setWindow(Widget *const window)
Definition: widget2.h:97
Widget2(const Widget2 *const widget)
Definition: widget2.h:103
Widget * mWindow
Definition: widget2.h:112
const Color & getThemeCharColor(const signed char c, bool &valid) const A_INLINE
Definition: widget2.h:52
void setPalette(int palette)
Definition: widget2.h:69
Widget * getWindow() const
Definition: widget2.h:92
int mPaletteOffset
Definition: widget2.h:111
void checkPalette()
Definition: widget2.h:77
Color mForegroundColor2
Definition: widget2.h:113
virtual void setWidget2(const Widget2 *const widget)
Definition: widget2.h:64
void setForegroundColor2(const Color &color)
Definition: widget2.h:87
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
Definition: widget.h:99
const int THEME_PALETTES
Definition: theme.h:31
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define notfinal
Definition: localconsts.h:261
#define noexcept2
Definition: localconsts.h:50
#define nullptr
Definition: localconsts.h:45
#define A_DEFAULT_COPY(func)
Definition: localconsts.h:41
RenderType
Definition: rendertype.h:26
Theme * theme
Definition: theme.cpp:62
ThemeColorId ::T ThemeColorIdT
Definition: themecolorid.h:35
RenderType openGLMode