Parcourir la source

Merge branch 'main' of github.com:raylib-extras/rlImGui

Jeffery Myers il y a 1 an
Parent
commit
f29be1c5ac
1 fichiers modifiés avec 18 ajouts et 12 suppressions
  1. 18 12
      rlImGui.cpp

+ 18 - 12
rlImGui.cpp

@@ -49,6 +49,8 @@ static Texture2D FontTexture;
 static ImGuiMouseCursor CurrentMouseCursor = ImGuiMouseCursor_COUNT;
 static MouseCursor MouseCursorMap[ImGuiMouseCursor_COUNT];
 
+ImGuiContext* GlobalContext = nullptr;
+
 static std::map<KeyboardKey, ImGuiKey> RaylibKeyMap;
 
 static bool LastFrameFocused = false;
@@ -187,9 +189,6 @@ static void rlImGuiEvents()
         keyId = GetKeyPressed();
     }
 
-    for (auto keyItr : RaylibKeyMap)
-        io.KeysData[keyItr.second].Down = IsKeyDown(keyItr.first);
-
     // look for any keys that were down last frame and see if they were down and are released
     for (const auto keyItr : RaylibKeyMap)
     {
@@ -304,6 +303,8 @@ void SetupMouseCursors()
 
 void rlImGuiEndInitImGui()
 {
+    ImGui::SetCurrentContext(GlobalContext);
+
     SetupMouseCursors();
 
     ImGuiIO& io = ImGui::GetIO();
@@ -436,8 +437,8 @@ void rlSetupKeymap()
 
 void rlImGuiBeginInitImGui()
 {
+    GlobalContext = ImGui::CreateContext(nullptr);
     rlSetupKeymap();
-    ImGui::CreateContext(nullptr);
 }
 
 void rlImGuiSetup(bool dark)
@@ -474,6 +475,8 @@ void rlImGuiSetup(bool dark)
 
 void rlImGuiReloadFonts()
 {
+    ImGui::SetCurrentContext(GlobalContext);
+
     ImGuiIO& io = ImGui::GetIO();
     unsigned char* pixels = nullptr;
 
@@ -498,6 +501,7 @@ void rlImGuiBegin()
 
 void rlImGuiBeginDelta(float deltaTime)
 {
+    ImGui::SetCurrentContext(GlobalContext);
 	rlImGuiNewFrame(deltaTime);
 	rlImGuiEvents();
 	ImGui::NewFrame();
@@ -505,6 +509,7 @@ void rlImGuiBeginDelta(float deltaTime)
 
 void rlImGuiEnd()
 {
+    ImGui::SetCurrentContext(GlobalContext);
     ImGui::Render();
     rlRenderData(ImGui::GetDrawData());
 }
@@ -513,6 +518,7 @@ void rlImGuiShutdown()
 {
     UnloadTexture(FontTexture);
 
+    ImGui::SetCurrentContext(GlobalContext);
     ImGui::DestroyContext();
 }
 
@@ -520,7 +526,7 @@ void rlImGuiImage(const Texture* image)
 {
 	if (!image)
 		return;
-
+    ImGui::SetCurrentContext(GlobalContext);
     ImGui::Image((ImTextureID)image, ImVec2(float(image->width), float(image->height)));
 }
 
@@ -528,7 +534,7 @@ bool rlImGuiImageButton(const char* name, const Texture* image)
 {
 	if (!image)
 		return false;
-
+    ImGui::SetCurrentContext(GlobalContext);
     return ImGui::ImageButton(name, (ImTextureID)image, ImVec2(float(image->width), float(image->height)));
 }
 
@@ -536,7 +542,7 @@ bool rlImGuiImageButtonSize(const char* name, const Texture* image, ImVec2 size)
 {
 	if (!image)
 		return false;
-
+    ImGui::SetCurrentContext(GlobalContext);
     return ImGui::ImageButton(name, (ImTextureID)image, size);
 }
 
@@ -544,7 +550,7 @@ void rlImGuiImageSize(const Texture* image, int width, int height)
 {
 	if (!image)
 		return;
-
+    ImGui::SetCurrentContext(GlobalContext);
     ImGui::Image((ImTextureID)image, ImVec2(float(width), float(height)));
 }
 
@@ -552,7 +558,7 @@ void rlImGuiImageSizeV(const Texture* image, Vector2 size)
 {
 	if (!image)
 		return;
-
+    ImGui::SetCurrentContext(GlobalContext);
 	ImGui::Image((ImTextureID)image, ImVec2(size.x, size.y));
 }
 
@@ -560,7 +566,7 @@ void rlImGuiImageRect(const Texture* image, int destWidth, int destHeight, Recta
 {
 	if (!image)
 		return;
-
+    ImGui::SetCurrentContext(GlobalContext);
     ImVec2 uv0;
     ImVec2 uv1;
 
@@ -593,7 +599,7 @@ void rlImGuiImageRenderTexture(const RenderTexture* image)
 {
     if (!image)
         return;
-
+    ImGui::SetCurrentContext(GlobalContext);
     rlImGuiImageRect(&image->texture, image->texture.width, image->texture.height, Rectangle{ 0,0, float(image->texture.width), -float(image->texture.height) });
 }
 
@@ -601,7 +607,7 @@ void rlImGuiImageRenderTextureFit(const RenderTexture* image, bool center)
 {
 	if (!image)
 		return;
-
+    ImGui::SetCurrentContext(GlobalContext);
     ImVec2 area = ImGui::GetContentRegionAvail();
 
     float scale =  area.x / image->texture.width;