TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Button.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
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_INCLUDED_
27 #define _TGUI_BUTTON_INCLUDED_
28 
30 
31 namespace tgui
32 {
34 
35  struct TGUI_API Button : public OBJECT
36  {
40  Button();
41 
42 
46  Button(const Button& copy);
47 
48 
52  virtual ~Button();
53 
54 
58  Button& operator= (const Button& right);
59 
60 
64  virtual void initialize();
65 
66 
70  virtual Button* clone();
71 
72 
85  virtual bool load(const std::string& pathname);
86 
87 
94  virtual void setSize(float width, float height);
95 
96 
100  virtual Vector2u getSize() const;
101 
102 
106  virtual Vector2f getScaledSize() const;
107 
108 
114  virtual std::string getLoadedPathname() const;
115 
116 
120  virtual void setText(const sf::String& text);
121 
122 
126  virtual sf::String getText() const;
127 
128 
135  virtual void setTextFont(const sf::Font& font);
136 
137 
141  virtual const sf::Font* getTextFont() const;
142 
143 
147  virtual void setTextColor(const sf::Color& color);
148 
149 
153  virtual const sf::Color& getTextColor() const;
154 
155 
161  virtual void setTextSize(unsigned int size);
162 
163 
167  virtual unsigned int getTextSize() const;
168 
169 
171  // These functions are used to receive callback from EventManager.
172  // You normally don't need them, but you can use them to simulate an event.
174  virtual bool mouseOnObject(float x, float y);
175  virtual void leftMousePressed(float x, float y);
176  virtual void leftMouseReleased(float x, float y);
177  virtual void mouseMoved(float x, float y);
178  virtual void keyPressed(sf::Keyboard::Key key);
179  virtual void objectFocused();
180 
181 
183  protected:
184 
185 
187  // Because this struct is derived from sf::Drawable, you can just call the Draw function from your sf::RenderTarget.
188  // This function will be called and it will draw the button on the render target.
190  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
191 
192 
194  protected:
195 
196  // The size of the button
197  Vector2f m_Size;
198 
199  // The SFML textures
200  sf::Texture* m_TextureNormal_L;
201  sf::Texture* m_TextureMouseHover_L;
202  sf::Texture* m_TextureMouseDown_L;
203  sf::Texture* m_TextureFocused_L;
204 
205  sf::Texture* m_TextureNormal_M;
206  sf::Texture* m_TextureMouseHover_M;
207  sf::Texture* m_TextureMouseDown_M;
208  sf::Texture* m_TextureFocused_M;
209 
210  sf::Texture* m_TextureNormal_R;
211  sf::Texture* m_TextureMouseHover_R;
212  sf::Texture* m_TextureMouseDown_R;
213  sf::Texture* m_TextureFocused_R;
214 
215  // The SFML sprites
216  sf::Sprite m_SpriteNormal_L;
217  sf::Sprite m_SpriteMouseHover_L;
218  sf::Sprite m_SpriteMouseDown_L;
219  sf::Sprite m_SpriteFocused_L;
220 
221  sf::Sprite m_SpriteNormal_M;
222  sf::Sprite m_SpriteMouseHover_M;
223  sf::Sprite m_SpriteMouseDown_M;
224  sf::Sprite m_SpriteFocused_M;
225 
226  sf::Sprite m_SpriteNormal_R;
227  sf::Sprite m_SpriteMouseHover_R;
228  sf::Sprite m_SpriteMouseDown_R;
229  sf::Sprite m_SpriteFocused_R;
230 
231  // The pathname used to load the button
232  std::string m_LoadedPathname;
233 
234  // If this is true then the L, M and R images will be used.
235  // If it is false then the button is just one big image that will be stored in the M image.
236  bool m_SplitImage;
237 
238  // Is there a separate hover image, or is it a semi-transparent image that is drawn on top of the others?
239  bool m_SeparateHoverImage;
240 
241  // The SFML text
242  sf::Text m_Text;
243 
244  // This will store the size of the text ( 0 to auto size )
245  unsigned int m_TextSize;
246 
247 
248  friend struct ChildWindow;
249  };
250 
252 }
253 
255 
256 #endif //_TGUI_BUTTON_INCLUDED_
257 
Movable Panel with title bar.
Definition: ChildWindow.hpp:36
The parent struct for every object.
Definition: Objects.hpp:36
Definition: Button.hpp:35