[retro-gtk/wip/aplazas/input: 2/3] Add RetroInput
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk/wip/aplazas/input: 2/3] Add RetroInput
- Date: Fri, 27 Oct 2017 06:50:12 +0000 (UTC)
commit 94d6622164578be13e4ca5b44935cb5b30de2a13
Author: Adrien Plazas <kekun plazas laposte net>
Date: Mon Oct 16 21:01:50 2017 +0200
Add RetroInput
This will be used in the next commits to make help describing input
requests in a cleaner way.
Also makes retro-keyboard-key.h public.
retro-gtk/Makefile.am | 5 +-
retro-gtk/retro-gtk.h | 7 +--
retro-gtk/retro-input-private.h | 28 ++++++++
retro-gtk/retro-input.c | 135 +++++++++++++++++++++++++++++++++++++++
retro-gtk/retro-input.h | 39 +++++++++++
5 files changed, 207 insertions(+), 7 deletions(-)
---
diff --git a/retro-gtk/Makefile.am b/retro-gtk/Makefile.am
index 18da904..1a29565 100644
--- a/retro-gtk/Makefile.am
+++ b/retro-gtk/Makefile.am
@@ -37,7 +37,9 @@ retro_gtk_public_h_sources = \
retro-core.h \
retro-core-view.h \
retro-gtk.h \
+ retro-input.h \
retro-joypad-id.h \
+ retro-keyboard-key.h \
retro-lightgun-id.h \
retro-log.h \
retro-main-loop.h \
@@ -60,7 +62,7 @@ retro_gtk_private_h_sources = \
retro-disk-control-callback.h \
retro-game-info.h \
retro-input-descriptor.h \
- retro-keyboard-key.h \
+ retro-input-private.h \
retro-module.h \
retro-option.h \
retro-options.h \
@@ -84,6 +86,7 @@ libretro_gtk_la_SOURCES = \
retro-core-view.c \
retro-core-view-controller.c \
retro-game-info.c \
+ retro-input.c \
retro-input-descriptor.c \
retro-joypad-id.c \
retro-keyboard-key.c \
diff --git a/retro-gtk/retro-gtk.h b/retro-gtk/retro-gtk.h
index 9d0266a..9075324 100644
--- a/retro-gtk/retro-gtk.h
+++ b/retro-gtk/retro-gtk.h
@@ -9,23 +9,18 @@
#error retro-gtk is unstable API. You must define RETRO_GTK_USE_UNSTABLE_API before including retro-gtk.h
#endif
-#include "retro-analog-id.h"
-#include "retro-analog-index.h"
#include "retro-controller.h"
#include "retro-controller-type.h"
#include "retro-core.h"
#include "retro-core-descriptor.h"
#include "retro-core-view.h"
-#include "retro-joypad-id.h"
-#include "retro-lightgun-id.h"
+#include "retro-input.h"
#include "retro-log.h"
#include "retro-main-loop.h"
#include "retro-memory-type.h"
#include "retro-module-iterator.h"
#include "retro-module-query.h"
-#include "retro-mouse-id.h"
#include "retro-pixdata.h"
-#include "retro-pointer-id.h"
#include "retro-video-filter.h"
#undef __RETRO_GTK_INSIDE__
diff --git a/retro-gtk/retro-input-private.h b/retro-gtk/retro-input-private.h
new file mode 100644
index 0000000..715dc93
--- /dev/null
+++ b/retro-gtk/retro-input-private.h
@@ -0,0 +1,28 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_INPUT_PRIVATE_H
+#define RETRO_INPUT_PRIVATE_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include "retro-input.h"
+
+G_BEGIN_DECLS
+
+struct _RetroInput
+{
+ RetroControllerType controller_type;
+ guint id;
+ guint index;
+};
+
+void retro_input_init (RetroInput *self,
+ RetroControllerType controller_type,
+ guint id,
+ guint index);
+
+G_END_DECLS
+
+#endif /* RETRO_INPUT_PRIVATE_H */
diff --git a/retro-gtk/retro-input.c b/retro-gtk/retro-input.c
new file mode 100644
index 0000000..45a08ba
--- /dev/null
+++ b/retro-gtk/retro-input.c
@@ -0,0 +1,135 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#include "retro-input-private.h"
+
+G_DEFINE_BOXED_TYPE (RetroInput, retro_input, retro_input_copy, retro_input_free)
+
+/* Private */
+
+/**
+ * retro_input_init:
+ * @self: a #RetroInput
+ * @controller_type: the controller type
+ * @id: the id
+ * @index: the index
+ *
+ * Initializes @self with the given parameters.
+ */
+void
+retro_input_init (RetroInput *self,
+ RetroControllerType controller_type,
+ guint id,
+ guint index)
+{
+ g_return_if_fail (self != NULL);
+
+ self->controller_type = controller_type;
+ self->id = id;
+ self->index = index;
+}
+
+/* Public */
+
+/**
+ * retro_input_new:
+ *
+ * Creates a new #RetroInput.
+ *
+ * Returns: (transfer full): a new #RetroInput, use retro_input_free() to free
+ * it
+ */
+RetroInput *
+retro_input_new (void)
+{
+ RetroInput *self;
+
+ self = g_slice_new0 (RetroInput);
+
+ return self;
+}
+
+/**
+ * retro_input_copy:
+ * @self: a #RetroInput
+ *
+ * Copies @self into a new #RetroInput.
+ *
+ * Returns: (transfer full): a new #RetroInput, use retro_input_free() to free
+ * it
+ */
+RetroInput *
+retro_input_copy (RetroInput *self)
+{
+ RetroInput *copy;
+
+ g_return_val_if_fail (self != NULL, NULL);
+
+ copy = retro_input_new ();
+ copy->controller_type = self->controller_type;
+ copy->id = self->id;
+ copy->index = self->index;
+
+ return copy;
+}
+
+/**
+ * retro_input_free:
+ * @self: a #RetroInput
+ *
+ * Frees the given #RetroInput.
+ */
+void
+retro_input_free (RetroInput *self)
+{
+ g_return_if_fail (self != NULL);
+
+ g_slice_free (RetroInput, self);
+}
+
+/**
+ * retro_input_get_controller_type:
+ * @self: a #RetroInput
+ *
+ * Gets the controller type of @self.
+ *
+ * Returns: the controller type of @self
+ */
+RetroControllerType
+retro_input_get_controller_type (RetroInput *self)
+{
+ g_return_val_if_fail (self != NULL, RETRO_CONTROLLER_TYPE_NONE);
+
+ return self->controller_type;
+}
+
+/**
+ * retro_input_get_id:
+ * @self: a #RetroInput
+ *
+ * Gets the id of @self.
+ *
+ * Returns: the id of @self
+ */
+guint
+retro_input_get_id (RetroInput *self)
+{
+ g_return_val_if_fail (self != NULL, 0);
+
+ return self->id;
+}
+
+/**
+ * retro_input_get_index:
+ * @self: a #RetroInput
+ *
+ * Gets the index of @self.
+ *
+ * Returns: the index of @self
+ */
+guint
+retro_input_get_index (RetroInput *self)
+{
+ g_return_val_if_fail (self != NULL, 0);
+
+ return self->index;
+}
diff --git a/retro-gtk/retro-input.h b/retro-gtk/retro-input.h
new file mode 100644
index 0000000..6aa64b8
--- /dev/null
+++ b/retro-gtk/retro-input.h
@@ -0,0 +1,39 @@
+// This file is part of retro-gtk. License: GPL-3.0+.
+
+#ifndef RETRO_INPUT_H
+#define RETRO_INPUT_H
+
+#if !defined(__RETRO_GTK_INSIDE__) && !defined(RETRO_GTK_COMPILATION)
+# error "Only <retro-gtk.h> can be included directly."
+#endif
+
+#include <glib-object.h>
+#include "retro-analog-id.h"
+#include "retro-analog-index.h"
+#include "retro-controller-type.h"
+#include "retro-joypad-id.h"
+#include "retro-keyboard-key.h"
+#include "retro-lightgun-id.h"
+#include "retro-mouse-id.h"
+#include "retro-pointer-id.h"
+
+G_BEGIN_DECLS
+
+#define RETRO_TYPE_INPUT (retro_input_get_type())
+
+GType retro_input_get_type (void) G_GNUC_CONST;
+
+typedef struct _RetroInput RetroInput;
+
+RetroInput *retro_input_new (void);
+RetroInput *retro_input_copy (RetroInput *self);
+void retro_input_free (RetroInput *self);
+RetroControllerType retro_input_get_controller_type (RetroInput *self);
+guint retro_input_get_id (RetroInput *self);
+guint retro_input_get_index (RetroInput *self);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (RetroInput, retro_input_free)
+
+G_END_DECLS
+
+#endif /* RETRO_INPUT_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]