Focusable.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 FOCUSABLE_H_
19 #define FOCUSABLE_H_
20 
21 #include <SFML/UI/Component.hpp>
22 
23 namespace sf
24 {
25 namespace ui
26 {
27 
28 class Focusable: public Component
29 {
30  //CONSTRUCTORS/DESTRUCTORS -------------------------------------------
31 public:
39  Focusable();
40 
51  Focusable(sf::Texture const &texture, sf::Texture const &textureFocused);
52 
53  virtual ~Focusable();
54  //--------------------------------------------------------------------
55 
56  //METHODS ------------------------------------------------------------
57 protected:
67  virtual bool checkClickOn(int x, int y) const;
68 
77  virtual bool isCoordOnComponent(int x, int y) const;
78 
84  virtual void gainFocus();
85 
91  virtual void lostFocus();
92  //--------------------------------------------------------------------
93 
94  //GETTERS/SETTERS ----------------------------------------------------
95 public:
101  bool isFocused() const;
102 
110  void setFocused(bool focused);
111 
117  const sf::Texture* getTextureFocused() const;
118 
126  void setTextureFocused(const sf::Texture& textureFocused);
127  //--------------------------------------------------------------------
128 
129  //FIELDS -------------------------------------------------------------
130 protected:
131  sf::Texture const *m_textureFocused;
132  bool m_focused;
133  //--------------------------------------------------------------------
134 };
135 
136 } /* namespace ui */
137 } /* namespace sf */
138 #endif /* FOCUSABLE_H_ */
139 
virtual bool isCoordOnComponent(int x, int y) const
The base class for all UI components that can be focused.
Definition: Focusable.hpp:28
Focusable()
Creates an empty Component Focusable, without textures.
const sf::Texture * getTextureFocused() const
bool isFocused() const
void setFocused(bool focused)
Set if the component is focused.
virtual bool checkClickOn(int x, int y) const
The base class for all UI components.
Definition: Component.hpp:29
void setTextureFocused(const sf::Texture &textureFocused)
Set the texture that is displayed when the component is displayed.
virtual void gainFocus()
Called when the component gain focus.
virtual void lostFocus()
Called when the component lost focus.