TGUI  v0.6.10
Widget.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 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_WIDGETS_HPP
27 #define TGUI_WIDGETS_HPP
28 
29 
30 #include <TGUI/Global.hpp>
31 #include <TGUI/ConfigFile.hpp>
32 #include <TGUI/Callback.hpp>
33 #include <TGUI/Transformable.hpp>
34 #include <TGUI/SharedWidgetPtr.hpp>
35 
37 
38 namespace tgui
39 {
40  class Container;
41 
45  class TGUI_API Widget : public sf::Drawable, public Transformable, public CallbackManager
46  {
47  public:
48 
50 
51 
56  Widget();
57 
58 
65  Widget(const Widget& copy);
66 
67 
72  virtual ~Widget();
73 
74 
83  Widget& operator= (const Widget& right);
84 
85 
87  // Makes a copy of the widget by just calling the copy constructor.
89  virtual Widget* clone() = 0;
90 
91 
98  virtual sf::Vector2f getAbsolutePosition() const;
99 
100 
107  virtual void show();
108 
109 
116  virtual void hide();
117 
118 
128  bool isVisible() const;
129 
130 
138  virtual void enable();
139 
140 
148  virtual void disable();
149 
150 
160  bool isEnabled() const;
161 
162 
172  bool isDisabled() const;
173 
174 
183  bool isLoaded() const;
184 
185 
195  virtual void focus();
196 
197 
205  virtual void unfocus();
206 
207 
214  bool isFocused() const;
215 
216 
223  WidgetTypes getWidgetType() const;
224 
225 
232  Container* getParent() const;
233 
234 
245  virtual void setTransparency(unsigned char transparency);
246 
247 
255  unsigned char getTransparency() const;
256 
257 
262  virtual void moveToFront();
263 
264 
269  virtual void moveToBack();
270 
271 
284  void setCallbackId(unsigned int callbackId);
285 
286 
295  unsigned int getCallbackId();
296 
297 
299  // This function is called right after the elapsed time is changed.
300  // The elapsed time is only changed when the widget has set m_AnimatedWidget to true.
302  virtual void update();
303 
304 
306  // The widgets use this function to send their callbacks to their parent and/or to a callback function.
308  void addCallback();
309 
310 
312  // This function is called when the mouse enters the widget. If requested, a callback will be send.
314  virtual void mouseEnteredWidget();
315 
316 
318  // This function is called when the mouse leaves the widget. If requested, a callback will be send.
320  virtual void mouseLeftWidget();
321 
322 
326  virtual bool mouseOnWidget(float x, float y) = 0;
327 
331  virtual void leftMousePressed(float x, float y);
332 
336  virtual void leftMouseReleased(float x, float y);
337 
341  virtual void mouseMoved(float x, float y);
342 
346  virtual void keyPressed(const sf::Event::KeyEvent& event);
347 
351  virtual void textEntered(sf::Uint32 key);
352 
356  virtual void mouseWheelMoved(int delta, int x, int y);
357 
361  virtual void widgetFocused();
362 
366  virtual void widgetUnfocused();
367 
371  virtual void mouseNotOnWidget();
372 
376  virtual void mouseNoLongerDown();
377 
378 
381  // This function is a (slow) way to set properties on the widget, no matter what type it is.
382  // When the requested property doesn't exist in the widget then the functions will return false.
384  virtual bool setProperty(std::string property, const std::string& value);
385 
388  // This function is a (slow) way to get properties of the widget, no matter what type it is.
389  // When the requested property doesn't exist in the widget then the functions will return false.
391  virtual bool getProperty(std::string property, std::string& value) const;
392 
393 
396  // Returns a list of all properties that can be used in setProperty and getProperty.
397  // The second value in the pair is the type of the property (e.g. int, uint, string, ...).
399  virtual std::list< std::pair<std::string, std::string> > getPropertyList() const;
400 
401 
403  private:
404 
406  // This function is called when the widget is added to a container.
408  virtual void initialize(Container *const container);
409 
410 
412  public:
413 
418  {
419  None = 0,
420  Focused = 1,
421  Unfocused = 2,
422  MouseEntered = 4,
423  MouseLeft = 8,
424  WidgetCallbacksCount = 16
425  };
426 
427 
429  protected:
430 
431  // When a widget is disabled, it will no longer receive events
432  bool m_Enabled;
433 
434  // Is the widget visible? When it is invisible it will not receive events and it won't be drawn.
435  bool m_Visible;
436 
437  // This bool will be true from the moment that the load function is completed successfully.
438  bool m_Loaded;
439 
440  // This will store the different phases that the widget can have
441  // e.g. if there isn't a mouse down image then a button should not try to change its image on mouse down
442  unsigned char m_WidgetPhase;
443 
444  // This will point to our parent widget. If there is no parent then this will be nullptr.
445  Container* m_Parent;
446 
447  // How transparent is the widget
448  unsigned char m_Opacity;
449 
450  // Is the mouse on top of the widget? Did the mouse go down on the widget?
451  bool m_MouseHover;
452  bool m_MouseDown;
453 
454  // Are you focused on the widget?
455  bool m_Focused;
456 
457  // Can the widget be focused?
458  bool m_AllowFocus;
459 
460  // Keep track of the elapsed time.
461  bool m_AnimatedWidget;
462  sf::Time m_AnimationTimeElapsed;
463 
464  // This is set to true for widgets that have something to be dragged around (e.g. sliders and scrollbars)
465  bool m_DraggableWidget;
466 
467  // This is set to true for widgets that store other widgets inside them
468  bool m_ContainerWidget;
469 
470 
472 
473  friend class Container;
474  };
475 
476 
480  class TGUI_API WidgetBorders
481  {
482  public:
483 
488  WidgetBorders();
489 
490 
495  virtual ~WidgetBorders();
496 
497 
507  virtual void setBorders(unsigned int leftBorder = 0, unsigned int topBorder = 0,
508  unsigned int rightBorder = 0, unsigned int bottomBorder = 0) = 0;
509 
510 
520  virtual Borders getBorders() const;
521 
522 
524  protected:
525 
526  unsigned int m_LeftBorder;
527  unsigned int m_TopBorder;
528  unsigned int m_RightBorder;
529  unsigned int m_BottomBorder;
530 
532  };
533 
535 }
536 
538 
539 #endif // TGUI_WIDGETS_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
Definition: Transformable.hpp:35
WidgetTypes
A list of all widget types.
Definition: Global.hpp:80
The parent class for every widget.
Definition: Widget.hpp:45
WidgetCallbacks
Defines specific triggers to Widget.
Definition: Widget.hpp:417
Definition: Callback.hpp:80
Parent class for every widget that has borders.
Definition: Widget.hpp:480
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
Definition: Borders.hpp:35
Definition: SharedWidgetPtr.hpp:44