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    this->backgroundColor = fromRGB(30, 30, 30);
 
   66#if defined(WII) || defined(WII_MOCK) 
   67    setScreenResolution(640, 480);
 
   68#elif defined(_3DS) || defined(_3DS_MOCK) 
   69    setScreenResolution(400, 480); 
 
   72    setScreenResolution(1280, 720);
 
   79    TextElement::loadI18nCache(
"en-us");
 
   85void RootDisplay::initMusic()
 
   90    AppletType at = appletGetAppletType();
 
   91    if (at != AppletType_Application && at != AppletType_SystemApplication) {
 
  100void RootDisplay::startMusic()
 
  102    CST_FadeInMusic(
this);
 
  105void RootDisplay::setScreenResolution(
int width, 
int height)
 
  108    SCREEN_WIDTH = 
width;
 
  109    SCREEN_HEIGHT = height;
 
  112    this->width = SCREEN_WIDTH;
 
  113    this->height = SCREEN_HEIGHT;
 
  116    CST_SetWindowSize(window, SCREEN_WIDTH / RootDisplay::dpiScale, SCREEN_HEIGHT / RootDisplay::dpiScale);
 
  119RootDisplay::~RootDisplay()
 
  123#if defined(USE_RAMFS) 
  130    if (nextsubscreen != subscreen)
 
  133        subscreen = nextsubscreen;
 
  140    if (RootDisplay::subscreen)
 
  141        return RootDisplay::subscreen->
process(event) || 
event->isTouchDrag();
 
  149    if (RootDisplay::subscreen)
 
  151        RootDisplay::subscreen->
render(
this);
 
  163void RootDisplay::update()
 
  175    CST_RenderPresent(this->renderer);
 
  179void RootDisplay::switchSubscreen(
Element* next)
 
  181    if (nextsubscreen != subscreen)
 
  182        delete nextsubscreen;
 
  183    nextsubscreen = next;
 
  186void RootDisplay::requestQuit()
 
  189    if (hasRequestedQuit) {
 
  192    hasRequestedQuit = 
true;
 
  198    this->isAppRunning = 
false;
 
  202int RootDisplay::mainLoop()
 
  204    DownloadQueue::init();
 
  209    auto updateDisplay = +[](
void* display) -> 
unsigned int {
 
  213    ProcUIRegisterCallback(PROCUI_CALLBACK_ACQUIRE, updateDisplay, 
this, 100);
 
  217    auto actuallyQuit = +[](
void* display) -> 
unsigned int {
 
  221    ProcUIRegisterCallback(PROCUI_CALLBACK_EXIT, actuallyQuit, 
this, 100);
 
  226        bool atLeastOneNewEvent = 
false;
 
  227        bool viewChanged = 
false;
 
  229        int frameStart = CST_GetTicks();
 
  232        DownloadQueue::downloadQueue->
process();
 
  235        while (events->update())
 
  238            viewChanged |= this->
process(events);
 
  239            atLeastOneNewEvent = 
true;
 
  242            if (this->canUseSelectToExit && events->pressed(SELECT_BUTTON)) {
 
  249        if ((!atLeastOneNewEvent && !viewChanged))
 
  252            viewChanged |= this->
process(events);
 
  263            int delayTime = (CST_GetTicks() - frameStart);
 
  267                CST_Delay(16 - delayTime);
 
  276    if (!isProtected) 
delete this;
 
  277    DownloadQueue::quit();
 
  282void 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