From 2bbed289f306cc8b570e65094aa5e2f7dd92dbfa Mon Sep 17 00:00:00 2001 From: Abbion Date: Tue, 28 Feb 2023 19:28:45 +0100 Subject: [PATCH] Clear example --- examples/CMakeLists.txt | 4 +- examples/areoBorderless.c | 234 -------------------------------------- examples/splitview.c | 1 + src/win32_window.c | 17 +-- 4 files changed, 7 insertions(+), 249 deletions(-) delete mode 100644 examples/areoBorderless.c diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c3243c73..e7a03797 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -27,7 +27,6 @@ set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" add_executable(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD_GL}) add_executable(gears WIN32 MACOSX_BUNDLE gears.c ${ICON} ${GLAD_GL}) -add_executable(areoBorderless WIN32 MACOSX_BUNDLE areoBorderless.c ${ICON} ${GLAD_GL}) add_executable(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD_GL}) add_executable(offscreen offscreen.c ${ICON} ${GLAD_GL}) add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD_GL}) @@ -43,7 +42,7 @@ if (RT_LIBRARY) target_link_libraries(particles "${RT_LIBRARY}") endif() -set(GUI_ONLY_BINARIES boing gears areoBorderless heightmap particles sharing splitview +set(GUI_ONLY_BINARIES boing gears heightmap particles sharing splitview triangle-opengl triangle-opengles wave windows) set(CONSOLE_BINARIES offscreen) @@ -64,7 +63,6 @@ endif() if (APPLE) set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") - set_target_properties(areoBorderless PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "WindowsOnly!!!") set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap") set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles") set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") diff --git a/examples/areoBorderless.c b/examples/areoBorderless.c deleted file mode 100644 index 13504c26..00000000 --- a/examples/areoBorderless.c +++ /dev/null @@ -1,234 +0,0 @@ -#if defined(_MSC_VER) - // Make MS math.h define M_PI -#define _USE_MATH_DEFINES -#endif - -#include -#include -#include -#include - -#define GLAD_GL_IMPLEMENTATION -#include -#define GLFW_INCLUDE_NONE -#include - -#include - -void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods); -void button_callback(GLFWwindow* window, int button, int action, int mods); - -int leftMousePressed = 0; -int leftMouseClicked = 0; -int lestMouseReleased = 0; - -void moveWindow(GLFWwindow* window) -{ - int resizeFrameSize = 5; - int grabBarSize = 20; - - int windowWidth; - int windowHeight; - - glfwGetWindowSize(window, &windowWidth, &windowHeight); - - int windowPosX; - int windowPosY; - - glfwGetWindowPos(window, &windowPosX, &windowPosY); - - double mousePositionInWindowX; - double mousePositionInWindowY; - - glfwGetCursorPos(window, &mousePositionInWindowX, &mousePositionInWindowY); - - static double lastMousePositionInWindowX = 0; - static double lastMousePositionInWindowY = 0; - - int mouseUpdated = 0; - - if (lastMousePositionInWindowX != mousePositionInWindowX || lastMousePositionInWindowY != mousePositionInWindowY) - { - lastMousePositionInWindowX = mousePositionInWindowX; - lastMousePositionInWindowY = mousePositionInWindowY; - mouseUpdated = 1; - } - - static int lockX = 0; - static int lockY = 0; - static int grabActive = 0; - - if (leftMouseClicked) - { - if (mousePositionInWindowX > resizeFrameSize && mousePositionInWindowX < windowWidth - resizeFrameSize && - mousePositionInWindowY > resizeFrameSize && mousePositionInWindowY < grabBarSize + resizeFrameSize) - { - lockX = mousePositionInWindowX; - lockY = mousePositionInWindowY; - grabActive = 1; - } - } - if (lestMouseReleased) - { - grabActive = 0; - } - - if (grabActive && mouseUpdated) - { - int currentX = windowPosX + mousePositionInWindowX - lockX; - int currentY = windowPosY + mousePositionInWindowY - lockY; - - glfwSetWindowPos(window, currentX, currentY); - } - -} - -void resizeWidnow(GLFWwindow* window) -{ - int resizeFrameSize = 4; - int grabBarSize = 20; - - int windowWidth; - int windowHeight; - - glfwGetWindowSize(window, &windowWidth, &windowHeight); - - int windowPosX; - int windowPosY; - - glfwGetWindowPos(window, &windowPosX, &windowPosY); - - double mousePositionInWindowX; - double mousePositionInWindowY; - - glfwGetCursorPos(window, &mousePositionInWindowX, &mousePositionInWindowY); - - static double lastMousePositionInWindowX = 0; - static double lastMousePositionInWindowY = 0; - - int mouseUpdated = 0; - - enum resizeType { - LEFT_TOP = 1 << 0, - RIGHT_TOP = 1 << 1, - LEFT_BOTTOM = 1 << 2, - RIGHT_BOTTOM = 1 << 3, - LEFT = 1 << 4, - RIGHT = 1 << 5, - TOP = 1 << 6, - BOTTOM = 1 << 7 - }; - - enum resizeType type = 0; - - if (mousePositionInWindowX >= 0 && mousePositionInWindowX < resizeFrameSize) - { - type |= LEFT; - } - if (mousePositionInWindowX <= windowWidth && mousePositionInWindowX > windowWidth - resizeFrameSize) - { - type |= RIGHT; - } - if (mousePositionInWindowY >= 0 && mousePositionInWindowY < resizeFrameSize) - { - type |= TOP; - } - if (mousePositionInWindowY <= windowHeight && mousePositionInWindowY > windowHeight - resizeFrameSize) - { - type |= BOTTOM; - } - - if (type == (LEFT & TOP)) - { - type = LEFT_TOP; - } - else if (type == (RIGHT & TOP)) - { - type = RIGHT_TOP; - } - else if (type == (LEFT & BOTTOM)) - { - type = LEFT_BOTTOM; - } - else if (type == (RIGHT & BOTTOM)) - { - type = RIGHT_BOTTOM; - } - - //printf("%d", type); -} - -/* program entry */ -int main(int argc, char* argv[]) -{ - GLFWwindow* window; - int width, height; - - if (!glfwInit()) - { - fprintf(stderr, "Failed to initialize GLFW\n"); - exit(EXIT_FAILURE); - } - - glfwWindowHint(GLFW_BORDERLESS_AREO, GLFW_TRUE); - - window = glfwCreateWindow(800, 600, "areoBorderless", NULL, NULL); - if (!window) - { - fprintf(stderr, "Failed to open GLFW window\n"); - glfwTerminate(); - exit(EXIT_FAILURE); - } - - glfwMakeContextCurrent(window); - glfwSetKeyCallback(window, key_callback); - glfwSetMouseButtonCallback(window, button_callback); - - glfwSetWindowPos(window, 300, 200); - glfwSetWindowBorderlessResizeBorderSize(window, 8); - glfwSetWindowTitle(window, "Hello"); - - while (!glfwWindowShouldClose(window)) - { - int w, h; - glfwGetWindowSize(window, &w, &h); - // printf("%d, %d\n", w, h); - - leftMouseClicked = 0; - lestMouseReleased = 0; - - glfwSwapBuffers(window); - glfwPollEvents(); - } - - glfwTerminate(); - - exit(EXIT_SUCCESS); -} - -void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) -{ - if (key == GLFW_KEY_E && action == GLFW_PRESS) - glfwIconifyWindow(window); - - if (key == GLFW_KEY_W && action == GLFW_PRESS) - glfwMaximizeWindow(window); - - - if (key == GLFW_KEY_Q && action == GLFW_PRESS) - glfwRestoreWindow(window); -} - -void button_callback(GLFWwindow* window, int button, int action, int mods) -{ - if (button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS) - { - leftMouseClicked = 1; - leftMousePressed = 1; - } - else if (button == GLFW_MOUSE_BUTTON_1 && action == GLFW_RELEASE) - { - leftMousePressed = 0; - lestMouseReleased = 1; - } -} \ No newline at end of file diff --git a/examples/splitview.c b/examples/splitview.c index 990df12c..ea2f8aa7 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -495,6 +495,7 @@ int main(void) } glfwWindowHint(GLFW_SAMPLES, 4); + glfwWindowHint(GLFW_BORDERLESS_AREO, GLFW_TRUE); // Open OpenGL window window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL); diff --git a/src/win32_window.c b/src/win32_window.c index 9306d230..86354bc7 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -117,17 +117,17 @@ LRESULT hit_test(_GLFWwindow* window, int posX, int posY) } } -int adjust_maximized_client_rect(_GLFWwindow* window, RECT* rect){ +void adjust_maximized_client_rect(_GLFWwindow* window, RECT* rect){ WINDOWPLACEMENT placement; if (!GetWindowPlacement(window->win32.handle, &placement)) - return 0; + return; if (placement.showCmd != SW_MAXIMIZE) - return 0; + return; auto monitor = MonitorFromWindow(window->win32.handle, MONITOR_DEFAULTTONULL); if (!monitor) - return 0; + return; MONITORINFO monitor_info; monitor_info.cbSize = sizeof(monitor_info); @@ -135,8 +135,6 @@ int adjust_maximized_client_rect(_GLFWwindow* window, RECT* rect){ return 0; (*rect) = monitor_info.rcWork; - - return 1; } // Returns the extended window style for the specified window @@ -634,9 +632,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l if (window->borderLessAreo == GLFW_TRUE) { NCCALCSIZE_PARAMS* pParams = (NCCALCSIZE_PARAMS*)lParam; - - if(!adjust_maximized_client_rect(window, &pParams->rgrc[0])) - pParams->rgrc[0].top -= 1; + adjust_maximized_client_rect(window, &pParams->rgrc[0]); return 0; } @@ -1752,9 +1748,6 @@ void _glfwGetWindowSizeWin32(_GLFWwindow* window, int* width, int* height) *width = area.right; if (height) *height = area.bottom; - - if(window->borderLessAreo && !window->win32.maximized) - (*height) -= 1; } void _glfwSetWindowSizeWin32(_GLFWwindow* window, int width, int height)