Исходник Перемещение елементов с помощью мышки

Тьомчик
Участник
Статус
Оффлайн
Регистрация
30 Июн 2020
Сообщения
752
Реакции[?]
154
Поинты[?]
62K
C++:
ImVec2 PortableSquare(ImVec2 position, const ImVec2& size) {
         ImVec2 rect_min = position;
         ImVec2 rect_max = position + size;

         bool is_hovered = ImGui::GetMousePos().x >= rect_min.x &&
             ImGui::GetMousePos().y >= rect_min.y &&
             ImGui::GetMousePos().x <= rect_max.x &&
             ImGui::GetMousePos().y <= rect_max.y;

         /*
         * also you can create a window and use it but which diffrence with default function?
         * bool is_hovered = ImGui::IsItemHovered();
         * bool is_hovered = ImGui::IsMouseHoveringRect(rect_min, rect_max);
         */

         if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && is_hovered) {
             position += ImGui::GetMouseDragDelta(ImGuiMouseButton_Left);
             ImGui::ResetMouseDragDelta(ImGuiMouseButton_Left);
         }

         position = ImClamp(position, ImVec2(0.0f, 0.0f), ImVec2(ImGui::GetScreenSize().x - size.x, ImGui::GetScreenSize().y - size.y));

         return position;
     }
 
Сверху Снизу