/* * Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved. */ #pragma once #include #include #include #include #include #include "event.hpp" #include "input.hpp" namespace turbine { class BaseClipboardObject { public: virtual ~BaseClipboardObject() noexcept = default; [[nodiscard]] virtual ox::String typeId() const noexcept = 0; [[nodiscard]] constexpr auto typeMatch(auto name, auto version) const noexcept { return typeId() == ox::buildTypeId(name, version); } }; template class ClipboardObject: public BaseClipboardObject { [[nodiscard]] ox::String typeId() const noexcept final { return ox::buildTypeId(T::TypeName, T::TypeVersion); } }; void shutdown(Context &ctx) noexcept; // User Input Output class Context { friend constexpr void setApplicationData(Context &ctx, void *applicationData) noexcept; template friend constexpr T *applicationData(Context &ctx) 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; public: UpdateHandler updateHandler = [](Context&) -> int {return 0;}; ox::UPtr clipboard; keel::Context keelCtx; protected: KeyEventHandler m_keyEventHandler = nullptr; void *m_applicationData = nullptr; Context() noexcept = default; Context(Context &other) noexcept = delete; Context(const Context &other) noexcept = delete; Context(const Context &&other) noexcept = delete; public: virtual inline ~Context() noexcept { shutdown(*this); } }; constexpr auto *rom(Context &ctx) noexcept { return ctx.keelCtx.rom.get(); } constexpr const auto *rom(const Context &ctx) noexcept { return ctx.keelCtx.rom.get(); } constexpr void setApplicationData(Context &ctx, void *applicationData) noexcept { ctx.m_applicationData = applicationData; } template [[nodiscard]] constexpr T *applicationData(Context &ctx) noexcept { return static_cast(ctx.m_applicationData); } constexpr void setKeyEventHandler(Context &ctx, KeyEventHandler h) noexcept { ctx.m_keyEventHandler = h; } constexpr KeyEventHandler keyEventHandler(Context &ctx) noexcept { return ctx.m_keyEventHandler; } void setConstantRefresh(Context &ctx, bool r) noexcept; }