[retro-gtk/wip/aplazas/c-port: 3/34] Port DeviceType to C
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/c-port: 3/34] Port DeviceType to C
- Date: Tue, 10 Oct 2017 04:52:46 +0000 (UTC)
commit 86f66cd4db735491a7f381bf856555fd7e32d427
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Sep 5 13:15:51 2017 +0200
Port DeviceType to C
retro-gtk/Makefile.am | 4 +++
retro-gtk/input/device.vala | 32 ---------------------------
retro-gtk/retro-device-type.c | 30 ++++++++++++++++++++++++++
retro-gtk/retro-device-type.h | 45 +++++++++++++++++++++++++++++++++++++++
retro-gtk/retro-gtk.h | 1 +
retro-gtk/vapi/retro-gtk-c.vapi | 13 +++++++++++
6 files changed, 93 insertions(+), 32 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 1fc2cf3..a711063 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -30,6 +30,7 @@ dist_vapi_DATA = retro-gtk-0.12.deps
BUILT_SOURCES = retro-gtk-internal.h
retro_gtk_public_h_sources = \
+ retro-device-type.h \
retro-gtk.h \
retro-gtk-vala.h \
$(NULL)
@@ -71,6 +72,7 @@ libretro_gtk_la_SOURCES = \
retro-core-view.vala \
retro-core-view-extern.c \
retro-core-view-input-device.c \
+ retro-device-type.c \
retro-game-info.c \
retro-log.c \
retro-module.c \
@@ -114,6 +116,7 @@ libretro_gtk_la_VALAFLAGS = \
--pkg gtk+-3.0 \
--pkg libpulse \
--pkg libpulse-simple \
+ --pkg retro-gtk-c \
--vapidir=vapi \
--thread \
--target-glib 2.32 \
@@ -180,6 +183,7 @@ EXTRA_DIST = \
$(retro_gtk_private_h_sources) \
retro-gtk-0.12.pc.in \
update-from-retroarch.sh \
+ vapi/retro-gtk-c.vapi \
$(NULL)
INPUTDIR=$(top_srcdir)/../RetroArch/libretro-common/include/
diff --git a/retro-gtk/input/device.vala b/retro-gtk/input/device.vala
index ce8a5bf..a6e618e 100644
--- a/retro-gtk/input/device.vala
+++ b/retro-gtk/input/device.vala
@@ -3,38 +3,6 @@
namespace Retro {
/**
- * The device types.
- */
-public enum DeviceType {
- TYPE_MASK = 0xff,
-
- /* See RETRO_DEVICE_NONE and below in libretro.h for docs */
- NONE = 0,
- JOYPAD = 1,
- MOUSE = 2,
- KEYBOARD = 3,
- LIGHTGUN = 4,
- ANALOG = 5,
- POINTER = 6;
-
- /**
- * Gets the basic type of a device type.
- *
- * Applies the type mask on a DeviceType to get its basic type.
- * If the device type is already basic, it will return the same type.
- *
- * E.g DeviceType.JOYPAD_MULTITAP.get_basic_type () returns
- * DeviceType.JOYPAD, and DeviceType.JOYPAD.get_basic_type () also
- * returns Type.JOYPAD.
- *
- * @return the basic type of a device type
- */
- public DeviceType get_basic_type () {
- return this & DeviceType.TYPE_MASK;
- }
-}
-
-/**
* The input types of a joypad.
*/
public enum JoypadId {
diff --git a/retro-gtk/retro-device-type.c b/retro-gtk/retro-device-type.c
new file mode 100644
index 0000000..91d7502
--- /dev/null
+++ b/retro-gtk/retro-device-type.c
@@ -0,0 +1,30 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-device-type.h"
+
+GType
+retro_device_type_get_type (void)
+{
+ static volatile gsize retro_device_type_type = 0;
+
+ if (g_once_init_enter (&retro_device_type_type)) {
+ static const GEnumValue values[] = {
+ { RETRO_DEVICE_TYPE_NONE, "RETRO_DEVICE_TYPE_NONE", "none" },
+ { RETRO_DEVICE_TYPE_JOYPAD, "RETRO_DEVICE_TYPE_JOYPAD", "joypad" },
+ { RETRO_DEVICE_TYPE_MOUSE, "RETRO_DEVICE_TYPE_MOUSE", "mouse" },
+ { RETRO_DEVICE_TYPE_KEYBOARD, "RETRO_DEVICE_TYPE_KEYBOARD", "keyboard" },
+ { RETRO_DEVICE_TYPE_LIGHTGUN, "RETRO_DEVICE_TYPE_LIGHTGUN", "lightgun" },
+ { RETRO_DEVICE_TYPE_ANALOG, "RETRO_DEVICE_TYPE_ANALOG", "analog" },
+ { RETRO_DEVICE_TYPE_POINTER, "RETRO_DEVICE_TYPE_POINTER", "pointer" },
+ { RETRO_DEVICE_TYPE_TYPE_MASK, "RETRO_DEVICE_TYPE_TYPE_MASK", "type-mask" },
+ { 0, NULL, NULL },
+ };
+ GType type;
+
+ type = g_enum_register_static ("RetroDeviceType", values);
+
+ g_once_init_leave (&retro_device_type_type, type);
+ }
+
+ return retro_device_type_type;
+}
diff --git a/retro-gtk/retro-device-type.h b/retro-gtk/retro-device-type.h
new file mode 100644
index 0000000..2587a69
--- /dev/null
+++ b/retro-gtk/retro-device-type.h
@@ -0,0 +1,45 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_DEVICE_TYPE_H
+#define RETRO_DEVICE_TYPE_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_DEVICE_TYPE (retro_device_type_get_type ())
+
+GType retro_device_type_get_type (void) G_GNUC_CONST;
+
+/**
+ * RetroDeviceType:
+ * @RETRO_DEVICE_TYPE_NONE: no controller
+ * @RETRO_DEVICE_TYPE_JOYPAD: a classic gamepad
+ * @RETRO_DEVICE_TYPE_MOUSE: a simple mouse
+ * @RETRO_DEVICE_TYPE_KEYBOARD: a keyboard
+ * @RETRO_DEVICE_TYPE_LIGHTGUN: a lightgun
+ * @RETRO_DEVICE_TYPE_ANALOG: a gamepad with analog sticks
+ * @RETRO_DEVICE_TYPE_POINTER: a screen pointer
+ * @RETRO_DEVICE_TYPE_TYPE_MASK: a mask to get the super type of a derived one
+ *
+ * Represents the base types for Libretro controllers.
+ */
+typedef enum
+{
+ RETRO_DEVICE_TYPE_NONE,
+ RETRO_DEVICE_TYPE_JOYPAD,
+ RETRO_DEVICE_TYPE_MOUSE,
+ RETRO_DEVICE_TYPE_KEYBOARD,
+ RETRO_DEVICE_TYPE_LIGHTGUN,
+ RETRO_DEVICE_TYPE_ANALOG,
+ RETRO_DEVICE_TYPE_POINTER,
+ RETRO_DEVICE_TYPE_TYPE_MASK = 0xff,
+} RetroDeviceType;
+
+G_END_DECLS
+
+#endif /* RETRO_DEVICE_TYPE_H */
diff --git a/retro-gtk/retro-gtk.h b/retro-gtk/retro-gtk.h
index 72f85f6..e9dabaa 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -9,6 +9,7 @@
#error retro-gtk is unstable API. You must define RETRO_GTK_USE_UNSTABLE_API before including retro-gtk.h
#endif
+#include "retro-device-type.h"
#include "retro-gtk-vala.h"
#undef __RETRO_GTK_INSIDE__
diff --git a/retro-gtk/vapi/retro-gtk-c.vapi b/retro-gtk/vapi/retro-gtk-c.vapi
new file mode 100644
index 0000000..208723a
--- /dev/null
+++ b/retro-gtk/vapi/retro-gtk-c.vapi
@@ -0,0 +1,13 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+[CCode (cheader_filename = "retro-device-type.h")]
+public enum Retro.DeviceType {
+ TYPE_MASK = 0xff,
+ NONE = 0,
+ JOYPAD = 1,
+ MOUSE = 2,
+ KEYBOARD = 3,
+ LIGHTGUN = 4,
+ ANALOG = 5,
+ POINTER = 6,
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]