Label.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 LABEL_H_
19 #define LABEL_H_
20 
21 #include <SFML/UI/Component.hpp>
22 #include <SFML/UI/IText.hpp>
23 
24 namespace sf
25 {
26 namespace ui
27 {
28 
29 class Label : public Component, public IText
30 {
31 public:
32 
33  //CONSTRUCTORS/DESTRUCTORS -------------------------------------------
34 
40  Label();
41 
49  Label(sf::Texture const &image);
50 
60  Label(sf::Font const &font, sf::String const &text, int fontSize = 35);
61 
62  virtual ~Label();
63  //--------------------------------------------------------------------
64 
65  //METHODS ------------------------------------------------------------
66 public:
74  virtual void updateEvent(sf::Event const &event);
75 
84  virtual void updateFixed(sf::Time delta);
85 
86 protected:
92  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
93 
100  virtual void updateCoord();
101  //--------------------------------------------------------------------
102 
103  //GETTERS/SETTERS ----------------------------------------------------
104 public:
110  virtual const sf::String& getText() const;
111 
120  virtual void setText(sf::String const &text);
121 
127  virtual const sf::Font* getFont() const;
128 
134  virtual void setFont(sf::Font const &font);
135 
141  virtual unsigned int getFontSize() const;
142 
150  virtual void setFontSize(unsigned int size);
151 
157  virtual sf::Color getFontColor() const;
158 
166  virtual void setFontColor(sf::Color color);
167 
174  const sf::Texture* getImage() const;
175 
182  void setImage(sf::Texture const &image);
183 
189  virtual sf::Vector2f getSize() const;
190  //--------------------------------------------------------------------
191 
192  //FIELDS -------------------------------------------------------------
193 protected:
194  sf::Text m_text;
195  //--------------------------------------------------------------------
196 };
197 
198 } /* namespace ui */
199 } /* namespace sf */
200 #endif /* LABEL_H_ */
201 
virtual void setText(sf::String const &text)
Sets the text's string of the component Don't forget to set the font.
virtual void draw(sf::RenderTarget &target, sf::RenderStates states) const
Draw the component to the render target.
virtual sf::Vector2f getSize() const
void setImage(sf::Texture const &image)
Sets the label's image Similar to setTexture(sf::Texture const&)
virtual void updateCoord()
Called when the component need update its geometry Inherit when you need to update some sprite...
A label which show text or image.
Definition: Label.hpp:29
virtual const sf::String & getText() const
virtual void updateFixed(sf::Time delta)
Update the component with the main loop's frequency Can be useful for animation, or time's needed stu...
virtual void updateEvent(sf::Event const &event)
Update the component each time an event has been polled.
Label()
Creates an empty label.
The base class for all UI components.
Definition: Component.hpp:29
virtual const sf::Font * getFont() const
An interface that allow component to have a text.
Definition: IText.hpp:28
virtual sf::Color getFontColor() const
virtual void setFont(sf::Font const &font)
Sets the font of the component's text.
const sf::Texture * getImage() const
virtual void setFontColor(sf::Color color)
Sets the color's font of the text.
virtual void setFontSize(unsigned int size)
Set the font's size of the component.
virtual unsigned int getFontSize() const