[cairo-commit] cairo-demo/tsetse ChangeLog, 1.3, 1.4 tsetse.c, 1.4, 1.5

Carl Worth commit at pdx.freedesktop.org
Thu Jul 21 09:49:35 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo-demo/tsetse
In directory gabe:/tmp/cvs-serv14006

Modified Files:
	ChangeLog tsetse.c 
Log Message:

        * tsetse.c: (draw_symbol), (draw_card), (win_refresh), (win_init),
        (win_deinit), (win_grow_pixmap): Port forward to the latest cairo
        API.


Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/tsetse/ChangeLog,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ChangeLog	21 Mar 2005 02:28:44 -0000	1.3
+++ ChangeLog	21 Jul 2005 16:49:33 -0000	1.4
@@ -1,3 +1,9 @@
+2005-07-21  Carl Worth  <cworth at cworth.org>
+
+	* tsetse.c: (draw_symbol), (draw_card), (win_refresh), (win_init),
+	(win_deinit), (win_grow_pixmap): Port forward to the latest cairo
+	API.
+
 2005-03-20  Carl Worth  <cworth at cworth.org>
 
 	* Makefile: Fix to not overwrite user's CFLAGS

Index: tsetse.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/tsetse/tsetse.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- tsetse.c	21 Mar 2005 02:28:44 -0000	1.4
+++ tsetse.c	21 Jul 2005 16:49:33 -0000	1.5
@@ -76,6 +76,7 @@
     Window win;
     GC gc;
     Pixmap pix;
+    cairo_surface_t *surface;
     int width, height;
     long event_mask;
 
@@ -171,28 +172,28 @@
     SHRINK (cr, .9);
 
     stripes = cairo_pattern_create_linear (0, 0, .1, .1);
-    cairo_pattern_add_color_stop (stripes, 0.0, 0, 0, 0, 0);
+    cairo_pattern_add_color_stop_rgba (stripes, 0.0, 0, 0, 0, 0);
     cairo_pattern_set_extend (stripes, CAIRO_EXTEND_REPEAT);
 
     switch (color) {
     case COLOR_RED:
-	cairo_set_rgb_color (cr, .8, 0, 0);
-	cairo_pattern_add_color_stop (stripes, 0.3, .8, 0, 0, 1.0);
-	cairo_pattern_add_color_stop (stripes, 0.7, .8, 0, 0, 1.0);
+	cairo_set_source_rgb (cr, .8, 0, 0);
+	cairo_pattern_add_color_stop_rgba (stripes, 0.3, .8, 0, 0, 1.0);
+	cairo_pattern_add_color_stop_rgba (stripes, 0.7, .8, 0, 0, 1.0);
 	break;
     case COLOR_GREEN:
-	cairo_set_rgb_color (cr, 0, .6, 0);
-	cairo_pattern_add_color_stop (stripes, 0.3, 0, .6, 0, 1.0);
-	cairo_pattern_add_color_stop (stripes, 0.7, 0, .6, 0, 1.0);
+	cairo_set_source_rgb (cr, 0, .6, 0);
+	cairo_pattern_add_color_stop_rgba (stripes, 0.3, 0, .6, 0, 1.0);
+	cairo_pattern_add_color_stop_rgba (stripes, 0.7, 0, .6, 0, 1.0);
 	break;
     case COLOR_PURPLE:
-	cairo_set_rgb_color (cr, .6, 0, .7);
-	cairo_pattern_add_color_stop (stripes, 0.3, .6, 0, .7, 1.0);
-	cairo_pattern_add_color_stop (stripes, 0.7, .6, 0, .7, 1.0);
+	cairo_set_source_rgb (cr, .6, 0, .7);
+	cairo_pattern_add_color_stop_rgba (stripes, 0.3, .6, 0, .7, 1.0);
+	cairo_pattern_add_color_stop_rgba (stripes, 0.7, .6, 0, .7, 1.0);
 	break;
     }
 
-    cairo_pattern_add_color_stop (stripes, 1.0, 0, 0, 0, 0);
+    cairo_pattern_add_color_stop_rgba (stripes, 1.0, 0, 0, 0, 0);
 
     switch (shape) {
     case SHAPE_DIAMOND:
@@ -232,7 +233,7 @@
 	break;
     case SHADING_STRIPED:
 	{
-	    cairo_set_pattern (cr, stripes);
+	    cairo_set_source (cr, stripes);
 	    cairo_fill (cr);
 /* XXX: This would probably work OK, but clipping is too slow right now. */	
 #if 0
@@ -277,7 +278,7 @@
     SHRINK (cr, .9);
 
     cairo_rectangle (cr, 0, 0, 1.0, 1.0);
-    cairo_set_rgb_color (cr, 0, 0, 0);
+    cairo_set_source_rgb (cr, 0, 0, 0);
     cairo_set_line_width (cr, border_width);
     cairo_stroke (cr);
  
@@ -297,8 +298,7 @@
 
     if (highlight) {
 	cairo_rectangle (cr, 0, 0, 1.0, 1.0);
-	cairo_set_rgb_color (cr, 0, 0, 1);
-	cairo_set_alpha (cr, 0.25);
+	cairo_set_source_rgba (cr, 0, 0, 1, 0.25);
 	cairo_fill (cr);
     }
 	
@@ -406,17 +406,13 @@
 static void
 win_refresh(win_t *win)
 {
-    Display *dpy = win->dpy;
-
     cairo_t *cr;
     cairo_status_t status;
-    Drawable drawable = win->pix;
 
-    cr = cairo_create();
-    cairo_set_target_drawable (cr, dpy, drawable);
+    cr = cairo_create(win->surface);
 
     cairo_rectangle (cr, 0, 0, win->width, win->height);
-    cairo_set_rgb_color (cr, 1, 1, 1);
+    cairo_set_source_rgb (cr, 1, 1, 1);
     cairo_fill (cr);
 
     draw_board (cr, &win->board, win->width, win->height);
@@ -430,15 +426,14 @@
 	
 	cairo_save (cr);
 	{
-	    cairo_select_font (cr, "sans", 0, 0);
-	    cairo_scale_font (cr, win->height / 1.2);
+	    cairo_select_font_face (cr, "sans", 0, 0);
+	    cairo_set_font_size (cr, win->height / 1.2);
 	    cairo_move_to (cr, 0, 0);
 	    cairo_text_extents (cr, sets_possible, &extents);
 	    cairo_move_to (cr,
 			   win->width/2 - (extents.x_bearing + extents.width/2),
 			   win->height/2 - (extents.y_bearing + extents.height/2));
-	    cairo_set_rgb_color (cr, 0, 0, .5);
-	    cairo_set_alpha (cr, .75);
+	    cairo_set_source_rgba (cr, 0, 0, .5, 0.75);
 	    cairo_show_text (cr, sets_possible);
 	}
 	cairo_restore (cr);
@@ -446,7 +441,8 @@
 
     status = cairo_status(cr);
     if (status) {
-	fprintf(stderr, "Cairo is unhappy: %s\n", cairo_status_string(cr));
+	fprintf(stderr, "Cairo is unhappy: %s\n",
+		cairo_status_to_string(cairo_status(cr)));
     }
 
     cairo_destroy(cr);
@@ -611,6 +607,8 @@
 				   WhitePixel(dpy, win->scr), WhitePixel(dpy, win->scr));
 
     win->pix = XCreatePixmap(dpy, win->win, win->width, win->height, DefaultDepth (dpy, win->scr));
+    win->surface = cairo_xlib_surface_create (dpy, win->pix, DefaultVisual (dpy, win->scr), win->width, win->height);
+
     gcv.foreground = WhitePixel(dpy, win->scr);
     win->gc = XCreateGC(dpy, win->pix, GCForeground, &gcv);
     XFillRectangle(dpy, win->pix, win->gc, 0, 0, win->width, win->height);
@@ -641,6 +639,7 @@
 {
     XFreeGC(win->dpy, win->gc);
     XFreePixmap(win->dpy, win->pix);
+    cairo_surface_destroy (win->surface);
     XDestroyWindow(win->dpy, win->win);
 }
 
@@ -720,7 +719,11 @@
     XFillRectangle(win->dpy, new, win->gc, 0, 0, win->width, win->height);
     XCopyArea(win->dpy, win->pix, new, win->gc, 0, 0, win->width, win->height, 0, 0);
     XFreePixmap(win->dpy, win->pix);
+    cairo_surface_destroy (win->surface);
     win->pix = new;
+    win->surface = cairo_xlib_surface_create (win->dpy, win->pix,
+					      DefaultVisual (win->dpy, win->scr),
+					      win->width, win->height);
 }
 
 static void




More information about the cairo-commit mailing list