Browse Source

Displaying the position, which should overlap with the cursor.

David Piuva 1 year ago
parent
commit
40f5a7068d

+ 7 - 0
Source/SDK/integrationTest/Test.cpp

@@ -35,3 +35,10 @@ void TestContext::finishTest(Grade result) {
 	testIndex++;
 	taskIndex = 0;
 }
+
+void TestContext::drawAides(AlignedImageRgbaU8 &canvas) {
+	int width = image_getWidth(canvas);
+	int height = image_getHeight(canvas);
+	draw_rectangle(canvas, IRect(0, this->lastPosition.y - 1, width, 3), ColorRgbaI32(0, 0, 0, 255));
+	draw_rectangle(canvas, IRect(this->lastPosition.x - 1, 0, 3, height), ColorRgbaI32(0, 0, 0, 255));
+}

+ 4 - 0
Source/SDK/integrationTest/Test.h

@@ -40,9 +40,13 @@ struct TestContext {
 	// Call when completing a test.
 	void finishTest(Grade result);
 
+	void drawAides(dsr::AlignedImageRgbaU8 &canvas);
+
 	bool leftMouseDown = false;
 	bool middleMouseDown = false;
 	bool rightMouseDown = false;
 
+	dsr::IVector2D lastPosition;
+
 	TestContext() {}
 };

+ 7 - 0
Source/SDK/integrationTest/main.cpp

@@ -61,6 +61,9 @@ void dsrMain(List<String> args) {
 	// TODO: Move to a method taking window as the argument in Test.cpp.
 	window_setMouseEvent(window, [](const MouseEvent& event) {
 		if (event.mouseEventType == MouseEventType::MouseDown) {
+			if (context.lastPosition != event.position) {
+				sendWarning(U"A mouse (button) down event changed the cursor location! Unless the window moved while the mouse was standing still, something might be wrong. Check if mouse move events are missing, off or arriving too late.\n");
+			}
 			if (event.key == MouseKeyEnum::Left) {
 				context.leftMouseDown = true;
 			} else if (event.key == MouseKeyEnum::Middle) {
@@ -69,6 +72,9 @@ void dsrMain(List<String> args) {
 				context.rightMouseDown = true;
 			}
 		} else if (event.mouseEventType == MouseEventType::MouseUp) {
+			if (context.lastPosition != event.position) {
+				sendWarning(U"A mouse (button) up event changed the cursor location! Unless the window moved while the mouse was standing still, something might be wrong. Check if mouse move events are missing, off or arriving too late.\n");
+			}
 			if (event.key == MouseKeyEnum::Left) {
 				context.leftMouseDown = false;
 			} else if (event.key == MouseKeyEnum::Middle) {
@@ -77,6 +83,7 @@ void dsrMain(List<String> args) {
 				context.rightMouseDown = false;
 			}
 		}
+		context.lastPosition = event.position;
 		if (context.testIndex >= 0 && context.testIndex < context.tests.length()) {
 			context.tests[context.testIndex].mouseCallback(event, context);
 		}

+ 5 - 2
Source/SDK/integrationTest/tests/inputTest.cpp

@@ -13,6 +13,7 @@ void inputTests_populate(List<Test> &target, int buttonCount, bool relative, boo
 		,
 			[](AlignedImageRgbaU8 &canvas, TestContext &context) {
 				image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
+				context.drawAides(canvas);
 				if (TASK_IS(0)) {
 					font_printLine(canvas, font_getDefault(), U"Press down the left mouse button, .", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
 				} else if (TASK_IS(1)) {
@@ -62,7 +63,7 @@ void inputTests_populate(List<Test> &target, int buttonCount, bool relative, boo
 			false
 		);
 	} else {
-		sendWarning(U"Skipped the left mouse button test due to settings.");
+		sendWarning(U"Skipped the mouse button test due to settings.\n");
 	}
 
 	if (buttonCount >= 1) {
@@ -71,6 +72,7 @@ void inputTests_populate(List<Test> &target, int buttonCount, bool relative, boo
 		,
 			[](AlignedImageRgbaU8 &canvas, TestContext &context) {
 				image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
+				context.drawAides(canvas);
 				if (TASK_IS(0)) {
 					font_printLine(canvas, font_getDefault(), U"Hover the cursor over the window.", IVector2D(40, 40), ColorRgbaI32(0, 0, 0, 255));
 				} else if (TASK_IS(1)) {
@@ -110,7 +112,7 @@ void inputTests_populate(List<Test> &target, int buttonCount, bool relative, boo
 			false
 		);
 	} else {
-		sendWarning(U"Skipped the left mouse button test due to settings.");
+		sendWarning(U"Skipped the mouse button drag test due to settings.\n");
 	}
 	if (buttonCount >= 1 && verticalScroll) {
 		target.pushConstruct(
@@ -118,6 +120,7 @@ void inputTests_populate(List<Test> &target, int buttonCount, bool relative, boo
 		,
 			[](AlignedImageRgbaU8 &canvas, TestContext &context) {
 				image_fill(canvas, ColorRgbaI32(255, 255, 255, 255));
+				context.drawAides(canvas);
 				// TODO: Show something moving in the background while scrolling to show the direction. Only pass once the end has been reached.
 				if (TASK_IS(0)) {
 					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));