WindowTests.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #define IMPORT_CORE
  2. #include <GLFW/glfw3.h>
  3. #include <core/Logger.h>
  4. #include <stdio.h>
  5. #include "../Tests.h"
  6. #include "core/Window.h"
  7. static int ticks = 200;
  8. static Button closeButton = 0;
  9. static Button testButton = 0;
  10. static bool isRunning(void*) {
  11. return !shouldWindowClose() && ticks > 0 && !isButtonDown(closeButton);
  12. }
  13. static void tick(void*) {
  14. ticks -= ticks > 0;
  15. printf("TPS: %.3f\nFPS: %.3f\n", (double)getWindowTicksPerSecond(),
  16. (double)getWindowFramesPerSecond());
  17. printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
  18. getButtonName(closeButton), isButtonDown(closeButton),
  19. getButtonDownTime(closeButton), wasButtonReleased(closeButton));
  20. printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
  21. getButtonName(testButton), isButtonDown(testButton),
  22. getButtonDownTime(testButton), wasButtonReleased(testButton));
  23. Vector2 mouse = getLastMousePosition();
  24. printf("Mouse: %.2f %.2f\n", (double)mouse.data[0], (double)mouse.data[1]);
  25. }
  26. static void render(void*, float) {
  27. }
  28. void testWindow(void) {
  29. WindowOptions options = {{{800, 480}}, false, "Test"};
  30. if(openWindow(&options)) {
  31. return;
  32. }
  33. closeButton = addButton("Close Button");
  34. bindKeyToButton(closeButton, GLFW_KEY_Q);
  35. testButton = addButton("Test Button");
  36. bindKeyToButton(testButton, GLFW_KEY_T);
  37. showWindow();
  38. setWindowRunHandler(isRunning, nullptr);
  39. setWindowTickHandler(tick, nullptr);
  40. setWindowRenderHandler(render, nullptr);
  41. setWindowNanosPerTick(50000000);
  42. runWindow();
  43. closeWindow();
  44. }