1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include <GLFW/glfw3.h>
- #include <core/Logger.h>
- #include <stdio.h>
- #include "../Tests.h"
- #include "core/WindowManager.h"
- static int ticks = 5;
- static Button closeButton = 0;
- static Button testButton = 0;
- static Button textButton = 0;
- static bool isRunning(void*) {
- return !shouldWindowClose() && ticks > 0 && !isButtonDown(closeButton);
- }
- static void tick(void*) {
- ticks -= ticks > 0;
- if(!isInputEnabled()) {
- printf("TPS: %.3f\nFPS: %.3f\n", (double)getWindowTicksPerSecond(),
- (double)getWindowFramesPerSecond());
- printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
- getButtonName(closeButton), isButtonDown(closeButton),
- getButtonDownTime(closeButton), wasButtonReleased(closeButton));
- printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
- getButtonName(testButton), isButtonDown(testButton),
- getButtonDownTime(testButton), wasButtonReleased(testButton));
- Vector2 mouse = getLastMousePosition();
- printf("Mouse: %.2f %.2f\n", (double)mouse.data[0],
- (double)mouse.data[1]);
- }
- if(getButtonDownTime(textButton) == 1) {
- if(isInputEnabled()) {
- disableInput();
- } else {
- enableInput();
- }
- }
- if(isInputEnabled()) {
- printf("Input: '%s'\n", getInputString());
- printf("Cursor: %zu\n", getInputCursor());
- }
- }
- static void render(void*, float) {
- }
- void testWindow(void) {
- WindowOptions options = {{{800, 480}}, false, "Test"};
- if(openWindow(&options)) {
- return;
- }
- closeButton = addButton("Close Button");
- bindKeyToButton(closeButton, GLFW_KEY_Q);
- testButton = addButton("Test Button");
- bindKeyToButton(testButton, GLFW_KEY_T);
- textButton = addButton("Text Button");
- bindKeyToButton(textButton, GLFW_KEY_C);
- showWindow();
- setWindowRunHandler(isRunning, nullptr);
- setWindowTickHandler(tick, nullptr);
- setWindowRenderHandler(render, nullptr);
- setWindowNanosPerTick(50000000);
- runWindow();
- closeWindow();
- }
|