[cairo-commit]
cairo-demo/gameoflife ChangeLog, 1.3, 1.4 cgolwin.cpp,
1.8, 1.9 cgolwin.h, 1.4, 1.5 main.cpp, 1.2, 1.3
Behdad Esfahbod
commit at pdx.freedesktop.org
Tue Aug 2 10:52:10 PDT 2005
Committed by: behdad
Update of /cvs/cairo/cairo-demo/gameoflife
In directory gabe:/tmp/cvs-serv31735
Modified Files:
ChangeLog cgolwin.cpp cgolwin.h main.cpp
Log Message:
2005-08-02 Behdad Esfahbod <behdad at behdad.org>
* cgolwin.h, cgolwin.cpp: Use cairo_mask if -s is passed at cmdline.
Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/ChangeLog,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ChangeLog 2 Aug 2005 09:06:47 -0000 1.3
+++ ChangeLog 2 Aug 2005 17:52:07 -0000 1.4
@@ -1,5 +1,9 @@
2005-08-02 Behdad Esfahbod <behdad at behdad.org>
+ * cgolwin.h, cgolwin.cpp: Use cairo_mask if -s is passed at cmdline.
+
+2005-08-02 Behdad Esfahbod <behdad at behdad.org>
+
* cgolwin.h, cgolwin.cpp: Get rid of xlib completely.
2005-07-29 Behdad Esfahbod <behdad at behdad.org>
Index: cgolwin.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/cgolwin.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cgolwin.cpp 2 Aug 2005 09:06:47 -0000 1.8
+++ cgolwin.cpp 2 Aug 2005 17:52:07 -0000 1.9
@@ -32,16 +32,17 @@
using std::cout;
gameoflifeWin::gameoflifeWin(Ctkapp * app, int wi, int h, int r, int c, bool s)
- :Ctkwin(app,wi,h), buffer(NULL), rows(r), cols(c), width(wi), height(h)
+ :Ctkwin(app,wi,h), buffer(NULL), rows(r), cols(c), width(wi), height(h),
+ use_cairo_mask(s)
{
- use_cairo_show_surface = s;
-
game = new gameoflife(rows, cols);
onscreen = cairo_xlib_surface_create(dpy, w,
DefaultVisual(dpy, DefaultScreen(dpy)),
wi, h);
onscreen_cr = cairo_create (onscreen);
+ cairo_set_source_rgb (onscreen_cr, 0, 0, 0);
+ cairo_paint (onscreen_cr);
// MAX 24 fps, really just means 1/24 s between advancements
app->regtimer(0,1000000/24,-1,advanceTimer, (void *)this);
@@ -55,7 +56,8 @@
grid = cairo_surface_create_similar (onscreen,
CAIRO_CONTENT_COLOR_ALPHA,
width, height);
- cellpix = cairo_surface_create_similar (onscreen,
+ if (use_cairo_mask)
+ cellpix = cairo_surface_create_similar (onscreen,
CAIRO_CONTENT_ALPHA,
width/cols+1, height/rows+1);
@@ -68,7 +70,8 @@
{
cairo_surface_destroy (buffer);
cairo_surface_destroy (grid);
- cairo_surface_destroy (cellpix);
+ if (use_cairo_mask)
+ cairo_surface_destroy (cellpix);
buffer = grid = cellpix = NULL;
}
}
@@ -97,8 +100,8 @@
cairo_stroke(cr);
cairo_destroy(cr);
- if (use_cairo_show_surface) // Broken
- { //todo : fix mem leak here
+ if (use_cairo_mask)
+ {
cr = cairo_create (cellpix);
cairo_set_matrix (cr, &matrix);
cairo_arc(cr, .5, .5, .5, 0, 2*M_PI);
@@ -167,7 +170,7 @@
{
double red,green,blue;
red = green = blue = 0;
- //Note colour weighting avoids white (Max .75 of each)
+ //Note colour weighting avoids white (Max < 1 of each)
if (i->dna & B1) blue += .50;
if (i->dna & B2) blue += .25;
if (i->dna & R1) red += .50;
@@ -175,16 +178,16 @@
if (i->dna & G1) green += .50;
if (i->dna & G2) green += .25;
- if (use_cairo_show_surface)
+ if (use_cairo_mask)
{
- //Note: broken
+ double x, y;
cairo_save (cr);
+ x = i->x;
+ y = i->y;
+ cairo_user_to_device (cr, &x, &y);
cairo_identity_matrix (cr);
cairo_set_source_rgb (cr, red, green, blue);
- cairo_set_source_surface (cr, cellpix, 0, 0);
- cairo_set_matrix (cr, &matrix);
- cairo_move_to(cr, i->x, i->y);
- cairo_paint (cr);
+ cairo_mask_surface (cr, cellpix, x, y);
cairo_restore (cr);
}
else
Index: cgolwin.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/cgolwin.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cgolwin.h 2 Aug 2005 09:06:47 -0000 1.4
+++ cgolwin.h 2 Aug 2005 17:52:07 -0000 1.5
@@ -43,7 +43,7 @@
cairo_t *onscreen_cr;
cairo_surface_t *onscreen, *buffer, *grid, *cellpix;
cairo_matrix_t matrix;
- bool use_cairo_show_surface;
int rows, cols, width, height;
+ bool use_cairo_mask;
};
Index: main.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/main.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- main.cpp 25 Nov 2003 07:13:17 -0000 1.2
+++ main.cpp 2 Aug 2005 17:52:07 -0000 1.3
@@ -26,7 +26,7 @@
using std::endl;
void usage(char * name)
{
- std::cout << "Usage: " << name << " [-w width] [-h height] [-c columns] [-r rows] [-s (use show surface)]\n";
+ std::cout << "Usage: " << name << " [-w width] [-h height] [-c columns] [-r rows] [-s (use mask surface)]\n";
}
int main(int argc, char * argv[])
More information about the cairo-commit
mailing list