inputTest.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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, because no mouse buttons were told to be available in the call to inputTests_populate.");
  52. }
  53. // TODO: Create tests for other mouse buttons by reusing code in functions.
  54. // TODO: Create tests for keyboards, that display pressed physical keys on a QWERTY keyboard and unicode values of characters.
  55. // The actual printed values depend on language settings, so this might have to be checked manually.
  56. }