From 01b9943e9cd886bcfd22ba58783137e554ef2a3c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 9 Sep 2022 23:28:29 +0200 Subject: Support png,jpg and gif clipboard. Use callback for clipboard --- depends/mgl | 2 +- include/mglpp/window/Window.hpp | 10 +++++++++- src/window/Window.cpp | 13 +++++++++++-- tests/main.cpp | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/depends/mgl b/depends/mgl index e6167bc..d6a5f9c 160000 --- a/depends/mgl +++ b/depends/mgl @@ -1 +1 @@ -Subproject commit e6167bc9300d497b1f2edf3a307164081e24f2bd +Subproject commit d6a5f9c394aea65684aa9d340ef26849bf49a2cc diff --git a/include/mglpp/window/Window.hpp b/include/mglpp/window/Window.hpp index bdf9c05..f284aa0 100644 --- a/include/mglpp/window/Window.hpp +++ b/include/mglpp/window/Window.hpp @@ -8,6 +8,7 @@ #include "Mouse.hpp" #include #include +#include extern "C" { #include @@ -26,6 +27,12 @@ namespace mgl { vec2i size; }; + /* + Return true to continue. |get_clipboard| returns false if this returns false. + Note: |size| is the size of the current data, not the total data (if the callback only contains a part of the data). + */ + using ClipboardCallback = std::function; + class Window { public: /* Has to match mgl_window_create_params */ @@ -84,7 +91,8 @@ namespace mgl { bool is_mouse_button_pressed(Mouse::Button button) const; void set_clipboard(const std::string &str); - std::string get_clipboard(); + bool get_clipboard(ClipboardCallback callback); + std::string get_clipboard_string(); WindowHandle get_system_handle() const; private: diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 5174504..ec187e3 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -10,6 +10,11 @@ extern "C" { } namespace mgl { + static bool clipboard_callback_interface(const unsigned char *data, size_t size, mgl_clipboard_type clipboard_type, void *userdata) { + ClipboardCallback *clipboard_callback = (ClipboardCallback*)userdata; + return (*clipboard_callback)(data, size, clipboard_type); + } + Window::Window() { window.window = 0; } @@ -138,11 +143,15 @@ namespace mgl { mgl_window_set_clipboard(&window, str.c_str(), str.size()); } - std::string Window::get_clipboard() { + bool Window::get_clipboard(ClipboardCallback callback) { + return mgl_window_get_clipboard(&window, clipboard_callback_interface, &callback); + } + + std::string Window::get_clipboard_string() { std::string result; char *str = nullptr; size_t size = 0; - if(mgl_window_get_clipboard(&window, &str, &size)) { + if(mgl_window_get_clipboard_string(&window, &str, &size)) { result.assign(str, size); free(str); } diff --git a/tests/main.cpp b/tests/main.cpp index f3ad539..eb134ac 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -107,7 +107,7 @@ int main(int argc, char **argv) { mgl::Event event; while(window.is_open()) { if(window.poll_event(event)) { - + } window.clear(mgl::Color(0, 0, 0, 255)); -- cgit v1.2.3