[retro-gtk/wip/aplazas/c-port: 4/34] Port JoypadId to C



commit 8e2cc8d4e1715dddcfcf13e396ddb39be4865314
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Sep 5 13:28:53 2017 +0200

    Port JoypadId to C

 retro-gtk/Makefile.am              |    2 +
 retro-gtk/input/device.vala        |   23 ------------
 retro-gtk/retro-core-view-extern.c |    1 +
 retro-gtk/retro-gtk.h              |    1 +
 retro-gtk/retro-joypad-id.c        |   39 ++++++++++++++++++++
 retro-gtk/retro-joypad-id.h        |   68 ++++++++++++++++++++++++++++++++++++
 6 files changed, 111 insertions(+), 23 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index a711063..589dee8 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -33,6 +33,7 @@ retro_gtk_public_h_sources = \
        retro-device-type.h \
        retro-gtk.h \
        retro-gtk-vala.h \
+       retro-joypad-id.h \
        $(NULL)
 
 retro_gtk_private_h_sources = \
@@ -74,6 +75,7 @@ libretro_gtk_la_SOURCES = \
        retro-core-view-input-device.c \
        retro-device-type.c \
        retro-game-info.c \
+       retro-joypad-id.c \
        retro-log.c \
        retro-module.c \
        retro-module-query.vala \
diff --git a/retro-gtk/input/device.vala b/retro-gtk/input/device.vala
index a6e618e..180630b 100644
--- a/retro-gtk/input/device.vala
+++ b/retro-gtk/input/device.vala
@@ -3,29 +3,6 @@
 namespace Retro {
 
 /**
- * The input types of a joypad.
- */
-public enum JoypadId {
-       B,
-       Y,
-       SELECT,
-       START,
-       UP,
-       DOWN,
-       LEFT,
-       RIGHT,
-       A,
-       X,
-       L,
-       R,
-       L2,
-       R2,
-       L3,
-       R3,
-       COUNT,
-}
-
-/**
  * The analog sticks of an analog joypad.
  */
 public enum AnalogIndex {
diff --git a/retro-gtk/retro-core-view-extern.c b/retro-gtk/retro-core-view-extern.c
index 089eaaf..8377168 100644
--- a/retro-gtk/retro-core-view-extern.c
+++ b/retro-gtk/retro-core-view-extern.c
@@ -3,6 +3,7 @@
 #include <linux/input-event-codes.h>
 #include "retro-gtk-internal.h"
 #include "retro-core-view-input-device.h"
+#include "retro-joypad-id.h"
 
 static guint16 DEFAULT_KEY_JOYPAD_BUTTON_MAPPING[RETRO_JOYPAD_ID_COUNT] = {
   KEY_S,
diff --git a/retro-gtk/retro-gtk.h b/retro-gtk/retro-gtk.h
index e9dabaa..2be93f4 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -11,6 +11,7 @@
 
 #include "retro-device-type.h"
 #include "retro-gtk-vala.h"
+#include "retro-joypad-id.h"
 
 #undef __RETRO_GTK_INSIDE__
 
diff --git a/retro-gtk/retro-joypad-id.c b/retro-gtk/retro-joypad-id.c
new file mode 100644
index 0000000..e67a28b
--- /dev/null
+++ b/retro-gtk/retro-joypad-id.c
@@ -0,0 +1,39 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-joypad-id.h"
+
+GType
+retro_joypad_id_get_type (void)
+{
+  static volatile gsize retro_joypad_id_type = 0;
+
+  if (g_once_init_enter (&retro_joypad_id_type)) {
+    static const GEnumValue values[] = {
+      { RETRO_JOYPAD_ID_B, "RETRO_JOYPAD_ID_B", "b" },
+      { RETRO_JOYPAD_ID_Y, "RETRO_JOYPAD_ID_Y", "y" },
+      { RETRO_JOYPAD_ID_SELECT, "RETRO_JOYPAD_ID_SELECT", "select" },
+      { RETRO_JOYPAD_ID_START, "RETRO_JOYPAD_ID_START", "start" },
+      { RETRO_JOYPAD_ID_UP, "RETRO_JOYPAD_ID_UP", "up" },
+      { RETRO_JOYPAD_ID_DOWN, "RETRO_JOYPAD_ID_DOWN", "down" },
+      { RETRO_JOYPAD_ID_LEFT, "RETRO_JOYPAD_ID_LEFT", "left" },
+      { RETRO_JOYPAD_ID_RIGHT, "RETRO_JOYPAD_ID_RIGHT", "right" },
+      { RETRO_JOYPAD_ID_A, "RETRO_JOYPAD_ID_A", "a" },
+      { RETRO_JOYPAD_ID_X, "RETRO_JOYPAD_ID_X", "x" },
+      { RETRO_JOYPAD_ID_L, "RETRO_JOYPAD_ID_L", "l" },
+      { RETRO_JOYPAD_ID_R, "RETRO_JOYPAD_ID_R", "r" },
+      { RETRO_JOYPAD_ID_L2, "RETRO_JOYPAD_ID_L2", "l2" },
+      { RETRO_JOYPAD_ID_R2, "RETRO_JOYPAD_ID_R2", "r2" },
+      { RETRO_JOYPAD_ID_L3, "RETRO_JOYPAD_ID_L3", "l3" },
+      { RETRO_JOYPAD_ID_R3, "RETRO_JOYPAD_ID_R3", "r3" },
+      { RETRO_JOYPAD_ID_COUNT, "RETRO_JOYPAD_ID_COUNT", "count" },
+      { 0, NULL, NULL },
+    };
+    GType type;
+
+    type = g_enum_register_static ("RetroJoypadId", values);
+
+    g_once_init_leave (&retro_joypad_id_type, type);
+  }
+
+  return retro_joypad_id_type;
+}
diff --git a/retro-gtk/retro-joypad-id.h b/retro-gtk/retro-joypad-id.h
new file mode 100644
index 0000000..63a6975
--- /dev/null
+++ b/retro-gtk/retro-joypad-id.h
@@ -0,0 +1,68 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_JOYPAD_ID_H
+#define RETRO_JOYPAD_ID_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_JOYPAD_ID (retro_joypad_id_get_type ())
+
+GType retro_joypad_id_get_type (void) G_GNUC_CONST;
+
+/**
+ * RetroJoypadId:
+ * @RETRO_JOYPAD_ID_B: the bottom action button
+ * @RETRO_JOYPAD_ID_Y: the left action button
+ * @RETRO_JOYPAD_ID_SELECT: the Select button
+ * @RETRO_JOYPAD_ID_START: the Start button
+ * @RETRO_JOYPAD_ID_UP: the up directional button
+ * @RETRO_JOYPAD_ID_DOWN: the down directional button
+ * @RETRO_JOYPAD_ID_LEFT: the left directional button
+ * @RETRO_JOYPAD_ID_RIGHT: the right directional button
+ * @RETRO_JOYPAD_ID_A: the right action button
+ * @RETRO_JOYPAD_ID_X: the top action button
+ * @RETRO_JOYPAD_ID_L: the first left shoulder button
+ * @RETRO_JOYPAD_ID_R: the first right shoulder button
+ * @RETRO_JOYPAD_ID_L2: the second left shoulder button
+ * @RETRO_JOYPAD_ID_R2: the second right shoulder button
+ * @RETRO_JOYPAD_ID_L3: the left thumb button
+ * @RETRO_JOYPAD_ID_R3: the right thumb button
+ * @RETRO_JOYPAD_ID_COUNT: the number of buttons
+ *
+ * Represents the buttons for the Libretro gamepad. The available buttons are
+ * the same as the W3C Standard Gamepad, the SDL GameController and many other
+ * modern standard gamepads, but the name of the buttons may differ. See the
+ * <ulink url="https://w3c.github.io/gamepad/";>W3C Gamepad Specification</ulink>
+ * and the <ulink url="https://wiki.libsdl.org/CategoryGameController";>SDL
+ * GamepadController definition</ulink> for more information.
+ */
+typedef enum
+{
+  RETRO_JOYPAD_ID_B,
+  RETRO_JOYPAD_ID_Y,
+  RETRO_JOYPAD_ID_SELECT,
+  RETRO_JOYPAD_ID_START,
+  RETRO_JOYPAD_ID_UP,
+  RETRO_JOYPAD_ID_DOWN,
+  RETRO_JOYPAD_ID_LEFT,
+  RETRO_JOYPAD_ID_RIGHT,
+  RETRO_JOYPAD_ID_A,
+  RETRO_JOYPAD_ID_X,
+  RETRO_JOYPAD_ID_L,
+  RETRO_JOYPAD_ID_R,
+  RETRO_JOYPAD_ID_L2,
+  RETRO_JOYPAD_ID_R2,
+  RETRO_JOYPAD_ID_L3,
+  RETRO_JOYPAD_ID_R3,
+  RETRO_JOYPAD_ID_COUNT,
+} RetroJoypadId;
+
+G_END_DECLS
+
+#endif /* RETRO_JOYPAD_ID_H */


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