GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/label.h Lines: 2 2 100.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  Aethyra Development Team
4
 *  Copyright (C) 2011-2019  The ManaPlus Developers
5
 *  Copyright (C) 2019-2021  Andrei Karas
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
/*      _______   __   __   __   ______   __   __   _______   __   __
24
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
25
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
26
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
27
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
28
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
29
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
30
 *
31
 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
32
 *
33
 *
34
 * Per Larsson a.k.a finalman
35
 * Olof Naessén a.k.a jansem/yakslem
36
 *
37
 * Visit: http://guichan.sourceforge.net
38
 *
39
 * License: (BSD)
40
 * Redistribution and use in source and binary forms, with or without
41
 * modification, are permitted provided that the following conditions
42
 * are met:
43
 * 1. Redistributions of source code must retain the above copyright
44
 *    notice, this list of conditions and the following disclaimer.
45
 * 2. Redistributions in binary form must reproduce the above copyright
46
 *    notice, this list of conditions and the following disclaimer in
47
 *    the documentation and/or other materials provided with the
48
 *    distribution.
49
 * 3. Neither the name of Guichan nor the names of its contributors may
50
 *    be used to endorse or promote products derived from this software
51
 *    without specific prior written permission.
52
 *
53
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
59
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64
 */
65
66
#ifndef GUI_WIDGETS_LABEL_H
67
#define GUI_WIDGETS_LABEL_H
68
69
#include "gui/fonts/textchunk.h"
70
71
#include "gui/widgets/widget.h"
72
73
#include "listeners/tooltiplistener.h"
74
#include "listeners/widgetlistener.h"
75
76
#include "render/graphics.h"
77
78
#include "localconsts.h"
79
80
class Skin;
81
82
/**
83
 * Label widget. Same as the Guichan label but modified to use the palette
84
 * system.
85
 *
86
 * \ingroup GUI
87
 */
88
class Label final : public Widget,
89
                    public WidgetListener,
90
                    public ToolTipListener
91
{
92
    public:
93
        /**
94
         * Constructor.
95
         */
96
        explicit Label(const Widget2 *const widget);
97
98
        /**
99
         * Constructor. This version of the constructor sets the label with an
100
         * inintialization string.
101
         */
102
        Label(const Widget2 *const widget,
103
              const std::string &caption);
104
105
        A_DELETE_COPY(Label)
106
107
        ~Label() override final;
108
109
        void init();
110
111
        /**
112
         * Draws the label.
113
         */
114
        void draw(Graphics *const graphics) override final A_NONNULL(2);
115
116
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
117
118
        void adjustSize();
119
120
        void setForegroundColor(const Color &color);
121
122
        void setForegroundColorAll(const Color &color1,
123
                                   const Color &color2);
124
125
        void resizeTo(const int maxSize, const int minSize);
126
127
        /**
128
         * Gets the caption of the label.
129
         *
130
         * @return The caption of the label.
131
         * @see setCaption
132
         */
133
        const std::string &getCaption() const
134
384
        { return mCaption; }
135
136
        /**
137
         * Sets the caption of the label. It's advisable to call
138
         * adjustSize after setting of the caption to adjust the
139
         * label's size to fit the caption.
140
         *
141
         * @param caption The caption of the label.
142
         * @see getCaption, adjustSize
143
         */
144
        void setCaption(const std::string& caption);
145
146
        /**
147
         * Sets the alignment of the caption. The alignment is relative
148
         * to the center of the label.
149
         *
150
         * @param alignment The alignment of the caption of the label.
151
         * @see getAlignment, Graphics
152
         */
153
        void setAlignment(Graphics::Alignment alignment)
154
17
        { mAlignment = alignment; }
155
156
        /**
157
         * Gets the alignment of the caption. The alignment is relative to
158
         * the center of the label.
159
         *
160
         * @return The alignment of caption of the label.
161
         * @see setAlignmentm Graphics
162
         */
163
        Graphics::Alignment getAlignment() const
164
        { return mAlignment; }
165
166
        void setParent(Widget *const widget) override final;
167
168
        void setWindow(Widget *const widget) override final;
169
170
        void widgetHidden(const Event &event) override final;
171
172
        static Skin *mSkin;
173
174
        static int mInstances;
175
176
        static void finalCleanup();
177
178
    private:
179
        /**
180
         * Holds the caption of the label.
181
         */
182
        std::string mCaption;
183
184
        TextChunk mTextChunk;
185
186
        /**
187
         * Holds the alignment of the caption.
188
         */
189
        Graphics::Alignment mAlignment;
190
191
        int mPadding;
192
193
        bool mTextChanged;
194
};
195
196
#endif  // GUI_WIDGETS_LABEL_H