Aether
SDL2 based UI Framework for NX
Window.hpp
1 #ifndef AETHER_WINDOW_HPP
2 #define AETHER_WINDOW_HPP
3 
4 #include <queue>
5 #include <stack>
6 
7 // Forward declare the typedef
8 namespace {
9  typedef std::function<void(const std::string, const bool)> LogHandler;
10 };
11 
12 // Forward declare pointers
13 namespace Aether {
14  class Overlay;
15  class Screen;
16  class Timer;
17 }
18 
19 namespace Aether {
27  class Window {
28  public:
32  enum class ScreenOperation {
33  Push,
34  Pop,
35  Set
36  };
37 
38  private:
42  enum class FadeAction {
43  None,
44  In,
45  Out
46  };
47 
51  struct FadeVars {
52  FadeAction action;
53  short alpha;
54  bool in;
55  bool out;
56  } fade;
57 
58  double lastMillis;
59  bool shouldLoop;
60  bool showDebug;
61  Timer * timer;
63  Colour bgColour;
64  Drawable * bgDrawable;
66  Button heldButton;
67  int heldTime;
68  int holdDelay_;
69  std::function<Colour(uint32_t)> highlight;
71  std::vector<Overlay *> overlays;
72  std::queue< std::pair<ScreenOperation, Screen *> > screenOps;
73  std::stack<Screen *> screenStack;
74  Screen * screen;
80  void performScreenOps();
81 
85  void processEvents();
86 
92  void renderDebug(const double delta);
93 
99  void renderFade(const double delta);
100 
106  void updateHeldButton(const double delta);
107 
113  void updateOverlays(const double delta);
114 
115  public:
126  Window(const std::string & name, const unsigned int width, const unsigned int height, const LogHandler & log);
127 
133  void showDebugInfo(const bool show);
134 
140  void setFadeIn(const bool fade);
141 
147  void setFadeOut(const bool fade);
148 
155  void setBackgroundColour(const Colour & col);
156 
165  bool setBackgroundImage(const std::string & path);
166 
173  void setFont(const std::string & path);
174 
180  void setFontSpacing(const double spacing);
181 
187  void setHighlightAnimation(const std::function<Colour(const uint32_t)> & func);
188 
194  void setHighlightBackground(const Colour & col);
195 
201  void setHighlightOverlay(const Colour & col);
202 
208  int holdDelay();
209 
216  void setHoldDelay(const int ms);
217 
224  void addOverlay(Overlay * ovl);
225 
230  void pushScreen();
231 
236  void popScreen();
237 
242  void removeScreen();
243 
250  void showScreen(Screen * screen);
251 
259  bool loop();
260 
264  void exit();
265 
269  ~Window();
270  };
271 };
272 
273 #endif
void setFont(const std::string &path)
Set a custom font to use for text rendering. Pass an empty string to revert back to internal fonts...
void setFadeIn(const bool fade)
Enable a fade in animation.
void addOverlay(Overlay *ovl)
Add the given overlay to the window, placing it on top of existing ones.
void exit()
Stop the main loop().
void setBackgroundColour(const Colour &col)
Set the colour used to clear the screen between frames. The alpha channel is ignored.
Small utility class to measure time.
Definition: Timer.hpp:10
void showDebugInfo(const bool show)
Set whether debugging information is shown.
~Window()
Cleans up Aether.
void setHighlightBackground(const Colour &col)
Set the background colour used for highlighting an element.
A class that represents a screen layout Stores all screen elements for a specific screen...
Definition: Screen.hpp:12
void showScreen(Screen *screen)
Set the screen to show (takes effect at next loop). Ths does not alter the screen stack in anyway; it...
ScreenOperation
Types of operations to perform on the screen stack.
Definition: Window.hpp:32
void setHighlightOverlay(const Colour &col)
Set the colour used to highlight an element when selected.
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
void pushScreen()
Push the current screen onto the stack at the next loop.
Base namespace for all Aether related classes and functions.
bool loop()
Handles rendering the current screen and events. This should be called until it returns false...
void setHighlightAnimation(const std::function< Colour(const uint32_t)> &func)
Set the function used to animate the highlight border.
bool setBackgroundImage(const std::string &path)
Set an image to use as the background. Pass an empty string to remove.
void setFontSpacing(const double spacing)
Set the spacing between wrapped lines of text.
void popScreen()
Pop a screen from the stack at the next loop.
void setHoldDelay(const int ms)
Set the time to wait before firing duplicate button events due to a button being held down...
Window(const std::string &name, const unsigned int width, const unsigned int height, const LogHandler &log)
Initializes an Aether instance. There should only ever be one Window instantiated at once (ideally on...
void removeScreen()
Remove the screen set with showScreen() immediately from the window. This does not wait until the nex...
An object representing an overlay.
Definition: Overlay.hpp:14
void setFadeOut(const bool fade)
Enable a fade out animation.
The Window is the root element, which initializes Aether and contains all of the screens/elements to ...
Definition: Window.hpp:27
Button
Enum class for buttons Avoids confusion with SDL/libnx names.
Definition: Types.hpp:12
int holdDelay()
Returns the current value for &#39;hold delay&#39; (see setHoldDelay()).