TGUI  0.8.9
BitmapButton.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_BITMAP_BUTTON_HPP
27#define TGUI_BITMAP_BUTTON_HPP
28
29
30#include <TGUI/Widgets/Button.hpp>
31
33
34namespace tgui
35{
39 class TGUI_API BitmapButton : public Button
40 {
41 public:
42
43 typedef std::shared_ptr<BitmapButton> Ptr;
44 typedef std::shared_ptr<const BitmapButton> ConstPtr;
45
46
48 // Default constructor
51
52
60 static BitmapButton::Ptr create(const sf::String& text = "");
61
62
69
70
75 void setSize(const Layout2d& size) override;
76 using Widget::setSize;
77
78
83 virtual void setText(const sf::String& text) override;
84
85
90 void setImage(const Texture& image);
91
92
97 const Texture& getImage() const;
98
99
106 void setImageScaling(float relativeHeight);
107
108
114 float getImageScaling() const;
115
116
122 void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
123
124
126 protected:
127
131 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
132
133
137 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
138
139
141 // Called when size of button is updated
143 void updateSize() override;
144
145
147 // Makes a copy of the widget
149 Widget::Ptr clone() const override
150 {
151 return std::make_shared<BitmapButton>(*this);
152 }
153
154
156 private:
157
158 void recalculateGlyphSize();
159
160
162 private:
163
164 Texture m_glyphTexture;
165 Sprite m_glyphSprite;
166 float m_relativeGlyphHeight = 0;
167 };
168
170}
171
173
174#endif // TGUI_BITMAP_BUTTON_HPP
175
Button widget with an image displayed next to the text (or centered in the button without text)
Definition: BitmapButton.hpp:40
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: BitmapButton.hpp:149
std::shared_ptr< const BitmapButton > ConstPtr
Shared constant widget pointer.
Definition: BitmapButton.hpp:44
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
void setSize(const Layout2d &size) override
Changes the size of the button.
static BitmapButton::Ptr copy(BitmapButton::ConstPtr button)
Makes a copy of another button.
void setImageScaling(float relativeHeight)
Sets the relative size of the image to display next to the text.
static BitmapButton::Ptr create(const sf::String &text="")
Creates a new bitmap button widget.
void setImage(const Texture &image)
Sets the image that should be displayed next to the text.
const Texture & getImage() const
Returns the image being displayed next to the text.
virtual void setText(const sf::String &text) override
Changes the caption of the button.
std::shared_ptr< BitmapButton > Ptr
Shared widget pointer.
Definition: BitmapButton.hpp:43
float getImageScaling() const
Returns the relative size of the image displayed next to the text.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
Button widget.
Definition: Button.hpp:42
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Definition: Sprite.hpp:46
Definition: Texture.hpp:42
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37