gnome-games r8647 - trunk/gnometris
- From: jclinton svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8647 - trunk/gnometris
- Date: Tue, 3 Feb 2009 18:55:51 +0000 (UTC)
Author: jclinton
Date: Tue Feb 3 18:55:50 2009
New Revision: 8647
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8647&view=rev
Log:
Factor out all calls to redraw so that we do not use cairo for
animation. This change eliminates more surface oriented drawing logic
but preserves backward compatibility with the old engine.
This also removes the 'target' drawing code which will have to be done
entirely differently in Clutter. For now, the UI elements remain in
order to avoid and warning about string changes during the string
freeze. It will be reimplemented eventually anyway.
Finally, this commit disables building -noclutter binary variant when
in the HAVE_CLUTTER case.
Modified:
trunk/gnometris/Makefile.am
trunk/gnometris/blockops.cpp
trunk/gnometris/blockops.h
trunk/gnometris/field.cpp
trunk/gnometris/field.h
trunk/gnometris/renderer.cpp
trunk/gnometris/tetris.cpp
Modified: trunk/gnometris/Makefile.am
==============================================================================
--- trunk/gnometris/Makefile.am (original)
+++ trunk/gnometris/Makefile.am Tue Feb 3 18:55:50 2009
@@ -64,30 +64,30 @@
endif
if HAVE_CLUTTER
-noinst_PROGRAMS = gnometris-noclutter
+#noinst_PROGRAMS = gnometris-noclutter
-gnometris_noclutter_SOURCES = \
- main.cpp \
- blocks.cpp \
- blocks.h \
- preview-noclutter.cpp \
- preview-noclutter.h \
- blockops.cpp \
- blockops.h \
- field-noclutter.cpp \
- field-noclutter.h \
- highscores.cpp \
- highscores.h \
- renderer-noclutter.cpp \
- renderer-noclutter.h \
- scoreframe.cpp \
- scoreframe.h \
- tetris.cpp \
- tetris.h
-
-gnometris_noclutter_CPPFLAGS = $(gnometris_CPPFLAGS) -UHAVE_CLUTTER
-gnometris_noclutter_CXXFLAGS = $(gnometris_CXXFLAGS) -UHAVE_CLUTTER
-gnometris_noclutter_LDADD = $(gnometris_LDADD)
+#gnometris_noclutter_SOURCES = \
+# main.cpp \
+# blocks.cpp \
+# blocks.h \
+# preview-noclutter.cpp \
+# preview-noclutter.h \
+# blockops.cpp \
+# blockops.h \
+# field-noclutter.cpp \
+# field-noclutter.h \
+# highscores.cpp \
+# highscores.h \
+# renderer-noclutter.cpp \
+# renderer-noclutter.h \
+# scoreframe.cpp \
+# scoreframe.h \
+# tetris.cpp \
+# tetris.h
+
+#gnometris_noclutter_CPPFLAGS = $(gnometris_CPPFLAGS) -UHAVE_CLUTTER
+#gnometris_noclutter_CXXFLAGS = $(gnometris_CXXFLAGS) -UHAVE_CLUTTER
+#gnometris_noclutter_LDADD = $(gnometris_LDADD)
gnometris_CPPFLAGS += -DHAVE_CLUTTER
gnometris_CXXFLAGS += $(CLUTTER_CFLAGS)
gnometris_LDADD += $(CLUTTER_LIBS)
Modified: trunk/gnometris/blockops.cpp
==============================================================================
--- trunk/gnometris/blockops.cpp (original)
+++ trunk/gnometris/blockops.cpp Tue Feb 3 18:55:50 2009
@@ -33,7 +33,9 @@
BlockOps::BlockOps() :
+#ifndef HAVE_CLUTTER
useTarget (false),
+#endif
blocknr (0),
rot (0),
color (0)
@@ -183,6 +185,7 @@
return fallen;
}
+#ifndef HAVE_CLUTTER
void
BlockOps::clearTarget ()
{
@@ -222,6 +225,7 @@
if (!useTarget)
clearTarget ();
}
+#endif
int
BlockOps::dropBlock()
@@ -363,9 +367,11 @@
int i = bx - 2 + x;
int j = y + by;
+#ifndef HAVE_CLUTTER
if ((fill == TARGET) &&
(field[i][j].what != EMPTY))
return;
+#endif
field[i][j].what = fill;
if ((fill == FALLING) || (fill == LAYING))
Modified: trunk/gnometris/blockops.h
==============================================================================
--- trunk/gnometris/blockops.h (original)
+++ trunk/gnometris/blockops.h Tue Feb 3 18:55:50 2009
@@ -26,7 +26,9 @@
enum SlotType {
EMPTY,
+#ifndef HAVE_CLUTTER
TARGET,
+#endif
FALLING,
LAYING
};
@@ -54,10 +56,12 @@
void putBlockInField (bool erase);
int getLinesToBottom ();
bool isFieldEmpty (void);
+#ifndef HAVE_CLUTTER
void setUseTarget (bool);
bool getUseTarget () {
return useTarget;
};
+#endif
private:
void putBlockInField (int bx, int by, int blocknr, int rotation,
@@ -65,11 +69,14 @@
bool blockOkHere (int x, int y, int b, int r);
void eliminateLine (int l);
+#ifndef HAVE_CLUTTER
bool useTarget;
-
+#endif
protected:
+#ifdef HAVE_CLUTTER
void clearTarget ();
void generateTarget ();
+#endif
Block **field;
Modified: trunk/gnometris/field.cpp
==============================================================================
--- trunk/gnometris/field.cpp (original)
+++ trunk/gnometris/field.cpp Tue Feb 3 18:55:50 2009
@@ -58,9 +58,6 @@
Field::~Field()
{
- if (background)
- clutter_actor_destroy(background);
-
if (renderer)
delete renderer;
}
@@ -136,8 +133,6 @@
cairo_paint(bg_cr);
cairo_destroy(bg_cr);
-
- redraw ();
}
void
@@ -153,91 +148,64 @@
field->height = widget->allocation.height;
field->rescaleField ();
- field->rescaleBlockCache ();
-
+
return TRUE;
}
void
-Field::drawMessage(cairo_t *cr, const char *msg)
+Field::drawMessage()
{
PangoLayout *dummy_layout;
PangoLayout *layout;
PangoFontDescription *desc;
int lw, lh;
+ cairo_t *cr;
+ char *msg;
- cairo_save(cr);
+ cr = clutter_cairo_create (CLUTTER_CAIRO(foreground));
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint(cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ if (showPause)
+ msg = _("Paused");
+ else if (showGameOver)
+ msg = _("Game Over");
+ else {
+ cairo_destroy (cr);
+ return;
+ }
// Center coordinates
cairo_translate(cr, width / 2, height / 2);
desc = pango_font_description_from_string(FONT);
- layout = pango_cairo_create_layout(cr);
- pango_layout_set_text(layout, msg, -1);
+ layout = pango_cairo_create_layout (cr);
+ pango_layout_set_text (layout, msg, -1);
- dummy_layout = pango_layout_copy(layout);
- pango_layout_set_font_description(dummy_layout, desc);
- pango_layout_get_size(dummy_layout, &lw, &lh);
- g_object_unref(dummy_layout);
+ dummy_layout = pango_layout_copy (layout);
+ pango_layout_set_font_description (dummy_layout, desc);
+ pango_layout_get_size (dummy_layout, &lw, &lh);
+ g_object_unref (dummy_layout);
// desired height : lh = widget width * 0.9 : lw
- pango_font_description_set_absolute_size(desc, ((float) lh / lw) * PANGO_SCALE * width * 0.8);
- pango_layout_set_font_description(layout, desc);
- pango_font_description_free(desc);
-
- pango_layout_get_size(layout, &lw, &lh);
- cairo_move_to(cr, -((double)lw / PANGO_SCALE) / 2, -((double)lh / PANGO_SCALE) / 2);
- pango_cairo_layout_path(cr, layout);
+ pango_font_description_set_absolute_size (desc, ((float) lh / lw) * PANGO_SCALE * width * 0.8);
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ pango_layout_get_size (layout, &lw, &lh);
+ cairo_move_to (cr, -((double)lw / PANGO_SCALE) / 2, -((double)lh / PANGO_SCALE) / 2);
+ pango_cairo_layout_path (cr, layout);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_fill_preserve (cr);
- cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
/* A linewidth of 2 pixels at the default size. */
cairo_set_line_width (cr, width/220.0);
cairo_stroke (cr);
g_object_unref(layout);
-
- cairo_restore(cr);
-}
-
-void
-Field::redraw()
-{
- cairo_t *cr;
-
- generateTarget ();
-
- cr = clutter_cairo_create (CLUTTER_CAIRO(foreground));
- cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
- cairo_paint(cr);
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-
- if (rendererTheme != themeID) {
-
- if (renderer)
- delete renderer;
-
- renderer = rendererFactory (themeID, foreground, field,
- COLUMNS, LINES, width, height);
- rendererTheme = themeID;
- } else {
- renderer->setTarget (foreground);
- renderer->data = field;
- renderer->width = COLUMNS;
- renderer->height = LINES;
- renderer->pxwidth = width;
- renderer->pxheight = height;
- }
-
- renderer->render ();
-
- if (showPause)
- drawMessage(cr, _("Paused"));
- else if (showGameOver)
- drawMessage(cr, _("Game Over"));
-
- cairo_destroy(cr);
+ cairo_destroy (cr);
}
void
@@ -268,7 +236,7 @@
{
showPause = true;
- redraw();
+ drawMessage ();
}
void
@@ -276,7 +244,7 @@
{
showPause = false;
- redraw();
+ drawMessage ();
}
void
@@ -284,7 +252,7 @@
{
showGameOver = true;
- redraw();
+ drawMessage ();
}
void
@@ -292,7 +260,7 @@
{
showGameOver = false;
- redraw();
+ drawMessage ();
}
void
Modified: trunk/gnometris/field.h
==============================================================================
--- trunk/gnometris/field.h (original)
+++ trunk/gnometris/field.h Tue Feb 3 18:55:50 2009
@@ -38,8 +38,8 @@
void hidePauseMessage ();
void showGameOverMessage ();
void hideGameOverMessage ();
- void redraw ();
void setTheme (gint id);
+ void drawMessage ();
GtkWidget *getWidget () {
return w;
Modified: trunk/gnometris/renderer.cpp
==============================================================================
--- trunk/gnometris/renderer.cpp (original)
+++ trunk/gnometris/renderer.cpp Tue Feb 3 18:55:50 2009
@@ -121,16 +121,12 @@
if (data[x][y].what == EMPTY)
return;
- if (data[x][y].what == TARGET) {
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.3);
- } else {
- i = data[x][y].color;
- i = CLAMP (i, 0, 6);
+ i = data[x][y].color;
+ i = CLAMP (i, 0, 6);
- cairo_set_source_rgb(cr, colours[i][0],
- colours[i][1],
- colours[i][2]);
- }
+ cairo_set_source_rgb(cr, colours[i][0],
+ colours[i][1],
+ colours[i][2]);
cairo_rectangle(cr, x+0.05, y+0.05,
0.9, 0.9);
@@ -244,13 +240,10 @@
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_width (cr, 0.05);
- if (data[x][y].what == TARGET) {
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0);
- } else {
- cairo_set_source_rgb (cr, colours[i][0],
- colours[i][1],
- colours[i][2]);
- }
+ cairo_set_source_rgb (cr, colours[i][0],
+ colours[i][1],
+ colours[i][2]);
+
cairo_rectangle (cr, -0.025, -0.025, 1.025, 1.025);
cairo_fill (cr);
cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
@@ -401,12 +394,8 @@
if (data[x][y].what == EMPTY)
return;
- if (data[x][y].what == TARGET) {
- i = 7;
- } else {
- i = data[x][y].color;
- i = CLAMP (i, 0, 6);
- }
+ i = data[x][y].color;
+ i = CLAMP (i, 0, 6);
if (usegrads) {
pat = cairo_pattern_create_linear (x+0.35, y, x+0.55, y+0.9);
@@ -437,48 +426,41 @@
cairo_stroke (cr); /* add darker outline */
drawRoundedRectangle (cr, x+0.15, y+0.15, 0.7, 0.7, 0.08);
- if (data[x][y].what != TARGET) {
- if (usegrads) {
- pat = cairo_pattern_create_linear (x-0.3, y-0.3, x+0.8, y+0.8);
- switch (i) { /* yellow and white blocks need a brighter highlight */
- case 3:
- case 4:
- cairo_pattern_add_color_stop_rgba (pat, 0.0, 1.0,
- 1.0,
- 1.0,
- 1.0);
- cairo_pattern_add_color_stop_rgba (pat, 1.0, 1.0,
- 1.0,
- 1.0,
- 0.0);
- break;
- default:
- cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.9295,
- 0.9295,
- 0.9295,
- 1.0);
- cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.9295,
- 0.9295,
- 0.9295,
- 0.0);
- break;
- }
- cairo_set_source (cr, pat);
- } else {
- cairo_set_source_rgba (cr, 1.0,
- 1.0,
- 1.0,
- 0.35);
+ if (usegrads) {
+ pat = cairo_pattern_create_linear (x-0.3, y-0.3, x+0.8, y+0.8);
+ switch (i) { /* yellow and white blocks need a brighter highlight */
+ case 3:
+ case 4:
+ cairo_pattern_add_color_stop_rgba (pat, 0.0, 1.0,
+ 1.0,
+ 1.0,
+ 1.0);
+ cairo_pattern_add_color_stop_rgba (pat, 1.0, 1.0,
+ 1.0,
+ 1.0,
+ 0.0);
+ break;
+ default:
+ cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.9295,
+ 0.9295,
+ 0.9295,
+ 1.0);
+ cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.9295,
+ 0.9295,
+ 0.9295,
+ 0.0);
+ break;
}
- } else { /* black preview block, use a much weaker highlight */
+ cairo_set_source (cr, pat);
+ } else {
cairo_set_source_rgba (cr, 1.0,
1.0,
1.0,
- 0.15);
+ 0.35);
}
cairo_stroke (cr); /* add inner edge highlight */
- if (usegrads && (data[x][y].what != TARGET))
+ if (usegrads)
cairo_pattern_destroy (pat);
}
Modified: trunk/gnometris/tetris.cpp
==============================================================================
--- trunk/gnometris/tetris.cpp (original)
+++ trunk/gnometris/tetris.cpp Tue Feb 3 18:55:50 2009
@@ -90,7 +90,9 @@
timeoutId(0),
onePause(false),
inPlay(false),
+#ifndef HAVE_CLUTTER
useTarget(false),
+#endif
bgimage(0),
setupdialog(0),
cmdlineLevel(cmdlLevel),
@@ -188,7 +190,9 @@
preview = new Preview ();
field = new Field();
+#ifndef HAVE_CLUTTER
field->setUseTarget (false);
+#endif
initOptions ();
@@ -439,7 +443,9 @@
games_sound_enable (confGetBoolean (KEY_OPTIONS_GROUP, KEY_SOUND, TRUE));
+#ifndef HAVE_CLUTTER
useTarget = confGetBoolean (KEY_OPTIONS_GROUP, KEY_USE_TARGET, FALSE);
+#endif
do_preview = confGetBoolean (KEY_OPTIONS_GROUP, KEY_DO_PREVIEW, TRUE);
@@ -540,6 +546,7 @@
ThemeTable[t->themeno].id);
}
+#ifndef HAVE_CLUTTER
void
Tetris::setTarget (GtkWidget *widget, void *data)
{
@@ -552,6 +559,7 @@
games_conf_set_boolean (KEY_OPTIONS_GROUP, KEY_USE_TARGET,
t->useTarget);
}
+#endif
void
Tetris::lineFillHeightChanged (GtkWidget *spin, gpointer data)
@@ -728,10 +736,12 @@
0, 0, 0);
t->useTargetToggle = gtk_check_button_new_with_mnemonic (_("Show _where the block will land"));
+#ifndef HAVE_CLUTTER
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (t->useTargetToggle),
t->useTarget);
g_signal_connect (t->useTargetToggle, "clicked",
G_CALLBACK (setTarget), d);
+#endif
gtk_box_pack_start (GTK_BOX (fvbox), t->useTargetToggle,
0, 0, 0);
@@ -894,13 +904,19 @@
if (t->onePause)
{
t->onePause = false;
+#ifdef HAVE_CLUTTER
+ t->field->drawMessage();
+#else
t->field->redraw();
+#endif
}
else
{
bool res = t->field->moveBlockDown();
+#ifndef HAVE_CLUTTER
t->field->redraw();
+#endif
if (res)
{
@@ -965,7 +981,9 @@
}
}
+#ifndef HAVE_CLUTTER
t->field->redraw();
+#endif
return res;
}
@@ -1254,7 +1272,9 @@
high_scores->show (GTK_WINDOW (w), pos);
}
+#ifndef HAVE_CLUTTER
field->setUseTarget (false);
+#endif
}
int
@@ -1282,7 +1302,9 @@
t->scoreFrame->setLevel(level);
t->scoreFrame->setStartingLevel(level);
+#ifndef HAVE_CLUTTER
t->field->setUseTarget (t->useTarget);
+#endif
t->generateTimer (level);
t->field->emptyField(t->line_fill_height,t->line_fill_prob);
@@ -1291,7 +1313,9 @@
t->paused = false;
t->field->generateFallingBlock();
+#ifndef HAVE_CLUTTER
t->field->redraw();
+#endif
t->preview->previewBlock(blocknr_next, rot_next, color_next);
gtk_widget_queue_draw(t->preview->getWidget());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]