| 997 | } |
| 998 | |
| 999 | void InputManager::call_paste(CustomEvents::PasteEvent::DataType type, const InputManagerCallPasteInfo& info) { |
| 1000 | // Workaround for not being able to copy richtext to system clipboard, this should at least work within the application itself |
| 1001 | #ifdef __EMSCRIPTEN__ |
| 1002 | switch(type) { |
| 1003 | case CustomEvents::PasteEvent::DataType::TEXT: { |
| 1004 | struct PasteData { |
| 1005 | bool allowRichText; |
| 1006 | InputManager* t; |
| 1007 | }; |
| 1008 | static PasteData pasteData; |
| 1009 | pasteData.allowRichText = info.allowRichText; |
| 1010 | pasteData.t = this; |
| 1011 | emscripten_browser_clipboard::paste_async([](std::string&& pasteData, void* callbackData){ |
| 1012 | PasteData* p = (PasteData*)callbackData; |
| 1013 | p->t->process_text_paste(pasteData, p->allowRichText); |
| 1014 | }, &pasteData); |
| 1015 | break; |
| 1016 | } |
| 1017 | case CustomEvents::PasteEvent::DataType::IMAGE: { |
| 1018 | struct PasteData { |
| 1019 | std::optional<Vector2f> pos; |
| 1020 | InputManager* t; |
| 1021 | }; |
| 1022 | static PasteData pasteData; |
| 1023 | pasteData.pos = info.pastePosition; |
| 1024 | pasteData.t = this; |
| 1025 | emscripten_browser_clipboard::paste_async_image([](std::string_view pasteData, void* callbackData){ |
| 1026 | PasteData* p = (PasteData*)callbackData; |
| 1027 | p->t->process_image_paste(pasteData, p->pos); |
| 1028 | }, &pasteData); |
| 1029 | break; |
| 1030 | } |
| 1031 | } |
| 1032 | #else |
| 1033 | switch(type) { |
| 1034 | case CustomEvents::PasteEvent::DataType::TEXT: |
| 1035 | process_text_paste(get_clipboard_str_SDL(), info.allowRichText); |
| 1036 | break; |
| 1037 | case CustomEvents::PasteEvent::DataType::IMAGE: |
| 1038 | get_clipboard_image_data_SDL([&](std::string_view pasteData) { |
| 1039 | process_image_paste(pasteData, info.pastePosition); |
| 1040 | }); |
| 1041 | break; |
| 1042 | } |
| 1043 | #endif |
| 1044 | } |
| 1045 | |
| 1046 | void InputManager::process_text_paste(const std::string& pasteStr, bool allowRichText) { |
| 1047 | CustomEvents::emit_event<CustomEvents::PasteEvent>({ |
no test coverage detected