[ion/events] Create event ExternalText

Added an event to represent the typing of text that is not on the
device's keyboard. ExternalText event's text is read from a buffer, that
will be filled when the event is generated.

ExternalText only exists on the simulator.

Change-Id: Ie78d2c7c2de91da986a1ce2130a5ecd123db48ee
This commit is contained in:
Gabriel Ozouf
2020-10-01 15:49:23 +02:00
committed by Émilie Feral
parent 65156c8e5a
commit 96b8e1859a
5 changed files with 54 additions and 16 deletions

View File

@@ -229,6 +229,9 @@ constexpr Event TimerFire = Event::Special(2);
constexpr Event USBEnumeration = Event::Special(3);
constexpr Event USBPlug = Event::Special(4);
constexpr Event BatteryCharging = Event::Special(5);
/* This event is only used in the simulator, to handle text that cannot be
* associated with a key. */
// constexpr Event ExternalText = Event::Special(6);
}
}

View File

@@ -1,4 +1,5 @@
#include <ion/events.h>
#include <layout_events.h>
namespace Ion {
namespace Events {
@@ -6,5 +7,20 @@ namespace Events {
void didPressNewKey() {
}
bool Event::isDefined() const {
if (isKeyboardEvent()) {
return s_dataForEvent[m_id].isDefined();
} else {
return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging);
}
}
const char * Event::text() const {
if (m_id >= 4*PageSize) {
return nullptr;
}
return s_dataForEvent[m_id].text();
}
}
}

View File

@@ -48,24 +48,9 @@ Event::Event(Keyboard::Key key, bool shift, bool alpha, bool lock) {
assert(m_id != Events::None.m_id);
}
const char * Event::text() const {
if (m_id >= 4*PageSize) {
return nullptr;
}
return s_dataForEvent[m_id].text();
}
bool Event::hasText() const {
return text() != nullptr;
}
bool Event::isDefined() const {
if (isKeyboardEvent()) {
return s_dataForEvent[m_id].isDefined();
} else {
return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging);
}
}
}
}

View File

@@ -1,5 +1,7 @@
#include <ion/events.h>
#include "events.h"
#include "haptics.h"
#include <ion/events.h>
#include <layout_events.h>
#include <SDL.h>
namespace Ion {
@@ -9,5 +11,28 @@ void didPressNewKey() {
Simulator::Haptics::rumble();
}
char * sharedExternalTextBuffer() {
static char buffer[32];
return buffer;
}
const char * Event::text() const {
if (m_id >= 4*PageSize) {
if (*this == ExternalText) {
return const_cast<const char *>(sharedExternalTextBuffer());
}
return nullptr;
}
return s_dataForEvent[m_id].text();
}
bool Event::isDefined() const {
if (isKeyboardEvent()) {
return s_dataForEvent[m_id].isDefined();
} else {
return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging || *this == ExternalText);
}
}
}
}

View File

@@ -1,6 +1,8 @@
#ifndef ION_SIMULATOR_EVENTS_H
#define ION_SIMULATOR_EVENTS_H
#include <ion/events.h>
namespace Ion {
namespace Simulator {
namespace Events {
@@ -9,6 +11,13 @@ void dumpEventCount(int i);
void logAfter(int numberOfEvents);
}
}
namespace Events {
char * sharedExternalTextBuffer();
constexpr Event ExternalText = Event::Special(6);
}
}