Commit 7fb77f18 authored by Abhinav Singh's avatar Abhinav Singh Committed by Adrien Plazas

core-view: Use RetroKeyJoypadMapping

This will allow changing the key joypad mappings.

https://bugzilla.gnome.org/show_bug.cgi?id=780755
parent ae04dc75
Pipeline #14244 passed with stage
in 6 minutes and 37 seconds
......@@ -2,32 +2,12 @@
#include "retro-core-view.h"
#include <linux/input-event-codes.h>
#include "retro-cairo-display.h"
#include "retro-gl-display.h"
#include "retro-controller-codes.h"
#include "retro-core-view-controller.h"
#include "retro-pa-player.h"
static guint16 DEFAULT_KEY_JOYPAD_BUTTON_MAPPING[RETRO_JOYPAD_ID_COUNT] = {
KEY_S,
KEY_A,
KEY_BACKSPACE,
KEY_ENTER,
KEY_UP,
KEY_DOWN,
KEY_LEFT,
KEY_RIGHT,
KEY_D,
KEY_W,
KEY_Q,
KEY_E,
KEY_Z,
KEY_C,
KEY_1,
KEY_3,
};
struct _RetroCoreView
{
GtkEventBox parent_instance;
......@@ -38,6 +18,7 @@ struct _RetroCoreView
gboolean can_grab_pointer;
gboolean snap_pointer_to_borders;
GHashTable *key_state;
RetroKeyJoypadMapping *key_joypad_mapping;
GHashTable *mouse_button_state;
GdkScreen *grabbed_screen;
GdkDevice *grabbed_device;
......@@ -343,8 +324,7 @@ retro_core_view_get_joypad_button_state (RetroCoreView *self,
if (button >= RETRO_JOYPAD_ID_COUNT)
return 0;
// GDK adds 8 to the Linux input event codes to create the hardware keycode.
hardware_keycode = DEFAULT_KEY_JOYPAD_BUTTON_MAPPING[button] + 8;
hardware_keycode = retro_key_joypad_mapping_get_button_key (self->key_joypad_mapping, button);
return retro_core_view_get_key_state (self, hardware_keycode);
}
......@@ -368,6 +348,7 @@ retro_core_view_finalize (GObject *object)
g_object_unref (self->sensitive_binding);
g_object_unref (self->audio_player);
g_hash_table_unref (self->key_state);
g_object_unref (self->key_joypad_mapping);
g_hash_table_unref (self->mouse_button_state);
g_clear_object (&self->grabbed_screen);
g_clear_object (&self->grabbed_device);
......@@ -483,6 +464,7 @@ retro_core_view_init (RetroCoreView *self)
self->audio_player = retro_pa_player_new ();
self->key_state = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free);
self->key_joypad_mapping = retro_key_joypad_mapping_new_default ();
self->mouse_button_state = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, g_free);
g_signal_connect_object (self, "key-press-event", (GCallback) retro_core_view_on_key_press_event, self, 0);
......@@ -573,6 +555,44 @@ retro_core_view_set_filter (RetroCoreView *self,
retro_gl_display_set_filter (self->display, filter);
}
/**
* retro_core_view_set_key_joypad_mapping:
* @self: a #RetroCoreView
* @mapping: (nullable): a #RetroKeyJoypadMapping
*
* Sets the key joypad mapping on @self. If given mapping is %NULL, then set to
* an empty configuration.
*/
void
retro_core_view_set_key_joypad_mapping (RetroCoreView *self,
RetroKeyJoypadMapping *mapping)
{
g_return_if_fail (RETRO_IS_CORE_VIEW (self));
g_return_if_fail (mapping == NULL || RETRO_IS_KEY_JOYPAD_MAPPING (mapping));
g_object_unref (self->key_joypad_mapping);
if (mapping != NULL)
self->key_joypad_mapping = g_object_ref (mapping);
else
self->key_joypad_mapping = retro_key_joypad_mapping_new ();
}
/**
* retro_core_view_get_key_joypad_mapping:
* @self: a #RetroCoreView
*
* Gets the currently set key joypad mapping.
*
* Returns: (transfer none): a #RetroKeyJoypadMapping
*/
RetroKeyJoypadMapping *
retro_core_view_get_key_joypad_mapping (RetroCoreView *self)
{
g_return_val_if_fail (RETRO_IS_CORE_VIEW (self), NULL);
return g_object_ref (self->key_joypad_mapping);
}
/**
* retro_core_view_as_controller:
* @self: a #RetroCoreView
......
......@@ -11,6 +11,7 @@
#include "retro-core.h"
#include "retro-controller.h"
#include "retro-input.h"
#include "retro-key-joypad-mapping.h"
#include "retro-video-filter.h"
G_BEGIN_DECLS
......@@ -28,6 +29,9 @@ void retro_core_view_set_pixbuf (RetroCoreView *self,
GdkPixbuf *retro_core_view_get_pixbuf (RetroCoreView *self);
void retro_core_view_set_filter (RetroCoreView *self,
RetroVideoFilter filter);
void retro_core_view_set_key_joypad_mapping (RetroCoreView *self,
RetroKeyJoypadMapping *mapping);
RetroKeyJoypadMapping *retro_core_view_get_key_joypad_mapping (RetroCoreView *self);
RetroController *retro_core_view_as_controller (RetroCoreView *self,
RetroControllerType controller_type);
void retro_core_view_set_as_default_controller (RetroCoreView *self,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment