Как я могу создать окно ImGui, которое может перемещать и перетаскивать родительское окно glfw? ⇐ C++
Как я могу создать окно ImGui, которое может перемещать и перетаскивать родительское окно glfw?
I have used the glfwgetwindowpos and glfwsetwindowpos with imgui's getmousedragdelta to try and move the parent glfw window using imgui. What I am trying to accomplish is to have an imgui window where I am able to drag on it, but rather than moving the imgui window, it moves the parent glfw window causing everything inside that window to move along with it. I have been able to accomplish what I am trying to do, but occasionally, the glfw window just teleports to a random location on my screen.
Here is a simplified version of the code that still causes the issue:
ImGui::Begin("Test Window"); ImGui::End(); if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { int windowXPos = 0; int windowYPos = 0; glfwGetWindowPos(window, &windowXPos, &windowYPos); glfwSetWindowPos(window, windowXPos + ImGui::GetMouseDragDelta(ImGuiMouseButton_Left).x, windowYPos + ImGui::GetMouseDragDelta(ImGuiMouseButton_Left).y); } edit possible fix:
I figured out the solution to remove the jitter. I used the glfwgetcursorpos to get the relative position of the cursor and then I used the imgui's mouseclickedpos to offset that to where I clicked on the imgui window at the time of holding the mouse. This removed the jitter and random teleportations, but I still don't understand why that occured with my original code.
new simplified version of my fix:
ImGui::Begin("Test Window"); ImGui::End(); if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { int windowXPos = 0; int windowYPos = 0; double mouseXPos = 0; double mouseYPos = 0; glfwGetWindowPos(window, &windowXPos, &windowYPos); glfwGetCursorPos(window, &mouseXPos, &mouseYPos); glfwSetWindowPos(window, windowXPos + mouseXPos - ImGui::GetIO().MouseClickedPos[0].x, windowYPos + mouseYPos - ImGui::GetIO().MouseClickedPos[0].y); }
Источник: https://stackoverflow.com/questions/780 ... ent-glfw-w
I have used the glfwgetwindowpos and glfwsetwindowpos with imgui's getmousedragdelta to try and move the parent glfw window using imgui. What I am trying to accomplish is to have an imgui window where I am able to drag on it, but rather than moving the imgui window, it moves the parent glfw window causing everything inside that window to move along with it. I have been able to accomplish what I am trying to do, but occasionally, the glfw window just teleports to a random location on my screen.
Here is a simplified version of the code that still causes the issue:
ImGui::Begin("Test Window"); ImGui::End(); if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { int windowXPos = 0; int windowYPos = 0; glfwGetWindowPos(window, &windowXPos, &windowYPos); glfwSetWindowPos(window, windowXPos + ImGui::GetMouseDragDelta(ImGuiMouseButton_Left).x, windowYPos + ImGui::GetMouseDragDelta(ImGuiMouseButton_Left).y); } edit possible fix:
I figured out the solution to remove the jitter. I used the glfwgetcursorpos to get the relative position of the cursor and then I used the imgui's mouseclickedpos to offset that to where I clicked on the imgui window at the time of holding the mouse. This removed the jitter and random teleportations, but I still don't understand why that occured with my original code.
new simplified version of my fix:
ImGui::Begin("Test Window"); ImGui::End(); if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { int windowXPos = 0; int windowYPos = 0; double mouseXPos = 0; double mouseYPos = 0; glfwGetWindowPos(window, &windowXPos, &windowYPos); glfwGetCursorPos(window, &mouseXPos, &mouseYPos); glfwSetWindowPos(window, windowXPos + mouseXPos - ImGui::GetIO().MouseClickedPos[0].x, windowYPos + mouseYPos - ImGui::GetIO().MouseClickedPos[0].y); }
Источник: https://stackoverflow.com/questions/780 ... ent-glfw-w
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение