TGUI  0.8-dev
BitmapButton.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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 
34 namespace 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
50  BitmapButton();
51 
52 
58  static BitmapButton::Ptr create();
59 
60 
66  static BitmapButton::Ptr copy(BitmapButton::ConstPtr button);
67 
68 
73  void setSize(const Layout2d& size) override;
74  using Widget::setSize;
75 
76 
81  virtual void setText(const sf::String& text) override;
82 
83 
88  void setImage(const Texture& image);
89 
90 
95  const Texture& getImage() const;
96 
97 
104  void setImageScaling(float relativeHeight);
105 
106 
112  float getImageScaling() const;
113 
114 
120  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
121 
122 
124  protected:
125 
129  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
130 
131 
135  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
136 
137 
139  // Called when size of button is updated
141  void updateSize() override;
142 
143 
145  // Makes a copy of the widget
147  Widget::Ptr clone() const override
148  {
149  return std::make_shared<BitmapButton>(*this);
150  }
151 
152 
154  private:
155 
156  void recalculateGlyphSize();
157 
158 
160  private:
161 
162  Texture m_glyphTexture;
163  Sprite m_glyphSprite;
164  float m_relativeGlyphHeight = 0;
165  };
166 
168 }
169 
171 
172 #endif // TGUI_BITMAP_BUTTON_HPP
173 
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:43
Button widget with an image displayed next to the text (or centered in the button without text) ...
Definition: BitmapButton.hpp:39
Class to store the position or size of a widget.
Definition: Layout.hpp:243
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:70
Button widget.
Definition: Button.hpp:41
Definition: Texture.hpp:40
std::shared_ptr< const BitmapButton > ConstPtr
Shared constant widget pointer.
Definition: BitmapButton.hpp:44
std::shared_ptr< BitmapButton > Ptr
Shared widget pointer.
Definition: BitmapButton.hpp:43
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: BitmapButton.hpp:147