Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
RootDisplay.hpp
1#pragma once
2#include "Element.hpp"
3
4#include "colorspaces.hpp"
5#include <unordered_map>
6#include <memory>
7#include <vector>
8
9#if defined(_3DS) || defined(_3DS_MOCK)
10#define ICON_SIZE 48
11#elif defined(WII) || defined(WII_MOCK)
12#define ICON_SIZE 120
13#else
14#define ICON_SIZE 150
15#endif
16
17namespace Chesto {
18
19class Screen;
20
21#define SCREEN_WIDTH RootDisplay::screenWidth
22#define SCREEN_HEIGHT RootDisplay::screenHeight
23
24class RootDisplay : public Element
25{
26public:
28 virtual ~RootDisplay();
29
30 bool process(InputEvents* event);
31 void render(Element* parent);
32
33 void update();
34 int mainLoop();
35
36 void initMusic();
37 void startMusic();
38
39 void setScreenResolution(int width, int height);
40
41 static CST_Renderer* renderer;
42 static CST_Window* window;
43 static RootDisplay* mainDisplay;
44
45 // New methods for managing the subscreen stack
46 static void pushScreen(std::unique_ptr<Screen> screen);
47 static void popScreen();
48 static Screen* topScreen();
49 static void clearScreens();
50 static bool hasScreens();
51
52 // Schedule an action callback to run after event processing in the main loop
53 static void deferAction(std::function<void()> action);
54
55 // Process any deferred actions (called after event processing)
56 static void processDeferredActions();
57
58 // Screen stack storage, iterateable to draw layers at a time
59 static std::vector<std::unique_ptr<Screen>> screenStack;
60
61 // Actions that need to be deferred until after event processing
62 static std::vector<std::function<void()>> deferredActions;
63
64 static bool isProcessingEvents;
65
66 // dimensions of the screen, which can be modified
67 static int screenWidth;
68 static int screenHeight;
69
70 // OS's DPI value (separate from our globalScale)
71 static float dpiScale;
72
73 // Global UI scale multiplier for DPI-like rendering
74 static float globalScale;
75
76 // if enabled, the cursor will pulse when idle
77 // this uses more energy and forces more redraws
78 // TODO: enable or disable based on battery level or user preference
79 static bool idleCursorPulsing;
80
81 static bool isDebug;
82 bool canUseSelectToExit = false;
83
84 int lastFrameTime = 99;
85 SDL_Event needsRender;
86
87 // our main input events
88 std::unique_ptr<InputEvents> events;
89
90 std::function<void()> windowResizeCallback = NULL; // Called when the window is resized
91
92 void requestQuit();
93
94#if !defined(SIMPLE_SDL2)
95 Mix_Music* music = NULL;
96#endif
97
98private:
99 // these bools are managed by RootDisplay mainLoop, and should not be modified
100 // to break out. Instead, call requestQuit() which will update it if needed
101 bool hasRequestedQuit = false;
102 bool isAppRunning = true;
103};
104
105} // namespace Chesto
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:132
Element * parent
the parent element (reference only, not owned)
Definition: Element.hpp:116
std::function< void()> action
the action to call (from binded callback) on touch or button selection https://stackoverflow....
Definition: Element.hpp:55
bool process(InputEvents *event)
process any input that is received for this element
void render(Element *parent)
display the current state of the display