inputTest.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "inputTest.h"
  2. using namespace dsr;
  3. void inputTests_populate(List<Test> &target, int buttonCount, bool relative, bool verticalScroll) {
  4. // TODO: Make notes about which tests were skipped and why.
  5. if (buttonCount >= 1) {
  6. target.pushConstruct(
  7. U"Mouse drag test"
  8. ,
  9. [](AlignedImageRgbaU8 &canvas, TestContext &context) {
  10. image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
  11. if (context.taskIndex == 0) {
  12. font_printLine(canvas, font_getDefault(), U"Hover the cursor over the window.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  13. } else if (context.taskIndex == 1) {
  14. font_printLine(canvas, font_getDefault(), U"Press down the left mouse key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  15. } else if (context.taskIndex == 2) {
  16. 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));
  17. } else if (context.taskIndex == 3) {
  18. font_printLine(canvas, font_getDefault(), U"Release the left key.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
  19. }
  20. }
  21. ,
  22. [](const MouseEvent& event, TestContext &context) {
  23. if (context.taskIndex == 0 && event.mouseEventType == MouseEventType::MouseMove && !context.leftMouseDown && !context.middleMouseDown && !context.rightMouseDown) {
  24. context.passTask();
  25. } else if (context.taskIndex == 1 && event.mouseEventType == MouseEventType::MouseDown) {
  26. if (event.key == MouseKeyEnum::Left) {
  27. context.passTask();
  28. } else {
  29. // TODO: Say which key was triggered instead and suggest skipping with escape if it can not be found.
  30. }
  31. } else if (context.taskIndex == 2 && event.mouseEventType == MouseEventType::MouseMove && context.leftMouseDown) {
  32. context.passTask();
  33. } else if (context.taskIndex == 3 && event.mouseEventType == MouseEventType::MouseUp) {
  34. if (event.key == MouseKeyEnum::Left) {
  35. context.finishTest(Grade::Passed);
  36. } else {
  37. // TODO: Say which key was triggered instead and suggest skipping with escape if it can not be found.
  38. }
  39. }
  40. }
  41. ,
  42. [](const KeyboardEvent& event, TestContext &context) {}
  43. ,
  44. false
  45. );
  46. } else {
  47. sendWarning(U"Skipped the left mouse button test, because 0 mouse buttons were selected as available.");
  48. }
  49. }