1#if defined(__EMSCRIPTEN__)
5#define PLATFORM "Switch"
7#define PLATFORM "Wii U"
8#include <coreinit/core.h>
9#include <coreinit/foreground.h>
10#include <proc_ui/procui.h>
11#include <sysapp/launch.h>
15#define PLATFORM "Console"
19#include "../libs/resinfs/include/romfs-wiiu.h"
22#include "RootDisplay.hpp"
23#include "DownloadQueue.hpp"
26CST_Renderer* RootDisplay::renderer = NULL;
27CST_Window* RootDisplay::window = NULL;
28Element* RootDisplay::subscreen = NULL;
29Element* RootDisplay::nextsubscreen = NULL;
31bool RootDisplay::isDebug =
false;
33int RootDisplay::screenWidth = 1280;
34int RootDisplay::screenHeight = 720;
35float RootDisplay::dpiScale = 1.0f;
37bool RootDisplay::idleCursorPulsing =
false;
39RootDisplay::RootDisplay()
50 this->
width = SCREEN_WIDTH;
51 this->height = SCREEN_HEIGHT;
53 this->hasBackground =
true;
60 RootDisplay::dpiScale = CST_GetDpiScale();
63#if defined(__WIIU__) || defined(WIIU_MOCK)
64 this->backgroundColor = fromRGB(0x20 - 0x10, 154 - 0x10, 199 - 0x10);
65#elif defined(WII) || defined(WII_MOCK)
67 this->backgroundColor = fromRGB(0x8b, 0x8b, 0x8b);
68#elif defined(_3DS) || defined(_3DS_MOCK)
69 this->backgroundColor = fromRGB(30, 30, 30);
70#elif defined(SWITCH) || defined(SWITCH_MOCK)
71 this->backgroundColor = fromRGB(0xd6, 0x0 + 0x20, 0x12 + 0x20);
73 this->backgroundColor = fromRGB(0x2d, 0x26, 0x49);
77#if defined(WII) || defined(WII_MOCK)
78 setScreenResolution(640, 480);
79#elif defined(_3DS) || defined(_3DS_MOCK)
80 setScreenResolution(400, 480);
83 setScreenResolution(1280, 720);
90 TextElement::loadI18nCache(
"en-us");
96void RootDisplay::initMusic()
101 AppletType at = appletGetAppletType();
102 if (at != AppletType_Application && at != AppletType_SystemApplication) {
111void RootDisplay::startMusic()
113 CST_FadeInMusic(
this);
116void RootDisplay::setScreenResolution(
int width,
int height)
119 SCREEN_WIDTH =
width;
120 SCREEN_HEIGHT = height;
123 this->width = SCREEN_WIDTH;
124 this->height = SCREEN_HEIGHT;
127 CST_SetWindowSize(window, SCREEN_WIDTH / RootDisplay::dpiScale, SCREEN_HEIGHT / RootDisplay::dpiScale);
130RootDisplay::~RootDisplay()
134#if defined(USE_RAMFS)
141 if (nextsubscreen != subscreen)
144 subscreen = nextsubscreen;
151 if (RootDisplay::subscreen)
152 return RootDisplay::subscreen->
process(event) ||
event->isTouchDrag();
160 if (RootDisplay::subscreen)
162 RootDisplay::subscreen->
render(
this);
174void RootDisplay::update()
186 CST_RenderPresent(this->renderer);
190void RootDisplay::switchSubscreen(
Element* next)
192 if (nextsubscreen != subscreen)
193 delete nextsubscreen;
194 nextsubscreen = next;
199void RootDisplay::processWiiUHomeOverlay() {
200 auto status = ProcUIProcessMessages(
true);
201 if (status == PROCUI_STATUS_EXITING)
203 else if (status == PROCUI_STATUS_RELEASE_FOREGROUND)
204 ProcUIDrawDoneRelease();
208int RootDisplay::mainLoop()
210 DownloadQueue::init();
215 auto updateDisplay = +[](
void* display) ->
unsigned int {
219 ProcUIRegisterCallback(PROCUI_CALLBACK_ACQUIRE, updateDisplay,
this, 100);
224 bool atLeastOneNewEvent =
false;
225 bool viewChanged =
false;
228 processWiiUHomeOverlay();
231 int frameStart = CST_GetTicks();
234 DownloadQueue::downloadQueue->
process();
237 while (events->update())
240 viewChanged |= this->
process(events);
241 atLeastOneNewEvent =
true;
244 if (events->pressed(SELECT_BUTTON) && this->canUseSelectToExit) {
245 if (events->quitaction != NULL) events->quitaction();
246 else isRunning =
false;
252 if ((!atLeastOneNewEvent && !viewChanged))
255 viewChanged |= this->
process(events);
266 int delayTime = (CST_GetTicks() - frameStart);
270 CST_Delay(16 - delayTime);
279 if (!isProtected)
delete this;
280 DownloadQueue::quit();
285void RootDisplay::recycle()
int process()
process finished and queued downloads
virtual bool process(InputEvents *event)
process any input that is received for this element
virtual void render(Element *parent)
display the current state of the display
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Element * parent
the parent element (can sometimes be null if it isn't set)
bool process(InputEvents *event)
process any input that is received for this element
void render(Element *parent)
display the current state of the display