Exemplo n.º 1
0
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (action != GLFW_PRESS)
        return;

    switch (key)
    {
        case GLFW_KEY_ESCAPE:
            glfwSetWindowShouldClose(window, GL_TRUE);
            break;

        case GLFW_KEY_T:
            delay = !delay;
            printf("Delay %s.\n", delay ? "enabled" : "disabled");
            break;

        default:
        {
            if (delay)
            {
                int i = 0;

                while (i < CommandCount && commands[i].key != key)
                    i++;

                if (i < CommandCount)
                    commands[i].time = glfwGetTime();
            }
            else
            {
                command_callback(key);
            }
        }
        break;
    }
}
Exemplo n.º 2
0
bool
WndForm::ClientAreaWindow::OnCommand(unsigned id, unsigned code)
{
  return (command_callback != NULL && command_callback(id))
    || ContainerWindow::OnCommand(id, code);
}
Exemplo n.º 3
0
int main(void)
{
    int i;
    GLboolean running = GL_TRUE;

    glfwSetErrorCallback(error_callback);

    if (!glfwInit())
        exit(EXIT_FAILURE);

    for (i = 0; i < 2; i++)
    {
        windows[i] = glfwCreateWindow(W, H, "Cursor testing", NULL, NULL);

        if (!windows[i])
        {
            glfwTerminate();
            exit(EXIT_FAILURE);
        }

        glfwSetWindowPos(windows[i], 100 + (i & 1) * (W + 50), 100);

        glfwSetWindowRefreshCallback(windows[i], refresh_callback);
        glfwSetFramebufferSizeCallback(windows[i], framebuffer_size_callback);
        glfwSetKeyCallback(windows[i], key_callback);
        glfwSetWindowFocusCallback(windows[i], focus_callback);

        glfwMakeContextCurrent(windows[i]);
        glClear(GL_COLOR_BUFFER_BIT);
        glfwSwapBuffers(windows[i]);
    }

    activeWindow = windows[0];

    key_callback(NULL, GLFW_KEY_H, 0, GLFW_PRESS, 0);

    while (running)
    {
        if (delay)
        {
            int i;
            double t = glfwGetTime();

            for (i = 0; i < CommandCount; i++)
            {
                if (commands[i].time != 0 && t - commands[i].time >= 3.0)
                {
                    command_callback(commands[i].key);
                    commands[i].time = 0;
                }
            }
        }

        running = !(glfwWindowShouldClose(windows[0]) || glfwWindowShouldClose(windows[1]));

        glfwPollEvents();
    }

    glfwTerminate();
    exit(EXIT_SUCCESS);
}