[gnome-games/wip/abhinavsingh/gamepad-config: 18/23] gamepad: Allow more hat mappings in MappingBuilder
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 18/23] gamepad: Allow more hat mappings in MappingBuilder
- Date: Tue, 20 Jun 2017 20:53:07 +0000 (UTC)
commit 48162a1b23f503b70f8384ce3509ccb8db8c9f8e
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.
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 c5ffc28..30ea686 100644
--- a/src/gamepad/gamepad-mapping-builder.vala
+++ b/src/gamepad/gamepad-mapping-builder.vala
@@ -11,10 +11,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 GamepadMappingBuilder (Gamepad gamepad) {
@@ -44,25 +46,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 e4dca61..9ce6af8 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]