inputTest.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "inputTest.h"
  2. using namespace dsr;
  3. #define TASK_IS(INDEX) context.taskIndex == INDEX
  4. #define EVENT_TYPE_IS(TYPE) event.mouseEventType == MouseEventType::TYPE
  5. void inputTests_populate(List<Test> &target, int buttonCount, bool relative, bool verticalScroll) {
  6. if (buttonCount >= 1) {
  7. target.pushConstruct(
  8. U"Mouse drag test"
  9. ,
  10. [](AlignedImageRgbaU8 &canvas, TestContext &context) {
  11. image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
  12. if (TASK_IS(0)) {
  13. font_printLine(canvas, font_getDefault(), U"Hover the cursor over the window.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  14. } else if (TASK_IS(1)) {
  15. font_printLine(canvas, font_getDefault(), U"Press down the left mouse key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  16. } else if (TASK_IS(2)) {
  17. font_printLine(canvas, font_getDefault(), U"Drag the mouse over the window with the left key pressed down.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  18. } else if (TASK_IS(3)) {
  19. font_printLine(canvas, font_getDefault(), U"Release the left key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  20. }
  21. // TODO: Draw expanding circles from lowering and raising buttons together with names of the keys used.
  22. // TODO: Draw fading lines from move events.
  23. // TODO: Make a reusable drawing system to be enabled or disabled as a reusable mouse visualization feature.
  24. }
  25. ,
  26. [](const MouseEvent& event, TestContext &context) {
  27. if (TASK_IS(0) && EVENT_TYPE_IS(MouseMove) && !context.leftMouseDown && !context.middleMouseDown && !context.rightMouseDown) {
  28. context.passTask();
  29. } else if (TASK_IS(1) && EVENT_TYPE_IS(MouseDown)) {
  30. if (event.key == MouseKeyEnum::Left) {
  31. context.passTask();
  32. } else {
  33. // TODO: Say which key was triggered instead and suggest skipping with escape if it can not be found.
  34. }
  35. } else if (TASK_IS(2) && EVENT_TYPE_IS(MouseMove) && context.leftMouseDown) {
  36. context.passTask();
  37. } else if (TASK_IS(3) && EVENT_TYPE_IS(MouseUp)) {
  38. if (event.key == MouseKeyEnum::Left) {
  39. context.finishTest(Grade::Passed);
  40. } else {
  41. // TODO: Say which key was triggered instead and suggest skipping with escape if it can not be found.
  42. }
  43. }
  44. }
  45. ,
  46. [](const KeyboardEvent& event, TestContext &context) {}
  47. ,
  48. false
  49. );
  50. } else {
  51. sendWarning(U"Skipped the left mouse button test due to settings.");
  52. }
  53. if (buttonCount >= 1 && verticalScroll) {
  54. target.pushConstruct(
  55. U"Mouse scroll test"
  56. ,
  57. [](AlignedImageRgbaU8 &canvas, TestContext &context) {
  58. image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
  59. // TODO: Show something moving in the background while scrolling to show the direction. Only pass once the end has been reached.
  60. if (TASK_IS(0)) {
  61. font_printLine(canvas, font_getDefault(), U"Scroll in the direction used to reach the top of a document by moving content down.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  62. } else if (TASK_IS(1)) {
  63. font_printLine(canvas, font_getDefault(), U"Click when you are down scrolling up.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  64. } else if (TASK_IS(2)) {
  65. font_printLine(canvas, font_getDefault(), U"Scroll in the direction used to reach the bottom of a document by moving content up.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  66. } else if (TASK_IS(3)) {
  67. font_printLine(canvas, font_getDefault(), U"Click when you are down scrolling down.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  68. }
  69. }
  70. ,
  71. [](const MouseEvent& event, TestContext &context) {
  72. // Due to many laptops having the scroll direction inverted by default so that draging down scrolls up
  73. // Comparing how scrolling works in external text editors would be a useful addition to this test,
  74. // because many users probably don't know what is scrolling up and what is scrolling down when the direction is inverted on a track-pad.
  75. if (TASK_IS(0) && EVENT_TYPE_IS(Scroll)) {
  76. if (event.key == MouseKeyEnum::ScrollUp) {
  77. context.passTask();
  78. } else if (event.key == MouseKeyEnum::ScrollDown) {
  79. // Just give a warning, because this test can be very
  80. sendWarning(U"Scroll down was detected when attempting to scroll up. Compare the scrolling direction of a textbox with an external text editor to ensure consistent behavior.\n");
  81. }
  82. } else if (TASK_IS(1) && EVENT_TYPE_IS(MouseDown)) {
  83. context.passTask();
  84. } else if (TASK_IS(2) && EVENT_TYPE_IS(Scroll)) {
  85. if (event.key == MouseKeyEnum::ScrollDown) {
  86. context.passTask();
  87. } else if (event.key == MouseKeyEnum::ScrollUp) {
  88. sendWarning(U"Scroll up was detected when attempting to scroll down. Compare the scrolling direction of a textbox with an external text editor to ensure consistent behavior.\n");
  89. }
  90. } else if (TASK_IS(3) && EVENT_TYPE_IS(MouseDown)) {
  91. context.finishTest(Grade::Passed);
  92. }
  93. }
  94. ,
  95. [](const KeyboardEvent& event, TestContext &context) {}
  96. ,
  97. false
  98. );
  99. } else {
  100. sendWarning(U"Skipped the vertical scroll test due to settings.\n");
  101. }
  102. // TODO: Create tests for other mouse buttons by reusing code in functions.
  103. // TODO: Create tests for keyboards, that display pressed physical keys on a QWERTY keyboard and unicode values of characters.
  104. // The actual printed values depend on language settings, so this might have to be checked manually.
  105. }