GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/textpreview.h Lines: 0 8 0.0 %
Date: 2017-11-29 Branches: 0 4 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2006-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef GUI_WIDGETS_TEXTPREVIEW_H
24
#define GUI_WIDGETS_TEXTPREVIEW_H
25
26
#include "gui/widgets/widget.h"
27
28
#include "enums/simpletypes/opaque.h"
29
30
#include "localconsts.h"
31
32
/**
33
 * Preview widget for particle colors, etc.
34
 */
35
class TextPreview final : public Widget
36
{
37
    public:
38
        TextPreview(const Widget2 *const widget,
39
                    const std::string &text);
40
41
        A_DELETE_COPY(TextPreview)
42
43
        ~TextPreview();
44
45
        inline void setTextColor(const Color *color)
46
        { mTextColor = color; adjustSize(); }
47
48
        inline void setTextColor2(const Color *color)
49
        { mTextColor2 = color; adjustSize(); }
50
51
        /**
52
         * Sets the text to use the set alpha value.
53
         *
54
         * @param alpha whether to use alpha values for the text or not
55
         */
56
        inline void useTextAlpha(const bool alpha)
57
        { mTextAlpha = alpha; }
58
59
        /**
60
         * Sets the color the text background is drawn in. This is only the
61
         * rectangle directly behind the text, not to full widget.
62
         *
63
         * @param color the color to set
64
         */
65
        inline void setTextBGColor(const Color *color)
66
        { mTextBGColor = color; }
67
68
        /**
69
         * Sets the background color of the widget.
70
         *
71
         * @param color the color to set
72
         */
73
        inline void setBGColor(const Color *color)
74
        { mBGColor = color; }
75
76
        /**
77
         * Sets the font to render the text in.
78
         *
79
         * @param font the font to use.
80
         */
81
        inline void setFont(Font *const font)
82
        { mFont = font; }
83
84
        /**
85
         * Sets whether to use a shadow while rendering.
86
         *
87
         * @param shadow true, if a shadow is wanted, false else
88
         */
89
        inline void setShadow(const bool shadow)
90
        { mShadow = shadow; }
91
92
        /**
93
         * Sets whether to use an outline while rendering.
94
         *
95
         * @param outline true, if an outline is wanted, false else
96
         */
97
        inline void setOutline(const bool outline)
98
        { mOutline = outline; }
99
100
        /**
101
         * Widget's draw method. Does the actual job.
102
         *
103
         * @param graphics graphics to draw into
104
         */
105
        void draw(Graphics *const graphics) override final A_NONNULL(2);
106
107
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
108
109
        /**
110
         * Set opacity for this widget (whether or not to show the background
111
         * color)
112
         *
113
         * @param opaque Whether the widget should be opaque or not
114
         */
115
        void setOpaque(const Opaque opaque) noexcept2
116
        { mOpaque = opaque; }
117
118
        /**
119
         * Gets opacity for this widget (whether or not the background color
120
         * is shown below the widget)
121
         */
122
        bool isOpaque() const noexcept2 A_WARN_UNUSED
123
        { return mOpaque == Opaque_true; }
124
125
        void adjustSize();
126
127
    private:
128
        Font *mFont;
129
        std::string mText;
130
        const Color *mTextColor;
131
        const Color *mTextColor2;
132
        const Color *mBGColor;
133
        const Color *mTextBGColor;
134
        int mPadding;
135
        static int instances;
136
        static float mAlpha;
137
        static Skin *mSkin;
138
        bool mTextAlpha;
139
        Opaque mOpaque;
140
        bool mShadow;
141
        bool mOutline;
142
};
143
144
#endif  // GUI_WIDGETS_TEXTPREVIEW_H