From d6a6974c3eef8d96a9ba6591229f594fc873e4ab Mon Sep 17 00:00:00 2001 From: vittorioromeo Date: Sat, 15 Jun 2024 19:44:04 +0200 Subject: [PATCH] Update to latest changes --- imgui-SFML.cpp | 18 +++++++++++------- imgui-SFML.h | 4 +++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/imgui-SFML.cpp b/imgui-SFML.cpp index 6633719..82dcf85 100644 --- a/imgui-SFML.cpp +++ b/imgui-SFML.cpp @@ -172,8 +172,8 @@ struct WindowContext { const sf::Window* window; ImGuiContext* imContext{ImGui::CreateContext()}; - sf::Texture fontTexture; // internal font atlas which is used if user doesn't set a custom - // sf::Texture. + std::optional fontTexture; // internal font atlas which is used if user doesn't set + // a custom sf::Texture. bool windowHasFocus; bool mouseMoved{false}; @@ -499,20 +499,24 @@ bool UpdateFontTexture() { io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); - sf::Texture& texture = s_currWindowCtx->fontTexture; - if (!texture.create({static_cast(width), static_cast(height)})) { + auto newTexture = + sf::Texture::create({static_cast(width), static_cast(height)}); + + if (!newTexture.has_value()) { return false; } - texture.update(pixels); + newTexture->update(pixels); - ImTextureID texID = convertGLTextureHandleToImTextureID(texture.getNativeHandle()); + ImTextureID texID = convertGLTextureHandleToImTextureID(newTexture->getNativeHandle()); io.Fonts->SetTexID(texID); + s_currWindowCtx->fontTexture = std::move(newTexture); + return true; } -sf::Texture& GetFontTexture() { +std::optional& GetFontTexture() { assert(s_currWindowCtx); return s_currWindowCtx->fontTexture; } diff --git a/imgui-SFML.h b/imgui-SFML.h index 4738562..93d1d87 100644 --- a/imgui-SFML.h +++ b/imgui-SFML.h @@ -7,6 +7,8 @@ #include #include +#include + #include "imgui-SFML_export.h" namespace sf { @@ -44,7 +46,7 @@ IMGUI_SFML_API void Shutdown(const sf::Window& window); IMGUI_SFML_API void Shutdown(); [[nodiscard]] IMGUI_SFML_API bool UpdateFontTexture(); -IMGUI_SFML_API sf::Texture& GetFontTexture(); +IMGUI_SFML_API std::optional& GetFontTexture(); // joystick functions IMGUI_SFML_API void SetActiveJoystickId(unsigned int joystickId);