Sfoglia il codice sorgente

On Windows use SDL event watch to repaint the window while resizing

JSandusky 7 anni fa
parent
commit
b3d2573eb5
1 ha cambiato i file con 41 aggiunte e 0 eliminazioni
  1. 41 0
      Source/Urho3D/Input/Input.cpp

+ 41 - 0
Source/Urho3D/Input/Input.cpp

@@ -38,6 +38,12 @@
 #include "../UI/Text.h"
 #include "../UI/UI.h"
 
+#ifdef _WIN32
+#include "../Engine/Engine.h"
+#include "../Graphics/Renderer.h"
+#endif
+
+
 #include <SDL/SDL.h>
 
 #ifdef __EMSCRIPTEN__
@@ -295,6 +301,32 @@ int EmscriptenInput::HandleSDLEvents(void* userData, SDL_Event* event)
 
 #endif
 
+#ifdef _WIN32
+// On Windows repaint while the window is actively being resized.
+int Win32_ResizingEventWatcher(void* data, SDL_Event* event)
+{
+    if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_RESIZED) 
+    {
+        SDL_Window* win = SDL_GetWindowFromID(event->window.windowID);
+        if (win == (SDL_Window*)data)
+        {
+            if (Context* ctx = (Context*)SDL_GetWindowData(win, "URHO3D_CONTEXT"))
+            {
+                if (auto graphics = ctx->GetSubsystem<Graphics>())
+                {
+                    if (graphics->IsInitialized())
+                    {
+                        graphics->OnWindowResized();
+                        ctx->GetSubsystem<Engine>()->RunFrame();
+                    }
+                }
+            }
+        }
+    }
+    return 0;
+}
+#endif
+
 void JoystickState::Initialize(unsigned numButtons, unsigned numAxes, unsigned numHats)
 {
     buttons_.Resize(numButtons);
@@ -1510,6 +1542,15 @@ void Input::Initialize()
     SubscribeToEvent(E_ENDFRAME, URHO3D_HANDLER(Input, HandleEndFrame));
 #endif
 
+#ifdef _WIN32
+    // Register callback for resizing in order to repaint.
+    if (SDL_Window* window = graphics_->GetWindow())
+    {
+        SDL_SetWindowData(window, "URHO3D_CONTEXT", GetContext());
+        SDL_AddEventWatch(Win32_ResizingEventWatcher, window);
+    }
+#endif
+
     URHO3D_LOGINFO("Initialized input");
 }