WindowManagerTests.c 2.1 KB

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