[atomix/wip/gtk3-port] Added board test application
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [atomix/wip/gtk3-port] Added board test application
- Date: Mon, 12 Jan 2015 04:46:40 +0000 (UTC)
commit e65b08aa6b42979899aa67cf73650700f53ecca9
Author: Robert Roth <robert roth off gmail com>
Date: Mon Jan 12 06:46:23 2015 +0200
Added board test application
src/Makefile.am | 20 ++++++++++-
src/board-test.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/board_gtk.c | 2 +-
src/main.c | 3 +-
src/undo.c | 6 ++--
5 files changed, 124 insertions(+), 6 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4f563d9..2647872 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,7 +12,7 @@ INCLUDES = -I$(top_srcdir) \
bin_PROGRAMS = atomix
-noinst_PROGRAMS = pf-test
+noinst_PROGRAMS = pf-test board-test
atomix_SOURCES = \
main.c main.h \
@@ -47,6 +47,24 @@ pf_test_SOURCES = \
theme.c theme.h \
pf-test.c
+board_test_SOURCES = \
+ playfield.h playfield.c \
+ tile.c tile.h \
+ theme.c theme.h \
+ board_gtk.c board_gtk.h \
+ undo.c undo.h \
+ goal.c goal.h \
+ theme-manager.c theme-manager.h \
+ canvas_helper.c canvas_helper.h \
+ level.c level.h level-private.h \
+ level-manager.c level-manager.h \
+ board-test.c
+
+board_test_LDADD = \
+ -L$(top_builddir)/src \
+ -lm \
+ $(ATOMIX_LIBS)
+
pf_test_LDADD = \
-L$(top_builddir)/src \
$(ATOMIX_LIBS)
diff --git a/src/board-test.c b/src/board-test.c
new file mode 100644
index 0000000..ddb6d62
--- /dev/null
+++ b/src/board-test.c
@@ -0,0 +1,99 @@
+#include <gtk/gtk.h>
+
+#include "board_gtk.h"
+#include "theme-manager.h"
+#include "level-manager.h"
+
+
+static Theme *theme = NULL;
+
+static void hello( GtkWidget *widget,
+ gpointer data )
+{
+ g_print ("Hello World\n");
+}
+
+static gboolean delete_event( GtkWidget *widget,
+ GdkEvent *event,
+ gpointer data )
+{
+
+ g_print ("delete event occurred\n");
+ gtk_widget_destroy (widget);
+ return TRUE;
+}
+
+/* Another callback */
+static void destroy( GtkWidget *widget,
+ gpointer data )
+{
+ gtk_main_quit ();
+}
+
+static void setup_level (void)
+{
+ Level *next_level;
+ PlayField *goal_pf;
+ LevelManager *lm;
+ Goal *goal;
+ PlayField *env_pf;
+ PlayField *sce_pf;
+
+ lm = level_manager_new ();
+ level_manager_init_levels (lm);
+
+ next_level = level_manager_get_next_level (lm, NULL);
+ goal_pf = level_get_goal (next_level);
+
+ goal = goal_new (goal_pf);
+
+ g_object_unref (goal_pf);
+ g_object_unref (lm);
+
+ /* init board */
+ env_pf = level_get_environment (next_level);
+ sce_pf = level_get_scenario (next_level);
+ board_gtk_init_level (env_pf, sce_pf, goal);
+
+ g_object_unref (env_pf);
+ g_object_unref (sce_pf);
+}
+
+int main( int argc,
+ char *argv[] )
+{
+ GtkWidget *window;
+ GtkWidget *board;
+ ThemeManager *tm;
+
+ gtk_init (&argc, &argv);
+ /* init theme manager */
+ tm = theme_manager_new ();
+ theme_manager_init_themes (tm);
+ theme = theme_manager_get_theme (tm, "default");
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ g_signal_connect (window, "delete-event",
+ G_CALLBACK (delete_event), NULL);
+
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (destroy), NULL);
+
+ board = gtk_fixed_new ();
+ gtk_widget_show (board);
+ board_gtk_init (theme, GTK_FIXED (board));
+ setup_level ();
+ /* This packs the button into the window (a gtk container). */
+ gtk_container_add (GTK_CONTAINER (window), board);
+
+ /* and the window */
+ gtk_widget_show (window);
+ gtk_widget_set_size_request (GTK_WIDGET (window), 478, 478);
+ /* All GTK applications must have a gtk_main(). Control ends here
+ * and waits for an event to occur (like a key press or
+ * mouse event). */
+ gtk_main ();
+
+ return 0;
+}
diff --git a/src/board_gtk.c b/src/board_gtk.c
index 30e85f3..643ba6a 100644
--- a/src/board_gtk.c
+++ b/src/board_gtk.c
@@ -395,7 +395,7 @@ GtkImage* create_tile (double x, double y,
// TODO handle button click
if (tile_get_tile_type (tile) == TILE_TYPE_ATOM) {
printf ("Adding button event handler\n");
- g_signal_connect (G_OBJECT (item), "button-press-event",
+ g_signal_connect (G_OBJECT (item), "event",
G_CALLBACK (board_handle_item_event), NULL);
}
diff --git a/src/main.c b/src/main.c
index 3077c6a..6ee70a2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -368,6 +368,7 @@ static void atomix_exit (void)
static gboolean on_key_press_event (GObject *widget, GdkEventKey *event,
gpointer user_data)
{
+ printf ("Key pressed\n");
if ((app->state == GAME_STATE_RUNNING) || (app->state == GAME_STATE_RUNNING_UNMOVED))
{
board_gtk_handle_key_event (NULL, event, NULL);
@@ -665,7 +666,7 @@ static GtkWidget *create_mainwin_content (AtomixApp *app)
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (pf), TRUE, TRUE, 0);
- g_signal_connect (G_OBJECT (app->fi_matrix), "key_press_event",
+ g_signal_connect (G_OBJECT (app->fi_matrix), "key-press-event",
G_CALLBACK (on_key_press_event), app);
/* create right window side */
diff --git a/src/undo.c b/src/undo.c
index 16f9cda..a45ec98 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -19,7 +19,7 @@
#include "main.h"
#include "undo.h"
-extern AtomixApp *app;
+// extern AtomixApp *app;
static GSList *undo_stack = NULL;
gboolean undo_exists (void)
@@ -68,8 +68,8 @@ UndoMove *undo_pop_move (void)
if (undo_stack == NULL)
{
- app->state = GAME_STATE_RUNNING_UNMOVED;
- update_menu_item_state ();
+// app->state = GAME_STATE_RUNNING_UNMOVED;
+// update_menu_item_state ();
}
return move;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]