Как я могу создать окно ImGui, которое может перемещать и перетаскивать родительское окно glfw?C++

Программы на 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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»