[cairo-commit] cairo-demo/gameoflife ChangeLog, NONE, 1.1 cgolwin.cpp, 1.5, 1.6 cgolwin.h, 1.2, 1.3

Behdad Esfahbod commit at pdx.freedesktop.org
Thu Jul 28 22:40:46 PDT 2005


Committed by: behdad

Update of /cvs/cairo/cairo-demo/gameoflife
In directory gabe:/tmp/cvs-serv31911

Modified Files:
	cgolwin.cpp cgolwin.h 
Added Files:
	ChangeLog 
Log Message:
2005-07-29  Behdad Esfahbod  <behdad at behdad.org>

        * cgolwin.cpp: Updated to cairo 0.6.0 API.



--- NEW FILE: ChangeLog ---
2005-07-29  Behdad Esfahbod  <behdad at behdad.org>

	* cgolwin.cpp: Updated to cairo 0.6.0 API.


Index: cgolwin.cpp
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/cgolwin.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cgolwin.cpp	23 Dec 2003 18:38:05 -0000	1.5
+++ cgolwin.cpp	29 Jul 2005 05:40:44 -0000	1.6
@@ -24,6 +24,7 @@
 
 
 #include <cairo.h>
+#include <cairo-xlib.h>
 #include <math.h>
 #include <iostream>
 #include <assert.h>
@@ -40,7 +41,12 @@
 	use_cairo_show_surface = s;
 	game = new gameoflife(rows, cols);
 
-	cr = cairo_create();
+	surface = cairo_xlib_surface_create(dpy, cellpix, 
+			DefaultVisual(dpy, DefaultScreen(dpy)),
+			CAIRO_FORMAT_RGB24, DefaultColormap(dpy, DefaultScreen(dpy)));
+	if (surface == NULL)
+		exit(1); // no mem
+	cr = cairo_create(surface);
 	
 	XGCValues xgcv;
 	// Helps prevent *some* choking on opaque resize 
@@ -102,7 +108,7 @@
 	   	 the cairo transform matrix handles resizing etc */
 	if (grid == 0)
 	{	  
-		cairo_default_matrix(cr);
+		cairo_identity_matrix(cr);
 		cairo_scale(cr, (double)width/(double)cols,(double)height/(double)rows); 
 		cairo_set_line_width(cr, 0.1); // set to one tenth of a unit... will that be row or col?
 		radius = 0.5; // so, the edges of circles in connecting cells should just touch.
@@ -115,26 +121,20 @@
 		if (use_cairo_show_surface) // Broken
 		{	//todo : fix mem leak here 
 			cairo_save(cr);
-			cairo_default_matrix(cr);
+			cairo_identity_matrix(cr);
 			cairo_scale(cr,50,50);
 			cellpix = XCreatePixmap(dpy, w, 50, 
 					50, DefaultDepth(dpy, DefaultScreen(dpy)));
 			XFillRectangle(dpy, cellpix, gc, 0, 0, 50, 50);
-			surface = cairo_xlib_surface_create(dpy, cellpix, 
-					DefaultVisual(dpy, DefaultScreen(dpy)),
-					CAIRO_FORMAT_RGB24, DefaultColormap(dpy, DefaultScreen(dpy)));
-			if (surface == NULL)
-				exit(1); // no mem
-			cairo_set_target_surface(cr, surface);
-			cairo_set_rgb_color(cr,0,0,0);
+			cairo_set_source_rgb(cr,0,0,0);
 			cairo_arc(cr, .5,  .5, .5, 0, 2*M_PI);
 			cairo_fill(cr);
 			cairo_restore(cr);
 		}
 		
 		
-		cairo_set_target_drawable(cr, dpy, grid);
-		cairo_set_rgb_color(cr, .8, .8, .8);
+                cairo_xlib_surface_set_drawable (surface, grid, width, height);
+		cairo_set_source_rgb(cr, .8, .8, .8);
 		for (int col = 0; col <= cols; col++)
 		{
 			cairo_move_to(cr, col, 0);
@@ -146,13 +146,13 @@
 			cairo_rel_line_to(cr, cols, 0);
 		}
 		cairo_stroke(cr);
-		cairo_set_rgb_color(cr, 0, 0, 0);
+		cairo_set_source_rgb(cr, 0, 0, 0);
 	}
 	
 	cells = game->getboard();
 	// Copy gen'd grid to buffer
 	XCopyArea(dpy, grid, buffer, gc, 0, 0, width, height, 0, 0);
-	cairo_set_target_drawable(cr, dpy, buffer);
+        cairo_xlib_surface_set_drawable (surface, buffer, width, height);
 	for (list<struct cell>::const_iterator i = cells->begin();
 		i != cells->end(); i++)
 	{
@@ -170,16 +170,17 @@
 		{
 			//Note: broken 
 			cairo_move_to(cr, i->x, i->y);
-			cairo_show_surface(cr, surface, 1, 1);
+			cairo_set_source_surface(cr, surface, 1, 1);
+			cairo_paint(cr);
 		}
 		else 
 		{ 
-			cairo_set_rgb_color(cr, red, green, blue);
+			cairo_set_source_rgb(cr, red, green, blue);
 			cairo_arc(cr, i->x + .5, i->y + .5, radius, 0, 2*M_PI);
 			cairo_fill(cr);
 		}
 	}
-	cairo_set_rgb_color(cr, 0, 0, 0);
+	cairo_set_source_rgb(cr, 0, 0, 0);
 	XCopyArea(dpy, buffer, w, gc, 0, 0, width, height, 0, 0);
 	XFlush(dpy);
 }

Index: cgolwin.h
===================================================================
RCS file: /cvs/cairo/cairo-demo/gameoflife/cgolwin.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cgolwin.h	25 Nov 2003 07:13:17 -0000	1.2
+++ cgolwin.h	29 Jul 2005 05:40:44 -0000	1.3
@@ -38,13 +38,12 @@
 	gameoflife * game;
 private:
 	Pixmap grid, buffer, cellpix;
-	cairo * cr;
-	cairo_surface * surface;
+	cairo_t * cr;
+	cairo_surface_t * surface;
 	bool use_cairo_show_surface;
 	int rows, cols, width, height;
 	double cellheight, cellwidth;
 	double radius;
 	GC gc;
-	
 };
 




More information about the cairo-commit mailing list