Mercurial > MadButterfly
comparison src/X_main.c @ 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 | |
children | 9c331ec9e210 |
comparison
equal
deleted
inserted
replaced
2:31402929c587 | 3:164162781a7a |
---|---|
1 #include <stdio.h> | |
2 #include <unistd.h> | |
3 #include <X11/Xlib.h> | |
4 #include <cairo.h> | |
5 | |
6 void drawing(cairo_surface_t *surface, int w, int h) { | |
7 cairo_t *cr; | |
8 | |
9 cr = cairo_create(surface); | |
10 cairo_set_source_rgb(cr, 0xff, 0xff, 0x80); | |
11 cairo_move_to(cr, 10, h / 2); | |
12 cairo_set_font_size(cr, 48.0); | |
13 cairo_text_path(cr, "hello \xe4\xb8\xad\xe6\x96\x87"); | |
14 cairo_set_line_width(cr, 1); | |
15 cairo_stroke(cr); | |
16 } | |
17 | |
18 int | |
19 main(int argc, char * const argv[]) { | |
20 Display *display; | |
21 Window root; | |
22 Visual *visual; | |
23 int screen; | |
24 XSetWindowAttributes wattr; | |
25 Window win; | |
26 int depth; | |
27 cairo_surface_t *surface; | |
28 int w, h; | |
29 int x, y; | |
30 int r; | |
31 | |
32 display = XOpenDisplay(":0.0"); | |
33 if(display == NULL) | |
34 printf("XOpenDisplay\n"); | |
35 screen = DefaultScreen(display); | |
36 root = DefaultRootWindow(display); | |
37 visual = DefaultVisual(display, screen); | |
38 depth = DefaultDepth(display, screen); | |
39 wattr.override_redirect = False; | |
40 x = 10; | |
41 y = 10; | |
42 w = 200; | |
43 h = 200; | |
44 win = XCreateWindow(display, root, | |
45 x, y, | |
46 w, h, | |
47 1, depth, InputOutput, visual, | |
48 CWOverrideRedirect, &wattr); | |
49 r = XMapWindow(display, win); | |
50 | |
51 surface = cairo_xlib_surface_create(display, win, visual, w, h); | |
52 if(surface == NULL) | |
53 printf("cairo_xlib_surface_create\n"); | |
54 | |
55 drawing(surface, w, h); | |
56 | |
57 XFlush(display); | |
58 sleep(10); | |
59 | |
60 XCloseDisplay(display); | |
61 } |