TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
EventManager.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
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_EVENT_MANAGER_INCLUDED_
27 #define _TGUI_EVENT_MANAGER_INCLUDED_
28 
30 
31 namespace tgui
32 {
34  // Keeps track of all objects and passes the events to them.
36  struct TGUI_API EventManager : public sf::NonCopyable
37  {
39  // The default constructor.
41  EventManager();
42 
43 
44  protected:
45 
47  // When this function is called then all the objects receive the event (if there are objects).
49  virtual void handleEvent(sf::Event& event);
50 
51 
53  // You can use this function to change the focus to another object.
54  // You cannot manually call this function. You should call the focus function from the object's parent instead.
56  virtual void focusObject(OBJECT* const object);
57 
58 
60  // Unfocuses the given object.
62  virtual void unfocusObject(OBJECT* const object);
63 
64 
66  // Unfocuses all the objects.
68  virtual void unfocusAllObjects();
69 
70 
72  // Places an object before all other objects.
74  virtual void updateTime(const sf::Time& elapsedTime);
75 
76 
78  // When the tab key is pressed then this function is called. The focus will move to the next object (if there is one).
79  // This function will only work when tabKeyUsageEnabled is true.
81  virtual void tabKeyPressed();
82 
83 
85  // Checks above which object the mouse is standing.
86  // The object can be signaled through Objects[ObjectNr] on condition that this function returned true.
87  //
88  // return: true when the mouse is standing on an object
89  // false if the mouse isn't on any object
91  virtual bool mouseOnObject(unsigned int& objectNr, float x, float y);
92 
93 
95  // Tells all the objects that the mouse is not on top of them.
97  virtual void mouseNotOnObject();
98 
99 
101  // Tells all the objects that the mouse is no longer down.
103  virtual void mouseNoLongerDown();
104 
105 
107  // This function is similar to the tabKeyPressed function.
108  // The difference is that this function will return false and unfocus all objects when the last object was focused.
109  // The tabKeyPressed function on the other hand would just focus the first object.
111  virtual bool focusNextObject();
112 
113 
115  protected:
116 
117  // This vector will hold all objects
118  std::vector<OBJECT*> m_Objects;
119 
120  // The id of the focused object
121  unsigned int m_FocusedObject;
122 
123  // When one of the elements of the array becomes true then the key is held down.
124  // When nothing happend (e.g. focus another object) and it goes up again then the focused object receives a signal.
125  // When something happens then this key will also becomes false again (while the key is still down).
126  // Not all elements are used, only a few elements of the array are changed.
127  bool m_KeyPress[sf::Keyboard::KeyCount];
128 
129  // A pointer to the struct that owns the event manager (NULL when it is the window)
130  OBJECT* m_Parent;
131 
133 
134  // The event handler can only be used by objects and by the window
135  friend struct Group;
136  friend struct GroupObject;
137  friend struct Panel;
138  friend struct ChildWindow;
139  friend struct Grid;
140  friend struct Window;
141  friend struct Form;
142 
144  };
145 
147 
148 }
149 
151 
152 #endif //_TGUI_EVENT_MANAGER_INCLUDED_
153