TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
AnimatedButton.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_ANIMATED_BUTTON_INCLUDED_
27 #define _TGUI_ANIMATED_BUTTON_INCLUDED_
28 
30 
31 namespace tgui
32 {
34 
35  struct TGUI_API AnimatedButton : public OBJECT, OBJECT_ANIMATION
36  {
41 
42 
46  AnimatedButton(const AnimatedButton& copy);
47 
48 
52  virtual ~AnimatedButton();
53 
54 
58  AnimatedButton& operator= (const AnimatedButton& right);
59 
60 
64  virtual void initialize();
65 
66 
70  virtual AnimatedButton* clone();
71 
72 
88  virtual bool load(const std::string& pathname);
89 
90 
100  virtual void setSize(float width, float height);
101 
102 
106  virtual Vector2u getSize() const;
107 
108 
112  virtual Vector2f getScaledSize() const;
113 
114 
120  virtual std::string getLoadedPathname() const;
121 
122 
126  virtual void setText(const sf::String& text);
127 
128 
132  virtual sf::String getText() const;
133 
134 
141  virtual void setTextFont(const sf::Font& font);
142 
143 
147  virtual const sf::Font* getTextFont();
148 
149 
153  virtual void setTextColor(const sf::Color& color);
154 
155 
159  virtual const sf::Color& getTextColor() const;
160 
161 
167  virtual void setTextSize(unsigned int size);
168 
169 
173  virtual unsigned int getTextSize() const;
174 
175 
182  virtual void setFrame(unsigned int frame);
183 
184 
186  // These functions are used to receive callback from EventManager.
187  // You normally don't need them, but you can use them to simulate an event.
189  virtual bool mouseOnObject(float x, float y);
190  virtual void leftMousePressed(float x, float y);
191  virtual void leftMouseReleased(float x, float y);
192  virtual void mouseMoved(float x, float y);
193  virtual void keyPressed(sf::Keyboard::Key key);
194  virtual void objectFocused();
195  virtual void mouseNotOnObject();
196  virtual void mouseNoLongerDown();
197 
198 
200  protected:
201 
203  // Used internally by the load function.
205  virtual unsigned int getLoadingID(const std::string& property);
206 
207 
209  // When the elapsed time changes then this function is called.
211  virtual void update();
212 
213 
215  // Because this struct is derived from sf::Drawable, you can just call the Draw function from your sf::RenderTarget.
216  // This function will be called and it will draw the button on the render target.
218  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
219 
220 
222  protected:
223 
224  // The size of the button
225  Vector2f m_Size;
226 
227  // The SFML textures
228  std::vector<sf::Texture*> m_TexturesNormal;
229  std::vector<sf::Texture*> m_TexturesMouseHover;
230  std::vector<sf::Texture*> m_TexturesMouseDown;
231  std::vector<sf::Texture*> m_TexturesFocused;
232 
233  // The SFML sprites
234  std::vector<sf::Sprite> m_SpritesNormal;
235  std::vector<sf::Sprite> m_SpritesMouseHover;
236  std::vector<sf::Sprite> m_SpritesMouseDown;
237  std::vector<sf::Sprite> m_SpritesFocused;
238 
239  // Frame durations (in milliseconds)
240  std::vector<int> m_DurationsNormal;
241  std::vector<int> m_DurationsMouseHover;
242  std::vector<int> m_DurationsMouseDown;
243  std::vector<int> m_DurationsFocused;
244 
245  // The pathname used to load the animated button
246  std::string m_LoadedPathname;
247 
248  // Is there a separate hover image, or is it a semi-transparent image that is drawn on top of the others?
249  bool m_SeparateHoverImage;
250 
251  // The SFML text
252  sf::Text m_Text;
253 
254  // This will store the size of the text ( 0 to auto size )
255  unsigned int m_TextSize;
256 
257  // The frame that is currently displayed
258  unsigned int m_CurrentFrame;
259  };
260 
262 }
263 
265 
266 #endif //_TGUI_ANIMATED_BUTTON_INCLUDED_
267 
The parent struct for every object.
Definition: Objects.hpp:36
Definition: AnimatedButton.hpp:35
Parent object for all objects that need to access the internal clock of the window.
Definition: Objects.hpp:338