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