WindowManagerTests.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/WindowManager.h"
  7. static int ticks = 2000;
  8. static Button closeButton = 0;
  9. static Button testButton = 0;
  10. static Button textButton = 0;
  11. static bool isRunning(void*) {
  12. return !shouldWindowClose() && ticks > 0 && !isButtonDown(closeButton);
  13. }
  14. static void tick(void*) {
  15. ticks -= ticks > 0;
  16. if(!isInputEnabled()) {
  17. printf("TPS: %.3f\nFPS: %.3f\n", (double)getWindowTicksPerSecond(),
  18. (double)getWindowFramesPerSecond());
  19. printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
  20. getButtonName(closeButton), isButtonDown(closeButton),
  21. getButtonDownTime(closeButton), wasButtonReleased(closeButton));
  22. printf("%12s | Down: %d | DownTime: %3d | Released: %d\n",
  23. getButtonName(testButton), isButtonDown(testButton),
  24. getButtonDownTime(testButton), wasButtonReleased(testButton));
  25. Vector2 mouse = getLastMousePosition();
  26. printf("Mouse: %.2f %.2f\n", (double)mouse.data[0],
  27. (double)mouse.data[1]);
  28. }
  29. if(getButtonDownTime(textButton) == 1) {
  30. if(isInputEnabled()) {
  31. disableInput();
  32. } else {
  33. enableInput();
  34. }
  35. }
  36. if(isInputEnabled()) {
  37. printf("Input: '%s'\n", getInputString());
  38. printf("Cursor: %zu\n", getInputCursor());
  39. }
  40. }
  41. static void render(void*, float) {
  42. }
  43. void testWindow(void) {
  44. WindowOptions options = {{{800, 480}}, false, "Test"};
  45. if(openWindow(&options)) {
  46. return;
  47. }
  48. closeButton = addButton("Close Button");
  49. bindKeyToButton(closeButton, GLFW_KEY_Q);
  50. testButton = addButton("Test Button");
  51. bindKeyToButton(testButton, GLFW_KEY_T);
  52. textButton = addButton("Text Button");
  53. bindKeyToButton(textButton, GLFW_KEY_C);
  54. showWindow();
  55. setWindowRunHandler(isRunning, nullptr);
  56. setWindowTickHandler(tick, nullptr);
  57. setWindowRenderHandler(render, nullptr);
  58. setWindowNanosPerTick(50000000);
  59. runWindow();
  60. closeWindow();
  61. }