TGUI  v0.6.10
Button.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 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_BUTTON_HPP
27 #define TGUI_BUTTON_HPP
28 
29 
30 #include <TGUI/ClickableWidget.hpp>
31 
33 
34 namespace tgui
35 {
36  class Container;
37 
39 
40  class TGUI_API Button : public ClickableWidget
41  {
42  public:
43 
45 
46 
51  Button();
52 
53 
60  Button(const Button& copy);
61 
62 
67  virtual ~Button();
68 
69 
78  Button& operator= (const Button& right);
79 
80 
83  // Makes a copy of the widget by calling the copy constructor.
84  // This function calls new and if you use this function then you are responsible for calling delete.
86  virtual Button* clone();
87 
88 
98  bool load(const std::string& configFileFilename, const std::string& sectionName = "Button");
99 
100 
108  const std::string& getLoadedConfigFile() const;
109 
110 
124  virtual void setPosition(float x, float y);
126 
127 
135  virtual void setSize(float width, float height);
136 
137 
144  void setText(const sf::String& text);
145 
146 
153  sf::String getText() const;
154 
155 
165  void setTextFont(const sf::Font& font);
166 
167 
174  const sf::Font* getTextFont() const;
175 
176 
183  void setTextColor(const sf::Color& color);
184 
185 
192  const sf::Color& getTextColor() const;
193 
194 
202  void setTextSize(unsigned int size);
203 
204 
211  unsigned int getTextSize() const;
212 
213 
224  virtual void setTransparency(unsigned char transparency);
225 
226 
230  virtual void keyPressed(const sf::Event::KeyEvent& event);
231 
235  virtual void widgetFocused();
236 
237 
240  // This function is a (slow) way to set properties on the widget, no matter what type it is.
241  // When the requested property doesn't exist in the widget then the functions will return false.
243  virtual bool setProperty(std::string property, const std::string& value);
244 
247  // This function is a (slow) way to get properties of the widget, no matter what type it is.
248  // When the requested property doesn't exist in the widget then the functions will return false.
250  virtual bool getProperty(std::string property, std::string& value) const;
251 
252 
255  // Returns a list of all properties that can be used in setProperty and getProperty.
256  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
258  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
259 
260 
262  protected:
263 
266  // This function is called when the widget is added to a container.
268  virtual void initialize(Container *const container);
269 
270 
273  // Draws the widget on the render target.
275  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
276 
277 
279  public:
280 
285  {
286  SpaceKeyPressed = ClickableWidgetCallbacksCount * 1,
287  ReturnKeyPressed = ClickableWidgetCallbacksCount * 2,
288  AllButtonCallbacks = ClickableWidgetCallbacksCount * 4 - 1,
289  ButtonCallbacksCount = ClickableWidgetCallbacksCount * 4
290  };
291 
292 
294  protected:
295 
296  std::string m_LoadedConfigFile;
297 
298  Texture m_TextureNormal_L;
299  Texture m_TextureHover_L;
300  Texture m_TextureDown_L;
301  Texture m_TextureFocused_L;
302 
303  Texture m_TextureNormal_M;
304  Texture m_TextureHover_M;
305  Texture m_TextureDown_M;
306  Texture m_TextureFocused_M;
307 
308  Texture m_TextureNormal_R;
309  Texture m_TextureHover_R;
310  Texture m_TextureDown_R;
311  Texture m_TextureFocused_R;
312 
313  // If this is true then the L, M and R images will be used.
314  // If it is false then the button is just one big image that will be stored in the M image.
315  bool m_SplitImage;
316 
317  // Is there a separate hover image, or is it a semi-transparent image that is drawn on top of the others?
318  bool m_SeparateHoverImage;
319 
320  // The SFML text
321  sf::Text m_Text;
322 
323  // This will store the size of the text ( 0 to auto size )
324  unsigned int m_TextSize;
325 
326 
327  friend class ChildWindow;
328  };
329 
331 }
332 
334 
335 #endif // TGUI_BUTTON_HPP
336 
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
virtual void setPosition(float x, float y)
Set the position of the widget.
Movable Panel with title bar.
Definition: ChildWindow.hpp:41
Definition: TextureManager.hpp:52
Definition: ClickableWidget.hpp:38
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: Button.hpp:40
ButtonCallbacks
Defines specific triggers to Button.
Definition: Button.hpp:284
Definition: SharedWidgetPtr.hpp:44