[gnome-games/wip/abhinavsingh/gamepad-config] gamepad: Add util functions to std axis and button



commit fac7b9623a6289f7c32429b0875b4182f1797ba5
Author: theawless <theawless gmail com>
Date:   Fri May 12 12:48:26 2017 +0530

    gamepad: Add util functions to std axis and button
    
    Add size() and values() to StandardGamepadAxis and StandardGamepadButton
    enums. These will be of use in subsequent commits.

 src/gamepad/standard-gamepad-axis.c      |   37 ++++++++++++++++++++++++++++++
 src/gamepad/standard-gamepad-axis.h      |    2 +
 src/gamepad/standard-gamepad-axis.vapi   |    5 +++-
 src/gamepad/standard-gamepad-button.c    |   37 ++++++++++++++++++++++++++++++
 src/gamepad/standard-gamepad-button.h    |    2 +
 src/gamepad/standard-gamepad-button.vapi |    5 +++-
 6 files changed, 86 insertions(+), 2 deletions(-)
---
diff --git a/src/gamepad/standard-gamepad-axis.c b/src/gamepad/standard-gamepad-axis.c
index 0aa346f..47e6761 100644
--- a/src/gamepad/standard-gamepad-axis.c
+++ b/src/gamepad/standard-gamepad-axis.c
@@ -2,6 +2,43 @@
 
 #include "standard-gamepad-axis.h"
 
+/* Public */
+
+guint
+games_standard_gamepad_axis_size (void)
+{
+  GEnumClass *enum_class = NULL;
+  guint n_values;
+
+  enum_class = g_type_class_ref (GAMES_TYPE_STANDARD_GAMEPAD_AXIS);
+  n_values = enum_class->n_values;
+  g_type_class_unref (enum_class);
+
+  return n_values;
+}
+
+GamesStandardGamepadAxis *
+games_standard_gamepad_axis_values (gint* size)
+{
+  GEnumClass *enum_class = NULL;
+  GEnumValue *enum_values = NULL;
+  GamesStandardGamepadAxis *values = NULL;
+  gint i;
+
+  enum_class = g_type_class_ref (GAMES_TYPE_STANDARD_GAMEPAD_AXIS);
+  enum_values = enum_class->values;
+  *size = games_standard_gamepad_axis_size ();
+  values = g_new (GamesStandardGamepadAxis, *size);
+
+  for (i = 0; i < *size; ++i) {
+    values[i] = enum_values[i].value;
+  }
+
+  return values;
+}
+
+/* Type */
+
 GType
 games_standard_gamepad_axis_get_type (void)
 {
diff --git a/src/gamepad/standard-gamepad-axis.h b/src/gamepad/standard-gamepad-axis.h
index 457868e..a4bcdc4 100644
--- a/src/gamepad/standard-gamepad-axis.h
+++ b/src/gamepad/standard-gamepad-axis.h
@@ -31,6 +31,8 @@ typedef enum {
 } GamesStandardGamepadAxis;
 
 GType games_standard_gamepad_axis_get_type (void) G_GNUC_CONST;
+guint games_standard_gamepad_axis_size (void);
+GamesStandardGamepadAxis *games_standard_gamepad_axis_values (gint* size);
 
 G_END_DECLS
 
diff --git a/src/gamepad/standard-gamepad-axis.vapi b/src/gamepad/standard-gamepad-axis.vapi
index d306075..d96105d 100644
--- a/src/gamepad/standard-gamepad-axis.vapi
+++ b/src/gamepad/standard-gamepad-axis.vapi
@@ -6,5 +6,8 @@ private enum Games.StandardGamepadAxis {
        LEFT_X,
        LEFT_Y,
        RIGHT_X,
-       RIGHT_Y,
+       RIGHT_Y;
+
+       public static uint size ();
+       public static StandardGamepadAxis[] values ();
 }
diff --git a/src/gamepad/standard-gamepad-button.c b/src/gamepad/standard-gamepad-button.c
index ba17680..1f17fb1 100644
--- a/src/gamepad/standard-gamepad-button.c
+++ b/src/gamepad/standard-gamepad-button.c
@@ -2,6 +2,43 @@
 
 #include "standard-gamepad-button.h"
 
+/* Public */
+
+guint
+games_standard_gamepad_button_size (void)
+{
+  GEnumClass *enum_class = NULL;
+  guint n_values;
+
+  enum_class = g_type_class_ref (GAMES_TYPE_STANDARD_GAMEPAD_BUTTON);
+  n_values = enum_class->n_values;
+  g_type_class_unref (enum_class);
+
+  return n_values;
+}
+
+GamesStandardGamepadButton *
+games_standard_gamepad_button_values (gint* size)
+{
+  GEnumClass *enum_class = NULL;
+  GEnumValue *enum_values = NULL;
+  GamesStandardGamepadButton *values = NULL;
+  gint i;
+
+  enum_class = g_type_class_ref (GAMES_TYPE_STANDARD_GAMEPAD_BUTTON);
+  enum_values = enum_class->values;
+  *size = games_standard_gamepad_button_size ();
+  values = g_new (GamesStandardGamepadButton, *size);
+
+  for (i = 0; i < *size; ++i) {
+    values[i] = enum_values[i].value;
+  }
+
+  return values;
+}
+
+/* Type */
+
 GType
 games_standard_gamepad_button_get_type (void)
 {
diff --git a/src/gamepad/standard-gamepad-button.h b/src/gamepad/standard-gamepad-button.h
index cd5e7bd..c1567bd 100644
--- a/src/gamepad/standard-gamepad-button.h
+++ b/src/gamepad/standard-gamepad-button.h
@@ -54,6 +54,8 @@ typedef enum {
 } GamesStandardGamepadButton;
 
 GType games_standard_gamepad_button_get_type (void) G_GNUC_CONST;
+guint games_standard_gamepad_button_size (void);
+GamesStandardGamepadButton *games_standard_gamepad_button_values (gint *size);
 
 G_END_DECLS
 
diff --git a/src/gamepad/standard-gamepad-button.vapi b/src/gamepad/standard-gamepad-button.vapi
index bfde8af..c2533c2 100644
--- a/src/gamepad/standard-gamepad-button.vapi
+++ b/src/gamepad/standard-gamepad-button.vapi
@@ -19,5 +19,8 @@ private enum Games.StandardGamepadButton {
        DPAD_DOWN,
        DPAD_LEFT,
        DPAD_RIGHT,
-       HOME,
+       HOME;
+
+       public static uint size ();
+       public static StandardGamepadButton[] values ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]