From efe61bab6ff7b2ffea81e77266c46c6a8dd745d4 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 16 Jul 2021 20:51:10 -0500 Subject: [PATCH] [nostalgia/core] Add clipboard support --- src/nostalgia/core/clipboard.hpp | 19 +++++++++++++++++ src/nostalgia/core/core.hpp | 1 + src/nostalgia/core/glfw/CMakeLists.txt | 1 + src/nostalgia/core/glfw/clipboard.cpp | 29 ++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 src/nostalgia/core/clipboard.hpp create mode 100644 src/nostalgia/core/glfw/clipboard.cpp diff --git a/src/nostalgia/core/clipboard.hpp b/src/nostalgia/core/clipboard.hpp new file mode 100644 index 00000000..579c4958 --- /dev/null +++ b/src/nostalgia/core/clipboard.hpp @@ -0,0 +1,19 @@ +/* + * Copyright 2016 - 2021 gary@drinkingtea.net + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include + +namespace nostalgia::core { + +ox::String getClipboardText(class Context *ctx) noexcept; + +void setClipboardText(class Context *ctx, const ox::String &text) noexcept; + +} diff --git a/src/nostalgia/core/core.hpp b/src/nostalgia/core/core.hpp index b790d0a4..fe624f60 100644 --- a/src/nostalgia/core/core.hpp +++ b/src/nostalgia/core/core.hpp @@ -10,6 +10,7 @@ #include +#include "clipboard.hpp" #include "consts.hpp" #include "gfx.hpp" #include "input.hpp" diff --git a/src/nostalgia/core/glfw/CMakeLists.txt b/src/nostalgia/core/glfw/CMakeLists.txt index 036dc166..cb88996f 100644 --- a/src/nostalgia/core/glfw/CMakeLists.txt +++ b/src/nostalgia/core/glfw/CMakeLists.txt @@ -1,5 +1,6 @@ add_library( NostalgiaCore-GLFW + clipboard.cpp core.cpp gfx.cpp ) diff --git a/src/nostalgia/core/glfw/clipboard.cpp b/src/nostalgia/core/glfw/clipboard.cpp new file mode 100644 index 00000000..2374a0ed --- /dev/null +++ b/src/nostalgia/core/glfw/clipboard.cpp @@ -0,0 +1,29 @@ +/* + * Copyright 2016 - 2021 gary@drinkingtea.net + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +#include + +#include "core.hpp" + +namespace nostalgia::core { + +ox::String getClipboardText(Context *ctx) noexcept { + const auto id = ctx->windowerData(); + return glfwGetClipboardString(id->window); +} + +void setClipboardText(Context *ctx, const ox::String &text) noexcept { + const auto id = ctx->windowerData(); + glfwSetClipboardString(id->window, text.c_str()); +} + +}