annotate src/X_main.c @ 26:d50f33040de6

Set line width for path. - consider width of line when compute bounding box area.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 03 Aug 2008 13:04:55 +0800
parents e598bc809c0f
children 19c603dd6ff9
rev   line source
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <unistd.h>
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <X11/Xlib.h>
6
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
4 #include <X11/Xutil.h>
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <cairo.h>
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
6 #include <cairo-xlib.h>
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
8 #include <string.h>
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
9 #include "shapes.h"
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
10 #include "redraw_man.h"
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
11 #include "paint.h"
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
12
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
13 Display *display;
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
14
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
15 void draw_path(cairo_t *cr, int w, int h) {
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
16 cairo_t *tmpcr;
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
17 cairo_surface_t *tmpsuf;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
18 redraw_man_t rdman;
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
19 shape_t *path1, *path2, *path3;
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
20 coord_t *coord1, *coord2;
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
21 paint_t *fill1, *fill2, *fill3;
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 21
diff changeset
22 paint_t *stroke;
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
23 grad_stop_t fill3_stops[3];
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
24 int i;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
25
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
26 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
27 tmpcr = cairo_create(tmpsuf);
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
28 cairo_set_source_surface(cr, tmpsuf, 0, 0);
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
29 redraw_man_init(&rdman, tmpcr, cr);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
30 coord1 = rdman_coord_new(&rdman, rdman.root_coord);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
31 coord2 = rdman_coord_new(&rdman, rdman.root_coord);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
32
21
83d24300a992 opacity (alpha) channel
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
33 fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5);
83d24300a992 opacity (alpha) channel
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
34 fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5);
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 21
diff changeset
35 stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
36 path1 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z ");
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
37 rdman_paint_fill(&rdman, fill1, path1);
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 21
diff changeset
38 rdman_paint_stroke(&rdman, stroke, path1);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
39 coord1->matrix[0] = 0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
40 coord1->matrix[1] = 0;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
41 coord1->matrix[2] = 20;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
42 coord1->matrix[4] = 0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
43 coord1->matrix[5] = 20;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
44 path2 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z ");
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
45 rdman_paint_fill(&rdman, fill2, path2);
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 21
diff changeset
46 rdman_paint_stroke(&rdman, stroke, path2);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
47 coord2->matrix[0] = -0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
48 coord2->matrix[1] = 0;
20
74d3d5dc9aaa rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents: 19
diff changeset
49 coord2->matrix[2] = 180;
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
50 coord2->matrix[4] = 0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
51 coord2->matrix[5] = 20;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
52 rdman_coord_changed(&rdman, coord1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
53 rdman_coord_changed(&rdman, coord2);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
54 rdman_add_shape(&rdman, (shape_t *)path1, coord1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
55 rdman_add_shape(&rdman, (shape_t *)path2, coord2);
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
56
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
57
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
58 fill3 = paint_linear_new(&rdman, 50, 50, 150, 150);
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
59 grad_stop_init(fill3_stops, 0, 1, 0, 0, 0.5);
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
60 grad_stop_init(fill3_stops + 1, 0.5, 0, 1, 0, 0.5);
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
61 grad_stop_init(fill3_stops + 2, 1, 0, 0, 1, 0.5);
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
62 paint_linear_stops(fill3, 3, fill3_stops);
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
63 path3 = sh_path_new("M 50,50 L 50,150 L 150,150 L 150,50 z");
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
64 rdman_paint_fill(&rdman, fill3, path3);
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
65 rdman_add_shape(&rdman, (shape_t *)path3, rdman.root_coord);
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
66
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
67 rdman_redraw_all(&rdman);
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
68
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
69 XFlush(display);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
70
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
71 for(i = 0; i < 50; i++) {
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
72 usleep(20000);
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
73 path1->stroke_width = i / 10;
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
74 path2->stroke_width = i / 10;
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
75 coord1->matrix[2] += 1;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
76 coord1->matrix[5] += 1;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
77 coord2->matrix[2] -= 1;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
78 coord2->matrix[5] += 1;
21
83d24300a992 opacity (alpha) channel
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
79 paint_color_set(fill1, 1, 1, (i/25) & 0x1, 0.5);
83d24300a992 opacity (alpha) channel
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
80 paint_color_set(fill2, (i/25) & 0x1, 1, 1, 0.5);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
81 rdman_paint_changed(&rdman, fill1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
82 rdman_paint_changed(&rdman, fill2);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
83 rdman_coord_changed(&rdman, coord1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
84 rdman_coord_changed(&rdman, coord2);
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
85 rdman_redraw_changed(&rdman);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
86 XFlush(display);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
87 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
88
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
89 for(i = 0; i < 5; i++) {
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
90 usleep(500000);
21
83d24300a992 opacity (alpha) channel
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
91 paint_color_set(fill1, 1, i % 2, 0, 0.5);
83d24300a992 opacity (alpha) channel
Thinker K.F. Li <thinker@branda.to>
parents: 20
diff changeset
92 paint_color_set(fill2, 0, i % 2, 1, 0.5);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
93 rdman_paint_changed(&rdman, fill1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
94 rdman_paint_changed(&rdman, fill2);
18
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
95 rdman_redraw_changed(&rdman);
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
96 XFlush(display);
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
97 }
0f3baa488a62 Support solid color paint for fill.
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
98
26
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
99 for(i = 0; i < 4; i++) {
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
100 usleep(500000);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
101 path1->stroke_width -= 1;
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
102 path2->stroke_width -= 1;
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
103 rdman_shape_changed(&rdman, path1);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
104 rdman_shape_changed(&rdman, path2);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
105 rdman_redraw_changed(&rdman);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
106 XFlush(display);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
107 }
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
108 for(i = 0; i < 4; i++) {
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
109 usleep(500000);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
110 path1->stroke_width += 1;
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
111 path2->stroke_width += 1;
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
112 rdman_shape_changed(&rdman, path1);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
113 rdman_shape_changed(&rdman, path2);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
114 rdman_redraw_changed(&rdman);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
115 XFlush(display);
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
116 }
d50f33040de6 Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents: 24
diff changeset
117
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
118 fill1->free(fill1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
119 fill2->free(fill2);
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
120 redraw_man_destroy(&rdman);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
121 sh_path_free(path1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
122 sh_path_free(path2);
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
123 cairo_destroy(tmpcr);
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
124 cairo_surface_destroy(tmpsuf);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
125 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
126
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
127 void drawing(cairo_surface_t *surface, int w, int h) {
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
128 cairo_t *cr;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 cr = cairo_create(surface);
7
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
131 cairo_set_source_rgb(cr, 0, 0, 0);
569f3168ba53 Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents: 6
diff changeset
132 cairo_paint(cr);
6
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
133 cairo_set_source_rgb(cr, 0.9, 0.1, 0.1);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
134 draw_path(cr, w, h);
6
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
135 cairo_set_source_rgb(cr, 0.5, 0.9, 0.8);
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 cairo_move_to(cr, 10, h / 2);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
137 cairo_set_font_size(cr, 36.0);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
138 cairo_text_path(cr, "hello \xe6\xbc\xa2\xe5\xad\x97");
6
772511b8b9be Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
139 cairo_set_line_width(cr, 2);
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 cairo_stroke(cr);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 }
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
142
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 int
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144 main(int argc, char * const argv[]) {
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 Window root;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146 Visual *visual;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 int screen;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 XSetWindowAttributes wattr;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 Window win;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 int depth;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
151 cairo_surface_t *surface;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
152 int w, h;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
153 int x, y;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154 int r;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
155
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156 display = XOpenDisplay(":0.0");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157 if(display == NULL)
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
158 printf("XOpenDisplay\n");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159 screen = DefaultScreen(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160 root = DefaultRootWindow(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 visual = DefaultVisual(display, screen);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162 depth = DefaultDepth(display, screen);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
163 wattr.override_redirect = False;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 x = 10;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165 y = 10;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 w = 200;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 h = 200;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 win = XCreateWindow(display, root,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169 x, y,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 w, h,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 1, depth, InputOutput, visual,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 CWOverrideRedirect, &wattr);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 r = XMapWindow(display, win);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 surface = cairo_xlib_surface_create(display, win, visual, w, h);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 if(surface == NULL)
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
177 printf("cairo_xlib_surface_create\n");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179 drawing(surface, w, h);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181 XFlush(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182 sleep(10);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184 XCloseDisplay(display);
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
185 return 0;
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186 }