152 lines
3.6 KiB
C++
152 lines
3.6 KiB
C++
#include <glad/glad.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <imgui.h>
|
|
#include <imgui_impl_glfw.h>
|
|
#include <imgui_impl_opengl3.h>
|
|
#include <iostream>
|
|
|
|
int main(int argc, char **argv) {
|
|
std::cout << "Hello working!" << std::endl;
|
|
|
|
|
|
glfwInit();
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
|
|
// make the window
|
|
GLFWwindow *window = glfwCreateWindow(640, 480, "OpenGL Demo", NULL, NULL);
|
|
if (!window) {
|
|
|
|
std::cout << "Failed to create GLFW window." << std::endl;
|
|
glfwTerminate();
|
|
return -1;
|
|
}
|
|
glfwMakeContextCurrent(window);
|
|
// d
|
|
|
|
// load graphics
|
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
std::cerr << "Failed to initialize OpenGL loader!" << std::endl;
|
|
return -1;
|
|
}
|
|
glViewport(0, 0, 640, 480);
|
|
// d
|
|
|
|
// now make ImGui
|
|
IMGUI_CHECKVERSION();
|
|
ImGui::CreateContext();
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
(void)io;
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
ImGui::StyleColorsDark();
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
ImGui_ImplOpenGL3_Init("#version 130");
|
|
/// im a dumbass
|
|
///
|
|
|
|
// program
|
|
while (!glfwWindowShouldClose(window)) {
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
ImGui_ImplGlfw_NewFrame();
|
|
ImGui::NewFrame();
|
|
|
|
static bool dragging_window = false;
|
|
static double drag_start_global_x, drag_start_global_y;
|
|
static int drag_start_window_x, drag_start_window_y;
|
|
|
|
glClearColor(1.0f, .5f, .2f, 1.0f);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glfwPollEvents();
|
|
|
|
|
|
if (ImGui::BeginMainMenuBar()) {
|
|
// --- DRAG LOGIC FIRST ---
|
|
bool is_hovered = ImGui::IsWindowHovered();
|
|
bool is_clicked = ImGui::IsMouseClicked(0);
|
|
bool is_held = ImGui::IsMouseDown(0);
|
|
|
|
// Get current window position
|
|
int window_x, window_y;
|
|
glfwGetWindowPos(window, &window_x, &window_y);
|
|
|
|
// Get current mouse position relative to window
|
|
double local_mouse_x, local_mouse_y;
|
|
glfwGetCursorPos(window, &local_mouse_x, &local_mouse_y);
|
|
|
|
// Convert to global mouse position
|
|
double global_mouse_x = window_x + local_mouse_x;
|
|
double global_mouse_y = window_y + local_mouse_y;
|
|
|
|
// ✅ Only start dragging if not over any ImGui menu item
|
|
if (is_hovered && is_clicked && !ImGui::IsAnyItemHovered()) {
|
|
dragging_window = true;
|
|
drag_start_global_x = global_mouse_x;
|
|
drag_start_global_y = global_mouse_y;
|
|
drag_start_window_x = window_x;
|
|
drag_start_window_y = window_y;
|
|
}
|
|
|
|
if (dragging_window) {
|
|
if (is_held) {
|
|
double dx = global_mouse_x - drag_start_global_x;
|
|
double dy = global_mouse_y - drag_start_global_y;
|
|
|
|
glfwSetWindowPos(window,
|
|
drag_start_window_x + static_cast<int>(dx),
|
|
drag_start_window_y + static_cast<int>(dy));
|
|
} else {
|
|
dragging_window = false;
|
|
}
|
|
}
|
|
|
|
// --- MENU ITEMS ALWAYS RENDERED ---
|
|
if (ImGui::BeginMenu("File")) {
|
|
if (ImGui::MenuItem("Quit")) {
|
|
glfwSetWindowShouldClose(window, true);
|
|
}
|
|
ImGui::EndMenu();
|
|
}
|
|
|
|
float window_width = ImGui::GetWindowWidth();
|
|
ImVec2 size = ImGui::CalcTextSize("x");
|
|
float button_width = size.x + ImGui::GetStyle().FramePadding.x * 2;
|
|
ImGui::SameLine(window_width - button_width - ImGui::GetStyle().ItemSpacing.x);
|
|
|
|
if (ImGui::Button("x")) {
|
|
// Button clicked logic
|
|
std::cout << "Exiting..." << std::endl;
|
|
glfwSetWindowShouldClose(window, true);
|
|
}
|
|
|
|
ImGui::EndMainMenuBar();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Editor");
|
|
ImGui::Text("Hello from editor");
|
|
ImGui::End();
|
|
|
|
ImGui::Render();
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
glfwSwapBuffers(window);
|
|
}
|
|
|
|
glfwDestroyWindow(window);
|
|
glfwTerminate();
|
|
|
|
return 0;
|
|
}
|