Mercurial > MadButterfly
changeset 3:164162781a7a
Test cairo with Xlib surface
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 25 Jul 2008 10:09:53 +0800 |
parents | 31402929c587 |
children | 399517bf65dc |
files | src/X_main.c src/coord.c |
diffstat | 2 files changed, 62 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/X_main.c Fri Jul 25 10:09:53 2008 +0800 @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <unistd.h> +#include <X11/Xlib.h> +#include <cairo.h> + +void drawing(cairo_surface_t *surface, int w, int h) { + cairo_t *cr; + + cr = cairo_create(surface); + cairo_set_source_rgb(cr, 0xff, 0xff, 0x80); + cairo_move_to(cr, 10, h / 2); + cairo_set_font_size(cr, 48.0); + cairo_text_path(cr, "hello \xe4\xb8\xad\xe6\x96\x87"); + cairo_set_line_width(cr, 1); + cairo_stroke(cr); +} + +int +main(int argc, char * const argv[]) { + Display *display; + Window root; + Visual *visual; + int screen; + XSetWindowAttributes wattr; + Window win; + int depth; + cairo_surface_t *surface; + int w, h; + int x, y; + int r; + + display = XOpenDisplay(":0.0"); + if(display == NULL) + printf("XOpenDisplay\n"); + screen = DefaultScreen(display); + root = DefaultRootWindow(display); + visual = DefaultVisual(display, screen); + depth = DefaultDepth(display, screen); + wattr.override_redirect = False; + x = 10; + y = 10; + w = 200; + h = 200; + win = XCreateWindow(display, root, + x, y, + w, h, + 1, depth, InputOutput, visual, + CWOverrideRedirect, &wattr); + r = XMapWindow(display, win); + + surface = cairo_xlib_surface_create(display, win, visual, w, h); + if(surface == NULL) + printf("cairo_xlib_surface_create\n"); + + drawing(surface, w, h); + + XFlush(display); + sleep(10); + + XCloseDisplay(display); +}
--- a/src/coord.c Wed Jul 23 16:07:37 2008 +0800 +++ b/src/coord.c Fri Jul 25 10:09:53 2008 +0800 @@ -22,6 +22,7 @@ struct coord *children, *sibling; } coord_t; +/* To keep possibility of changing type of aix */ #define MUL(a, b) ((a) * (b)) #define ADD(a, b) ((a) + (b)) #define DIV(a, b) ((a) / (b))