[cairo-commit] cairo-demo/X11 .cvsignore, 1.1, 1.2 ChangeLog, 1.13, 1.14 Makefile, 1.5, 1.6 cairo-demo-xcb.c, NONE, 1.1 cairo-demo.c, 1.12, 1.13 cairo-knockout.c, 1.14, 1.15 cairo-spline.c, 1.11, 1.12

Carl Worth commit at pdx.freedesktop.org
Fri May 13 15:34:01 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo-demo/X11
In directory gabe:/tmp/cvs-serv9131

Modified Files:
	.cvsignore ChangeLog Makefile cairo-demo.c cairo-knockout.c 
	cairo-spline.c 
Added Files:
	cairo-demo-xcb.c 
Log Message:

        * .cvsignore:
        * Makefile:
        * cairo-demo-xcb.c: Split XCB stuff out out cairo-demo and into
        its own cairo-demo-xcb.

        * cairo-demo.c:
        * cairo-demo-xcb.c:
        * cairo-knockout.c:
        * cairo-spline.c: Update all X11 demos to latest cairo API
        changes.


Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/cairo-demo/X11/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- .cvsignore	4 Sep 2003 13:54:29 -0000	1.1
+++ .cvsignore	13 May 2005 22:33:59 -0000	1.2
@@ -1,4 +1,4 @@
 cairo-demo
-cairo-freq
+cairo-demo-xcb
 cairo-knockout
 cairo-spline

Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/X11/ChangeLog,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- ChangeLog	21 Feb 2005 20:41:18 -0000	1.13
+++ ChangeLog	13 May 2005 22:33:59 -0000	1.14
@@ -1,3 +1,16 @@
+2005-05-13  Carl Worth  <cworth at cworth.org>
+
+	* .cvsignore:
+	* Makefile:
+	* cairo-demo-xcb.c: Split XCB stuff out out cairo-demo and into
+	its own cairo-demo-xcb.
+	
+	* cairo-demo.c:
+	* cairo-demo-xcb.c:
+	* cairo-knockout.c:
+	* cairo-spline.c: Update all X11 demos to latest cairo API
+	changes.
+
 2005-02-21  Carl Worth  <cworth at cworth.org>
 
 	* cairo-knockout.c (main): Switch from Xutf8SetWMProperties to

Index: Makefile
===================================================================
RCS file: /cvs/cairo/cairo-demo/X11/Makefile,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile	21 Feb 2005 20:32:17 -0000	1.5
+++ Makefile	13 May 2005 22:33:59 -0000	1.6
@@ -1,4 +1,4 @@
-PROGS=cairo-demo cairo-spline cairo-knockout
+PROGS=cairo-demo cairo-demo-xcb cairo-spline cairo-knockout
 
 # I'd like to put a bunch of compiler-specific warning flags here, but
 # I don't know a good way to choose the right flags based on the

--- NEW FILE: cairo-demo-xcb.c ---
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <cairo.h>
#include <cairo-xcb.h>

#define PI 3.1415926535

typedef struct win {
    XCBConnection *dpy;

    XCBWINDOW win;
    XCBGCONTEXT gc;

    int width, height;

    XCBVISUALTYPE *visual;
} win_t;

static void triangle(cairo_t *cr);
static void square(cairo_t *cr);
static void bowtie(cairo_t *cr);
static void win_init(win_t *win);
static void win_deinit(win_t *win);
static void win_draw(win_t *win);
static void win_handle_events(win_t *win);

int
main(int argc, char *argv[])
{
    win_t win;

    win.dpy = XCBConnectBasic();

    if (win.dpy == NULL) {
	fprintf(stderr, "Failed to open display\n");
	return 1;
    }

    win_init(&win);

    win_draw(&win);

    win_handle_events(&win);

    win_deinit(&win);

    XCBDisconnect(win.dpy);

    return 0;
}

#define SIZE 20
static void
triangle(cairo_t *cr)
{
    cairo_move_to(cr, SIZE, 0);
    cairo_rel_line_to(cr, SIZE,  2*SIZE);
    cairo_rel_line_to(cr, -2*SIZE, 0);
    cairo_close_path(cr);
}

static void
square(cairo_t *cr)
{
    cairo_move_to(cr, 0, 0);
    cairo_rel_line_to(cr,  2*SIZE,   0);
    cairo_rel_line_to(cr,   0,  2*SIZE);
    cairo_rel_line_to(cr, -2*SIZE,   0); 
    cairo_close_path(cr);
}

static void
bowtie(cairo_t *cr)
{
    cairo_move_to(cr, 0, 0);
    cairo_rel_line_to(cr,  2*SIZE,  2*SIZE);
    cairo_rel_line_to(cr, -2*SIZE,   0); 
    cairo_rel_line_to(cr,  2*SIZE, -2*SIZE);
    cairo_close_path(cr);
}

static void
inf(cairo_t *cr)
{
    cairo_move_to(cr, 0, SIZE);
    cairo_rel_curve_to(cr,
		 0, SIZE,
		 SIZE, SIZE,
		 2*SIZE, 0);
    cairo_rel_curve_to(cr,
		 SIZE, -SIZE,
		 2*SIZE, -SIZE,
		 2*SIZE, 0);
    cairo_rel_curve_to(cr,
		 0, SIZE,
		 -SIZE, SIZE,
		 -2*SIZE, 0);
    cairo_rel_curve_to(cr,
		 -SIZE, -SIZE,
		 -2*SIZE, -SIZE,
		 -2*SIZE, 0);
    cairo_close_path(cr);
}

static void
draw_shapes(cairo_t *cr, int x, int y, int fill)
{
    cairo_save(cr);

    cairo_new_path(cr);
    cairo_translate(cr, x+SIZE, y+SIZE);
    bowtie(cr);
    if (fill)
	cairo_fill(cr);
    else
	cairo_stroke(cr);

    cairo_new_path(cr);
    cairo_translate(cr, 4*SIZE, 0);
    square(cr);
    if (fill)
	cairo_fill(cr);
    else
	cairo_stroke(cr);

    cairo_new_path(cr);
    cairo_translate(cr, 4*SIZE, 0);
    triangle(cr);
    if (fill)
	cairo_fill(cr);
    else
	cairo_stroke(cr);

    cairo_new_path(cr);
    cairo_translate(cr, 4*SIZE, 0);
    inf(cr);
    if (fill)
	cairo_fill(cr);
    else
	cairo_stroke(cr);

    cairo_restore(cr);
}

static void
fill_shapes(cairo_t *cr, int x, int y)
{
    draw_shapes(cr, x, y, 1);
}

static void
stroke_shapes(cairo_t *cr, int x, int y)
{
    draw_shapes(cr, x, y, 0);
}

/*
static void
draw_broken_shapes(cairo_t *cr)
{
    cairo_save(cr);

    cairo_set_line_width(cr, 1);
    cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
    cairo_set_source_rgb(cr, 1, 1, 1);

    cairo_move_to(cr, 19.153717041015625, 144.93951416015625);
    cairo_line_to(cr, 412.987396240234375, 99.407318115234375);
    cairo_line_to(cr, 412.99383544921875, 99.4071807861328125);
    cairo_line_to(cr, 413.15008544921875, 99.5634307861328125);
    cairo_line_to(cr, 413.082489013671875, 99.6920928955078125);
    cairo_line_to(cr, 413.000274658203125, 99.71954345703125);
    cairo_line_to(cr, 273.852630615234375, 138.1925201416015625);
    cairo_line_to(cr, 273.934844970703125, 138.165069580078125);
    cairo_line_to(cr, 16.463653564453125, 274.753662109375);
    cairo_line_to(cr, 16.286346435546875, 274.496337890625);
    cairo_line_to(cr, 273.757537841796875, 137.907745361328125);
    cairo_line_to(cr, 273.839752197265625, 137.8802947998046875);
    cairo_line_to(cr, 412.987396240234375, 99.407318115234375);
    cairo_line_to(cr, 412.99383544921875, 99.4071807861328125);
    cairo_line_to(cr, 413.15008544921875, 99.5634307861328125);
    cairo_line_to(cr, 413.082489013671875, 99.6920928955078125);
    cairo_line_to(cr, 413.000274658203125, 99.71954345703125);
    cairo_line_to(cr, 19.166595458984375, 145.251739501953125);

    cairo_fill(cr);

    cairo_restore(cr);
}
*/

static void
win_draw(win_t *win)
{
#define NUM_DASH 2
    static double dash[NUM_DASH] = {SIZE/4.0, SIZE/4.0};
    cairo_surface_t *surface;
    cairo_t *cr;
    XCBDRAWABLE drawable;
    drawable.window = win->win;

    XCBClearArea(win->dpy, 0, win->win, 0, 0, 0, 0);

    surface = cairo_xcb_surface_create_for_window_with_visual (win->dpy,
							       win->win,
							       win->visual);
    cr = cairo_create(surface);

    cairo_set_source_rgb(cr, 1, 1, 1);

    cairo_save(cr);
    cairo_set_font_size (cr, 20);
    cairo_move_to (cr, 10, 10);
    cairo_rotate(cr, PI / 2);
    cairo_show_text (cr, "Hello World.");
    cairo_restore(cr);

/*
    cairo_scale(cr, 5, 5);
    inf(cr);
    cairo_translate(cr, 0, 2 * SIZE);
    inf(cr);
    cairo_translate(cr, 0, - 2 * SIZE);
    cairo_clip(cr);
    cairo_scale(cr, 1/5.0, 1/5.0);
*/

    /* This is handy for examining problems more closely */
    /*    cairo_scale(cr, 4, 4);  */

    cairo_set_line_width(cr, SIZE / 4);

    cairo_set_tolerance(cr, .1);

    cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
    cairo_set_dash(cr, dash, NUM_DASH, 0);
    stroke_shapes(cr, 0, 0);

    cairo_translate(cr, 0, 4*SIZE);

    cairo_set_dash(cr, NULL, 0, 0);
    stroke_shapes(cr, 0, 0);

    cairo_translate(cr, 0, 4*SIZE);

    cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
    stroke_shapes(cr, 0, 0);

    cairo_translate(cr, 0, 4*SIZE);

    cairo_set_line_join(cr, CAIRO_LINE_JOIN_MITER);
    stroke_shapes(cr, 0, 0);

    cairo_translate(cr, 0, 4*SIZE);

    fill_shapes(cr, 0, 0);

    cairo_translate(cr, 0, 4*SIZE);

    cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
    fill_shapes(cr, 0, 0);
    cairo_set_source_rgb(cr, 1, 0, 0);
    stroke_shapes(cr, 0, 0);
/*
    draw_broken_shapes(cr);
*/
    if (cairo_status(cr)) {
	printf("Cairo is unhappy: %s\n", cairo_status_string(cr));
	exit(0);
    }

    cairo_destroy(cr);
}

static int
id_to_visual(XCBSCREEN *root, XCBVISUALTYPE **visual)
{
    XCBDEPTHIter di;
    XCBVISUALTYPE *v;

    for(di = XCBSCREENAllowedDepthsIter(root); di.rem; XCBDEPTHNext(&di))
    {
	int i;
	const int count = XCBDEPTHVisualsLength(di.data);
	v = XCBDEPTHVisuals(di.data);
	for(i = 0; i < count; ++i)
	    if(v->visual_id.id == root->root_visual.id)
	    {
		*visual = v;
		return di.data->depth;
	    }
    }
    return 0;
}

static void
win_init(win_t *win)
{
    XCBSCREEN *root = XCBConnSetupSuccessRepRootsIter(XCBGetSetup(win->dpy)).data;
    CARD32 mask = XCBCWBackPixel | XCBCWEventMask;
    CARD32 values[] = { root->black_pixel, StructureNotifyMask | ExposureMask };
    int depth;

    win->width = 400;
    win->height = 400;

    win->win = XCBWINDOWNew(win->dpy);
    depth = id_to_visual(root, &win->visual);
    XCBCreateWindow(win->dpy, depth, win->win, root->root, 0, 0, win->width,
		    win->height, 0, InputOutput, win->visual->visual_id,
		    mask, values);
    XCBMapWindow(win->dpy, win->win);
}

static void
win_deinit(win_t *win)
{
    XCBDestroyWindow(win->dpy, win->win);
}

static void
win_handle_events(win_t *win)
{
    XCBGenericEvent *xev;

    while (1) {
	xev = XCBWaitEvent(win->dpy);
	if(!xev)
		return;
	switch(xev->response_type) {
	case XCBConfigureNotify:
	{
	    XCBConfigureNotifyEvent *cev = (XCBConfigureNotifyEvent *) xev;

	    win->width = cev->width;
	    win->height = cev->height;
	}
	break;
	case XCBExpose:
	{
	    XCBExposeEvent *eev = (XCBExposeEvent *) xev;

	    if (eev->count == 0)
		win_draw(win);
	}
	break;
	}
    }
}

Index: cairo-demo.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/X11/cairo-demo.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- cairo-demo.c	7 Feb 2005 13:41:34 -0000	1.12
+++ cairo-demo.c	13 May 2005 22:33:59 -0000	1.13
@@ -3,38 +3,19 @@
 #include <math.h>
 
 #include <cairo.h>
-
-#ifdef CAIRO_HAS_XCB_SURFACE
-#include <cairo-xcb.h>
-#undef CAIRO_HAS_XLIB_SURFACE
-#endif
-
-#ifdef CAIRO_HAS_XLIB_SURFACE
 #include <cairo-xlib.h>
-#endif
 
 #define PI 3.1415926535
 
 typedef struct win {
-#ifndef CAIRO_HAS_XCB_SURFACE
     Display *dpy;
     int scr;
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBConnection *dpy;
-#endif /* CAIRO_HAS_XCB_SURFACE */
-#ifndef CAIRO_HAS_XCB_SURFACE
+
     Window win;
     GC gc;
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBWINDOW win;
-    XCBGCONTEXT gc;
-#endif /* CAIRO_HAS_XCB_SURFACE */
+
     int width, height;
-#ifndef CAIRO_HAS_XCB_SURFACE
     KeyCode quit_code;
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBVISUALTYPE *visual;
-#endif /* CAIRO_HAS_XCB_SURFACE */
 } win_t;
 
 static void triangle(cairo_t *cr);
@@ -50,11 +31,7 @@
 {
     win_t win;
 
-#ifndef CAIRO_HAS_XCB_SURFACE
     win.dpy = XOpenDisplay(0);
-#else /* CAIRO_HAS_XCB_SURFACE */
-    win.dpy = XCBConnectBasic();
-#endif /* CAIRO_HAS_XCB_SURFACE */
 
     if (win.dpy == NULL) {
 	fprintf(stderr, "Failed to open display\n");
@@ -69,11 +46,7 @@
 
     win_deinit(&win);
 
-#ifndef CAIRO_HAS_XCB_SURFACE
     XCloseDisplay(win.dpy);
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBDisconnect(win.dpy);
-#endif /* CAIRO_HAS_XCB_SURFACE */
 
     return 0;
 }
@@ -191,7 +164,7 @@
 
     cairo_set_line_width(cr, 1);
     cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
-    cairo_set_rgb_color(cr, 1, 1, 1);
+    cairo_set_source_rgb(cr, 1, 1, 1);
 
     cairo_move_to(cr, 19.153717041015625, 144.93951416015625);
     cairo_line_to(cr, 412.987396240234375, 99.407318115234375);
@@ -223,30 +196,21 @@
 {
 #define NUM_DASH 2
     static double dash[NUM_DASH] = {SIZE/4.0, SIZE/4.0};
+    cairo_surface_t *surface;
     cairo_t *cr;
-#ifndef CAIRO_HAS_XCB_SURFACE
-    Drawable drawable = win->win;
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBDRAWABLE drawable;
-    drawable.window = win->win;
-#endif /* CAIRO_HAS_XCB_SURFACE */
+    Visual *visual = DefaultVisual(win->dpy, DefaultScreen (win->dpy));
 
-#ifndef CAIRO_HAS_XCB_SURFACE
     XClearWindow(win->dpy, win->win);
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBClearArea(win->dpy, 0, win->win, 0, 0, 0, 0);
-#endif /* CAIRO_HAS_XCB_SURFACE */
 
-    cr = cairo_create();
-#ifndef CAIRO_HAS_XCB_SURFACE
-    cairo_set_target_drawable (cr, win->dpy, drawable);
-#else /* CAIRO_HAS_XCB_SURFACE */
-    cairo_set_target_xcb (cr, win->dpy, drawable, win->visual, 0);
-#endif /* CAIRO_HAS_XCB_SURFACE */
-    cairo_set_rgb_color(cr, 1, 1, 1);
+    surface = cairo_xlib_surface_create_for_window_with_visual (win->dpy,
+								win->win,
+								visual);
+    cr = cairo_create(surface);
+
+    cairo_set_source_rgb(cr, 1, 1, 1);
 
     cairo_save(cr);
-    cairo_scale_font (cr, 20);
+    cairo_set_font_size (cr, 20);
     cairo_move_to (cr, 10, 10);
     cairo_rotate(cr, PI / 2);
     cairo_show_text (cr, "Hello World.");
@@ -296,7 +260,7 @@
 
     cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
     fill_shapes(cr, 0, 0);
-    cairo_set_rgb_color(cr, 1, 0, 0);
+    cairo_set_source_rgb(cr, 1, 0, 0);
     stroke_shapes(cr, 0, 0);
 /*
     draw_broken_shapes(cr);
@@ -307,47 +271,17 @@
     }
 
     cairo_destroy(cr);
+    cairo_surface_destroy (surface);
 }
 
-#ifdef CAIRO_HAS_XCB_SURFACE
-static int
-id_to_visual(XCBSCREEN *root, XCBVISUALTYPE **visual)
-{
-    XCBDEPTHIter di;
-    XCBVISUALTYPE *v;
-
-    for(di = XCBSCREENAllowedDepthsIter(root); di.rem; XCBDEPTHNext(&di))
-    {
-	int i;
-	const int count = XCBDEPTHVisualsLength(di.data);
-	v = XCBDEPTHVisuals(di.data);
-	for(i = 0; i < count; ++i)
-	    if(v->visual_id.id == root->root_visual.id)
-	    {
-		*visual = v;
-		return di.data->depth;
-	    }
-    }
-    return 0;
-}
-#endif /* CAIRO_HAS_XCB_SURFACE */
-
 static void
 win_init(win_t *win)
 {
-#ifndef CAIRO_HAS_XCB_SURFACE
     Window root;
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBSCREEN *root = XCBConnSetupSuccessRepRootsIter(XCBGetSetup(win->dpy)).data;
-    CARD32 mask = XCBCWBackPixel | XCBCWEventMask;
-    CARD32 values[] = { root->black_pixel, StructureNotifyMask | ExposureMask };
-    int depth;
-#endif /* CAIRO_HAS_XCB_SURFACE */
 
     win->width = 400;
     win->height = 400;
 
-#ifndef CAIRO_HAS_XCB_SURFACE
     root = DefaultRootWindow(win->dpy);
     win->scr = DefaultScreen(win->dpy);
 
@@ -363,46 +297,22 @@
 		 |ExposureMask);
 
     XMapWindow(win->dpy, win->win);
-#else /* CAIRO_HAS_XCB_SURFACE */
-    win->win = XCBWINDOWNew(win->dpy);
-    depth = id_to_visual(root, &win->visual);
-    XCBCreateWindow(win->dpy, depth, win->win, root->root, 0, 0, win->width,
-		    win->height, 0, InputOutput, win->visual->visual_id,
-		    mask, values);
-    XCBMapWindow(win->dpy, win->win);
-#endif /* CAIRO_HAS_XCB_SURFACE */
 }
 
 static void
 win_deinit(win_t *win)
 {
-#ifndef CAIRO_HAS_XCB_SURFACE
     XDestroyWindow(win->dpy, win->win);
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBDestroyWindow(win->dpy, win->win);
-#endif /* CAIRO_HAS_XCB_SURFACE */
 }
 
 static void
 win_handle_events(win_t *win)
 {
-#ifndef CAIRO_HAS_XCB_SURFACE
     XEvent xev;
-#else /* CAIRO_HAS_XCB_SURFACE */
-    XCBGenericEvent *xev;
-#endif /* CAIRO_HAS_XCB_SURFACE */
 
     while (1) {
-#ifndef CAIRO_HAS_XCB_SURFACE
 	XNextEvent(win->dpy, &xev);
 	switch(xev.type) {
-#else /* CAIRO_HAS_XCB_SURFACE */
-	xev = XCBWaitEvent(win->dpy);
-	if(!xev)
-		return;
-	switch(xev->response_type) {
-#endif /* CAIRO_HAS_XCB_SURFACE */
-#ifdef CAIRO_HAS_XLIB_SURFACE
 	case KeyPress:
 	{
 	    XKeyEvent *kev = &xev.xkey;
@@ -412,34 +322,17 @@
 	    }
 	}
 	break;
-#endif
-#ifndef CAIRO_HAS_XCB_SURFACE
 	case ConfigureNotify:
-#else /* CAIRO_HAS_XCB_SURFACE */
-	case XCBConfigureNotify:
-#endif /* CAIRO_HAS_XCB_SURFACE */
 	{
-#ifndef CAIRO_HAS_XCB_SURFACE
 	    XConfigureEvent *cev = &xev.xconfigure;
-#else /* CAIRO_HAS_XCB_SURFACE */
-	    XCBConfigureNotifyEvent *cev = (XCBConfigureNotifyEvent *) xev;
-#endif /* CAIRO_HAS_XCB_SURFACE */
 
 	    win->width = cev->width;
 	    win->height = cev->height;
 	}
 	break;
-#ifndef CAIRO_HAS_XCB_SURFACE
 	case Expose:
-#else /* CAIRO_HAS_XCB_SURFACE */
-	case XCBExpose:
-#endif /* CAIRO_HAS_XCB_SURFACE */
 	{
-#ifndef CAIRO_HAS_XCB_SURFACE
 	    XExposeEvent *eev = &xev.xexpose;
-#else /* CAIRO_HAS_XCB_SURFACE */
-	    XCBExposeEvent *eev = (XCBExposeEvent *) xev;
-#endif /* CAIRO_HAS_XCB_SURFACE */
 
 	    if (eev->count == 0)
 		win_draw(win);

Index: cairo-knockout.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/X11/cairo-knockout.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- cairo-knockout.c	21 Feb 2005 20:41:18 -0000	1.14
+++ cairo-knockout.c	13 May 2005 22:33:59 -0000	1.15
@@ -27,10 +27,9 @@
            double xc, double yc,
            double xr, double yr)
 {
-    cairo_matrix_t *matrix;
+    cairo_matrix_t matrix;
 
-    matrix = cairo_matrix_create ();
-    cairo_current_matrix (cr, matrix);
+    cairo_get_matrix (cr, &matrix);
 
     cairo_translate (cr, xc, yc);
     cairo_scale (cr, 1.0, yr / xr);
@@ -41,8 +40,7 @@
                0, 2 * M_PI);
     cairo_close_path (cr);
 
-    cairo_set_matrix (cr, matrix);
-    cairo_matrix_destroy (matrix);
+    cairo_set_matrix (cr, &matrix);
 }
 
 /* Fill the given area with checks in the standard style
@@ -60,38 +58,38 @@
 
 #define CHECK_SIZE 32
 
-    check = cairo_surface_create_similar (cairo_current_target_surface (cr),
+    check = cairo_surface_create_similar (cairo_get_target (cr),
                                    CAIRO_FORMAT_RGB24,
                                    2 * CHECK_SIZE, 2 * CHECK_SIZE);
-    cairo_surface_set_repeat (check, 1);
 
     /* Draw the check */
     {
-        cairo_save (cr);
+        cairo_t *cr2;
 
-        cairo_set_target_surface (cr, check);
+        cr2 = cairo_create (check);
 
-        cairo_set_operator (cr, CAIRO_OPERATOR_SRC);
+        cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
 
-        cairo_set_rgb_color (cr, 0.4, 0.4, 0.4);
+        cairo_set_source_rgb (cr2, 0.4, 0.4, 0.4);
 
-        cairo_rectangle (cr, 0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
-        cairo_fill (cr);
+        cairo_rectangle (cr2, 0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
+        cairo_fill (cr2);
 
-        cairo_set_rgb_color (cr, 0.7, 0.7, 0.7);
+        cairo_set_source_rgb (cr2, 0.7, 0.7, 0.7);
 
-        cairo_rectangle (cr, x, y, CHECK_SIZE, CHECK_SIZE);
-        cairo_fill (cr);
-        cairo_rectangle (cr, x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
-        cairo_fill (cr);
+        cairo_rectangle (cr2, x, y, CHECK_SIZE, CHECK_SIZE);
+        cairo_fill (cr2);
+        cairo_rectangle (cr2, x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
+        cairo_fill (cr2);
 
-        cairo_restore (cr);
+        cairo_destroy (cr2);
     }
 
     /* Fill the whole surface with the check */
 
     check_pattern = cairo_pattern_create_for_surface (check);
-    cairo_set_pattern (cr, check_pattern);
+    cairo_pattern_set_extend (check_pattern, CAIRO_EXTEND_REPEAT);
+    cairo_set_source (cr, check_pattern);
     cairo_rectangle (cr, 0, 0, width, height);
     cairo_fill (cr);
 
@@ -107,25 +105,26 @@
 static void
 draw_3circles (cairo_t *cr,
                double xc, double yc,
-               double radius)
+               double radius,
+               double alpha)
 {
     double subradius = radius * (2 / 3. - 0.1);
     
-    cairo_set_rgb_color (cr, 1., 0., 0.);
+    cairo_set_source_rgba (cr, 1., 0., 0., alpha);
     oval_path (cr,
                xc + radius / 3. * cos (M_PI * (0.5)),
                yc - radius / 3. * sin (M_PI * (0.5)),
                subradius, subradius);
     cairo_fill (cr);
     
-    cairo_set_rgb_color (cr, 0., 1., 0.);
+    cairo_set_source_rgba (cr, 0., 1., 0., alpha);
     oval_path (cr,
                xc + radius / 3. * cos (M_PI * (0.5 + 2/.3)),
                yc - radius / 3. * sin (M_PI * (0.5 + 2/.3)),
                subradius, subradius);
     cairo_fill (cr);
     
-    cairo_set_rgb_color (cr, 0., 0., 1.);
+    cairo_set_source_rgba (cr, 0., 0., 1., alpha);
     oval_path (cr,
                xc + radius / 3. * cos (M_PI * (0.5 + 4/.3)),
                yc - radius / 3. * sin (M_PI * (0.5 + 4/.3)),
@@ -145,19 +144,19 @@
     double xc = width / 2.;
     double yc = height / 2.;
 
-    overlay = cairo_surface_create_similar (cairo_current_target_surface (cr),
+    overlay = cairo_surface_create_similar (cairo_get_target (cr),
                                      CAIRO_FORMAT_ARGB32,
                                      width, height);
     if (overlay == NULL)
         return;
 
-    punch = cairo_surface_create_similar (cairo_current_target_surface (cr),
+    punch = cairo_surface_create_similar (cairo_get_target (cr),
                                    CAIRO_FORMAT_A8,
                                    width, height);
     if (punch == NULL)
         return;
 
-    circles = cairo_surface_create_similar (cairo_current_target_surface (cr),
+    circles = cairo_surface_create_similar (cairo_get_target (cr),
                                      CAIRO_FORMAT_ARGB32,
                                      width, height);
     if (circles == NULL)
@@ -166,46 +165,59 @@
     fill_checks (cr, 0, 0, width, height);
 
     cairo_save (cr);
-    cairo_set_target_surface (cr, overlay);
 
-    /* Draw a black circle on the overlay
-     */
-    cairo_set_rgb_color (cr, 0., 0., 0.);
-    oval_path (cr, xc, yc, radius, radius);
-    cairo_fill (cr);
+    {
+        cairo_t *cr_overlay;
 
-    cairo_save (cr);
-    cairo_set_target_surface (cr, punch);
+        cr_overlay = cairo_create (overlay);
 
-    /* Draw 3 circles to the punch surface, then cut
-     * that out of the main circle in the overlay
-     */
-    draw_3circles (cr, xc, yc, radius);
+        /* Draw a black circle on the overlay
+         */
+        cairo_set_source_rgb (cr_overlay, 0., 0., 0.);
+        oval_path (cr_overlay, xc, yc, radius, radius);
+        cairo_fill (cr_overlay);
 
-    cairo_restore (cr);
+        {
+            cairo_t *cr_tmp;
 
-    cairo_set_operator (cr, CAIRO_OPERATOR_OUT_REVERSE);
-    cairo_show_surface (cr, punch, width, height);
+            cr_tmp = cairo_create (punch);
 
-    /* Now draw the 3 circles in a subgroup again
-     * at half intensity, and use OperatorAdd to join up
-     * without seams.
-     */
-    cairo_save (cr);
-    cairo_set_target_surface (cr, circles);
+            /* Draw 3 circles to the punch surface, then cut
+             * that out of the main circle in the overlay
+             */
+            draw_3circles (cr_tmp, xc, yc, radius, 1.0);
 
-    cairo_set_alpha (cr, 0.5);
-    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-    draw_3circles (cr, xc, yc, radius);
+            cairo_destroy (cr_tmp);
+        }
 
-    cairo_restore (cr);
+        cairo_set_operator (cr_overlay, CAIRO_OPERATOR_DEST_OUT);
+        cairo_set_source_surface (cr_overlay, punch, 0, 0);
+        cairo_paint (cr_overlay);
 
-    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
-    cairo_show_surface (cr, circles, width, height);
+        /* Now draw the 3 circles in a subgroup again
+         * at half intensity, and use OperatorAdd to join up
+         * without seams.
+         */
+        {
+            cairo_t *cr_tmp;
 
-    cairo_restore (cr);
+            cr_tmp = cairo_create (circles);
 
-    cairo_show_surface (cr, overlay, width, height);
+            cairo_set_operator (cr_tmp, CAIRO_OPERATOR_OVER);
+            draw_3circles (cr_tmp, xc, yc, radius, 0.5);
+            
+            cairo_destroy (cr_tmp);
+        }
+
+        cairo_set_operator (cr_overlay, CAIRO_OPERATOR_ADD);
+        cairo_set_source_surface (cr_overlay, circles, 0, 0);
+        cairo_paint (cr_overlay);
+
+        cairo_destroy (cr_overlay);
+    }
+
+    cairo_set_source_surface (cr, overlay, 0, 0);
+    cairo_paint (cr);
 
     cairo_surface_destroy (overlay);
     cairo_surface_destroy (punch);
@@ -277,13 +289,17 @@
        * consecutive resize events for example.
        */
       if (!XPending (dpy) && needs_redraw) {
-          cairo_t *cr = cairo_create ();
-
-          cairo_set_target_drawable (cr, dpy, pixmap);
+          cairo_surface_t *surface;
+          cairo_t *cr;
+          surface = cairo_xlib_surface_create_for_pixmap_with_visual (dpy,
+                                                                      pixmap,
+                                                                      DefaultVisual (dpy, DefaultScreen (dpy)));
+          cr = cairo_create (surface);
 
           draw (cr, width, height);
 
           cairo_destroy (cr);
+          cairo_surface_destroy (surface);
 
           XCopyArea (dpy, pixmap, w, gc,
                      0, 0,

Index: cairo-spline.c
===================================================================
RCS file: /cvs/cairo/cairo-demo/X11/cairo-spline.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- cairo-spline.c	7 Feb 2005 13:38:19 -0000	1.11
+++ cairo-spline.c	13 May 2005 22:33:59 -0000	1.12
@@ -165,7 +165,7 @@
 {
     cairo_save(cr);
 
-    cairo_set_rgb_color(cr, 0, 0, 1);
+    cairo_set_source_rgb(cr, 0, 0, 1);
     cairo_set_line_width(cr, width);
 
     cairo_move_to(cr, a->x, a->y);
@@ -185,7 +185,7 @@
 
     int i;
 
-    cairo_inverse_transform_point (cr, &drag_user_x, &drag_user_y);
+    cairo_device_to_user (cr, &drag_user_x, &drag_user_y);
 
     cairo_save(cr);
 
@@ -207,9 +207,7 @@
     for (i=0; i < 4; i++) {
 	cairo_save(cr);
 
-	cairo_set_rgb_color(cr, 1, 0, 0);
-
-	cairo_set_alpha (cr, 0.5);
+	cairo_set_source_rgba (cr, 1, 0, 0, 0.5);
 
 	cairo_new_path (cr);
 	cairo_arc (cr,
@@ -232,17 +230,18 @@
 {
     Display *dpy = win->dpy;
 
+    cairo_surface_t *surface;
     cairo_t *cr;
     cairo_status_t status;
-    Drawable drawable = win->pix;
 
     XFillRectangle(dpy, win->pix, win->gc, 0, 0, win->width, win->height);
 
-    cr = cairo_create();
-
-    cairo_set_target_drawable (cr, dpy, drawable);
+    surface = cairo_xlib_surface_create_for_pixmap_with_visual (dpy,
+								win->pix,
+								DefaultVisual (dpy, win->scr));
+    cr = cairo_create(surface);
 
-    cairo_set_rgb_color(cr, 0, 0, 0);
+    cairo_set_source_rgb(cr, 0, 0, 0);
 
     cairo_set_line_width(cr, win->line_width);
     cairo_set_line_cap(cr, win->line_cap);
@@ -258,6 +257,7 @@
     }
 
     cairo_destroy(cr);
+    cairo_surface_destroy (surface);
 
     XCopyArea(win->dpy, win->pix, win->win, win->gc,
 	      0, 0, win->width, win->height,




More information about the cairo-commit mailing list