Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
73a7b914
Commit
73a7b914
authored
Sep 26, 2016
by
Rémi Verschelde
Committed by
GitHub
Sep 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6568 from Hinsbart/joy_names
Add functions to get readable names for joystick events
parents
db1a9863
e0fcd933
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
0 deletions
+72
-0
input.cpp
core/os/input.cpp
+4
-0
input.h
core/os/input.h
+5
-0
input_default.cpp
main/input_default.cpp
+58
-0
input_default.h
main/input_default.h
+5
-0
No files found.
core/os/input.cpp
View file @
73a7b914
...
...
@@ -64,6 +64,10 @@ void Input::_bind_methods() {
ObjectTypeDB
::
bind_method
(
_MD
(
"get_connected_joysticks"
),
&
Input
::
get_connected_joysticks
);
ObjectTypeDB
::
bind_method
(
_MD
(
"get_joy_vibration_strength"
,
"device"
),
&
Input
::
get_joy_vibration_strength
);
ObjectTypeDB
::
bind_method
(
_MD
(
"get_joy_vibration_duration"
,
"device"
),
&
Input
::
get_joy_vibration_duration
);
ObjectTypeDB
::
bind_method
(
_MD
(
"get_joy_button_string"
,
"button_index"
),
&
Input
::
get_joy_button_string
);
ObjectTypeDB
::
bind_method
(
_MD
(
"get_joy_button_index_from_string"
,
"button"
),
&
Input
::
get_joy_button_index_from_string
);
ObjectTypeDB
::
bind_method
(
_MD
(
"get_joy_axis_string"
,
"axis_index"
),
&
Input
::
get_joy_axis_string
);
ObjectTypeDB
::
bind_method
(
_MD
(
"get_joy_axis_index_from_string"
,
"axis"
),
&
Input
::
get_joy_axis_index_from_string
);
ObjectTypeDB
::
bind_method
(
_MD
(
"start_joy_vibration"
,
"device"
,
"weak_magnitude"
,
"strong_magnitude"
,
"duration"
),
&
Input
::
start_joy_vibration
,
DEFVAL
(
0
));
ObjectTypeDB
::
bind_method
(
_MD
(
"stop_joy_vibration"
,
"device"
),
&
Input
::
stop_joy_vibration
);
ObjectTypeDB
::
bind_method
(
_MD
(
"get_accelerometer"
),
&
Input
::
get_accelerometer
);
...
...
core/os/input.h
View file @
73a7b914
...
...
@@ -96,6 +96,11 @@ public:
virtual
void
set_custom_mouse_cursor
(
const
RES
&
p_cursor
,
const
Vector2
&
p_hotspot
=
Vector2
())
=
0
;
virtual
void
set_mouse_in_window
(
bool
p_in_window
)
=
0
;
virtual
String
get_joy_button_string
(
int
p_button
)
=
0
;
virtual
String
get_joy_axis_string
(
int
p_axis
)
=
0
;
virtual
int
get_joy_button_index_from_string
(
String
p_button
)
=
0
;
virtual
int
get_joy_axis_index_from_string
(
String
p_axis
)
=
0
;
Input
();
};
...
...
main/input_default.cpp
View file @
73a7b914
...
...
@@ -1159,3 +1159,61 @@ Array InputDefault::get_connected_joysticks() {
}
return
ret
;
}
static
const
char
*
_buttons
[]
=
{
"Face Button Bottom"
,
"Face Button Right"
,
"Face Button Left"
,
"Face Button Top"
,
"L"
,
"R"
,
"L2"
,
"R2"
,
"L3"
,
"R3"
,
"Select"
,
"Start"
,
"DPAD Up"
,
"DPAD Down"
,
"DPAD Left"
,
"DPAD Right"
};
static
const
char
*
_axes
[]
=
{
"Left Stick X"
,
"Left Stick Y"
,
"Right Stick X"
,
"Right Stick Y"
,
""
,
""
,
"L2"
,
"R2"
};
String
InputDefault
::
get_joy_button_string
(
int
p_button
)
{
ERR_FAIL_INDEX_V
(
p_button
,
JOY_BUTTON_MAX
,
""
);
return
_buttons
[
p_button
];
}
int
InputDefault
::
get_joy_button_index_from_string
(
String
p_button
)
{
for
(
int
i
=
0
;
i
<
JOY_BUTTON_MAX
;
i
++
)
{
if
(
p_button
==
_buttons
[
i
])
{
return
i
;
}
}
ERR_FAIL_V
(
-
1
);
}
String
InputDefault
::
get_joy_axis_string
(
int
p_axis
)
{
ERR_FAIL_INDEX_V
(
p_axis
,
JOY_AXIS_MAX
,
""
);
return
_axes
[
p_axis
];
}
int
InputDefault
::
get_joy_axis_index_from_string
(
String
p_axis
)
{
for
(
int
i
=
0
;
i
<
JOY_AXIS_MAX
;
i
++
)
{
if
(
p_axis
==
_axes
[
i
])
{
return
i
;
}
}
ERR_FAIL_V
(
-
1
);
}
main/input_default.h
View file @
73a7b914
...
...
@@ -235,6 +235,11 @@ public:
virtual
bool
is_joy_known
(
int
p_device
);
virtual
String
get_joy_guid
(
int
p_device
)
const
;
virtual
String
get_joy_button_string
(
int
p_button
);
virtual
String
get_joy_axis_string
(
int
p_axis
);
virtual
int
get_joy_axis_index_from_string
(
String
p_axis
);
virtual
int
get_joy_button_index_from_string
(
String
p_button
);
bool
is_joy_mapped
(
int
p_device
);
String
get_joy_guid_remapped
(
int
p_device
)
const
;
void
set_fallback_mapping
(
String
p_guid
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment