mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Which allows Ion::Events::getEvent to be non-blocking Change-Id: I2715b10ace2ecbac153b0f7d00ea5f2ca5de399c
49 lines
939 B
C++
49 lines
939 B
C++
#include <escher/container.h>
|
|
#include <ion/display.h>
|
|
#ifdef __EMSCRIPTEN__
|
|
#include <emscripten.h>
|
|
#endif
|
|
|
|
Container::Container() :
|
|
m_activeApp(nullptr)
|
|
{
|
|
}
|
|
|
|
void Container::switchTo(App * app) {
|
|
m_activeApp = app;
|
|
m_activeApp->setWindow(&m_window);
|
|
}
|
|
|
|
App * Container::activeApp() {
|
|
return m_activeApp;
|
|
}
|
|
|
|
bool Container::handleEvent(Ion::Events::Event event) {
|
|
return false;
|
|
}
|
|
|
|
void Container::run() {
|
|
m_window.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height));
|
|
m_window.redraw();
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
emscripten_set_main_loop_arg([](void * ctx){ ((Container *)ctx)->step(); }, this, 0, 1);
|
|
#else
|
|
while (true) {
|
|
step();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void Container::step() {
|
|
Ion::Events::Event event = Ion::Events::getEvent(); // This is a blocking call
|
|
if (event == Ion::Events::None) {
|
|
return;
|
|
}
|
|
if (handleEvent(event)) {
|
|
return;
|
|
}
|
|
m_activeApp->processEvent(event);
|
|
m_window.redraw();
|
|
}
|