From a6983ce53b060a7f63bac843f3c617c211311256 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 10 Mar 2022 20:41:22 -0600 Subject: [PATCH] [nostalgia/core] Add object clipboard in addition to text clipboard --- src/nostalgia/core/CMakeLists.txt | 1 + src/nostalgia/core/clipboard.hpp | 31 +++++++++++++++++++++++++++++++ src/nostalgia/core/context.hpp | 2 ++ 3 files changed, 34 insertions(+) diff --git a/src/nostalgia/core/CMakeLists.txt b/src/nostalgia/core/CMakeLists.txt index a6a89b12..7ac386ff 100644 --- a/src/nostalgia/core/CMakeLists.txt +++ b/src/nostalgia/core/CMakeLists.txt @@ -92,6 +92,7 @@ endif() install( FILES assetmanager.hpp + clipboard.hpp color.hpp config.hpp consts.hpp diff --git a/src/nostalgia/core/clipboard.hpp b/src/nostalgia/core/clipboard.hpp index 786bcfbb..36a4fd5e 100644 --- a/src/nostalgia/core/clipboard.hpp +++ b/src/nostalgia/core/clipboard.hpp @@ -4,12 +4,43 @@ #pragma once +#include #include +#include "context.hpp" + namespace nostalgia::core { ox::String getClipboardText(class Context *ctx) noexcept; void setClipboardText(class Context *ctx, const ox::String &text) noexcept; +void setClipboardObject([[maybe_unused]] class Context *ctx, [[maybe_unused]] auto *obj) noexcept { +#ifndef OX_BARE_METAL + auto [buff, err] = ox::writeClaw(obj); + if (err) { + oxLogError(err); + return; + } + ctx->clipboard = std::move(buff); +#endif +} + +ox::Error getClipboardObject([[maybe_unused]] class Context *ctx, [[maybe_unused]] auto *obj) noexcept { +#ifndef OX_BARE_METAL + return ox::readClaw(ctx->clipboard).moveTo(obj); +#else + return OxError(0); +#endif +} + +template +ox::Result getClipboardObject([[maybe_unused]] class Context *ctx) noexcept { +#ifndef OX_BARE_METAL + return ox::readClaw(ctx->clipboard); +#else + return OxError(0); +#endif +} + } diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 3ae10330..7931ce3b 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include "assetmanager.hpp" #include "event.hpp" @@ -58,6 +59,7 @@ class Context { #ifndef OX_BARE_METAL AssetManager assetManager; int uninterruptedRefreshes = 0; + ox::Buffer clipboard; #endif protected: #ifndef OX_BARE_METAL