uhhh pt2?
This commit is contained in:
47
Osmium.cpp
47
Osmium.cpp
@@ -8,13 +8,12 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
std::cout << "Hello working!" << std::endl;
|
std::cout << "Hello working!" << std::endl;
|
||||||
static bool dragging_window = false;
|
|
||||||
static ImVec2 move_offset;
|
|
||||||
|
|
||||||
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
|
||||||
@@ -41,6 +40,7 @@ int main(int argc, char **argv) {
|
|||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
(void)io;
|
(void)io;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
ImGui_ImplOpenGL3_Init("#version 130");
|
ImGui_ImplOpenGL3_Init("#version 130");
|
||||||
@@ -49,6 +49,9 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// program
|
// program
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
static bool dragging_window = false;
|
||||||
|
static double drag_start_mouse_x, drag_start_mouse_y;
|
||||||
|
static int drag_start_window_x,drag_start_window_y;
|
||||||
|
|
||||||
glClearColor(1.0f, .5f, .2f, 1.0f);
|
glClearColor(1.0f, .5f, .2f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
@@ -60,30 +63,38 @@ int main(int argc, char **argv) {
|
|||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
ImGui::BeginMainMenuBar();
|
ImGui::BeginMainMenuBar();
|
||||||
ImVec2 mouse_pos = ImGui::GetMousePos();
|
|
||||||
ImVec2 window_pos = ImGui::GetWindowPos();
|
|
||||||
|
|
||||||
if (ImGui::IsMouseDown(0) && ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) {
|
||||||
|
dragging_window = true;
|
||||||
|
|
||||||
if (!dragging_window) {
|
|
||||||
dragging_window = true;
|
|
||||||
move_offset = ImVec2(mouse_pos.x - window_pos.x,
|
|
||||||
mouse_pos.y - window_pos.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
int new_x = static_cast<int>(mouse_pos.x - move_offset.x);
|
glfwGetCursorPos(window, &drag_start_mouse_x, &drag_start_mouse_y);
|
||||||
int new_y = static_cast<int>(mouse_pos.y - move_offset.y);
|
|
||||||
glfwSetWindowPos(window, new_x, new_y);
|
|
||||||
|
|
||||||
|
// Get window pos
|
||||||
|
glfwGetWindowPos(window, &drag_start_window_x, &drag_start_window_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dragging_window && ImGui::IsMouseDown(0)) {
|
||||||
|
double current_mouse_x, current_mouse_y;
|
||||||
|
glfwGetCursorPos(window, ¤t_mouse_x, ¤t_mouse_y);
|
||||||
|
|
||||||
|
|
||||||
|
double dx = current_mouse_x - drag_start_mouse_x;
|
||||||
|
double dy = current_mouse_y - drag_start_mouse_y;
|
||||||
|
|
||||||
|
// Move window
|
||||||
|
glfwSetWindowPos(window,
|
||||||
|
drag_start_window_x + static_cast<int>(dx),
|
||||||
|
drag_start_window_y + static_cast<int>(dy));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
dragging_window = false;
|
dragging_window = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Menu items
|
||||||
|
|
||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
ImGui::MenuItem("Exit");
|
if (ImGui::MenuItem("Exit")) {
|
||||||
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
|
|||||||
Reference in New Issue
Block a user