ManaPlus
label.h
Go to the documentation of this file.
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 
75 
76 #include "render/graphics.h"
77 
78 #include "localconsts.h"
79 
80 class Skin;
81 
88 class Label final : public Widget,
89  public WidgetListener,
90  public ToolTipListener
91 {
92  public:
96  explicit Label(const Widget2 *const widget);
97 
102  Label(const Widget2 *const widget,
103  const std::string &caption);
104 
106 
107  ~Label() override final;
108 
109  void init();
110 
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 
133  const std::string &getCaption() const
134  { return mCaption; }
135 
144  void setCaption(const std::string& caption);
145 
154  { mAlignment = alignment; }
155 
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:
182  std::string mCaption;
183 
185 
190 
191  int mPadding;
192 
194 };
195 
196 #endif // GUI_WIDGETS_LABEL_H
Definition: color.h:76
Definition: event.h:79
Definition: label.h:91
void setForegroundColor(const Color &color)
Definition: label.cpp:208
void resizeTo(const int maxSize, const int minSize)
Definition: label.cpp:227
bool mTextChanged
Definition: label.h:193
void init()
Definition: label.cpp:126
static void finalCleanup()
Definition: label.cpp:297
~Label()
Definition: label.cpp:108
void adjustSize()
Definition: label.cpp:200
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: label.cpp:217
static Skin * mSkin
Definition: label.h:172
void setAlignment(Graphics::Alignment alignment)
Definition: label.h:153
static int mInstances
Definition: label.h:174
int mPadding
Definition: label.h:191
void setParent(Widget *const widget)
Definition: label.cpp:271
void widgetHidden(const Event &event)
Definition: label.cpp:291
void safeDraw(Graphics *const graphics)
Definition: label.cpp:195
void draw(Graphics *const graphics)
Definition: label.cpp:151
Graphics::Alignment mAlignment
Definition: label.h:189
TextChunk mTextChunk
Definition: label.h:184
const std::string & getCaption() const
Definition: label.h:133
void setCaption(const std::string &caption)
Definition: label.cpp:264
Graphics::Alignment getAlignment() const
Definition: label.h:163
std::string mCaption
Definition: label.h:182
Label(const Widget2 *const widget)
Definition: label.cpp:78
void setWindow(Widget *const widget)
Definition: label.cpp:278
Definition: skin.h:37
Definition: widget.h:99
#define A_NONNULL(...)
Definition: localconsts.h:168
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53