inputTest.cpp 7.9 KB

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