aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------depends/mgl0
-rw-r--r--include/mglpp/window/Window.hpp10
-rw-r--r--src/window/Window.cpp13
-rw-r--r--tests/main.cpp2
4 files changed, 21 insertions, 4 deletions
diff --git a/depends/mgl b/depends/mgl
-Subproject e6167bc9300d497b1f2edf3a307164081e24f2b
+Subproject d6a5f9c394aea65684aa9d340ef26849bf49a2c
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 <stddef.h>
#include <string>
+#include <functional>
extern "C" {
#include <mgl/window/window.h>
@@ -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<bool(const unsigned char *data, size_t size, mgl_clipboard_type clipboard_type)>;
+
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));