#include #include #include #include "../Tests.h" #include "core/WindowManager.h" static int ticks = 2; 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) { } static void printReport( LogLevel l, const char* file, int line, void*, const char* message) { printLog(l, file, line, "", TERMINAL_RED, "%s", message); } void testWindow(void) { setReportHandler(printReport, nullptr); 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(50'000'000); runWindow(); closeWindow(); }