2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* input.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2018-01-01 13:40:08 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "input.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
|
|
|
|
#include "core/input_map.h"
|
|
|
|
#include "core/os/os.h"
|
|
|
|
#include "core/project_settings.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Input *Input::singleton = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Input *Input::get_singleton() {
|
|
|
|
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::set_mouse_mode(MouseMode p_mode) {
|
2018-10-04 07:17:59 +00:00
|
|
|
ERR_FAIL_INDEX((int)p_mode, 4);
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
Input::MouseMode Input::get_mouse_mode() const {
|
|
|
|
|
|
|
|
return (MouseMode)OS::get_singleton()->get_mouse_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_key_pressed", "scancode"), &Input::is_key_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &Input::is_action_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &Input::is_action_just_pressed);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &Input::is_action_just_released);
|
2018-02-21 21:06:34 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &Input::get_action_strength);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &Input::add_joy_mapping, DEFVAL(false));
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &Input::remove_joy_mapping);
|
2017-10-11 16:45:44 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("joy_connection_changed", "device", "connected", "name", "guid"), &Input::joy_connection_changed);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_joy_known", "device"), &Input::is_joy_known);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_axis", "device", "axis"), &Input::get_joy_axis);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_name", "device"), &Input::get_joy_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_guid", "device"), &Input::get_joy_guid);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_connected_joypads"), &Input::get_connected_joypads);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &Input::get_joy_button_string);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &Input::get_joy_button_index_from_string);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &Input::get_joy_axis_string);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string);
|
|
|
|
ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0));
|
|
|
|
ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &Input::stop_joy_vibration);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_gravity"), &Input::get_gravity);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_accelerometer"), &Input::get_accelerometer);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_magnetometer"), &Input::get_magnetometer);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_gyroscope"), &Input::get_gyroscope);
|
2017-03-29 15:29:38 +00:00
|
|
|
//ClassDB::bind_method(D_METHOD("get_mouse_position"),&Input::get_mouse_position); - this is not the function you want
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &Input::get_last_mouse_speed);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode);
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &Input::warp_mouse_position);
|
2018-11-17 20:45:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("action_press", "action", "strength"), &Input::action_press, DEFVAL(1.f));
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release);
|
2018-04-09 20:48:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW));
|
2017-11-10 10:50:11 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2()));
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE);
|
|
|
|
BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN);
|
|
|
|
BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED);
|
|
|
|
BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-11-10 10:50:11 +00:00
|
|
|
BIND_ENUM_CONSTANT(CURSOR_ARROW);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_IBEAM);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_CROSS);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_WAIT);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_BUSY);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_DRAG);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_CAN_DROP);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_VSIZE);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_HSIZE);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_MOVE);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_VSPLIT);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
|
|
|
|
BIND_ENUM_CONSTANT(CURSOR_HELP);
|
|
|
|
|
2018-04-06 07:09:40 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "device"), PropertyInfo(Variant::BOOL, "connected")));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
|
2015-01-03 16:03:13 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String pf = p_function;
|
2018-02-21 21:06:34 +00:00
|
|
|
if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) {
|
2015-01-03 16:03:13 +00:00
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
2017-07-19 20:00:46 +00:00
|
|
|
ProjectSettings::get_singleton()->get_property_list(&pinfo);
|
2015-01-03 16:03:13 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
|
|
|
const PropertyInfo &pi = E->get();
|
2015-01-03 16:03:13 +00:00
|
|
|
|
|
|
|
if (!pi.name.begins_with("input/"))
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
|
|
|
|
r_options->push_back("\"" + name + "\"");
|
2015-01-03 16:03:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Input::Input() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
singleton = this;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////
|