12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include <core/Logger.hpp>
- #include <cstdio>
- #include <GLFW/glfw3.h>
- #include "../Tests.hpp"
- #include "core/WindowManager.hpp"
- namespace W = Core::Window;
- static W::Button closeButton = 0;
- static W::Button testButton = 0;
- static W::Button textButton = 0;
- static bool isRunning(void*) {
- return !W::shouldClose() && !W::isButtonDown(closeButton);
- }
- static void tick(void*) {
- if(!W::isInputEnabled()) {
- LOG_INFO(
- "TPS: #\nFPS: #\n", W::getTicksPerSecond(),
- W::getFramesPerSecond());
- printf(
- "%12s | Down: %d | DownTime: %3d | Released: %d\n",
- W::getButtonName(closeButton), W::isButtonDown(closeButton),
- W::getButtonDownTime(closeButton),
- W::wasButtonReleased(closeButton));
- printf(
- "%12s | Down: %d | DownTime: %3d | Released: %d\n",
- W::getButtonName(testButton), W::isButtonDown(testButton),
- W::getButtonDownTime(testButton), W::wasButtonReleased(testButton));
- Core::Vector2 mouse = W::getLastMousePosition();
- LOG_INFO("Mouse: # #\n", mouse[0], mouse[1]);
- }
- if(W::getButtonDownTime(textButton) == 1) {
- if(W::isInputEnabled()) {
- W::disableInput();
- } else {
- W::enableInput();
- }
- }
- if(W::isInputEnabled()) {
- printf("Input: '%s'\n", W::getInputString());
- printf("Cursor: %zu\n", W::getInputCursor());
- }
- }
- static void render(void*, float) {
- }
- static void printReport(
- Core::LogLevel l, const char* file, int line, void*, const char* message) {
- printLog(l, file, line, TERMINAL_RED, "#", message);
- }
- void testWindow() {
- setReportHandler(printReport, nullptr);
- W::Options options = {{800, 480}, false, "Test"};
- if(W::open(options)) {
- return;
- }
- closeButton = W::addButton("Close Button");
- W::bindKeyToButton(closeButton, GLFW_KEY_Q);
- testButton = W::addButton("Test Button");
- W::bindKeyToButton(testButton, GLFW_KEY_T);
- textButton = W::addButton("Text Button");
- W::bindKeyToButton(textButton, GLFW_KEY_C);
- W::show();
- W::setRunHandler(isRunning, nullptr);
- W::setTickHandler(tick, nullptr);
- W::setRenderHandler(render, nullptr);
- W::setNanosPerTick(50'000'000);
- W::run();
- W::close();
- }
|