Component.hpp
1 /*
2  * Copyright © 2013 mathdu07
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef COMPONENT_H_
19 #define COMPONENT_H_
20 
21 #include <SFML/Graphics.hpp>
22 #include <SFML/UI/ComponentObservable.hpp>
23 
24 namespace sf
25 {
26 namespace ui
27 {
28 
29 class Component : public Drawable, public ComponentObservable
30 {
31 
32  //CONSTRUCTORS/DESTRUCTORS -------------------------------------------
33 public:
39  Component();
40 
48  Component(sf::Texture const &texture);
49 
50  virtual ~Component();
51  //--------------------------------------------------------------------
52 
53  //METHODS ------------------------------------------------------------
54 public:
62  virtual void updateEvent(sf::Event const &event) = 0;
63 
72  virtual void updateFixed(sf::Time delta) = 0;
73 
90  void updateSize();
91 
99  void move(sf::Vector2f const &vector);
100 
108  void move(float x, float y);
109 
110 protected:
116  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
117 
124  virtual void updateCoord();
125  //--------------------------------------------------------------------
126 
127  //GETTERS/SETTERS ----------------------------------------------------
128 public:
134  const sf::Texture* getTexture() const;
135 
141  void setTexture(const sf::Texture& texture);
142 
148  const sf::Vector2f& getPosition() const;
149 
157  void setPosition(sf::Vector2f const &position);
158 
168  void setPosition(float x, float y);
169 
175  virtual sf::Vector2f getSize() const;
176  //--------------------------------------------------------------------
177 
178  //FIELDS -------------------------------------------------------------
179 protected:
180  sf::Sprite m_sprite; // The component's sprite displayed
181  sf::Texture const *m_texture; //The component's texture
182  //--------------------------------------------------------------------
183 };
184 
185 } /* namespace ui */
186 } /* namespace sf */
187 
188 #endif /* COMPONENT_H_ */
189 
Component()
Creates an empty component, without texture.
const sf::Vector2f & getPosition() const
const sf::Texture * getTexture() const
void move(sf::Vector2f const &vector)
Move the component.
The class who call the observers.
The base class for all UI components.
Definition: Component.hpp:29
void setTexture(const sf::Texture &texture)
Set the texture of the component.
virtual void updateEvent(sf::Event const &event)=0
Update the component each time an event has been polled.
void setPosition(sf::Vector2f const &position)
Set the component's position.
virtual sf::Vector2f getSize() const
void updateSize()
Update the size of the component Call it when you update your texture after it was set...
virtual void updateCoord()
Called when the component need update its geometry Inherit when you need to update some sprite...
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const
Draw the component to the render target.
virtual void updateFixed(sf::Time delta)=0
Update the component with the main loop's frequency Can be useful for animation, or time's needed stu...