Aether
SDL2 based UI Framework for NX
Element.hpp
1 #ifndef AETHER_ELEMENT_HPP
2 #define AETHER_ELEMENT_HPP
3 
4 #include "Aether/types/Drawable.hpp"
5 #include "Aether/InputEvent.hpp"
6 #include <vector>
7 
8 // Forward declare the Window class
9 namespace Aether {
10  class Window;
11 };
12 
13 namespace Aether {
18  class Element {
19  // Allow Window to access the private members (i.e. statics)
20  friend Window;
21 
22  private:
24  int x_;
26  int y_;
28  int w_;
30  int h_;
32  bool hidden_;
34  std::function<void()> onPressFunc_;
36  bool hasHighlighted_;
38  bool hasSelectable_;
40  bool hasSelected_;
42  bool highlighted_;
44  bool selectable_;
46  bool selected_;
48  bool touchable_;
49 
51  static Element * hiOwner;
53  static Element * selOwner;
54 
55  protected:
61  static Colour selColour;
63  static unsigned int hiSize;
65  static Drawable * hiBGTex;
69  static Drawable * selTex;
70 
71  static Renderer * renderer;
72 
77 
79  static bool isTouch;
83  std::vector<Element *> children;
86 
94  void addElementAt(Element * e, size_t i);
95 
96  public:
110  Element(int x = 0, int y = 0, int w = 100, int h = 100);
111 
117  int x();
118 
124  int y();
125 
131  int w();
132 
138  int h();
139 
145  virtual void setX(int x);
146 
152  virtual void setY(int y);
153 
159  virtual void setW(int w);
160 
166  virtual void setH(int h);
167 
174  virtual void setXY(int x, int y);
175 
182  virtual void setWH(int w, int h);
183 
192  virtual void setXYWH(int x, int y, int w, int h);
193 
199  Element * parent();
200 
206  void setParent(Element * p);
207 
213  virtual void addElement(Element * e);
214 
223  virtual bool removeElement(Element * e);
224 
228  virtual void removeAllElements();
229 
238  virtual bool returnElement(Element * e);
239 
243  virtual void returnAllElements();
244 
251  bool isVisible();
252 
259  bool hidden();
260 
266  void setHidden(bool b);
267 
274  bool selected();
275 
281  virtual void setSelected(bool b);
282 
289  bool selectable();
290 
296  void setSelectable(bool b);
297 
304  bool touchable();
305 
311  void setTouchable(bool b);
312 
319  bool highlighted();
320 
326  void setHighlighted(bool b);
327 
334  bool hasHighlighted();
335 
341  void setHasHighlighted(bool b);
342 
349  bool hasSelectable();
355  void setHasSelectable(bool b);
356 
363  bool hasSelected();
369  void setHasSelected(bool b);
370 
374  virtual void setActive();
375 
379  virtual void setInactive();
380 
388  void setFocused(Element * e);
389 
397  void setFocussed(Element * e);
398 
405  Element * focused();
406 
413  Element * focussed();
414 
420  std::function<void()> onPressFunc();
421 
427  void onPress(std::function<void()> f);
428 
436  virtual bool handleEvent(InputEvent * e);
437 
443  virtual void update(unsigned int dt);
444 
448  virtual void render();
449 
456  virtual Drawable * renderHighlightBG();
457 
464  virtual Drawable * renderHighlight();
465 
472  virtual Drawable * renderSelection();
473 
477  virtual ~Element();
478 
484  friend void moveHighlight(Element * e);
485  };
486 };
487 
488 #endif
virtual void removeAllElements()
Deletes all children elements.
void setHidden(bool b)
Set whether element is hidden or not.
std::function< void()> onPressFunc()
Returns function invoked when the element is pressed.
void setSelectable(bool b)
Set whether element is selectable or not.
virtual void setSelected(bool b)
Set whether element is selected or not.
static Colour selColour
Selected colour if element is highlighted.
Definition: Element.hpp:61
bool hasHighlighted()
Check if current element has highlighted children element.
virtual void update(unsigned int dt)
Update is passed time since last frame (for animations)
void setHasSelected(bool b)
Set whether element has selected children element or not.
virtual Drawable * renderHighlightBG()
Renders the highlight background.
virtual void setWH(int w, int h)
Set size of element.
bool selected()
Check if current element is selected.
virtual void setH(int h)
Set height of element.
Element(int x=0, int y=0, int w=100, int h=100)
Construct a new Element object.
virtual bool handleEvent(InputEvent *e)
Attempt to handle a given event.
virtual Drawable * renderHighlight()
Renders the highlight border.
virtual Drawable * renderSelection()
Renders the selection overlay.
static bool isTouch
Indicator on whether the touch is "active" (i.e. hide highlighting) or not.
Definition: Element.hpp:79
Element * parent_
Pointer to parent element, if there is one.
Definition: Element.hpp:81
void setHighlighted(bool b)
Set whether element is highlighted or not.
static Colour hiBorderColour
Border colour if element is highlighted.
Definition: Element.hpp:59
Element * focused()
Returns the currently focused element.
Aether&#39;s main renderer instance. It provides all methods relating to drawing directly to the screen...
Definition: Renderer.hpp:30
virtual void addElement(Element *e)
Adds new element a child.
bool hasSelectable()
Check if current element has selectable children element.
virtual void setW(int w)
Set width of element.
bool touchable()
Check if current element is touch responsive.
static Drawable * hiBGTex
Highlight background texture.
Definition: Element.hpp:65
Element * focussed()
Returns the currently focused element.
bool hidden()
Check if current element is hidden.
virtual void setY(int y)
Set y-coordinate of element.
int w()
Returns width of element.
Stores RGBA values representing a colour. Each component can be within the range 0 to 255 (inclusive)...
Definition: Colour.hpp:9
Stores either a surface or texture which can be drawn on screen by providing a renderer to render()...
Definition: Drawable.hpp:22
int x()
Returns x-coordinate of element.
void onPress(std::function< void()> f)
Sets the function to invoked when the element is pressed.
virtual void setInactive()
Set element as in-activated.
virtual void setX(int x)
Set x-coordinate of element.
Element is the base class to be inherited to form all other types of elements.
Definition: Element.hpp:18
static unsigned int hiSize
Size of highlight border.
Definition: Element.hpp:63
int h()
Returns height of element.
Base namespace for all Aether related classes and functions.
virtual void returnAllElements()
Removes (but does not delete) all children elements.
virtual void setActive()
Set element as activated.
void setTouchable(bool b)
Set whether element is touch responsive or not.
void setHasHighlighted(bool b)
Set whether element has highlighted children element or not.
void setFocussed(Element *e)
Sets current element as unfocused and instead focuses a sub-element.
std::vector< Element * > children
Vector of child elements (used to call their methods)
Definition: Element.hpp:83
friend void moveHighlight(Element *e)
Returns the element currently highlighted within given element or nullptr if none found...
A class that represents an Aether input event.
Definition: InputEvent.hpp:25
virtual void setXYWH(int x, int y, int w, int h)
Setter size and co-ordinates of element.
bool isVisible()
Check if current element is visible on-screen.
static Drawable * selTex
Selection texture.
Definition: Element.hpp:69
virtual void render()
Render child elements + highlights.
void renderHighlightTextures()
Renders cached highlight textures.
bool hasSelected()
Check if current element has selected children element.
Element * focused_
Children element which is highlighted/focused (to regain focus on activation)
Definition: Element.hpp:85
virtual ~Element()
Destroy the Element object.
void setFocused(Element *e)
Sets current element as unfocused and instead focuses a sub-element.
static Drawable * hiBorderTex
Highlight border texture.
Definition: Element.hpp:67
virtual bool returnElement(Element *e)
Attempt to remove the given child element.
void setHasSelectable(bool b)
Set whether element has selectable children element or not.
void setParent(Element *p)
Set the parent element of this element.
The Window is the root element, which initializes Aether and contains all of the screens/elements to ...
Definition: Window.hpp:27
static Colour hiBGColour
Background colour if element is highlighted.
Definition: Element.hpp:57
virtual bool removeElement(Element *e)
Attempt to delete given child element.
void renderSelectionTexture()
Renders cached selection texture.
bool selectable()
Check if current element is selectable.
void addElementAt(Element *e, size_t i)
Add element at given index in vector.
Element * parent()
Returns the parent element of this element.
bool highlighted()
Check if current element is highlighted.
virtual void setXY(int x, int y)
Set co-ordinates of element.
int y()
Returns y-coordinate of element.