ok remake pt4

This commit is contained in:
2025-07-15 20:56:12 +03:00
parent bb793e876a
commit 22ad2002e4

View File

@@ -13,9 +13,10 @@ int main(int argc, char **argv) {
glfwInit(); glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
//glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// make the window // make the window
GLFWwindow *window = glfwCreateWindow(640, 480, "OpenGL Demo", NULL, NULL); GLFWwindow *window = glfwCreateWindow(640, 480, "OpenGL Demo", NULL, NULL);
if (!window) { if (!window) {
@@ -63,32 +64,33 @@ int main(int argc, char **argv) {
ImGui::NewFrame(); ImGui::NewFrame();
ImGui::BeginMainMenuBar(); ImGui::BeginMainMenuBar();
bool is_hovered = ImGui::IsWindowHovered();
bool is_clicked = ImGui::IsMouseClicked(0);
bool is_held = ImGui::IsMouseDown(0);
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) { if (is_hovered && is_clicked) {
dragging_window = true; dragging_window = true;
// Get initial mouse and window positions
glfwGetCursorPos(window, &drag_start_mouse_x, &drag_start_mouse_y); glfwGetCursorPos(window, &drag_start_mouse_x, &drag_start_mouse_y);
// Get window pos
glfwGetWindowPos(window, &drag_start_window_x, &drag_start_window_y); glfwGetWindowPos(window, &drag_start_window_x, &drag_start_window_y);
} }
if (dragging_window && ImGui::IsMouseDown(0)) { if (dragging_window) {
if (is_held) {
double current_mouse_x, current_mouse_y; double current_mouse_x, current_mouse_y;
glfwGetCursorPos(window, &current_mouse_x, &current_mouse_y); glfwGetCursorPos(window, &current_mouse_x, &current_mouse_y);
double dx = current_mouse_x - drag_start_mouse_x; double dx = current_mouse_x - drag_start_mouse_x;
double dy = current_mouse_y - drag_start_mouse_y; double dy = current_mouse_y - drag_start_mouse_y;
// Move window
glfwSetWindowPos(window, glfwSetWindowPos(window,
drag_start_window_x + static_cast<int>(dx), drag_start_window_x + static_cast<int>(dx),
drag_start_window_y + static_cast<int>(dy)); drag_start_window_y + static_cast<int>(dy));
} else { } else {
dragging_window = false; dragging_window = false;
} }
}
// Menu items // Menu items
if (ImGui::BeginMenu("File")) { if (ImGui::BeginMenu("File")) {