[nostalgia/core] Add key event handler

This commit is contained in:
2022-03-20 01:42:08 -05:00
parent 2223fe7863
commit ea318bb6c8
5 changed files with 120 additions and 24 deletions
+13 -1
View File
@@ -68,6 +68,8 @@ class Context {
friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
friend void setClipboardText(Context *ctx, const ox::String &text) noexcept;
friend void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept;
friend constexpr void setKeyEventHandler(Context *ctx, KeyEventHandler h) noexcept;
friend constexpr KeyEventHandler keyEventHandler(Context *ctx) noexcept;
friend void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcept;
friend void setWindowTitle(Context *ctx, const char *title) noexcept;
@@ -75,6 +77,7 @@ class Context {
ox::UniquePtr<ox::FileSystem> rom;
ox::Vector<Drawer*, 5> drawers;
const char *appName = "Nostalgia";
#ifndef OX_BARE_METAL
AssetManager assetManager;
int uninterruptedRefreshes = 3;
@@ -85,6 +88,7 @@ class Context {
// sets screen refresh to constant instead of only on event
bool constantRefresh = true;
#endif
KeyEventHandler m_keyEventHandler = nullptr;
void *m_customData = nullptr;
private:
@@ -98,13 +102,13 @@ class Context {
Context(const Context &other) noexcept = delete;
Context(const Context &&other) noexcept = delete;
protected:
template<typename T>
[[nodiscard]]
constexpr T *windowerData() noexcept {
return static_cast<T*>(m_windowerData);
}
protected:
constexpr void setWindowerData(void *windowerData) noexcept {
m_windowerData = windowerData;
}
@@ -131,6 +135,14 @@ constexpr T *applicationData(Context *ctx) noexcept {
return static_cast<T*>(ctx->m_customData);
}
constexpr void setKeyEventHandler(Context *ctx, KeyEventHandler h) noexcept {
ctx->m_keyEventHandler = h;
}
constexpr KeyEventHandler keyEventHandler(Context *ctx) noexcept {
return ctx->m_keyEventHandler;
}
constexpr void setConstantRefresh([[maybe_unused]] Context *ctx, [[maybe_unused]] bool r) noexcept {
#ifndef OX_BARE_METAL
ctx->constantRefresh = r;