inputTest.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 >= 3) {
  7. target.pushConstruct(
  8. U"Mouse button 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"Press down the left mouse button, .", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  14. } else if (TASK_IS(1)) {
  15. font_printLine(canvas, font_getDefault(), U"Release the left mouse button.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  16. } else if (TASK_IS(2)) {
  17. font_printLine(canvas, font_getDefault(), U"Press down the right mouse button.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  18. } else if (TASK_IS(3)) {
  19. font_printLine(canvas, font_getDefault(), U"Release the right mouse button.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  20. } else if (TASK_IS(4)) {
  21. font_printLine(canvas, font_getDefault(), U"Press down the middle mouse button.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  22. } else if (TASK_IS(5)) {
  23. font_printLine(canvas, font_getDefault(), U"Release the middle mouse button.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  24. }
  25. // TODO: Draw expanding circles from lowering and raising buttons together with names of the keys used.
  26. // TODO: Draw fading lines from move events.
  27. // TODO: Make a reusable drawing system to be enabled or disabled as a reusable mouse visualization feature.
  28. }
  29. ,
  30. [](const MouseEvent& event, TestContext &context) {
  31. if (EVENT_TYPE_IS(MouseDown)) {
  32. if (TASK_IS(0) && event.key == MouseKeyEnum::Left) {
  33. context.passTask();
  34. } else if (TASK_IS(2) && event.key == MouseKeyEnum::Right) {
  35. context.passTask();
  36. } else if (TASK_IS(4) && event.key == MouseKeyEnum::Middle) {
  37. context.passTask();
  38. } else {
  39. sendWarning(U"Detected a different key!\n");
  40. }
  41. } else if (EVENT_TYPE_IS(MouseUp)) {
  42. if (TASK_IS(1) && event.key == MouseKeyEnum::Left) {
  43. context.passTask();
  44. } else if (TASK_IS(3) && event.key == MouseKeyEnum::Right) {
  45. context.passTask();
  46. } else if (TASK_IS(5) && event.key == MouseKeyEnum::Middle) {
  47. context.finishTest(Grade::Passed);
  48. } else {
  49. sendWarning(U"Detected a different key!\n");
  50. }
  51. }
  52. }
  53. ,
  54. [](const KeyboardEvent& event, TestContext &context) {
  55. sendWarning(U"Detected a keyboard event with ", event.dsrKey, " instead of a mouse button!\n");
  56. }
  57. ,
  58. false
  59. );
  60. } else {
  61. sendWarning(U"Skipped the left mouse button test due to settings.");
  62. }
  63. if (buttonCount >= 1) {
  64. target.pushConstruct(
  65. U"Mouse drag test"
  66. ,
  67. [](AlignedImageRgbaU8 &canvas, TestContext &context) {
  68. image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
  69. if (TASK_IS(0)) {
  70. font_printLine(canvas, font_getDefault(), U"Hover the cursor over the window.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  71. } else if (TASK_IS(1)) {
  72. font_printLine(canvas, font_getDefault(), U"Press down the left mouse key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  73. } else if (TASK_IS(2)) {
  74. 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));
  75. } else if (TASK_IS(3)) {
  76. font_printLine(canvas, font_getDefault(), U"Release the left key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  77. }
  78. // TODO: Draw expanding circles from lowering and raising buttons together with names of the keys used.
  79. // TODO: Draw fading lines from move events.
  80. // TODO: Make a reusable drawing system to be enabled or disabled as a reusable mouse visualization feature.
  81. }
  82. ,
  83. [](const MouseEvent& event, TestContext &context) {
  84. if (TASK_IS(0) && EVENT_TYPE_IS(MouseMove) && !context.leftMouseDown && !context.middleMouseDown && !context.rightMouseDown) {
  85. context.passTask();
  86. } else if (TASK_IS(1) && EVENT_TYPE_IS(MouseDown)) {
  87. if (event.key == MouseKeyEnum::Left) {
  88. context.passTask();
  89. } else {
  90. // TODO: Say which key was triggered instead and suggest skipping with escape if it can not be found.
  91. }
  92. } else if (TASK_IS(2) && EVENT_TYPE_IS(MouseMove) && context.leftMouseDown) {
  93. context.passTask();
  94. } else if (TASK_IS(3) && EVENT_TYPE_IS(MouseUp)) {
  95. if (event.key == MouseKeyEnum::Left) {
  96. context.finishTest(Grade::Passed);
  97. } else {
  98. // TODO: Say which key was triggered instead and suggest skipping with escape if it can not be found.
  99. }
  100. }
  101. }
  102. ,
  103. [](const KeyboardEvent& event, TestContext &context) {}
  104. ,
  105. false
  106. );
  107. } else {
  108. sendWarning(U"Skipped the left mouse button test due to settings.");
  109. }
  110. if (buttonCount >= 1 && verticalScroll) {
  111. target.pushConstruct(
  112. U"Mouse scroll test"
  113. ,
  114. [](AlignedImageRgbaU8 &canvas, TestContext &context) {
  115. image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
  116. // TODO: Show something moving in the background while scrolling to show the direction. Only pass once the end has been reached.
  117. if (TASK_IS(0)) {
  118. 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));
  119. } else if (TASK_IS(1)) {
  120. font_printLine(canvas, font_getDefault(), U"Click when you are down scrolling up.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  121. } else if (TASK_IS(2)) {
  122. 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));
  123. } else if (TASK_IS(3)) {
  124. font_printLine(canvas, font_getDefault(), U"Click when you are down scrolling down.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  125. }
  126. }
  127. ,
  128. [](const MouseEvent& event, TestContext &context) {
  129. // Due to many laptops having the scroll direction inverted by default so that draging down scrolls up
  130. // Comparing how scrolling works in external text editors would be a useful addition to this test,
  131. // 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.
  132. if (TASK_IS(0) && EVENT_TYPE_IS(Scroll)) {
  133. if (event.key == MouseKeyEnum::ScrollUp) {
  134. context.passTask();
  135. } else if (event.key == MouseKeyEnum::ScrollDown) {
  136. // Just give a warning, because this test can be very
  137. 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");
  138. }
  139. } else if (TASK_IS(1) && EVENT_TYPE_IS(MouseDown)) {
  140. context.passTask();
  141. } else if (TASK_IS(2) && EVENT_TYPE_IS(Scroll)) {
  142. if (event.key == MouseKeyEnum::ScrollDown) {
  143. context.passTask();
  144. } else if (event.key == MouseKeyEnum::ScrollUp) {
  145. 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");
  146. }
  147. } else if (TASK_IS(3) && EVENT_TYPE_IS(MouseDown)) {
  148. context.finishTest(Grade::Passed);
  149. }
  150. }
  151. ,
  152. [](const KeyboardEvent& event, TestContext &context) {}
  153. ,
  154. false
  155. );
  156. } else {
  157. sendWarning(U"Skipped the vertical scroll test due to settings.\n");
  158. }
  159. // TODO: Create tests for other mouse buttons by reusing code in functions.
  160. // TODO: Create tests for keyboards, that display pressed physical keys on a QWERTY keyboard and unicode values of characters.
  161. // The actual printed values depend on language settings, so this might have to be checked manually.
  162. }