move clipboard wrappers into DFSDL module (but not in the namespace)

develop
Myk Taylor 2023-07-05 12:08:18 -07:00
parent 0bbb72b44f
commit 43ea9b94c3
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
4 changed files with 29 additions and 22 deletions

@ -472,11 +472,3 @@ DFHACK_EXPORT std::string DF2CONSOLE(DFHack::color_ostream &out, const std::stri
{
return out.is_console() ? DF2CONSOLE(in) : in;
}
DFHACK_EXPORT std::string getClipboardTextCp437() {
return UTF2DF(DFHack::DFSDL::DFSDL_GetClipboardText());
}
DFHACK_EXPORT bool setClipboardTextCp437(std::string text) {
return DFHack::DFSDL::DFSDL_SetClipboardText(DF2UTF(text).c_str());
}

@ -496,7 +496,3 @@ DFHACK_EXPORT std::string UTF2DF(const std::string &in);
DFHACK_EXPORT std::string DF2UTF(const std::string &in);
DFHACK_EXPORT std::string DF2CONSOLE(const std::string &in);
DFHACK_EXPORT std::string DF2CONSOLE(DFHack::color_ostream &out, const std::string &in);
// System clipboard -- submitted and returned text must be in CP437
DFHACK_EXPORT std::string getClipboardTextCp437();
DFHACK_EXPORT bool setClipboardTextCp437(std::string text);

@ -47,12 +47,17 @@ DFHACK_EXPORT void DFSDL_FreeSurface(SDL_Surface *surface);
// DFHACK_EXPORT int DFSDL_SemWait(SDL_sem *sem);
// DFHACK_EXPORT int DFSDL_SemPost(SDL_sem *sem);
DFHACK_EXPORT int DFSDL_PushEvent(SDL_Event *event);
DFHACK_EXPORT void DFSDL_free(void *ptr);
// submitted and returned text is UTF-8
// see wrapper functions in MiscUtils.h for cp-437 variants
DFHACK_EXPORT std::string DFSDL_GetClipboardText();
DFHACK_EXPORT bool DFSDL_SetClipboardText(const char *text);
// see wrapper functions below for cp-437 variants
DFHACK_EXPORT char * DFSDL_GetClipboardText();
DFHACK_EXPORT int DFSDL_SetClipboardText(const char *text);
}
// System clipboard -- submitted and returned text must be in CP437
DFHACK_EXPORT std::string getClipboardTextCp437();
DFHACK_EXPORT bool setClipboardTextCp437(std::string text);
}

@ -135,15 +135,29 @@ int DFSDL::DFSDL_PushEvent(SDL_Event *event) {
return g_SDL_PushEvent(event);
}
std::string DFSDL::DFSDL_GetClipboardText() {
if (g_SDL_HasClipboardText() != SDL_TRUE)
void DFSDL::DFSDL_free(void *ptr) {
g_SDL_free(ptr);
}
char * DFSDL::DFSDL_GetClipboardText() {
return g_SDL_GetClipboardText();
}
int DFSDL::DFSDL_SetClipboardText(const char *text) {
return g_SDL_SetClipboardText(text);
}
DFHACK_EXPORT std::string DFHack::getClipboardTextCp437() {
if (!g_sdl_handle || g_SDL_HasClipboardText() != SDL_TRUE)
return "";
char *text = g_SDL_GetClipboardText();
std::string ret = text;
g_SDL_free(text);
return ret;
std::string textcp437 = UTF2DF(text);
DFHack::DFSDL::DFSDL_free(text);
return textcp437;
}
bool DFSDL::DFSDL_SetClipboardText(const char *text) {
return g_SDL_SetClipboardText(text) == 0;
DFHACK_EXPORT bool DFHack::setClipboardTextCp437(std::string text) {
if (!g_sdl_handle)
return false;
return 0 == DFHack::DFSDL::DFSDL_SetClipboardText(DF2UTF(text).c_str());
}