Show proper string with InputEvent.as_text()

This commit is contained in:
volzhs 2017-08-25 01:14:36 +09:00
parent 05a6785344
commit 62bb600b5c
2 changed files with 84 additions and 0 deletions

View File

@ -483,6 +483,38 @@ bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event) const {
return mb->button_index == button_index; 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() { void InputEventMouseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor); 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; 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() { void InputEventMouseMotion::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative); 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)); 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() { void InputEventJoypadMotion::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis); 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; 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() { void InputEventJoypadButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index); 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; return st;
} }
String InputEventScreenTouch::as_text() const {
return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")";
}
void InputEventScreenTouch::_bind_methods() { void InputEventScreenTouch::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index); 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; 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() { void InputEventScreenDrag::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index); 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; return action == p_action;
} }
String InputEventAction::as_text() const {
return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false");
}
void InputEventAction::_bind_methods() { void InputEventAction::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action); ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);

View File

@ -307,6 +307,7 @@ public:
virtual bool action_match(const Ref<InputEvent> &p_event) const; virtual bool action_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const { return true; } virtual bool is_action_type() const { return true; }
virtual String as_text() const;
InputEventMouseButton(); InputEventMouseButton();
}; };
@ -328,6 +329,7 @@ public:
Vector2 get_speed() const; Vector2 get_speed() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
InputEventMouseMotion(); InputEventMouseMotion();
}; };
@ -352,6 +354,7 @@ public:
virtual bool action_match(const Ref<InputEvent> &p_event) const; virtual bool action_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const { return true; } virtual bool is_action_type() const { return true; }
virtual String as_text() const;
InputEventJoypadMotion(); InputEventJoypadMotion();
}; };
@ -378,6 +381,7 @@ public:
virtual bool action_match(const Ref<InputEvent> &p_event) const; virtual bool action_match(const Ref<InputEvent> &p_event) const;
virtual bool is_action_type() const { return true; } virtual bool is_action_type() const { return true; }
virtual String as_text() const;
InputEventJoypadButton(); InputEventJoypadButton();
}; };
@ -402,6 +406,7 @@ public:
virtual bool is_pressed() const; virtual bool is_pressed() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
InputEventScreenTouch(); InputEventScreenTouch();
}; };
@ -431,6 +436,7 @@ public:
Vector2 get_speed() const; Vector2 get_speed() const;
virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
virtual String as_text() const;
InputEventScreenDrag(); InputEventScreenDrag();
}; };
@ -455,6 +461,7 @@ public:
virtual bool is_action(const StringName &p_action) const; virtual bool is_action(const StringName &p_action) const;
virtual bool is_action_type() const { return true; } virtual bool is_action_type() const { return true; }
virtual String as_text() const;
InputEventAction(); InputEventAction();
}; };