TGUI  v0.5.2
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Objects.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_OBJECTS_INCLUDED_
27 #define _TGUI_OBJECTS_INCLUDED_
28 
30 
31 namespace tgui
32 {
36  struct TGUI_API OBJECT : public sf::Drawable, sf::Transformable
37  {
41  OBJECT();
42 
43 
47  OBJECT(const OBJECT& copy);
48 
49 
53  virtual ~OBJECT();
54 
55 
59  OBJECT& operator= (const OBJECT& right);
60 
61 
63  // This function is called when the object is created (when it is added to a group).
65  virtual void initialize();
66 
67 
69  // Makes a copy of the object by just calling the copy constructor.
71  virtual OBJECT* clone() = 0;
72 
73 
77  virtual void setSize(float width, float height) = 0;
78 
79 
83  virtual Vector2u getSize() const = 0;
84 
85 
89  virtual Vector2f getScaledSize() const = 0;
90 
91 
97  virtual void show();
98 
99 
105  virtual void hide();
106 
107 
114  virtual bool isVisible() const;
115 
116 
122  virtual void enable();
123 
124 
130  virtual void disable();
131 
132 
139  virtual bool isEnabled() const;
140 
141 
147  virtual bool isDisabled() const;
148 
149 
155  virtual bool isLoaded() const;
156 
157 
159  // Get the ObjectPhases from the string read from the info file
161  virtual void extractPhases(std::string phases);
162 
163 
173  void focus();
174 
175 
183  void unfocus();
184 
185 
195  void focusNextObject();
196 
197 
201  virtual bool isFocused() const;
202 
203 
207  virtual ObjectTypes getObjectType() const;
208 
209 
213  virtual void moveToFront();
214 
215 
219  virtual void moveToBack();
220 
221 
223  // These functions are used to receive callback from the EventManager.
224  // You normally don't need them, but you can use them to simulate an event.
226  virtual bool mouseOnObject(float x, float y);
227  virtual void leftMousePressed(float x, float y);
228  virtual void leftMouseReleased(float x, float y);
229  virtual void mouseMoved(float x, float y);
230  virtual void keyPressed(sf::Keyboard::Key key);
231  virtual void textEntered(sf::Uint32 key);
232  virtual void mouseWheelMoved(int delta);
233  virtual void objectFocused();
234  virtual void objectUnfocused();
235 
236  virtual void mouseNotOnObject();
237  virtual void mouseNoLongerDown();
238 
239 
241  public:
242 
243  // When the id is 0 then there will be no callback. Otherwise, this will be the callbackID inside the Callback struct.
244  unsigned int callbackID;
245 
246 
248  protected:
249 
250  // When an object is disabled, it will no longer receive events
251  bool m_Enabled;
252 
253  // Is the object visible? When it is invisible it will not receive events and it won't be drawn.
254  bool m_Visible;
255 
256  // This bool will be true from the moment that the load function is completed successfully.
257  bool m_Loaded;
258 
259  // This will store the different phases that the object can have
260  // e.g. if there isn't a mouse down image then a button should not try to change its image on mouse down
261  unsigned char m_ObjectPhase;
262 
263  // This will point to our parent object. If there is no parent then this will be NULL.
264  Group* m_Parent;
265 
266  // Is the mouse on top of the object? Did the mouse go down on the object?
267  bool m_MouseHover;
268  bool m_MouseDown;
269 
270  // Are you focused on the object?
271  bool m_Focused;
272 
273  // Can the object be focused?
274  bool m_AllowFocus;
275 
276  // Is the object a button, an edit box, a checkbox, ...
277  ObjectTypes m_ObjectType;
278 
279  // This is set to true for objects that are also derived from OBJECT_ANIMATION.
280  bool m_AnimatedObject;
281 
282  // This is set to true for objects that have something to be dragged around (e.g. sliders and scrollbars)
283  bool m_DraggableObject;
284 
285  // This is set to true for objects that store other objects inside them
286  bool m_GroupObject;
287 
288 
290 
291  friend struct EventManager;
292  friend struct Group;
293  };
294 
295 
299  struct TGUI_API OBJECT_BORDERS
300  {
304  OBJECT_BORDERS();
305 
306 
310  virtual void setBorders(unsigned int leftBorder = 0, unsigned int topBorder = 0,
311  unsigned int rightBorder = 0, unsigned int bottomBorder = 0) = 0;
312 
313 
320  virtual Vector4u getBorders() const;
321 
322 
324  protected:
325 
326  unsigned int m_LeftBorder;
327  unsigned int m_TopBorder;
328  unsigned int m_RightBorder;
329  unsigned int m_BottomBorder;
330 
332  };
333 
334 
338  struct TGUI_API OBJECT_ANIMATION
339  {
340  // The event manager will be able to change the elapsed time from any object
341  friend struct EventManager;
342 
344  protected:
345 
347  // This function is called right after the elapsed time is changed.
349  virtual void update() = 0;
350 
352  protected:
353 
354  // This will store the elapsed time since the last animation
355  sf::Time m_AnimationTimeElapsed;
356  };
357 
358 
362  struct Callback
363  {
364  // All objects
365 
366  // The id that was passed to the object. It is used to identify from what object the callback came from. It can'b be 0.
367  unsigned int callbackID;
368 
369  // How did the callbak occur? (one of the elements from the Triggers enum)
370  unsigned int trigger;
371 
372  // Pointer to the object
373  OBJECT* object;
374 
375 
376  // Checkbox and RadioButton
377 
378  // True when the checkbox is checked, false otherwise.
379  bool checked;
380 
381 
382  // Button (these members are still in there because of what I did in v0.1, but they shouldn't be used)
383 
384  // This will store the mouse position. Only used on mouse clicks.
385  float mouseX;
386  float mouseY;
387 
388  // When you click on an object then this contains the button
389  sf::Mouse::Button mouseButton;
390 
391 
392  // Editbox and ListBox
393 
394  // This string will contain the new string inside the editbox
395  sf::String text;
396 
397 
398  // Slider, ListBox and LoadingBar
399 
400  unsigned int value;
401 
402 
403  // This enum contains the different values for Trigger.
404  enum triggers
405  {
406  mouseDown, // Button
407  mouseClick, // Button, Checkbox, RadioButton
408  keyPress_Space, // Button, Checkbox, RadioButton
409  keyPress_Return, // Button, Checkbox, RadioButton
410  textChanged, // EditBox
411  valueChanged, // Slider, LoadingBar
412  itemSelected, // ListBox, ComboBox
413  animationFinished, // AnimatedPicture
414  closed, // ChildWindow
415 
416  count // Keep this one last
417  };
418  };
419 
420 
422  // Get a sf::Color from a string. The string must look like: "(r, g, b)" or "(r, g, b, a)".
423  // When this function fails then it will return black.
425  TGUI_API sf::Color extractColor(std::string string);
426 
427 
429  // This function does exactly the opposite of extractColor.
430  // The returned string will be "(r,g,b)" when a=255 or "(r,g,b,a)" when a<255.
432  TGUI_API std::string convertColorToString(const sf::Color& color);
433 
434 
436  // Get a Vector2f from a string. The string must look like: "(x, y)".
438  TGUI_API bool extractVector2f(std::string string, Vector2f& vector);
439 
440 
442  // Get a Vector2u from a string. The string must look like: "(x, y)".
444  TGUI_API bool extractVector2u(std::string string, Vector2u& vector);
445 
446 
448  // Get a Vector4u from a string. The string must look like: "(x1, x2, x3, x4)".
450  TGUI_API bool extractVector4u(std::string string, Vector4u& vector);
451 }
452 
454 
455 #endif //_TGUI_OBJECTS_INCLUDED_
When you receive an action callback from an object then this struct will be passed as parameter...
Definition: Objects.hpp:362
The parent struct for every object.
Definition: Objects.hpp:36
Parent struct for every object that has borders.
Definition: Objects.hpp:299
Parent struct for objects that store multiple objects.
Definition: Group.hpp:38
ObjectTypes
A list of all objects in tgui.
Definition: TGUI.hpp:107
Definition: Vectors.hpp:36
Parent object for all objects that need to access the internal clock of the window.
Definition: Objects.hpp:338