From 29f6df6bbdbc3a20a963d27d73e50953c48e0e99 Mon Sep 17 00:00:00 2001 From: Bruno Van de Velde Date: Thu, 29 Jun 2017 18:40:43 +0200 Subject: [PATCH] Make use of the system clipboard on all OSes when using SFML >= 2.5 With older SFML versions, the system clipboard will only be accessed on Windows --- include/TGUI/Clipboard.hpp | 6 +++--- include/TGUI/Gui.hpp | 2 ++ src/TGUI/Clipboard.cpp | 22 ++++++++++++++++++---- src/TGUI/Gui.cpp | 24 +++++++++++++++++++++--- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/include/TGUI/Clipboard.hpp b/include/TGUI/Clipboard.hpp index 4cf50f4a..0d2db26b 100644 --- a/include/TGUI/Clipboard.hpp +++ b/include/TGUI/Clipboard.hpp @@ -57,7 +57,7 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static void set(const sf::String& contents); - +#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @brief Sets the window handle which is needed to access the system clipboard on windows /// @@ -68,12 +68,12 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - protected: + protected: static sf::String m_contents; static sf::WindowHandle m_windowHandle; static bool m_isWindowHandleSet; - +#endif ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }; diff --git a/include/TGUI/Gui.hpp b/include/TGUI/Gui.hpp index 48c3daa1..18edc448 100644 --- a/include/TGUI/Gui.hpp +++ b/include/TGUI/Gui.hpp @@ -408,8 +408,10 @@ namespace tgui // The sfml window or other target to draw on sf::RenderTarget* m_window; + #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 // Does m_Window contains a sf::RenderWindow? bool m_accessToWindow; + #endif // Internal container to store all widgets GuiContainer::Ptr m_container = std::make_shared(); diff --git a/src/TGUI/Clipboard.cpp b/src/TGUI/Clipboard.cpp index f375fa07..39f239af 100644 --- a/src/TGUI/Clipboard.cpp +++ b/src/TGUI/Clipboard.cpp @@ -26,8 +26,12 @@ #include -#ifdef SFML_SYSTEM_WINDOWS - #include +#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5) + #include +#else + #ifdef SFML_SYSTEM_WINDOWS + #include + #endif #endif ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -36,14 +40,19 @@ namespace tgui { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 sf::String Clipboard::m_contents; sf::WindowHandle Clipboard::m_windowHandle = sf::WindowHandle(); bool Clipboard::m_isWindowHandleSet = false; +#endif ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// sf::String Clipboard::get() { +#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5) + return sf::Clipboard::getString(); +#else #ifdef SFML_SYSTEM_WINDOWS if (m_isWindowHandleSet) { @@ -67,12 +76,16 @@ namespace tgui #endif return m_contents; +#endif } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Clipboard::set(const sf::String& contents) { +#if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5) + sf::Clipboard::setString(contents); +#else m_contents = contents; #ifdef SFML_SYSTEM_WINDOWS @@ -101,16 +114,17 @@ namespace tgui } } #endif +#endif } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +#if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 void Clipboard::setWindowHandle(const sf::WindowHandle& windowHandle) { m_windowHandle = windowHandle; m_isWindowHandleSet = true; } - +#endif ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } diff --git a/src/TGUI/Gui.cpp b/src/TGUI/Gui.cpp index 447337e9..2bb5fd0c 100644 --- a/src/TGUI/Gui.cpp +++ b/src/TGUI/Gui.cpp @@ -39,8 +39,12 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Gui::Gui() : + #if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5) + m_window(nullptr) + #else m_window (nullptr), m_accessToWindow(false) + #endif { m_container->m_focused = true; @@ -52,13 +56,19 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Gui::Gui(sf::RenderWindow& window) : + #if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5) + m_window(&window) + #else m_window (&window), m_accessToWindow(true) + #endif { m_container->m_window = &window; m_container->m_focused = true; + #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 Clipboard::setWindowHandle(window.getSystemHandle()); + #endif setView(window.getDefaultView()); @@ -70,8 +80,12 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Gui::Gui(sf::RenderTarget& window) : + #if SFML_VERSION_MAJOR > 2 || (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR >= 5) + m_window(&window) + #else m_window (&window), m_accessToWindow(false) + #endif { m_container->m_window = &window; m_container->m_focused = true; @@ -87,12 +101,13 @@ namespace tgui void Gui::setWindow(sf::RenderWindow& window) { - m_accessToWindow = true; - m_window = &window; m_container->m_window = &window; + #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 + m_accessToWindow = true; Clipboard::setWindowHandle(window.getSystemHandle()); + #endif setView(window.getDefaultView()); } @@ -101,7 +116,9 @@ namespace tgui void Gui::setWindow(sf::RenderTarget& window) { + #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 m_accessToWindow = false; + #endif m_window = &window; m_container->m_window = &window; @@ -222,9 +239,10 @@ namespace tgui else if (event.type == sf::Event::GainedFocus) { m_container->m_focused = true; - + #if SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 5 if (m_accessToWindow) Clipboard::setWindowHandle(static_cast(m_window)->getSystemHandle()); + #endif } // Let the event manager handle the event