TGUI  0.8.0
BitmapButton.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 
57  static BitmapButton::Ptr create();
58 
59 
65  static BitmapButton::Ptr copy(BitmapButton::ConstPtr button);
66 
67 
72  void setSize(const Layout2d& size) override;
73  using Widget::setSize;
74 
75 
80  virtual void setText(const sf::String& text) override;
81 
82 
87  void setImage(const Texture& image);
88 
89 
94  const Texture& getImage() const;
95 
96 
103  void setImageScaling(float relativeHeight);
104 
105 
111  float getImageScaling() const;
112 
113 
119  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
120 
121 
123  protected:
124 
128  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
129 
130 
134  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
135 
136 
138  // Called when size of button is updated
140  void updateSize() override;
141 
142 
144  // Makes a copy of the widget
146  Widget::Ptr clone() const override
147  {
148  return std::make_shared<BitmapButton>(*this);
149  }
150 
151 
153  private:
154 
155  void recalculateGlyphSize();
156 
157 
159  private:
160 
161  Texture m_glyphTexture;
162  Sprite m_glyphSprite;
163  float m_relativeGlyphHeight = 0;
164  };
165 
167 }
168 
170 
171 #endif // TGUI_BITMAP_BUTTON_HPP
172 
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:76
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:146