[gnome-games/wip/exalm/gameapd: 11/14] gamepad-view: Support analog sticks
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/gameapd: 11/14] gamepad-view: Support analog sticks
- Date: Wed, 4 Mar 2020 16:51:25 +0000 (UTC)
commit c10ebdf932c0113574974b03c682b25771fd72ef
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Mar 4 20:10:45 2020 +0500
gamepad-view: Support analog sticks
Currently we show analog sticks by highlighting either horizontal or
vertical part of the image. Allow showing the position precisely
instead.
src/ui/gamepad-view-configuration.vala | 9 +++++++++
src/ui/gamepad-view.vala | 37 +++++++++++++++++++++++++++++++---
2 files changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/src/ui/gamepad-view-configuration.vala b/src/ui/gamepad-view-configuration.vala
index 8f3fdb52..cd65e24f 100644
--- a/src/ui/gamepad-view-configuration.vala
+++ b/src/ui/gamepad-view-configuration.vala
@@ -30,9 +30,17 @@ namespace Games {
string path;
}
+ private struct GamepadAnalogPath {
+ GamepadInput input_x;
+ GamepadInput input_y;
+ double offset_radius;
+ string path;
+ }
+
private struct GamepadViewConfiguration {
string svg_path;
GamepadButtonPath[] button_paths;
+ GamepadAnalogPath[] analog_paths;
string[] background_paths;
public static GamepadViewConfiguration get_default () {
@@ -40,6 +48,7 @@ namespace Games {
conf.svg_path = "/org/gnome/Games/gamepads/standard-gamepad.svg";
conf.button_paths = STANDARD_GAMEPAD_BUTTON_PATHS;
+ conf.analog_paths = {};
conf.background_paths = {};
return conf;
diff --git a/src/ui/gamepad-view.vala b/src/ui/gamepad-view.vala
index d986d764..8bbd886a 100644
--- a/src/ui/gamepad-view.vala
+++ b/src/ui/gamepad-view.vala
@@ -3,6 +3,8 @@
private class Games.GamepadView : Gtk.DrawingArea {
private struct InputState {
bool highlight;
+ double offset_x;
+ double offset_y;
}
private Rsvg.Handle handle;
@@ -44,6 +46,13 @@ private class Games.GamepadView : Gtk.DrawingArea {
input_state[path.path] = {};
}
+ foreach (var path in configuration.analog_paths) {
+ if (path.path in input_state)
+ continue;
+
+ input_state[path.path] = {};
+ }
+
reset ();
}
}
@@ -72,6 +81,8 @@ private class Games.GamepadView : Gtk.DrawingArea {
public void reset () {
input_state.foreach ((path, state) => {
state.highlight = false;
+ state.offset_x = 0;
+ state.offset_y = 0;
});
queue_draw ();
@@ -92,6 +103,24 @@ private class Games.GamepadView : Gtk.DrawingArea {
return false;
}
+ public bool set_analog (GamepadInput input, double value) {
+ foreach (var path in configuration.analog_paths) {
+ if (input != path.input_x && input != path.input_y)
+ continue;
+
+ if (input == path.input_x)
+ input_state[path.path].offset_x = value * path.offset_radius;
+ else
+ input_state[path.path].offset_y = value * path.offset_radius;
+
+ queue_draw ();
+
+ return true;
+ }
+
+ return false;
+ }
+
public override bool draw (Cairo.Context context) {
double x, y, scale;
calculate_image_dimensions (out x, out y, out scale);
@@ -103,7 +132,7 @@ private class Games.GamepadView : Gtk.DrawingArea {
Gdk.RGBA color;
get_style_context ().lookup_color ("theme_fg_color", out color);
- draw_path (context, path, color);
+ draw_path (context, path, color, 0, 0);
}
input_state.for_each ((path, state) => {
@@ -112,15 +141,17 @@ private class Games.GamepadView : Gtk.DrawingArea {
Gdk.RGBA color;
get_style_context ().lookup_color (color_name, out color);
- draw_path (context, path, color);
+ draw_path (context, path, color, state.offset_x, state.offset_y);
});
return false;
}
- private void draw_path (Cairo.Context context, string path, Gdk.RGBA color) {
+ private void draw_path (Cairo.Context context, string path, Gdk.RGBA color, double offset_x, double
offset_y) {
context.push_group ();
+ context.translate (offset_x, offset_y);
+
handle.render_cairo_sub (context, @"#$path");
var group = context.pop_group ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]