/* retro-core-view.c generated by valac 0.36.4, the Vala compiler
 * generated from retro-core-view.vala, do not modify */

/* This file is part of retro-gtk. License: GPL-3.0+.*/

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>


#define RETRO_TYPE_CORE_VIEW (retro_core_view_get_type ())
#define RETRO_CORE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_CORE_VIEW, RetroCoreView))
#define RETRO_CORE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_CORE_VIEW, RetroCoreViewClass))
#define RETRO_IS_CORE_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_CORE_VIEW))
#define RETRO_IS_CORE_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_CORE_VIEW))
#define RETRO_CORE_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_CORE_VIEW, RetroCoreViewClass))

typedef struct _RetroCoreView RetroCoreView;
typedef struct _RetroCoreViewClass RetroCoreViewClass;
typedef struct _RetroCoreViewPrivate RetroCoreViewPrivate;

#define RETRO_TYPE_CORE (retro_core_get_type ())
#define RETRO_CORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_CORE, RetroCore))
#define RETRO_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_CORE, RetroCoreClass))
#define RETRO_IS_CORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_CORE))
#define RETRO_IS_CORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_CORE))
#define RETRO_CORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_CORE, RetroCoreClass))

typedef struct _RetroCore RetroCore;
typedef struct _RetroCoreClass RetroCoreClass;

#define RETRO_TYPE_CAIRO_DISPLAY (retro_cairo_display_get_type ())
#define RETRO_CAIRO_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_CAIRO_DISPLAY, RetroCairoDisplay))
#define RETRO_CAIRO_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_CAIRO_DISPLAY, RetroCairoDisplayClass))
#define RETRO_IS_CAIRO_DISPLAY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_CAIRO_DISPLAY))
#define RETRO_IS_CAIRO_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_CAIRO_DISPLAY))
#define RETRO_CAIRO_DISPLAY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_CAIRO_DISPLAY, RetroCairoDisplayClass))

typedef struct _RetroCairoDisplay RetroCairoDisplay;
typedef struct _RetroCairoDisplayClass RetroCairoDisplayClass;

#define RETRO_TYPE_INPUT_DEVICE_MANAGER (retro_input_device_manager_get_type ())
#define RETRO_INPUT_DEVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_INPUT_DEVICE_MANAGER, RetroInputDeviceManager))
#define RETRO_INPUT_DEVICE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_INPUT_DEVICE_MANAGER, RetroInputDeviceManagerClass))
#define RETRO_IS_INPUT_DEVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_INPUT_DEVICE_MANAGER))
#define RETRO_IS_INPUT_DEVICE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_INPUT_DEVICE_MANAGER))
#define RETRO_INPUT_DEVICE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_INPUT_DEVICE_MANAGER, RetroInputDeviceManagerClass))

typedef struct _RetroInputDeviceManager RetroInputDeviceManager;
typedef struct _RetroInputDeviceManagerClass RetroInputDeviceManagerClass;

#define RETRO_TYPE_KEYBOARD (retro_keyboard_get_type ())
#define RETRO_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_KEYBOARD, RetroKeyboard))
#define RETRO_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_KEYBOARD, RetroKeyboardClass))
#define RETRO_IS_KEYBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_KEYBOARD))
#define RETRO_IS_KEYBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_KEYBOARD))
#define RETRO_KEYBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_KEYBOARD, RetroKeyboardClass))

typedef struct _RetroKeyboard RetroKeyboard;
typedef struct _RetroKeyboardClass RetroKeyboardClass;

#define RETRO_TYPE_MOUSE (retro_mouse_get_type ())
#define RETRO_MOUSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_MOUSE, RetroMouse))
#define RETRO_MOUSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RETRO_TYPE_MOUSE, RetroMouseClass))
#define RETRO_IS_MOUSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_MOUSE))
#define RETRO_IS_MOUSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RETRO_TYPE_MOUSE))
#define RETRO_MOUSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RETRO_TYPE_MOUSE, RetroMouseClass))

typedef struct _RetroMouse RetroMouse;
typedef struct _RetroMouseClass RetroMouseClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define RETRO_TYPE_INPUT (retro_input_get_type ())
#define RETRO_INPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_INPUT, RetroInput))
#define RETRO_IS_INPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_INPUT))
#define RETRO_INPUT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), RETRO_TYPE_INPUT, RetroInputIface))

typedef struct _RetroInput RetroInput;
typedef struct _RetroInputIface RetroInputIface;

#define RETRO_TYPE_DEVICE_TYPE (retro_device_type_get_type ())

#define RETRO_TYPE_INPUT_DESCRIPTOR (retro_input_descriptor_get_type ())
typedef struct _RetroInputDescriptor RetroInputDescriptor;

#define RETRO_TYPE_INPUT_DEVICE (retro_input_device_get_type ())
#define RETRO_INPUT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RETRO_TYPE_INPUT_DEVICE, RetroInputDevice))
#define RETRO_IS_INPUT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RETRO_TYPE_INPUT_DEVICE))
#define RETRO_INPUT_DEVICE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), RETRO_TYPE_INPUT_DEVICE, RetroInputDeviceIface))

typedef struct _RetroInputDevice RetroInputDevice;
typedef struct _RetroInputDeviceIface RetroInputDeviceIface;

struct _RetroCoreView {
	GtkEventBox parent_instance;
	RetroCoreViewPrivate * priv;
};

struct _RetroCoreViewClass {
	GtkEventBoxClass parent_class;
};

struct _RetroCoreViewPrivate {
	RetroCore* core;
	RetroCairoDisplay* display;
	RetroInputDeviceManager* input;
	RetroKeyboard* keyboard;
	RetroMouse* mouse;
};

typedef enum  {
	RETRO_DEVICE_TYPE_TYPE_MASK = 0xff,
	RETRO_DEVICE_TYPE_NONE = 0,
	RETRO_DEVICE_TYPE_JOYPAD = 1,
	RETRO_DEVICE_TYPE_MOUSE = 2,
	RETRO_DEVICE_TYPE_KEYBOARD = 3,
	RETRO_DEVICE_TYPE_LIGHTGUN = 4,
	RETRO_DEVICE_TYPE_ANALOG = 5,
	RETRO_DEVICE_TYPE_POINTER = 6
} RetroDeviceType;

struct _RetroInputDescriptor {
	guint port;
	RetroDeviceType device;
	guint index;
	guint id;
	gchar* description;
};

struct _RetroInputDeviceIface {
	GTypeInterface parent_iface;
	void (*poll) (RetroInputDevice* self);
	gint16 (*get_input_state) (RetroInputDevice* self, RetroDeviceType device, guint index, guint id);
	RetroDeviceType (*get_device_type) (RetroInputDevice* self);
	guint64 (*get_device_capabilities) (RetroInputDevice* self);
};

typedef void (*RetroInputControllerCallback) (guint port, RetroInputDevice* device, void* user_data);
struct _RetroInputIface {
	GTypeInterface parent_iface;
	void (*poll) (RetroInput* self);
	gint16 (*get_state) (RetroInput* self, guint port, RetroDeviceType device, guint index, guint id);
	void (*set_descriptors) (RetroInput* self, RetroInputDescriptor* input_descriptors, int input_descriptors_length1);
	guint64 (*get_device_capabilities) (RetroInput* self);
	void (*foreach_controller) (RetroInput* self, RetroInputControllerCallback callback, void* callback_target);
};


static gpointer retro_core_view_parent_class = NULL;

GType retro_core_view_get_type (void) G_GNUC_CONST;
GType retro_core_get_type (void) G_GNUC_CONST;
GType retro_cairo_display_get_type (void) G_GNUC_CONST;
GType retro_input_device_manager_get_type (void) G_GNUC_CONST;
GType retro_keyboard_get_type (void) G_GNUC_CONST;
GType retro_mouse_get_type (void) G_GNUC_CONST;
#define RETRO_CORE_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RETRO_TYPE_CORE_VIEW, RetroCoreViewPrivate))
enum  {
	RETRO_CORE_VIEW_DUMMY_PROPERTY
};
void retro_core_view_set_core (RetroCoreView* self, RetroCore* core);
void retro_cairo_display_set_core (RetroCairoDisplay* self, RetroCore* core);
GType retro_device_type_get_type (void) G_GNUC_CONST;
GType retro_input_descriptor_get_type (void) G_GNUC_CONST;
RetroInputDescriptor* retro_input_descriptor_dup (const RetroInputDescriptor* self);
void retro_input_descriptor_free (RetroInputDescriptor* self);
void retro_input_descriptor_copy (const RetroInputDescriptor* self, RetroInputDescriptor* dest);
void retro_input_descriptor_destroy (RetroInputDescriptor* self);
GType retro_input_device_get_type (void) G_GNUC_CONST;
GType retro_input_get_type (void) G_GNUC_CONST;
void retro_core_set_input_interface (RetroCore* self, RetroInput* value);
RetroCoreView* retro_core_view_new (void);
RetroCoreView* retro_core_view_construct (GType object_type);
static GObject * retro_core_view_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
RetroCairoDisplay* retro_cairo_display_new (void);
RetroCairoDisplay* retro_cairo_display_construct (GType object_type);
RetroInputDeviceManager* retro_input_device_manager_new (void);
RetroInputDeviceManager* retro_input_device_manager_construct (GType object_type);
RetroKeyboard* retro_keyboard_new (GtkWidget* widget);
RetroKeyboard* retro_keyboard_construct (GType object_type, GtkWidget* widget);
RetroMouse* retro_mouse_new (GtkWidget* widget);
RetroMouse* retro_mouse_construct (GType object_type, GtkWidget* widget);
void retro_input_device_manager_set_keyboard (RetroInputDeviceManager* self, RetroKeyboard* keyboard);
void retro_input_device_manager_set_controller_device (RetroInputDeviceManager* self, guint port, RetroInputDevice* device);
static void retro_core_view_finalize (GObject * obj);


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


void retro_core_view_set_core (RetroCoreView* self, RetroCore* core) {
	RetroCore* _tmp0_;
	RetroCore* _tmp3_;
	RetroCore* _tmp4_;
	RetroCore* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->core;
	if (_tmp0_ != NULL) {
		RetroCairoDisplay* _tmp1_;
		RetroCore* _tmp2_;
		_tmp1_ = self->priv->display;
		retro_cairo_display_set_core (_tmp1_, NULL);
		_tmp2_ = core;
		retro_core_set_input_interface (_tmp2_, NULL);
	}
	_tmp3_ = core;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_g_object_unref0 (self->priv->core);
	self->priv->core = _tmp4_;
	_tmp5_ = core;
	if (_tmp5_ != NULL) {
		RetroCairoDisplay* _tmp6_;
		RetroCore* _tmp7_;
		RetroCore* _tmp8_;
		RetroInputDeviceManager* _tmp9_;
		_tmp6_ = self->priv->display;
		_tmp7_ = core;
		retro_cairo_display_set_core (_tmp6_, _tmp7_);
		_tmp8_ = core;
		_tmp9_ = self->priv->input;
		retro_core_set_input_interface (_tmp8_, (RetroInput*) _tmp9_);
	}
}


RetroCoreView* retro_core_view_construct (GType object_type) {
	RetroCoreView * self = NULL;
	self = (RetroCoreView*) g_object_new (object_type, NULL);
	return self;
}


RetroCoreView* retro_core_view_new (void) {
	return retro_core_view_construct (RETRO_TYPE_CORE_VIEW);
}


static GObject * retro_core_view_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	RetroCoreView * self;
	RetroCairoDisplay* _tmp0_;
	RetroCairoDisplay* _tmp1_;
	RetroCairoDisplay* _tmp2_;
	RetroCairoDisplay* _tmp3_;
	RetroInputDeviceManager* _tmp4_;
	RetroKeyboard* _tmp5_;
	RetroMouse* _tmp6_;
	RetroInputDeviceManager* _tmp7_;
	RetroKeyboard* _tmp8_;
	RetroInputDeviceManager* _tmp9_;
	RetroMouse* _tmp10_;
	parent_class = G_OBJECT_CLASS (retro_core_view_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RETRO_TYPE_CORE_VIEW, RetroCoreView);
	g_object_set ((GtkWidget*) self, "can-focus", TRUE, NULL);
	_tmp0_ = retro_cairo_display_new ();
	g_object_ref_sink (_tmp0_);
	_g_object_unref0 (self->priv->display);
	self->priv->display = _tmp0_;
	_tmp1_ = self->priv->display;
	gtk_widget_set_visible ((GtkWidget*) _tmp1_, TRUE);
	_tmp2_ = self->priv->display;
	g_object_set ((GtkWidget*) _tmp2_, "can-focus", FALSE, NULL);
	_tmp3_ = self->priv->display;
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp3_);
	_tmp4_ = retro_input_device_manager_new ();
	_g_object_unref0 (self->priv->input);
	self->priv->input = _tmp4_;
	_tmp5_ = retro_keyboard_new ((GtkWidget*) self);
	_g_object_unref0 (self->priv->keyboard);
	self->priv->keyboard = _tmp5_;
	_tmp6_ = retro_mouse_new ((GtkWidget*) self);
	_g_object_unref0 (self->priv->mouse);
	self->priv->mouse = _tmp6_;
	_tmp7_ = self->priv->input;
	_tmp8_ = self->priv->keyboard;
	retro_input_device_manager_set_keyboard (_tmp7_, _tmp8_);
	_tmp9_ = self->priv->input;
	_tmp10_ = self->priv->mouse;
	retro_input_device_manager_set_controller_device (_tmp9_, (guint) 0, (RetroInputDevice*) _tmp10_);
	return obj;
}


static void retro_core_view_class_init (RetroCoreViewClass * klass) {
	retro_core_view_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (RetroCoreViewPrivate));
	G_OBJECT_CLASS (klass)->constructor = retro_core_view_constructor;
	G_OBJECT_CLASS (klass)->finalize = retro_core_view_finalize;
}


static void retro_core_view_instance_init (RetroCoreView * self) {
	self->priv = RETRO_CORE_VIEW_GET_PRIVATE (self);
}


static void retro_core_view_finalize (GObject * obj) {
	RetroCoreView * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, RETRO_TYPE_CORE_VIEW, RetroCoreView);
	_g_object_unref0 (self->priv->core);
	_g_object_unref0 (self->priv->display);
	_g_object_unref0 (self->priv->input);
	_g_object_unref0 (self->priv->keyboard);
	_g_object_unref0 (self->priv->mouse);
	G_OBJECT_CLASS (retro_core_view_parent_class)->finalize (obj);
}


GType retro_core_view_get_type (void) {
	static volatile gsize retro_core_view_type_id__volatile = 0;
	if (g_once_init_enter (&retro_core_view_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RetroCoreViewClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) retro_core_view_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RetroCoreView), 0, (GInstanceInitFunc) retro_core_view_instance_init, NULL };
		GType retro_core_view_type_id;
		retro_core_view_type_id = g_type_register_static (gtk_event_box_get_type (), "RetroCoreView", &g_define_type_info, 0);
		g_once_init_leave (&retro_core_view_type_id__volatile, retro_core_view_type_id);
	}
	return retro_core_view_type_id__volatile;
}



