summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvolzhs <volzhs@gmail.com>2017-08-25 01:14:36 +0900
committervolzhs <volzhs@gmail.com>2017-08-25 01:14:36 +0900
commit62bb600b5ce72b46d8cedb3452652f66dcf74697 (patch)
tree6c2b6061ae8551f298b7dcc9529ecc3ac83405ec
parent05a678534433997c71f542ae1b3cecd35abde298 (diff)
Show proper string with InputEvent.as_text()
-rw-r--r--core/os/input_event.cpp77
-rw-r--r--core/os/input_event.h7
2 files changed, 84 insertions, 0 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index cb38eb67b6..c5f787b6c7 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -483,6 +483,38 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event) const {
return mb->button_index == button_index;
}
+String InputEventMouseButton::as_text() const {
+
+ String button_index_string = "";
+ switch (get_button_index()) {
+ case BUTTON_LEFT:
+ button_index_string = "BUTTON_LEFT";
+ break;
+ case BUTTON_RIGHT:
+ button_index_string = "BUTTON_RIGHT";
+ break;
+ case BUTTON_MIDDLE:
+ button_index_string = "BUTTON_MIDDLE";
+ break;
+ case BUTTON_WHEEL_UP:
+ button_index_string = "BUTTON_WHEEL_UP";
+ break;
+ case BUTTON_WHEEL_DOWN:
+ button_index_string = "BUTTON_WHEEL_DOWN";
+ break;
+ case BUTTON_WHEEL_LEFT:
+ button_index_string = "BUTTON_WHEEL_LEFT";
+ break;
+ case BUTTON_WHEEL_RIGHT:
+ button_index_string = "BUTTON_WHEEL_RIGHT";
+ break;
+ default:
+ button_index_string = itos(get_button_index());
+ break;
+ }
+ return "InputEventMouseButton : button_index=" + button_index_string + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + "), button_mask=" + itos(get_button_mask()) + ", doubleclick=" + (doubleclick ? "true" : "false");
+}
+
void InputEventMouseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
@@ -559,6 +591,26 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co
return mm;
}
+String InputEventMouseMotion::as_text() const {
+
+ String button_mask_string = "";
+ switch (get_button_mask()) {
+ case BUTTON_MASK_LEFT:
+ button_mask_string = "BUTTON_MASK_LEFT";
+ break;
+ case BUTTON_MASK_MIDDLE:
+ button_mask_string = "BUTTON_MASK_MIDDLE";
+ break;
+ case BUTTON_MASK_RIGHT:
+ button_mask_string = "BUTTON_MASK_RIGHT";
+ break;
+ default:
+ button_mask_string = itos(get_button_mask());
+ break;
+ }
+ return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
+}
+
void InputEventMouseMotion::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
@@ -609,6 +661,11 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event) const
return (axis == jm->axis && (axis_value < 0) == (jm->axis_value < 0));
}
+String InputEventJoypadMotion::as_text() const {
+
+ return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
+}
+
void InputEventJoypadMotion::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
@@ -665,6 +722,11 @@ bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event) const
return button_index == jb->button_index;
}
+String InputEventJoypadButton::as_text() const {
+
+ return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
+}
+
void InputEventJoypadButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
@@ -730,6 +792,11 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co
return st;
}
+String InputEventScreenTouch::as_text() const {
+
+ return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
+}
+
void InputEventScreenTouch::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
@@ -808,6 +875,11 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con
return sd;
}
+String InputEventScreenDrag::as_text() const {
+
+ return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
+}
+
void InputEventScreenDrag::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
@@ -857,6 +929,11 @@ bool InputEventAction::is_action(const StringName &p_action) const {
return action == p_action;
}
+String InputEventAction::as_text() const {
+
+ return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
+}
+
void InputEventAction::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
diff --git a/core/os/input_event.h b/core/os/input_event.h
index d1fd7cc90f..06d157b2b2 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -307,6 +307,7 @@ public:
virtual bool action_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const { return true; }
+ virtual String as_text() const;
InputEventMouseButton();
};
@@ -328,6 +329,7 @@ public:
Vector2 get_speed() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+ virtual String as_text() const;
InputEventMouseMotion();
};
@@ -352,6 +354,7 @@ public:
virtual bool action_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const { return true; }
+ virtual String as_text() const;
InputEventJoypadMotion();
};
@@ -378,6 +381,7 @@ public:
virtual bool action_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const { return true; }
+ virtual String as_text() const;
InputEventJoypadButton();
};
@@ -402,6 +406,7 @@ public:
virtual bool is_pressed() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+ virtual String as_text() const;
InputEventScreenTouch();
};
@@ -431,6 +436,7 @@ public:
Vector2 get_speed() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+ virtual String as_text() const;
InputEventScreenDrag();
};
@@ -455,6 +461,7 @@ public:
virtual bool is_action(const StringName &p_action) const;
virtual bool is_action_type() const { return true; }
+ virtual String as_text() const;
InputEventAction();
};