[gnome-games] Removed the GtkClutterEmbed from GnibblesBoard and replaced it with a
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-games] Removed the GtkClutterEmbed from GnibblesBoard and replaced it with a
- Date: Wed, 14 Oct 2009 02:51:05 +0000 (UTC)
commit e492e0daddbd1ad489291c86af120ee62eecf7d7
Author: Guillaume Beland <guillaume beland gmail com>
Date: Mon Jul 20 23:40:57 2009 -0400
Removed the GtkClutterEmbed from GnibblesBoard and replaced it with a
ClutterStage
gnibbles/board.c | 25 +++++++------------------
gnibbles/board.h | 5 ++---
gnibbles/bonus.c | 3 +--
gnibbles/gnibbles.c | 4 +---
gnibbles/main.c | 27 ++++++++++++++-------------
gnibbles/warp.c | 3 +--
gnibbles/worm-clutter.c | 41 +++++++++++++++++++++++++++++++++--------
7 files changed, 59 insertions(+), 49 deletions(-)
---
diff --git a/gnibbles/board.c b/gnibbles/board.c
index 3b8025d..7c53777 100644
--- a/gnibbles/board.c
+++ b/gnibbles/board.c
@@ -40,7 +40,7 @@ extern GnibblesProperties *properties;
extern GdkPixbuf *wall_pixmaps[];
GnibblesBoard *
-gnibbles_board_new (gint t_w, gint t_h)
+gnibbles_board_new (ClutterActor *stage)
{
ClutterColor stage_color = {0x00,0x00,0x00,0xff};
gchar *filename;
@@ -48,15 +48,12 @@ gnibbles_board_new (gint t_w, gint t_h)
GValue val = {0,};
GnibblesBoard *board = g_new (GnibblesBoard, 1);
- board->width = t_w;
- board->height = t_h;
+ board->width = BOARDWIDTH;
+ board->height = BOARDHEIGHT;
board->level = NULL;
board->surface = NULL;
- board->clutter_widget = gtk_clutter_embed_new ();
+ board->stage = stage;
- ClutterActor *stage;
-
- stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (board->clutter_widget));
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), FALSE);
@@ -87,12 +84,6 @@ gnibbles_board_new (gint t_w, gint t_h)
return board;
}
-ClutterActor *
-gnibbles_board_get_stage (GnibblesBoard *board)
-{
- return gtk_clutter_embed_get_stage(GTK_CLUTTER_EMBED(board->clutter_widget));
-}
-
void
gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
{
@@ -167,9 +158,8 @@ gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level)
}
}
- ClutterActor *stage = gnibbles_board_get_stage (board);
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), board->level);
- clutter_actor_raise (board->level,board->surface);
+ clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), board->level);
+ clutter_actor_raise (board->level, board->surface);
clutter_actor_set_opacity (board->level, 0);
clutter_actor_animate (board->level, CLUTTER_EASE_IN_QUAD, 410,
@@ -192,9 +182,8 @@ gnibbles_board_resize (GnibblesBoard *board, gint newtile)
int count;
ClutterActor *tmp;
- ClutterActor *stage = gnibbles_board_get_stage (board);
- clutter_actor_set_size (stage,
+ clutter_actor_set_size (board->stage,
BOARDWIDTH * newtile,
BOARDHEIGHT * newtile);
clutter_actor_set_size (board->surface,
diff --git a/gnibbles/board.h b/gnibbles/board.h
index 3907244..9ed8461 100644
--- a/gnibbles/board.h
+++ b/gnibbles/board.h
@@ -31,13 +31,12 @@
typedef struct {
gint width;
gint height;
- GtkWidget *clutter_widget;
+ ClutterActor *stage;
ClutterActor *surface;
ClutterActor *level;
} GnibblesBoard;
-GnibblesBoard* gnibbles_board_new (gint t_w, gint t_h);
-ClutterActor* gnibbles_board_get_stage (GnibblesBoard *board);
+GnibblesBoard* gnibbles_board_new (ClutterActor *stage);
void gnibbles_board_load_level (GnibblesBoard *board, GnibblesLevel *level);
void gnibbles_board_resize (GnibblesBoard *board, gint newtile);
diff --git a/gnibbles/bonus.c b/gnibbles/bonus.c
index de83c64..210ec35 100644
--- a/gnibbles/bonus.c
+++ b/gnibbles/bonus.c
@@ -61,8 +61,7 @@ gnibbles_bonus_draw (GnibblesBonus *bonus)
clutter_actor_set_position (CLUTTER_ACTOR (bonus->actor),
bonus->x * properties->tilesize,
bonus->y * properties->tilesize);
- ClutterActor *stage = gnibbles_board_get_stage (board);
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), bonus->actor);
+ clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), bonus->actor);
clutter_actor_set_opacity (bonus->actor, 0);
clutter_actor_animate (bonus->actor, CLUTTER_EASE_IN_QUAD, 410,
"opacity", 0xff,
diff --git a/gnibbles/gnibbles.c b/gnibbles/gnibbles.c
index e013a11..666f396 100644
--- a/gnibbles/gnibbles.c
+++ b/gnibbles/gnibbles.c
@@ -203,11 +203,9 @@ gnibbles_init ()
colorval_name (properties->wormprops[i]->color));
}
- ClutterActor *stage = gnibbles_board_get_stage (board);
-
for (i = 0; i < properties->numworms; i++) {
if (worms[i]) {
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors);
+ clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), worms[i]->actors);
clutter_actor_raise_top (worms[i]->actors);
gnibbles_worm_show (worms[i]);
}
diff --git a/gnibbles/main.c b/gnibbles/main.c
index 454924c..bd08204 100644
--- a/gnibbles/main.c
+++ b/gnibbles/main.c
@@ -90,6 +90,8 @@ GnibblesLevel *level;
GnibblesScoreboard *scoreboard;
+GtkWidget *clutter_widget;
+
extern GnibblesWorm *worms[];
extern GnibblesBoni *boni;
@@ -126,8 +128,7 @@ static ClutterActor *logo;
static void
hide_cursor (void)
{
- ClutterActor *stage = gnibbles_board_get_stage (board);
- clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
+ clutter_stage_hide_cursor (CLUTTER_STAGE (board->stage));
}
static void
@@ -182,8 +183,7 @@ window_state_cb (GtkWidget * widget, GdkEventWindowState * event)
static void
show_cursor (void)
{
- ClutterActor *stage = gnibbles_board_get_stage (board);
- clutter_stage_show_cursor (CLUTTER_STAGE (stage));
+ clutter_stage_show_cursor (CLUTTER_STAGE (board->stage));
}
gint
@@ -327,7 +327,7 @@ new_game_2_cb (GtkWidget * widget, gpointer data)
{
if (!paused) {
if (!keyboard_id)
- keyboard_id = g_signal_connect (G_OBJECT (gnibbles_board_get_stage (board)),
+ keyboard_id = g_signal_connect (G_OBJECT (board->stage),
"key-press-event",
G_CALLBACK (key_press_cb), NULL);
#ifdef GGZ_CLIENT
@@ -798,10 +798,14 @@ setup_window ()
GtkWidget *main_vbox;
GtkWidget *packing;
GtkWidget *menubar;
+
GtkUIManager *ui_manager;
GtkAccelGroup *accel_group;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ clutter_widget = gtk_clutter_embed_new ();
+ board = gnibbles_board_new (gtk_clutter_embed_get_stage (
+ GTK_CLUTTER_EMBED (clutter_widget)));
gtk_window_set_title (GTK_WINDOW (window), _("Nibbles"));
gtk_window_set_default_size (GTK_WINDOW (window),
@@ -837,13 +841,13 @@ setup_window ()
gtk_widget_show (packing);
- gtk_container_add (GTK_CONTAINER (packing), board->clutter_widget);
+ gtk_container_add (GTK_CONTAINER (packing), clutter_widget);
#ifdef GGZ_CLIENT
chat = create_chat_widget ();
gtk_box_pack_start (GTK_BOX (vbox), chat, FALSE, TRUE, 0);
#endif
- g_signal_connect (G_OBJECT (board->clutter_widget), "configure_event",
+ g_signal_connect (G_OBJECT (clutter_widget), "configure_event",
G_CALLBACK (configure_event_cb), NULL);
g_signal_connect (G_OBJECT (window), "focus_out_event",
@@ -876,10 +880,9 @@ render_logo (void)
ClutterActor *desc;
ClutterColor actor_color = {0xff,0xff,0xff,0xff};
- ClutterActor *stage = gnibbles_board_get_stage (board);
logo = clutter_group_new ();
- clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
+ clutter_actor_get_size (CLUTTER_ACTOR (board->stage), &width, &height);
if (!logo_pixmap)
gnibbles_load_logo ();
@@ -904,7 +907,7 @@ render_logo (void)
CLUTTER_ACTOR (desc),
NULL);
- clutter_container_add_actor (CLUTTER_CONTAINER (stage),
+ clutter_container_add_actor (CLUTTER_CONTAINER (board->stage),
CLUTTER_ACTOR (logo));
}
@@ -968,11 +971,9 @@ main (int argc, char **argv)
games_conf_initialise ("Gnibbles");
properties = gnibbles_properties_new ();
-
+ setup_window ();
gnibbles_load_pixmap (properties->tilesize);
- board = gnibbles_board_new (BOARDWIDTH, BOARDHEIGHT);
- setup_window ();
gnibbles_load_logo ();
#ifdef GGZ_CLIENT
diff --git a/gnibbles/warp.c b/gnibbles/warp.c
index daeedac..f689f84 100644
--- a/gnibbles/warp.c
+++ b/gnibbles/warp.c
@@ -57,8 +57,7 @@ gnibbles_warp_draw (GnibblesWarp *warp)
clutter_actor_set_position (CLUTTER_ACTOR (warp->actor),
properties->tilesize * warp->x,
properties->tilesize * warp->y);
- ClutterActor *stage = gnibbles_board_get_stage (board);
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), warp->actor);
+ clutter_container_add_actor (CLUTTER_CONTAINER (board->stage), warp->actor);
clutter_actor_set_opacity (warp->actor, 0);
clutter_actor_animate (warp->actor, CLUTTER_EASE_IN_QUAD, 410,
"opacity", 0xff,
diff --git a/gnibbles/worm-clutter.c b/gnibbles/worm-clutter.c
index 1e6f57f..884a5bf 100644
--- a/gnibbles/worm-clutter.c
+++ b/gnibbles/worm-clutter.c
@@ -650,7 +650,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
level->walls[worm->xhead][worm->yhead] = WORMCHAR;
worm->xhead++;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->xtail++;
+ if (worm->xtail == BOARDWIDTH)
+ worm->xtail = 0;
+ else
+ worm->xtail++;
break;
case WORMDOWN:
clutter_actor_set_position (CLUTTER_ACTOR (head),
@@ -658,7 +661,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
level->walls[worm->xhead][worm->yhead] = WORMCHAR;
worm->yhead++;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->ytail++;
+ if (worm->ytail == BOARDHEIGHT)
+ worm->ytail = 0;
+ else
+ worm->ytail++;
break;
case WORMLEFT:
clutter_actor_set_position (CLUTTER_ACTOR (head),
@@ -666,7 +672,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
level->walls[worm->xhead][worm->yhead] = WORMCHAR;
worm->xhead--;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->xtail--;
+ if (worm->xtail == 0)
+ worm->xtail = BOARDWIDTH;
+ else
+ worm->xtail--;
break;
case WORMUP:
clutter_actor_set_position (CLUTTER_ACTOR (head),
@@ -674,7 +683,10 @@ gnibbles_worm_move_straight_worm (GnibblesWorm *worm)
level->walls[worm->xhead][worm->yhead] = WORMCHAR;
worm->yhead--;
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->ytail--;
+ if (worm->ytail == 0)
+ worm->ytail = BOARDHEIGHT;
+ else
+ worm->ytail--;
break;
default:
break;
@@ -791,8 +803,12 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
properties->tilesize);
clutter_actor_set_position (CLUTTER_ACTOR (tail),
x + properties->tilesize, y);
+
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->xtail++;
+ if (worm->xtail == BOARDWIDTH)
+ worm->xtail = 0;
+ else
+ worm->xtail++;
break;
case WORMDOWN:
clutter_actor_set_size (CLUTTER_ACTOR (tail),
@@ -801,21 +817,30 @@ gnibbles_worm_move_tail (GnibblesWorm *worm)
clutter_actor_set_position (CLUTTER_ACTOR (tail),
x, y + properties->tilesize);
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->ytail++;
+ if (worm->ytail == BOARDHEIGHT)
+ worm->ytail = 0;
+ else
+ worm->ytail++;
break;
case WORMLEFT:
clutter_actor_set_size (CLUTTER_ACTOR (tail),
size,
properties->tilesize);
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->xtail--;
+ if (worm->xtail == 0)
+ worm->xtail = BOARDWIDTH;
+ else
+ worm->xtail--;
break;
case WORMUP:
clutter_actor_set_size (CLUTTER_ACTOR (tail),
properties->tilesize,
size);
level->walls[worm->xtail][worm->ytail] = EMPTYCHAR;
- worm->ytail--;
+ if (worm->ytail == 0)
+ worm->ytail = BOARDHEIGHT;
+ else
+ worm->ytail--;
break;
default:
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]