mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-22 18:28:52 -05:00
Remove command-line options from GUI-only test
This commit is contained in:
parent
f6d44cedfd
commit
ce9d124243
|
@ -51,7 +51,7 @@ add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD} ${GLAD_GL})
|
|||
add_executable(timeout WIN32 MACOSX_BUNDLE timeout.c ${GLAD_GL})
|
||||
add_executable(title WIN32 MACOSX_BUNDLE title.c ${GLAD_GL})
|
||||
add_executable(triangle-vulkan WIN32 triangle-vulkan.c ${ICON} ${GLAD_VULKAN})
|
||||
add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD_GL})
|
||||
add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GLAD_GL})
|
||||
|
||||
target_link_libraries(empty "${CMAKE_THREAD_LIBS_INIT}")
|
||||
target_link_libraries(threads "${CMAKE_THREAD_LIBS_INIT}")
|
||||
|
|
|
@ -34,8 +34,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
static GLFWwindow* windows[4];
|
||||
static const char* titles[] =
|
||||
{
|
||||
"Red",
|
||||
|
@ -55,20 +54,26 @@ static const struct
|
|||
{ 0.98f, 0.74f, 0.04f }
|
||||
};
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: windows [-h] [-b] [-f] \n");
|
||||
printf("Options:\n");
|
||||
printf(" -b create decorated windows\n");
|
||||
printf(" -f set focus on show off for all but first window\n");
|
||||
printf(" -h show this help\n");
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void arrange_windows(void)
|
||||
{
|
||||
int xbase, ybase;
|
||||
glfwGetWindowPos(windows[0], &xbase, &ybase);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom);
|
||||
glfwSetWindowPos(windows[i],
|
||||
xbase + (i & 1) * (200 + left + right),
|
||||
ybase + (i >> 1) * (200 + top + bottom));
|
||||
}
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action != GLFW_PRESS)
|
||||
|
@ -87,49 +92,34 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
|
|||
case GLFW_KEY_ESCAPE:
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
break;
|
||||
|
||||
case GLFW_KEY_D:
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
const int decorated = glfwGetWindowAttrib(windows[i], GLFW_DECORATED);
|
||||
glfwSetWindowAttrib(windows[i], GLFW_DECORATED, !decorated);
|
||||
}
|
||||
|
||||
arrange_windows();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int i, ch;
|
||||
int decorated = GLFW_FALSE;
|
||||
int focusOnShow = GLFW_TRUE;
|
||||
int running = GLFW_TRUE;
|
||||
GLFWwindow* windows[4];
|
||||
|
||||
while ((ch = getopt(argc, argv, "bfh")) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'b':
|
||||
decorated = GLFW_TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
focusOnShow = GLFW_FALSE;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
default:
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
glfwWindowHint(GLFW_DECORATED, decorated);
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int left, top, right, bottom;
|
||||
if (i)
|
||||
glfwWindowHint(GLFW_FOCUS_ON_SHOW, focusOnShow);
|
||||
if (i > 0)
|
||||
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
|
||||
|
||||
windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL);
|
||||
if (!windows[i])
|
||||
|
@ -143,32 +133,29 @@ int main(int argc, char** argv)
|
|||
glfwMakeContextCurrent(windows[i]);
|
||||
gladLoadGL(glfwGetProcAddress);
|
||||
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
|
||||
|
||||
glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom);
|
||||
glfwSetWindowPos(windows[i],
|
||||
100 + (i & 1) * (200 + left + right),
|
||||
100 + (i >> 1) * (200 + top + bottom));
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
arrange_windows();
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
glfwShowWindow(windows[i]);
|
||||
|
||||
while (running)
|
||||
for (;;)
|
||||
{
|
||||
for (i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
glfwMakeContextCurrent(windows[i]);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(windows[i]);
|
||||
|
||||
if (glfwWindowShouldClose(windows[i]))
|
||||
running = GLFW_FALSE;
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
glfwWaitEvents();
|
||||
}
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user