i have no clue what i am doing ... but terrible full screen
This commit is contained in:
86
Osmium.cpp
86
Osmium.cpp
@@ -13,6 +13,7 @@ int main(int argc, char **argv) {
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
@@ -92,19 +93,68 @@ int main(int argc, char **argv) {
|
||||
drag_start_window_y = window_y;
|
||||
}
|
||||
|
||||
|
||||
static bool is_maximized = false;
|
||||
static int restore_x, restore_y, restore_w, restore_h;
|
||||
|
||||
|
||||
|
||||
|
||||
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));
|
||||
int new_x = drag_start_window_x + static_cast<int>(dx);
|
||||
int new_y = drag_start_window_y + static_cast<int>(dy);
|
||||
|
||||
glfwSetWindowPos(window, new_x, new_y);
|
||||
|
||||
|
||||
GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();
|
||||
int monitor_x, monitor_y, monitor_w, monitor_h;
|
||||
if (glfwGetMonitorWorkarea) {
|
||||
glfwGetMonitorWorkarea(primaryMonitor, &monitor_x, &monitor_y, &monitor_w, &monitor_h);
|
||||
}
|
||||
|
||||
|
||||
const int tolerance = 2;
|
||||
if (!is_maximized && abs(new_y - monitor_y) <= tolerance) {
|
||||
|
||||
glfwGetWindowPos(window, &restore_x, &restore_y);
|
||||
glfwGetWindowSize(window, &restore_w, &restore_h);
|
||||
|
||||
|
||||
glfwSetWindowPos(window, monitor_x, monitor_y);
|
||||
glfwSetWindowSize(window, monitor_w, monitor_h);
|
||||
is_maximized = true;
|
||||
dragging_window = false;
|
||||
}
|
||||
} else {
|
||||
dragging_window = false;
|
||||
}
|
||||
|
||||
if (!dragging_window && is_maximized) {
|
||||
double mx, my;
|
||||
glfwGetCursorPos(window, &mx, &my);
|
||||
if (ImGui::IsMouseDown(0) && my < 10.0) {
|
||||
// Start unmaximize drag
|
||||
is_maximized = false;
|
||||
glfwSetWindowSize(window, restore_w, restore_h);
|
||||
glfwSetWindowPos(window,
|
||||
static_cast<int>(global_mouse_x - restore_w / 2),
|
||||
static_cast<int>(global_mouse_y - 10));
|
||||
dragging_window = true;
|
||||
drag_start_global_x = global_mouse_x;
|
||||
drag_start_global_y = global_mouse_y;
|
||||
drag_start_window_x = static_cast<int>(global_mouse_x - restore_w / 2);
|
||||
drag_start_window_y = static_cast<int>(global_mouse_y - 10);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// --- MENU ITEMS ALWAYS RENDERED ---
|
||||
if (ImGui::BeginMenu("File")) {
|
||||
if (ImGui::MenuItem("Quit")) {
|
||||
@@ -113,23 +163,45 @@ int main(int argc, char **argv) {
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
float window_width = ImGui::GetWindowWidth();
|
||||
float window_widthA = 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);
|
||||
ImGui::SameLine(window_widthA - button_width - ImGui::GetStyle().ItemSpacing.x);
|
||||
|
||||
if (ImGui::Button("x")) {
|
||||
// Button clicked logic
|
||||
|
||||
std::cout << "Exiting..." << std::endl;
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();
|
||||
int monitor_x, monitor_y, monitor_width, monitor_height;
|
||||
|
||||
|
||||
if (glfwGetMonitorWorkarea) {
|
||||
glfwGetMonitorWorkarea(primaryMonitor, &monitor_x, &monitor_y, &monitor_width, &monitor_height);
|
||||
} else {
|
||||
// Fallback
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor);
|
||||
glfwGetMonitorPos(primaryMonitor, &monitor_x, &monitor_y);
|
||||
monitor_width = mode->width;
|
||||
monitor_height = mode->height;
|
||||
}
|
||||
|
||||
|
||||
int win_x, win_y;
|
||||
glfwGetWindowPos(window, &win_x, &win_y);
|
||||
|
||||
|
||||
const int tolerance = 5;
|
||||
if (abs(win_y - monitor_y) <= tolerance) {
|
||||
std::cout << "Window is at the top of the main screen!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user