ManaPlus
textpreview.h
Go to the documentation of this file.
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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WIDGETS_TEXTPREVIEW_H
25 #define GUI_WIDGETS_TEXTPREVIEW_H
26 
27 #include "gui/widgets/widget.h"
28 
30 
31 #include "localconsts.h"
32 
36 class TextPreview final : public Widget
37 {
38  public:
39  TextPreview(const Widget2 *const widget,
40  const std::string &text);
41 
43 
44  ~TextPreview() override final;
45 
46  inline void setTextColor(const Color *color)
47  { mTextColor = color; adjustSize(); }
48 
49  inline void setTextColor2(const Color *color)
50  { mTextColor2 = color; adjustSize(); }
51 
57  inline void useTextAlpha(const bool alpha)
58  { mTextAlpha = alpha; }
59 
66  inline void setTextBGColor(const Color *color)
67  { mTextBGColor = color; }
68 
74  inline void setBGColor(const Color *color)
75  { mBGColor = color; }
76 
82  inline void setFont(Font *const font)
83  { mFont = font; }
84 
90  inline void setShadow(const bool shadow)
91  { mShadow = shadow; }
92 
98  inline void setOutline(const bool outline)
99  { mOutline = outline; }
100 
106  void draw(Graphics *const graphics) override final A_NONNULL(2);
107 
108  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
109 
116  void setOpaque(const Opaque opaque) noexcept2
117  { mOpaque = opaque; }
118 
124  { return mOpaque == Opaque_true; }
125 
126  void adjustSize();
127 
128  private:
130  std::string mText;
133  const Color *mBGColor;
135  int mPadding;
136  static int instances;
137  static float mAlpha;
138  static Skin *mSkin;
141  bool mShadow;
142  bool mOutline;
143 };
144 
145 #endif // GUI_WIDGETS_TEXTPREVIEW_H
Definition: color.h:76
Definition: font.h:90
Definition: skin.h:37
const Color * mTextColor2
Definition: textpreview.h:132
static float mAlpha
Definition: textpreview.h:137
void adjustSize()
const Color * mBGColor
Definition: textpreview.h:133
TextPreview(const Widget2 *const widget, const std::string &text)
Definition: textpreview.cpp:41
void setTextColor(const Color *color)
Definition: textpreview.h:46
void setShadow(const bool shadow)
Definition: textpreview.h:90
static int instances
Definition: textpreview.h:136
void setTextColor2(const Color *color)
Definition: textpreview.h:49
void setTextBGColor(const Color *color)
Definition: textpreview.h:66
const Color * mTextBGColor
Definition: textpreview.h:134
static Skin * mSkin
Definition: textpreview.h:138
void draw(Graphics *const graphics)
Definition: textpreview.cpp:90
bool mTextAlpha
Definition: textpreview.h:139
bool isOpaque() const
Definition: textpreview.h:123
void useTextAlpha(const bool alpha)
Definition: textpreview.h:57
void setOpaque(const Opaque opaque)
Definition: textpreview.h:116
void safeDraw(Graphics *const graphics)
Font * mFont
Definition: textpreview.h:129
void setBGColor(const Color *color)
Definition: textpreview.h:74
void setFont(Font *const font)
Definition: textpreview.h:82
Opaque mOpaque
Definition: textpreview.h:140
std::string mText
Definition: textpreview.h:130
const Color * mTextColor
Definition: textpreview.h:131
void setOutline(const bool outline)
Definition: textpreview.h:98
Definition: widget.h:99
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
const bool Opaque_true
Definition: opaque.h:30
bool Opaque
Definition: opaque.h:30