[retro-gtk] demos: Add the retro-demo application



commit ce2f15f68018865588162ccf6bf7c9a0cb998f54
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue May 9 11:07:31 2017 +0200

    demos: Add the retro-demo application
    
    This will be used to build and test retro-gtk in GNOME Builder.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780919

 Makefile.am        |    2 +-
 configure.ac       |    4 ++
 demos/Makefile.am  |   33 ++++++++++++
 demos/retro-demo.c |  139 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 177 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 02b3f72..9a23d7c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
 
 NULL =
 
-SUBDIRS = retro-gtk po
+SUBDIRS = retro-gtk demos po
 
 dist_doc_DATA = \
        README \
diff --git a/configure.ac b/configure.ac
index d40e67e..4f1a5bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,6 +14,9 @@ AM_PROG_AR
 
 AM_PROG_VALAC
 
+# GResource
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
 GOBJECT_INTROSPECTION_CHECK([0.6.7])
 
 dnl ***************************************************************************
@@ -48,6 +51,7 @@ AC_SUBST(retro_gtk_pkg_modules)
 
 AC_OUTPUT([
 Makefile
+demos/Makefile
 retro-gtk/retro-gtk-0.10.pc
 retro-gtk/Makefile
 po/Makefile.in])
diff --git a/demos/Makefile.am b/demos/Makefile.am
new file mode 100644
index 0000000..e98afb6
--- /dev/null
+++ b/demos/Makefile.am
@@ -0,0 +1,33 @@
+NULL =
+
+bin_PROGRAMS = retro-demo
+
+retro_demo_SOURCES = \
+       retro-demo.c \
+       $(NULL)
+
+retro_demo_CFLAGS = \
+       $(RETRO_GTK_CFLAGS) \
+       $(GAMEPADS_CFLAGS) \
+       $(UDEV_CFLAGS) \
+       -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+       -DGAMES_PLUGINS_DIR=\"$(libdir)/gnome-games/plugins\" \
+       $(NULL)
+
+retro_demo_CPPFLAGS = \
+       -I$(top_srcdir) \
+       -I$(top_builddir)/retro-gtk \
+       -I$(top_srcdir)/retro-gtk \
+       -DRETRO_GTK_USE_UNSTABLE_API \
+       $(NULL)
+
+retro_demo_DEPENDENCIES = \
+       $(top_builddir)/retro-gtk/libretro-gtk.la \
+       $(NULL)
+
+retro_demo_LDADD = \
+       $(RETRO_GTK_LIBS) \
+       $(top_builddir)/retro-gtk/libretro-gtk.la \
+       $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/demos/retro-demo.c b/demos/retro-demo.c
new file mode 100644
index 0000000..74f16db
--- /dev/null
+++ b/demos/retro-demo.c
@@ -0,0 +1,139 @@
+// This file is part of retro-gtk. License: GPLv3
+
+#include <retro-gtk/retro-gtk.h>
+
+#define RETRO_TYPE_DEMO_APPLICATION (retro_demo_application_get_type())
+
+G_DECLARE_FINAL_TYPE (RetroDemoApplication, retro_demo_application, RETRO, DEMO_APPLICATION, GtkApplication)
+
+struct _RetroDemoApplication
+{
+  GtkApplication parent_instance;
+
+  GtkApplicationWindow *window;
+
+  RetroCore *core;
+  RetroMainLoop *loop;
+  RetroCairoDisplay *display;
+  RetroPaPlayer *pa_player;
+};
+
+G_DEFINE_TYPE (RetroDemoApplication, retro_demo_application, GTK_TYPE_APPLICATION)
+
+static void
+retro_demo_open (GApplication  *application,
+                 GFile        **files,
+                 gint           n_files,
+                 const gchar   *hint)
+{
+  RetroDemoApplication *self;
+  char *module_path;
+
+  self = RETRO_DEMO_APPLICATION (application);
+
+  if (n_files < 1)
+    return;
+
+  if (!g_file_query_exists (files[0], NULL))
+    return;
+
+  module_path = g_file_get_path (files[0]);
+  self->core = retro_core_new (module_path);
+  g_free (module_path);
+
+  if (self->core == NULL)
+    return;
+
+  g_signal_emit_by_name (self->core, "init");
+
+  retro_core_prepare (self->core);
+  g_application_activate (application);
+}
+
+static RetroDemoApplication *
+retro_demo_application_new (void)
+{
+  return g_object_new (RETRO_TYPE_DEMO_APPLICATION, NULL);
+}
+
+static void
+retro_demo_application_finalize (GObject *object)
+{
+  RetroDemoApplication *self = RETRO_DEMO_APPLICATION (object);
+
+  if (self->core != NULL)
+    g_object_unref (self->core);
+
+  if (self->loop != NULL)
+    g_object_unref (self->loop);
+
+  if (self->display != NULL)
+    g_object_unref (self->display);
+
+  if (self->pa_player != NULL)
+    g_object_unref (self->pa_player);
+
+  G_OBJECT_CLASS (retro_demo_application_parent_class)->finalize (object);
+}
+
+
+static void
+retro_demo_activate (GApplication *application)
+{
+  RetroDemoApplication *self;
+  GtkWidget *window;
+
+  self = RETRO_DEMO_APPLICATION (application);
+
+  self->display = retro_cairo_display_new ();
+  retro_cairo_display_set_core (self->display, self->core);
+
+  self->pa_player = retro_pa_player_new ();
+  retro_pa_player_set_core (self->pa_player, self->core);
+
+  window = gtk_window_new (GTK_WIN_POS_NONE);
+  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
+  gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (self->display));
+
+  gtk_widget_show_all (GTK_WIDGET (window));
+  gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (window));
+
+  self->loop = retro_main_loop_new (self->core);
+  retro_main_loop_start (self->loop);
+}
+
+static void
+retro_demo_application_class_init (RetroDemoApplicationClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
+
+  object_class->finalize = retro_demo_application_finalize;
+
+  application_class->activate = retro_demo_activate;
+  application_class->open = retro_demo_open;
+}
+
+static void
+retro_demo_application_init (RetroDemoApplication *self)
+{
+  g_application_set_application_id (G_APPLICATION (self), "org.gnome.Retro.Demo");
+  g_application_set_flags (G_APPLICATION (self), G_APPLICATION_HANDLES_OPEN);
+}
+
+gint
+main (gint   argc,
+      gchar *argv[])
+{
+  RetroDemoApplication *app;
+  int status;
+
+  g_set_prgname ("retro-demo");
+  g_set_application_name ("org.gnome.Retro.Demo");
+
+  app = retro_demo_application_new();
+  status = g_application_run (G_APPLICATION (app), argc, argv);
+  g_object_unref (app);
+
+  return status;
+}


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