TGUI  0.8.8
CustomWidgetForBindings.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 Bruno Van de Velde (vdv_b@tgui.eu)
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_CUSTOM_WIDGET_FOR_BINDINGS_HPP
27 #define TGUI_CUSTOM_WIDGET_FOR_BINDINGS_HPP
28 
30 
31 #include <TGUI/Widget.hpp>
32 
34 
35 namespace tgui
36 {
40  class TGUI_API CustomWidgetForBindings : public Widget
41  {
42  public:
43 
44  typedef std::shared_ptr<CustomWidgetForBindings> Ptr;
45  typedef std::shared_ptr<const CustomWidgetForBindings> ConstPtr;
46 
47 
53 
54 
78  void setPosition(const Layout2d& position) override;
79 
80 
98  void setSize(const Layout2d& size) override;
99 
100 
109  Vector2f getFullSize() const override;
110 
111 
117  Vector2f getAbsolutePosition() const override;
118 
119 
127  Vector2f getWidgetOffset() const override;
128 
129 
137  void setVisible(bool visible) override;
138 
139 
147  void setEnabled(bool enabled) override;
148 
149 
158  void setFocused(bool focused) override;
159 
160 
165  bool canGainFocus() const override;
166 
167 
172  bool update(sf::Time elapsedTime) override;
173 
174 
179  bool mouseOnWidget(Vector2f pos) const override;
180 
184  void leftMousePressed(Vector2f pos) override;
185 
189  void leftMouseReleased(Vector2f pos) override;
190 
194  void rightMousePressed(Vector2f pos) override;
195 
199  void rightMouseReleased(Vector2f pos) override;
200 
204  void mouseMoved(Vector2f pos) override;
205 
209  void keyPressed(const sf::Event::KeyEvent& event) override;
210 
214  void textEntered(std::uint32_t key) override;
215 
220  bool mouseWheelScrolled(float delta, Vector2f pos) override;
221 
225  void mouseNoLongerOnWidget() override;
226 
230  void leftMouseButtonNoLongerDown() override;
231 
232 
238  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
239 
240 
251  Widget::Ptr clone() const override
252  {
253  return std::make_shared<CustomWidgetForBindings>(*this);
254  }
255 
256 
258  protected:
259 
265  void rendererChanged(const std::string& property) override;
266 
267 
271  void mouseEnteredWidget() override;
272 
273 
277  void mouseLeftWidget() override;
278 
279 
280  public:
281 
282  std::function<void(sf::Vector2f)> implPositionChanged;
283  std::function<void(sf::Vector2f)> implSizeChanged;
284  std::function<void(bool)> implVisibleChanged;
285  std::function<void(bool)> implEnableChanged;
286  std::function<void(bool)> implFocusChanged;
287  std::function<bool()> implCanGainFocus;
288  std::function<sf::Vector2f()> implGetFullSize;
289  std::function<sf::Vector2f()> implGetAbsolutePosition;
290  std::function<sf::Vector2f()> implGetWidgetOffset;
291  std::function<void(sf::Time)> implUpdateFunction;
292  std::function<bool(sf::Vector2f)> implMouseOnWidget;
293  std::function<void(sf::Vector2f)> implLeftMousePressed;
294  std::function<void(sf::Vector2f)> implLeftMouseReleased;
295  std::function<void(sf::Vector2f)> implRightMousePressed;
296  std::function<void(sf::Vector2f)> implRightMouseReleased;
297  std::function<void(sf::Vector2f)> implMouseMoved;
298  std::function<void(const sf::Event::KeyEvent&)> implKeyPressed;
299  std::function<void(std::uint32_t)> implTextEntered;
300  std::function<bool(float, sf::Vector2f)> implMouseWheelScrolled;
301  std::function<void()> implMouseNoLongerOnWidget;
302  std::function<void()> implLeftMouseButtonNoLongerDown;
303  std::function<void()> implMouseEnteredWidget;
304  std::function<void()> implMouseLeftWidget;
305  std::function<bool(const std::string&)> implRendererChanged;
306  std::function<void(sf::RenderTarget&, sf::RenderStates)> implDrawFunction;
307 
309  };
310 
312 }
313 
315 
316 #endif // TGUI_WIDGET_HPP
void setSize(const Layout2d &size) override
Changes the size of the widget.
Vector2f getFullSize() const override
Returns the entire size that the widget is using.
std::shared_ptr< CustomWidgetForBindings > Ptr
Shared widget pointer.
Definition: CustomWidgetForBindings.hpp:44
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37
static CustomWidgetForBindings::Ptr create()
Creates a new widget.
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Vector2f getAbsolutePosition() const override
Get the absolute position of the widget instead of the relative position to its parent.
void setPosition(const Layout2d &position) override
sets the position of the widget
bool mouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
bool canGainFocus() const override
Returns whether the widget can gain focus.
Class used by bindings to implement custom widgets withing these bindings (e.g. a custom C# widget in...
Definition: CustomWidgetForBindings.hpp:41
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: CustomWidgetForBindings.hpp:251
Definition: Vector2f.hpp:39
std::shared_ptr< const CustomWidgetForBindings > ConstPtr
Shared constant widget pointer.
Definition: CustomWidgetForBindings.hpp:45
The parent class for every widget.
Definition: Widget.hpp:74
void setFocused(bool focused) override
Focus or unfocus the widget.
void mouseLeftWidget() override
This function is called when the mouse leaves the widget.
Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
void mouseEnteredWidget() override
This function is called when the mouse enters the widget.
void setVisible(bool visible) override
Shows or hides a widget.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
void setEnabled(bool enabled) override
Enables or disables the widget.