[gnome-games/wip/aplazas/gamepad-config: 16/26] gamepad: Allow more hat mappings in MappingBuilder
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/aplazas/gamepad-config: 16/26] gamepad: Allow more hat mappings in MappingBuilder
- Date: Mon, 10 Jul 2017 11:38:29 +0000 (UTC)
commit 7062d47c7067f604530f9cc2129acae288fd100d
Author: theawless <theawless gmail com>
Date: Sun Jun 18 17:54:07 2017 +0530
gamepad: Allow more hat mappings in MappingBuilder
Save previous hat axis and value to build the position for the current
hat press. This way we can support hat to buttons and axis mappings.
https://bugzilla.gnome.org/show_bug.cgi?id=780754
src/gamepad/gamepad-mapping-builder.vala | 27 ++++++++++++---------------
src/ui/gamepad-mapper.vala | 2 +-
2 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/src/gamepad/gamepad-mapping-builder.vala b/src/gamepad/gamepad-mapping-builder.vala
index d9a7a40..0adaaf0 100644
--- a/src/gamepad/gamepad-mapping-builder.vala
+++ b/src/gamepad/gamepad-mapping-builder.vala
@@ -9,10 +9,12 @@ private class Games.GamepadMappingBuilder : Object {
"back", "guide", "start",
"leftx", "rightx", "lefty", "righty" };
private string[] destinations;
+ private GamepadDPad[] dpads;
construct {
destinations = new string[sources.length];
inputs = GamepadInput.get_standard_inputs ();
+ dpads = new GamepadDPad[]{};
}
public string build_sdl_string () {
@@ -37,25 +39,20 @@ private class Games.GamepadMappingBuilder : Object {
return add_destination (destination_string, source);
}
- public bool set_hat_mapping (uint8 hardware_index, int32 hardware_value, GamepadInput source) {
+ public bool set_hat_mapping (uint8 hardware_index, int32 hardware_value, uint16 axis, GamepadInput
source) {
var destination_string = "h" + hardware_index.to_string ();
destination_string += ".";
- // doesn't work for many cases
- switch (source.code) {
- case EventCode.BTN_DPAD_UP:
- case EventCode.BTN_DPAD_DOWN:
- destination_string += (hardware_value == 1) ? "1" : "3";
+ while (dpads.length <= hardware_index)
+ dpads += GamepadDPad ();
+ var dpad = dpads[hardware_index];
+ var changed_value = hardware_value == 0 ? dpad.axis_values[axis] : hardware_value;
+ dpad.axis_values[axis] = hardware_value;
- break;
- case EventCode.BTN_DPAD_LEFT:
- case EventCode.BTN_DPAD_RIGHT:
- destination_string += (hardware_value == 1) ? "4" : "2";
-
- break;
- default:
- break;
- }
+ // add 4 so the remainder is positive
+ var dpad_position = (changed_value + axis + 4) % 4;
+ var dpad_position_2pow = Math.pow (2, dpad_position);
+ destination_string += dpad_position_2pow.to_string ();
return add_destination (destination_string, source);
}
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index e64a5b5..7675e35 100644
--- a/src/ui/gamepad-mapper.vala
+++ b/src/ui/gamepad-mapper.vala
@@ -167,7 +167,7 @@ private class Games.GamepadMapper : Gtk.Box {
if (event.gamepad_hat.value == 0)
return;
- if (!mapping_builder.set_hat_mapping (event.gamepad_hat.hardware_index,
event.gamepad_hat.value, input)) {
+ if (!mapping_builder.set_hat_mapping (event.gamepad_hat.hardware_index,
event.gamepad_hat.value, event.gamepad_hat.axis, input)) {
error_message.label = _("This hat is already in use");
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]