2
0
Эх сурвалжийг харах

Made debug printing methods for all InputEvent types.

David Piuva 1 жил өмнө
parent
commit
728c034394

+ 104 - 1
Source/DFPSR/gui/InputEvent.cpp

@@ -25,7 +25,7 @@
 
 
 using namespace dsr;
 using namespace dsr;
 
 
-inline String dsr::getName(DsrKey v) {
+String dsr::getName(DsrKey v) {
 	if (v == DsrKey_Unhandled) {
 	if (v == DsrKey_Unhandled) {
 		return U"Other";
 		return U"Other";
 	} else if (v == DsrKey_Escape) {
 	} else if (v == DsrKey_Escape) {
@@ -171,3 +171,106 @@ String& dsr::string_toStreamIndented(String& target, const DsrKey& source, const
 	string_append(target, indentation, getName(source));
 	string_append(target, indentation, getName(source));
 	return target;
 	return target;
 }
 }
+
+String dsr::getName(KeyboardEventType v) {
+	if (v == KeyboardEventType::KeyDown) {
+		return U"KeyDown"; // Pressing down a key on the keyboard.
+	} else if (v == KeyboardEventType::KeyUp) {
+		return U"KeyUp"; // Releasing a key on the keyboard.
+	} else if (v == KeyboardEventType::KeyType) {
+		return U"KeyType"; // The event that is sent repeatedly after holding down a character for a while.
+	} else {
+		return U"Invalid keyboard event type";
+	}
+}
+
+String& dsr::string_toStreamIndented(String& target, const KeyboardEventType& source, const ReadableString& indentation) {
+	string_append(target, indentation, getName(source));
+	return target;
+}
+
+String dsr::getName(MouseKeyEnum v) {
+	if (v == MouseKeyEnum::NoKey) {
+		return U"NoKey"; // For mouse move events.
+	} else if (v == MouseKeyEnum::Left) {
+		return U"Left"; // For mouse up and down events.
+	} else if (v == MouseKeyEnum::Right) {
+		return U"Right"; // For mouse up and down events.
+	} else if (v == MouseKeyEnum::Middle) {
+		return U"Middle"; // For mouse up and down events.
+	} else if (v == MouseKeyEnum::ScrollUp) {
+		return U"ScrollUp"; // For scroll events.
+	} else if (v == MouseKeyEnum::ScrollDown) {
+		return U"ScrollDown"; // For scroll events.
+	} else {
+		return U"Invalid mouse key enumeration";
+	}
+}
+
+String& dsr::string_toStreamIndented(String& target, const MouseKeyEnum& source, const ReadableString& indentation) {
+	string_append(target, indentation, getName(source));
+	return target;
+}
+
+String dsr::getName(MouseEventType v) {
+	if (v == MouseEventType::MouseDown) {
+		return U"MouseDown";
+	} else if (v == MouseEventType::MouseUp) {
+		return U"MouseUp";
+	} else if (v == MouseEventType::MouseMove) {
+		return U"MouseMove";
+	} else if (v == MouseEventType::Scroll) {
+		return U"Scroll";
+	} else {
+		return U"Invalid mouse event type";
+	}
+}
+
+String& dsr::string_toStreamIndented(String& target, const MouseEventType& source, const ReadableString& indentation) {
+	string_append(target, indentation, getName(source));
+	return target;
+}
+
+String dsr::getName(WindowEventType v) {
+	if (v == WindowEventType::Close) {
+		return U"Close";
+	} else if (v == WindowEventType::Redraw) {
+		return U"Redraw";
+	} else {
+		return U"Invalid window event type";
+	}
+}
+
+String& dsr::string_toStreamIndented(String& target, const WindowEventType& source, const ReadableString& indentation) {
+	string_append(target, indentation, getName(source));
+	return target;
+}
+
+String& dsr::string_toStreamIndented(String& target, const KeyboardEvent& source, const ReadableString& indentation) {
+	string_append(target, indentation, U"KeyboardEvent(");
+	string_append(target, U"keyboardEventType = ", source.keyboardEventType);
+	string_append(target, U", dsrKey = ", source.dsrKey);
+	string_append(target, U", character = ", source.character);
+	string_append(target, U")");
+	return target;
+}
+
+String& dsr::string_toStreamIndented(String& target, const MouseEvent& source, const ReadableString& indentation) {
+	string_append(target, indentation, U"MouseEvent(");
+	string_append(target, U"mouseEventType = ", source.mouseEventType);
+	// TODO: Assert that only the keys allowed by the mouse event type are given.
+	string_append(target, U", key = ", source.key);
+	string_append(target, U", position = ", source.position);
+	string_append(target, U")");
+	return target;
+}
+
+String& dsr::string_toStreamIndented(String& target, const WindowEvent& source, const ReadableString& indentation) {
+	string_append(target, indentation, U"WindowEvent(");
+	string_append(target, U"windowEventType = ", source.windowEventType);
+	// TODO: Assert that width and height are zero when not used by the event type.
+	string_append(target, U", width = ", source.width);
+	string_append(target, U", height = ", source.height);
+	string_append(target, U")");
+	return target;
+}

+ 15 - 3
Source/DFPSR/gui/InputEvent.h

@@ -57,9 +57,6 @@ enum DsrKey {
 	DsrKey_Unhandled
 	DsrKey_Unhandled
 };
 };
 
 
-inline String getName(DsrKey v);
-String& string_toStreamIndented(String& target, const DsrKey& source, const ReadableString& indentation);
-
 class KeyboardEvent : public InputEvent {
 class KeyboardEvent : public InputEvent {
 public:
 public:
 	// What the user did to the key.
 	// What the user did to the key.
@@ -133,6 +130,21 @@ static SizeCallback sizeCallback = [](int width, int height) {};
 static KeyboardCallback keyboardCallback = [](const KeyboardEvent& event) {};
 static KeyboardCallback keyboardCallback = [](const KeyboardEvent& event) {};
 static MouseCallback mouseCallback = [](const MouseEvent& event) {};
 static MouseCallback mouseCallback = [](const MouseEvent& event) {};
 
 
+// Conversion to text for easy debugging.
+String getName(DsrKey v);
+String getName(KeyboardEventType v);
+String getName(MouseKeyEnum v);
+String getName(MouseEventType v);
+String getName(WindowEventType v);
+String& string_toStreamIndented(String& target, const DsrKey& source, const ReadableString& indentation);
+String& string_toStreamIndented(String& target, const KeyboardEventType& source, const ReadableString& indentation);
+String& string_toStreamIndented(String& target, const MouseKeyEnum& source, const ReadableString& indentation);
+String& string_toStreamIndented(String& target, const MouseEventType& source, const ReadableString& indentation);
+String& string_toStreamIndented(String& target, const WindowEventType& source, const ReadableString& indentation);
+String& string_toStreamIndented(String& target, const KeyboardEvent& source, const ReadableString& indentation);
+String& string_toStreamIndented(String& target, const MouseEvent& source, const ReadableString& indentation);
+String& string_toStreamIndented(String& target, const WindowEvent& source, const ReadableString& indentation);
+
 }
 }
 
 
 #endif
 #endif