Files
Upsilon/escher/src/run_loop.cpp
Gabriel Ozouf 0185e0562c [escher/run_loop] Move kandinksy include
To check whether an ExternalText could be written with Epsilon's fonts,
UTF8Helper made a reference to Kandinsky, which is prohibited. This
check is now done in Escher, before dispatching the event.

Change-Id: I55e9db1ba43c3115775499db47b90a6bdd7cc7b3
2020-11-04 15:58:38 +01:00

78 lines
1.8 KiB
C++

#include <escher/run_loop.h>
#include <kandinsky/font.h>
#include <assert.h>
RunLoop::RunLoop() :
m_time(0) {
}
int RunLoop::numberOfTimers() {
return 0;
}
Timer * RunLoop::timerAtIndex(int i) {
assert(false);
return nullptr;
}
void RunLoop::run() {
runWhile(nullptr, nullptr);
}
void RunLoop::runWhile(bool (*callback)(void * ctx), void * ctx) {
while ((callback == nullptr || callback(ctx)) && step()) {
}
}
bool RunLoop::step() {
// Fetch the event, if any
int eventDuration = Timer::TickDuration;
int timeout = eventDuration;
Ion::Events::Event event = Ion::Events::getEvent(&timeout);
assert(event.isDefined());
eventDuration -= timeout;
assert(eventDuration >= 0);
assert(eventDuration <= Timer::TickDuration);
/* At this point, eventDuration contains the time it took to retrieve the
* event. It can be zero, and is at most equal to the timeout value, Timer::
* TickDuration. The event returned can be None if nothing worth taking care
* of happened. In other words, getEvent is a blocking call with a timeout. */
m_time += eventDuration;
if (m_time >= Timer::TickDuration) {
m_time -= Timer::TickDuration;
for (int i=0; i<numberOfTimers(); i++) {
Timer * timer = timerAtIndex(i);
if (timer->tick()) {
dispatchEvent(Ion::Events::TimerFire);
}
}
}
#if ESCHER_LOG_EVENTS_BINARY
Ion::Console::writeChar(static_cast<uint8_t>(event));
#endif
#if ESCHER_LOG_EVENTS_NAME
const char * name = event.name();
if (name == nullptr) {
name = "UNDEFINED";
}
Ion::Console::writeLine(name);
#endif
if (event != Ion::Events::None) {
#if !PLATFORM_DEVICE
if (event == Ion::Events::ExternalText && !KDFont::CanBeWrittenWithGlyphs(event.text())) {
return true;
}
#endif
dispatchEvent(event);
}
return event != Ion::Events::Termination;
}