[retro-gtk] controller: Add has_capability()



commit 731c47b84c7047fab9e74e06c983ecfddf531dd6
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun Oct 29 21:23:25 2017 +0100

    controller: Add has_capability()
    
    This will be used in the next commit to more easily check the
    capabilities of a RetroController.

 retro-gtk/retro-controller.c |   24 ++++++++++++++++++++++++
 retro-gtk/retro-controller.h |    2 ++
 2 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/retro-gtk/retro-controller.c b/retro-gtk/retro-controller.c
index 4af5b8d..12dd597 100644
--- a/retro-gtk/retro-controller.c
+++ b/retro-gtk/retro-controller.c
@@ -104,6 +104,30 @@ retro_controller_get_capabilities (RetroController *self)
 }
 
 /**
+ * retro_controller_has_capability:
+ * @self: a #RetroController
+ * @controller_type: a #RetroControllerType
+ *
+ * Gets whether @self has the capability to represent the given controller type.
+ *
+ * Returns: whether @self has the capability
+ */
+gboolean
+retro_controller_has_capability (RetroController     *self,
+                                 RetroControllerType  controller_type)
+{
+  guint64 capabilities;
+  RetroControllerType masked_controller_type;
+
+  g_return_val_if_fail (RETRO_IS_CONTROLLER (self), FALSE);
+
+  capabilities = retro_controller_get_capabilities (self);
+  masked_controller_type = controller_type & RETRO_CONTROLLER_TYPE_TYPE_MASK;
+
+  return (capabilities & (1 << masked_controller_type)) != 0;
+}
+
+/**
  * retro_controller_set_rumble_state:
  * @self: a #RetroController
  * @effect: the rumble effect
diff --git a/retro-gtk/retro-controller.h b/retro-gtk/retro-controller.h
index af05154..cd2a95f 100644
--- a/retro-gtk/retro-controller.h
+++ b/retro-gtk/retro-controller.h
@@ -33,6 +33,8 @@ gint16 retro_controller_get_input_state (RetroController *self,
                                          RetroInput      *input);
 RetroControllerType retro_controller_get_controller_type (RetroController *self);
 guint64 retro_controller_get_capabilities (RetroController *self);
+gboolean retro_controller_has_capability (RetroController     *self,
+                                          RetroControllerType  controller_type);
 gboolean retro_controller_set_rumble_state (RetroController   *self,
                                             RetroRumbleEffect  effect,
                                             guint16            strength);


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