GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/widget2.h Lines: 21 23 91.3 %
Date: 2017-11-29 Branches: 111 204 54.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  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
26
#include "enums/render/rendertype.h"
27
28
#include "gui/themecolorsidoperators.h"
29
#include "gui/theme.h"
30
31
#include "localconsts.h"
32
33
class Widget;
34
35
class Widget2 notfinal
36
{
37
    public:
38
        A_DEFAULT_COPY(Widget2)
39
40
        virtual ~Widget2()
41
        {
42
        }
43
44
        inline const Color &getThemeColor(const ThemeColorIdT type,
45
                                          const unsigned int alpha = 255U)
46
                                          const A_WARN_UNUSED A_INLINE
47
        {
48










































14190
            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

8
            if (theme == nullptr)
56
                return Palette::BLACK;
57

8
            const ThemeColorIdT colorId = theme->getIdByChar(c, valid);
58

8
            if (valid)
59


4
                return theme->getColor(colorId + mPaletteOffset, 255U);
60
            return Palette::BLACK;
61
        }
62
63
470
        virtual void setWidget2(const Widget2 *const widget)
64
        {
65
472
            mPaletteOffset = widget != nullptr ? widget->mPaletteOffset : 0;
66
470
        }
67
68
        void setPalette(int palette)
69
        {
70
470
            mPaletteOffset = palette * CAST_S32(
71
                ThemeColorId::THEME_COLORS_END);
72
470
            checkPalette();
73
470
            setWidget2(this);
74
        }
75
76
        void checkPalette()
77
        {
78

6164
            if (mPaletteOffset < 0 ||
79
                mPaletteOffset >= THEME_PALETTES * CAST_S32(
80
                ThemeColorId::THEME_COLORS_END))
81
            {
82
                mPaletteOffset = 0;
83
            }
84
        }
85
86
        void setForegroundColor2(const Color &color) noexcept2
87
        {
88
            mForegroundColor2 = color;
89
        }
90
91
        Widget* getWindow() const noexcept2 A_WARN_UNUSED
92
        {
93
5086
            return mWindow;
94
        }
95
96
130
        virtual void setWindow(Widget *const window)
97
        {
98
142
            mWindow = window;
99
130
        }
100
101
    protected:
102
5694
        explicit Widget2(const Widget2 *const widget) :
103

5694
            mPaletteOffset(widget != nullptr ? widget->mPaletteOffset : 0),
104

10768
            mWindow(widget != nullptr ? widget->getWindow() : nullptr),
105
22776
            mForegroundColor2()
106
        {
107
5694
            checkPalette();
108
        }
109
110
        int mPaletteOffset;
111
        Widget *mWindow;
112
        Color mForegroundColor2;
113
};
114
115
extern RenderType openGLMode;
116
117
#endif  // GUI_WIDGETS_WIDGET2_H