mirror of
https://github.com/glfw/glfw.git
synced 2025-06-08 00:34:56 +00:00
Clear example
This commit is contained in:
parent
a0f3dba201
commit
2bbed289f3
@ -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(boing WIN32 MACOSX_BUNDLE boing.c ${ICON} ${GLAD_GL})
|
||||||
add_executable(gears WIN32 MACOSX_BUNDLE gears.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(heightmap WIN32 MACOSX_BUNDLE heightmap.c ${ICON} ${GLAD_GL})
|
||||||
add_executable(offscreen offscreen.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})
|
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}")
|
target_link_libraries(particles "${RT_LIBRARY}")
|
||||||
endif()
|
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)
|
triangle-opengl triangle-opengles wave windows)
|
||||||
set(CONSOLE_BINARIES offscreen)
|
set(CONSOLE_BINARIES offscreen)
|
||||||
|
|
||||||
@ -64,7 +63,6 @@ endif()
|
|||||||
if (APPLE)
|
if (APPLE)
|
||||||
set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing")
|
set_target_properties(boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing")
|
||||||
set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears")
|
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(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap")
|
||||||
set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles")
|
set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles")
|
||||||
set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing")
|
set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing")
|
||||||
|
@ -1,234 +0,0 @@
|
|||||||
#if defined(_MSC_VER)
|
|
||||||
// Make MS math.h define M_PI
|
|
||||||
#define _USE_MATH_DEFINES
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define GLAD_GL_IMPLEMENTATION
|
|
||||||
#include <glad/gl.h>
|
|
||||||
#define GLFW_INCLUDE_NONE
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -495,6 +495,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||||
|
glfwWindowHint(GLFW_BORDERLESS_AREO, GLFW_TRUE);
|
||||||
|
|
||||||
// Open OpenGL window
|
// Open OpenGL window
|
||||||
window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL);
|
window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL);
|
||||||
|
@ -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;
|
WINDOWPLACEMENT placement;
|
||||||
if (!GetWindowPlacement(window->win32.handle, &placement))
|
if (!GetWindowPlacement(window->win32.handle, &placement))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (placement.showCmd != SW_MAXIMIZE)
|
if (placement.showCmd != SW_MAXIMIZE)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
auto monitor = MonitorFromWindow(window->win32.handle, MONITOR_DEFAULTTONULL);
|
auto monitor = MonitorFromWindow(window->win32.handle, MONITOR_DEFAULTTONULL);
|
||||||
if (!monitor)
|
if (!monitor)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
MONITORINFO monitor_info;
|
MONITORINFO monitor_info;
|
||||||
monitor_info.cbSize = sizeof(monitor_info);
|
monitor_info.cbSize = sizeof(monitor_info);
|
||||||
@ -135,8 +135,6 @@ int adjust_maximized_client_rect(_GLFWwindow* window, RECT* rect){
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
(*rect) = monitor_info.rcWork;
|
(*rect) = monitor_info.rcWork;
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the extended window style for the specified window
|
// 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)
|
if (window->borderLessAreo == GLFW_TRUE)
|
||||||
{
|
{
|
||||||
NCCALCSIZE_PARAMS* pParams = (NCCALCSIZE_PARAMS*)lParam;
|
NCCALCSIZE_PARAMS* pParams = (NCCALCSIZE_PARAMS*)lParam;
|
||||||
|
adjust_maximized_client_rect(window, &pParams->rgrc[0]);
|
||||||
if(!adjust_maximized_client_rect(window, &pParams->rgrc[0]))
|
|
||||||
pParams->rgrc[0].top -= 1;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1752,9 +1748,6 @@ void _glfwGetWindowSizeWin32(_GLFWwindow* window, int* width, int* height)
|
|||||||
*width = area.right;
|
*width = area.right;
|
||||||
if (height)
|
if (height)
|
||||||
*height = area.bottom;
|
*height = area.bottom;
|
||||||
|
|
||||||
if(window->borderLessAreo && !window->win32.maximized)
|
|
||||||
(*height) -= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwSetWindowSizeWin32(_GLFWwindow* window, int width, int height)
|
void _glfwSetWindowSizeWin32(_GLFWwindow* window, int width, int height)
|
||||||
|
Loading…
Reference in New Issue
Block a user