Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some joystick functions to input. Enables manipulation of mapping… #3272

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/os/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ void Input::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_mouse_button_pressed","button"),&Input::is_mouse_button_pressed);
ObjectTypeDB::bind_method(_MD("is_joy_button_pressed","device","button"),&Input::is_joy_button_pressed);
ObjectTypeDB::bind_method(_MD("is_action_pressed","action"),&Input::is_action_pressed);
ObjectTypeDB::bind_method(_MD("add_joy_mapping","mapping", "update_existing"),&Input::add_joy_mapping, DEFVAL(false));
ObjectTypeDB::bind_method(_MD("remove_joy_mapping","guid"),&Input::remove_joy_mapping);
ObjectTypeDB::bind_method(_MD("is_joy_known","device"),&Input::is_joy_known);
ObjectTypeDB::bind_method(_MD("get_joy_axis","device","axis"),&Input::get_joy_axis);
ObjectTypeDB::bind_method(_MD("get_joy_name","device"),&Input::get_joy_name);
ObjectTypeDB::bind_method(_MD("get_joy_guid","device"),&Input::get_joy_guid);
ObjectTypeDB::bind_method(_MD("get_accelerometer"),&Input::get_accelerometer);
//ObjectTypeDB::bind_method(_MD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want
ObjectTypeDB::bind_method(_MD("get_mouse_speed"),&Input::get_mouse_speed);
Expand Down
5 changes: 4 additions & 1 deletion core/os/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ class Input : public Object {
virtual float get_joy_axis(int p_device,int p_axis)=0;
virtual String get_joy_name(int p_idx)=0;
virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid)=0;

virtual void add_joy_mapping(String p_mapping, bool p_update_existing=false)=0;
virtual void remove_joy_mapping(String p_guid)=0;
virtual bool is_joy_known(int p_device)=0;
virtual String get_joy_guid(int p_device) const=0;

virtual Point2 get_mouse_pos() const=0;
virtual Point2 get_mouse_speed() const=0;
Expand Down
7 changes: 7 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,13 @@ float OS::get_time_scale() const {
return _time_scale;
}

bool OS::is_joy_known(int p_device) {
return true;
}

String OS::get_joy_guid(int p_device) const {
return "Default Joystick";
}

OS::OS() {
last_error=NULL;
Expand Down
3 changes: 3 additions & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ friend class Main;

_FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }

virtual bool is_joy_known(int p_device);
virtual String get_joy_guid(int p_device)const;

OS();
virtual ~OS();

Expand Down
154 changes: 131 additions & 23 deletions doc/base/classes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
<method name="convert">
<return type="Object">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="type" type="int">
</argument>
Expand All @@ -443,9 +443,9 @@
<method name="str">
<return type="String">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="..." type="var">
<argument index="1" name="..." type="Variant">
</argument>
<description>
Convert one or more arguments to strings in the best way possible.
Expand All @@ -454,9 +454,9 @@
<method name="str">
<return type="String">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="..." type="var">
<argument index="1" name="..." type="Variant">
</argument>
<description>
Convert one or more arguments to strings in the best way possible.
Expand All @@ -465,9 +465,9 @@
<method name="print">
<return type="Nil">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="..." type="var">
<argument index="1" name="..." type="Variant">
</argument>
<description>
Print one or more arguments to strings in the best way possible to a console line.
Expand All @@ -476,9 +476,9 @@
<method name="printt">
<return type="Nil">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="..." type="var">
<argument index="1" name="..." type="Variant">
</argument>
<description>
Print one or more arguments to the console with a tab between each argument.
Expand All @@ -487,19 +487,19 @@
<method name="prints">
<return type="Nil">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="..." type="var">
<argument index="1" name="..." type="Variant">
</argument>
<description>
</description>
</method>
<method name="printerr">
<return type="Nil">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="..." type="var">
<argument index="1" name="..." type="Variant">
</argument>
<description>
Print one or more arguments to strings in the best way possible to standard error line.
Expand All @@ -508,9 +508,9 @@
<method name="printraw">
<return type="Nil">
</return>
<argument index="0" name="what" type="var">
<argument index="0" name="what" type="Variant">
</argument>
<argument index="1" name="..." type="var">
<argument index="1" name="..." type="Variant">
</argument>
<description>
Print one or more arguments to strings in the best way possible to console. No newline is added at the end.
Expand All @@ -519,25 +519,40 @@
<method name="var2str">
<return type="String">
</return>
<argument index="0" name="var" type="var">
<argument index="0" name="var" type="Variant">
</argument>
<description>
Converts the value of a variable to a String.
</description>
</method>
<method name="str2var:Variant">
<return type="Nil">
<method name="str2var">
<return type="Variant">
</return>
<argument index="0" name="string" type="String">
</argument>
<description>
Converts the value of a String to a Variant.
</description>
</method>
<method name="var2bytes">
<return type="RawArray">
</return>
<argument index="0" name="var" type="Variant">
</argument>
<description>
</description>
</method>
<method name="bytes2var">
<return type="Variant">
</return>
<argument index="0" name="bytes" type="RawArray">
</argument>
<description>
</description>
</method>
<method name="range">
<return type="Array">
</return>
<argument index="0" name="..." type="var">
<argument index="0" name="..." type="Variant">
</argument>
<description>
Return an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial,final-1,increment).
Expand Down Expand Up @@ -573,12 +588,26 @@
<method name="hash">
<return type="int">
</return>
<argument index="0" name="var:Variant" type="var">
<argument index="0" name="var:Variant" type="Variant">
</argument>
<description>
Hashes the variable passed and returns an integer.
</description>
</method>
<method name="Color8">
<return type="Color">
</return>
<argument index="0" name="r8" type="int">
</argument>
<argument index="1" name="g8" type="int">
</argument>
<argument index="2" name="b8" type="int">
</argument>
<argument index="3" name="a8" type="int">
</argument>
<description>
</description>
</method>
<method name="print_stack">
<return type="Nil">
</return>
Expand Down Expand Up @@ -1371,6 +1400,10 @@
</constant>
<constant name="JOY_ANALOG_2_Y" value="5">
</constant>
<constant name="JOY_ANALOG_L2" value="6">
</constant>
<constant name="JOY_ANALOG_R2" value="7">
</constant>
<constant name="OK" value="0">
Functions that return [Error] return OK when everything went ok. Most functions don't return error anyway and/or just print errors to stdout.
</constant>
Expand Down Expand Up @@ -7561,6 +7594,14 @@
</member>
<member name="v" type="float">
</member>
<member name="r8" type="int">
</member>
<member name="g8" type="int">
</member>
<member name="b8" type="int">
</member>
<member name="a8" type="int">
</member>
</members>
<constants>
</constants>
Expand Down Expand Up @@ -7968,6 +8009,8 @@
</argument>
<argument index="1" name="key" type="String">
</argument>
<argument index="2" name="default" type="var" default="NULL">
</argument>
<description>
</description>
</method>
Expand Down Expand Up @@ -13625,6 +13668,7 @@ returns:= "username=user&amp;password=pass"
<argument index="1" name="button" type="int">
</argument>
<description>
Returns true if the joystick button at the given index is currently pressed. Returns false otherwise. (see JOY_* constans in [InputEvent])
</description>
</method>
<method name="is_action_pressed">
Expand All @@ -13635,6 +13679,31 @@ returns:= "username=user&amp;password=pass"
<description>
</description>
</method>
<method name="add_joy_mapping">
<argument index="0" name="mapping" type="String">
</argument>
<argument index="1" name="update_existing" type="bool" default="false">
</argument>
<description>
Add a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices.
</description>
</method>
<method name="remove_joy_mapping">
<argument index="0" name="guid" type="String">
</argument>
<description>
Removes all mappings from the internal db that match the given uid.
</description>
</method>
<method name="is_joy_known">
<return type="bool">
</return>
<argument index="0" name="device" type="int">
</argument>
<description>
Returns true if the specified device is known by the system. This means that it sets all button and axis indices exactly as defined in [InputEvent]. Unknown joysticks are not expected to match these constants, but you can still retrieve events from them.
</description>
</method>
<method name="get_joy_axis">
<return type="float">
</return>
Expand All @@ -13643,6 +13712,7 @@ returns:= "username=user&amp;password=pass"
<argument index="1" name="axis" type="int">
</argument>
<description>
Returns the current value of the joystick axis at given index (see JOY_* enum in [InputEvent])
</description>
</method>
<method name="get_joy_name">
Expand All @@ -13651,6 +13721,16 @@ returns:= "username=user&amp;password=pass"
<argument index="0" name="device" type="int">
</argument>
<description>
Returns the name of the joystick at the specified device index
</description>
</method>
<method name="get_joy_guid" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="device" type="int">
</argument>
<description>
Returns a SDL2 compatible device guid on platforms that use gamepad remapping. Returns "Default Gamepad" otherwise.
</description>
</method>
<method name="get_accelerometer">
Expand Down Expand Up @@ -15479,7 +15559,7 @@ returns:= "username=user&amp;password=pass"
</description>
</method>
<method name="get_collider_metadata" qualifiers="const">
<return type="var">
<return type="Variant">
</return>
<description>
Return the metadata of the shape that collided with this body. If there is no collision, it will return 0, so collisions must be checked first with [method is_colliding]. Aditionally, this metadata can not be set with [method Object.set_meta], it must be set with [method Physics2DServer.body_set_shape_metadata].
Expand Down Expand Up @@ -18971,6 +19051,8 @@ returns:= "username=user&amp;password=pass"
</constant>
<constant name="NOTIFICATION_UNPAUSED" value="15">
</constant>
<constant name="NOTIFICATION_INSTANCED" value="20">
</constant>
<constant name="PAUSE_MODE_INHERIT" value="0">
</constant>
<constant name="PAUSE_MODE_STOP" value="1">
Expand Down Expand Up @@ -19138,7 +19220,7 @@ returns:= "username=user&amp;password=pass"
<description>
</description>
</method>
<method name="get_relative_transform" qualifiers="const">
<method name="get_relative_transform_to_parent" qualifiers="const">
<return type="Matrix32">
</return>
<argument index="0" name="parent" type="Object">
Expand Down Expand Up @@ -20178,6 +20260,14 @@ returns:= "username=user&amp;password=pass"
Return the list of signals as an array of dictionaries.
</description>
</method>
<method name="get_signal_connection_list" qualifiers="const">
<return type="Array">
</return>
<argument index="0" name="signal" type="String">
</argument>
<description>
</description>
</method>
<method name="connect">
<return type="int">
</return>
Expand Down Expand Up @@ -21601,6 +21691,10 @@ returns:= "username=user&amp;password=pass"
<description>
</description>
</method>
<method name="reset">
<description>
</description>
</method>
<method name="set_use_local_space">
<argument index="0" name="enable" type="bool">
</argument>
Expand Down Expand Up @@ -29631,6 +29725,14 @@ This method controls whether the position between two cached points is interpola
<description>
</description>
</method>
<method name="has_group" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="name" type="String">
</argument>
<description>
</description>
</method>
<method name="set_auto_accept_quit">
<argument index="0" name="enabled" type="bool">
</argument>
Expand Down Expand Up @@ -33335,6 +33437,12 @@ This method controls whether the position between two cached points is interpola
</description>
</method>
</methods>
<signals>
<signal name="finished">
<description>
</description>
</signal>
</signals>
<constants>
</constants>
</class>
Expand Down
Loading