[retro-gtk/wip/aplazas/core-view-joypad: 3/7] Add CoreViewInputDevice
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/core-view-joypad: 3/7] Add CoreViewInputDevice
- Date: Fri, 4 Aug 2017 19:41:02 +0000 (UTC)
commit 6f19c555ee38e2bf06f731b4374f92fa914641a9
Author: Adrien Plazas <kekun plazas laposte net>
Date: Sun Jul 30 12:50:50 2017 +0100
Add CoreViewInputDevice
It will be used to expose a CoreView as an input device of a specific
type.
retro-gtk/Makefile.am | 3 +
retro-gtk/retro-core-view-input-device.c | 127 ++++++++++++++++++++++++++++++
retro-gtk/retro-core-view-input-device.h | 20 +++++
3 files changed, 150 insertions(+), 0 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 1be8c9b..a14d581 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -56,6 +56,7 @@ libretro_gtk_la_SOURCES = \
retro-core-descriptor-error.vala \
retro-core-view.vala \
retro-core-view-extern.c \
+ retro-core-view-input-device.c \
retro-log.c \
retro-module.c \
retro-module-query.vala \
@@ -77,6 +78,8 @@ retro-core.c: retro-gtk-internal.h
retro-core-view-extern.c: retro-gtk-internal.h
+retro-core-view-input-device.c: retro-gtk-internal.h
+
retro-environment.c: retro-gtk-internal.h libretro-environment.h
retro-log.c: retro-gtk-internal.h
diff --git a/retro-gtk/retro-core-view-input-device.c b/retro-gtk/retro-core-view-input-device.c
new file mode 100644
index 0000000..0720744
--- /dev/null
+++ b/retro-gtk/retro-core-view-input-device.c
@@ -0,0 +1,127 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-core-view-input-device.h"
+
+struct _RetroCoreViewInputDevice
+{
+ GObject parent_instance;
+ GWeakRef view;
+ RetroDeviceType device_type;
+};
+
+static void retro_input_device_interface_init (RetroInputDeviceIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (RetroCoreViewInputDevice, retro_core_view_input_device, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (RETRO_TYPE_INPUT_DEVICE,
+ retro_input_device_interface_init))
+
+/* Private */
+
+static void
+retro_core_view_input_device_poll (RetroInputDevice *base)
+{
+}
+
+static gint16
+retro_core_view_input_device_get_input_state (RetroInputDevice *base,
+ RetroDeviceType device,
+ guint index,
+ guint id)
+{
+ RetroCoreViewInputDevice *self = RETRO_CORE_VIEW_INPUT_DEVICE (base);
+ gpointer view;
+ gint16 result;
+
+ g_return_val_if_fail (self != NULL, 0);
+
+ if (device != self->device_type)
+ return 0;
+
+ view = g_weak_ref_get (&self->view);
+
+ g_return_val_if_fail (view != NULL, 0);
+
+ result = retro_core_view_get_input_state (RETRO_CORE_VIEW (view),
+ self->device_type,
+ index, id);
+
+ g_object_unref (G_OBJECT (view));
+
+ return result;
+}
+
+static RetroDeviceType
+retro_core_view_input_device_get_device_type (RetroInputDevice *base)
+{
+ RetroCoreViewInputDevice *self = RETRO_CORE_VIEW_INPUT_DEVICE (base);
+
+ g_return_val_if_fail (self != NULL, 0);
+
+ return self->device_type;
+}
+
+static guint64 retro_core_view_input_device_get_device_capabilities (RetroInputDevice *base) {
+ RetroCoreViewInputDevice *self = RETRO_CORE_VIEW_INPUT_DEVICE (base);
+ gpointer view;
+ guint64 result;
+
+ g_return_val_if_fail (self != NULL, 0);
+
+ view = g_weak_ref_get (&self->view);
+
+ g_return_val_if_fail (view != NULL, 0);
+
+ result = retro_core_view_get_device_capabilities (RETRO_CORE_VIEW (view));
+
+ g_object_unref (G_OBJECT (view));
+
+ return result;
+}
+
+static void
+retro_core_view_input_device_finalize (GObject *object)
+{
+ RetroCoreViewInputDevice *self = RETRO_CORE_VIEW_INPUT_DEVICE (object);
+
+ g_weak_ref_clear (&self->view);
+
+ G_OBJECT_CLASS (retro_core_view_input_device_parent_class)->finalize (object);
+}
+
+static void
+retro_core_view_input_device_class_init (RetroCoreViewInputDeviceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = retro_core_view_input_device_finalize;
+}
+
+static void
+retro_core_view_input_device_init (RetroCoreViewInputDevice *self)
+{
+}
+
+static void
+retro_input_device_interface_init (RetroInputDeviceIface *iface)
+{
+ iface->poll = retro_core_view_input_device_poll;
+ iface->get_input_state = retro_core_view_input_device_get_input_state;
+ iface->get_device_type = retro_core_view_input_device_get_device_type;
+ iface->get_device_capabilities = retro_core_view_input_device_get_device_capabilities;
+}
+
+/* Public */
+
+RetroCoreViewInputDevice *
+retro_core_view_input_device_new (RetroCoreView *view, RetroDeviceType device_type)
+{
+ RetroCoreViewInputDevice *self = NULL;
+
+ g_return_val_if_fail (view != NULL, NULL);
+
+ self = g_object_new (RETRO_TYPE_CORE_VIEW_INPUT_DEVICE, NULL);
+ g_weak_ref_init (&self->view, view);
+ self->device_type = device_type;
+
+ return self;
+}
diff --git a/retro-gtk/retro-core-view-input-device.h b/retro-gtk/retro-core-view-input-device.h
new file mode 100644
index 0000000..cae68fb
--- /dev/null
+++ b/retro-gtk/retro-core-view-input-device.h
@@ -0,0 +1,20 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_CORE_VIEW_INPUT_DEVICE_H
+#define RETRO_CORE_VIEW_INPUT_DEVICE_H
+
+#include <glib-object.h>
+#include "retro-gtk-internal.h"
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_CORE_VIEW_INPUT_DEVICE (retro_core_view_input_device_get_type())
+
+G_DECLARE_FINAL_TYPE (RetroCoreViewInputDevice, retro_core_view_input_device, RETRO, CORE_VIEW_INPUT_DEVICE,
GObject)
+
+RetroCoreViewInputDevice *retro_core_view_input_device_new (RetroCoreView *view, RetroDeviceType
device_type);
+
+G_END_DECLS
+
+#endif /* RETRO_CORE_VIEW_INPUT_DEVICE_H */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]