TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tbx_interface_element.hpp
1 
9 #ifndef TurtleBrainsExpress_InterfaceElement_hpp
10 #define TurtleBrainsExpress_InterfaceElement_hpp
11 
12 #include <turtle_brains/express/interface/tbx_interface.hpp>
13 #include <turtle_brains/graphics/tb_graphic_list.hpp>
14 
15 #include <functional>
16 #include <array>
17 
18 namespace TurtleBrainsExpress
19 {
20  namespace Interface
21  {
22  namespace Unstable
23  {
24 
25  class Controller;
26  class InterfaceHandlerInterface;
27 
28  class Element
29  {
30  public:
31  enum class State
32  {
33  Hidden,
34  Disabled,
35  Enabled,
36  Focused,
37  Activated
38  };
39 
40  Element(void);
41  virtual ~Element(void);
42 
43  const State& GetState(void) const;
44  void SetState(const State& newState);
45 
46  //TODO: TurtleBrainsExpress: Interface: Refactor and move to base Element:
47 
56  void SetHandler(InterfaceHandlerInterface* handler, const ElementHandle& elementHandle);
57  void SetFunction(std::function<void(ElementHandle)> handlerFunction, ElementHandle elementHandle);
58  void SetFunction(std::function<void()> callbackFunction);
59 
60  void HandleUserEvent(const UserEvent& userEvent);
61  void LinkToNeighbor(const NavigationDirection& direction, Element* element);
62 
63  Point GetPosition(void) const;
64  void SetPosition(const tbGraphics::PixelSpace& pixelX, const tbGraphics::PixelSpace& pixelY);
65  inline tbGraphics::PixelSpace GetPixelWidth(void) const { return mPixelSize.x; }
66  inline tbGraphics::PixelSpace GetPixelHeight(void) const { return mPixelSize.y; }
67 
68  void Render(void) const;
69 
70  protected:
71  virtual void OnRender(void) const;
72  virtual void OnActivate(void);
73 
74  virtual bool ContainsPointer(const Point& pointerPosition) const;
75  virtual bool CanLinkWithNeighbor(const NavigationDirection& direction) const;
76  virtual void OnStateChange(const State& newState);
77 
78  virtual void OnHandleUserEvent(const UserEvent& userEvent);
79  virtual void OnHandleActiveUserEvent(const UserEvent& userEvent);
80 
81  Element* FindNextElementInDirection(const NavigationDirection& direction, bool enabledOnly);
82  void SetPixelSize(const tbGraphics::PixelSpace& width, const tbGraphics::PixelSpace& height);
83 
84  void ClearGraphics(void);
85  void AddGraphic(tbGraphics::Graphic& graphic);
86  void AddGraphic(tbGraphics::Graphic* graphic);
87  void ClearGraphics(const State& state);
88  void AddGraphic(const State& state, tbGraphics::Graphic& graphic);
89  void AddGraphic(const State& state, tbGraphics::Graphic* graphic);
90 
91  private:
92  tbGraphics::GraphicList mGraphics;
93  std::array<tbGraphics::GraphicList, 5> mStateGraphics;
94  std::array<Element*, 4> mNeighbors;
95  Point mPixelSize; //x = width, y = height
96  InterfaceHandlerInterface* mInterfaceHandler;
97  std::function<void(ElementHandle)> mFunctionHandler;
98  std::function<void(void)> mFunctionCallback;
99  ElementHandle mElementHandle;
100  State mState;
101  };
102 
103  };
104  }; /* namespace Interface */
105 }; /* namespace TurtleBrainsExpress */
106 
108 
109 #endif /* TurtleBrainsExpress_InterfaceElement_hpp */
Definition: tb_graphic.hpp:61
Definition: tb_graphic_list.hpp:27
A collection of objects and functions to express games quickly.
Definition: tbx_interface.hpp:18
Definition: tbx_interface_handler_interface.hpp:27
Definition: tbx_interface.hpp:58
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:36
Definition: tbx_interface_element.hpp:28
void SetHandler(InterfaceHandlerInterface *handler, const ElementHandle &elementHandle)