annotate src/X_main.c @ 294:2ca0773cd48d

* Add MBAF files * Change begin_index to be start_index * fix the color setting.
author wycc
date Sun, 01 Feb 2009 09:51:12 +0800
parents a90fd749af82
children 16116d84bc5e
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>
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
3 #include <sys/time.h>
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
4 #include <sys/select.h>
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #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
6 #include <X11/Xutil.h>
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include <cairo.h>
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
8 #include <cairo-xlib.h>
278
a90fd749af82 Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents: 186
diff changeset
9 #include <pango/pangocairo.h>
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
11 #include <string.h>
186
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
12 #include "mb_shapes.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
13 #include "mb_redraw_man.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
14 #include "mb_paint.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
15 #include "mb_timer.h"
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
16 #include "mb_animate.h"
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
17
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
18 #define OK 0
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
19 #define ERR -1
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
20
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
21 Display *display;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
22 Window win;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
23
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
24 void hint_shape(redraw_man_t *rdman, shape_t *shape) {
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
25 static shape_t *last_shape = NULL;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
26 if(last_shape != shape) {
33
d82749f77108 Fix bug of demo and remove *_fill() and *_stroke().
Thinker K.F. Li <thinker@branda.to>
parents: 32
diff changeset
27 if(last_shape != NULL && last_shape->stroke != NULL) {
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
28 last_shape->stroke_width -= 2;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
29 rdman_shape_changed(rdman, last_shape);
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
30 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
31 if(shape != NULL && shape->stroke != NULL) {
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
32 shape->stroke_width += 2;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
33 rdman_shape_changed(rdman, shape);
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
34 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
35 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
36 last_shape = shape;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
37 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
38
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
39 void event_interaction(Display *display,
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
40 redraw_man_t *rdman, int w, int h) {
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
41 XEvent evt;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
42 XMotionEvent *mevt;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
43 int r;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
44 co_aix x, y;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
45 shape_t *shape = NULL;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
46 int in_stroke;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
47
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
48 while(XEventsQueued(display, QueuedAfterReading) > 0) {
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
49 r = XNextEvent(display, &evt);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
50 if(r == -1)
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
51 break;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
52
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
53 switch(evt.type) {
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
54 case MotionNotify:
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
55 mevt = (XMotionEvent *)&evt;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
56 x = mevt->x;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
57 y = mevt->y;
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
58 shape = find_shape_at_pos(rdman, x, y, &in_stroke);
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
59 hint_shape(rdman, shape);
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
60 break;
37
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
61 case Expose:
77
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
62 rdman_redraw_area(rdman, evt.xexpose.x, evt.xexpose.y,
Thinker K.F. Li <thinker@branda.to>
parents: 73
diff changeset
63 evt.xexpose.width, evt.xexpose.height);
37
943acee7f346 update exposed area
Thinker K.F. Li <thinker@branda.to>
parents: 35
diff changeset
64 break;
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
65 }
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
66 }
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
67 rdman_redraw_changed(rdman);
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
68 XFlush(display);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
69 }
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
70
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
71 void handle_connection(Display *display, mb_tman_t *tman,
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
72 redraw_man_t *rdman, int w, int h) {
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
73 int xcon;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
74 fd_set rds;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
75 int nfds;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
76 struct timeval tmo;
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
77 mb_timeval_t mb_tmo, next_mb_tmo;
54
Thinker K.F. Li <thinker@branda.to>
parents: 53
diff changeset
78 int r;
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
79
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
80 XSelectInput(display, win, PointerMotionMask | ExposureMask);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
81 XFlush(display);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
82
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
83 xcon = XConnectionNumber(display);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
84 nfds = xcon + 1;
49
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
85
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
86 r = gettimeofday(&tmo, NULL);
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
87 if(r == -1) {
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
88 perror("gettimeofday");
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
89 return;
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
90 }
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
91 MB_TIMEVAL_SET(&mb_tmo, tmo.tv_sec, tmo.tv_usec);
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
92
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
93 while(1) {
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
94 FD_ZERO(&rds);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
95 FD_SET(xcon, &rds);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
96
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
97 r = mb_tman_next_timeout(tman, &mb_tmo, &next_mb_tmo);
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
98 if(r != OK)
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
99 r = select(nfds, &rds, NULL, NULL, NULL);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
100 else {
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
101 tmo.tv_sec = MB_TIMEVAL_SEC(&next_mb_tmo);
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
102 tmo.tv_usec = MB_TIMEVAL_USEC(&next_mb_tmo);
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
103 r = select(nfds, &rds, NULL, NULL, &tmo);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
104 }
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
105
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
106 if(r == -1) {
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
107 perror("select");
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
108 return;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
109 }
49
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
110
54
Thinker K.F. Li <thinker@branda.to>
parents: 53
diff changeset
111 if(r == 0) {
Thinker K.F. Li <thinker@branda.to>
parents: 53
diff changeset
112 MB_TIMEVAL_ADD(&mb_tmo, &next_mb_tmo);
49
6a3726fa7aad Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents: 48
diff changeset
113
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
114 mb_tman_handle_timeout(tman, &mb_tmo);
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
115 rdman_redraw_changed(rdman);
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
116 XFlush(display);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
117 } else if(FD_ISSET(xcon, &rds)) {
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
118 event_interaction(display, rdman, w, h);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
119 }
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
120 }
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
121 }
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
122
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
123 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
124 cairo_t *tmpcr;
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
125 cairo_surface_t *tmpsuf;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
126 redraw_man_t rdman;
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
127 shape_t *path1, *path2, *rect;
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
128 coord_t *coord1, *coord2, *coord3;
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
129 paint_t *fill1, *fill2, *fill3;
55
01ed2bc37eed Radial gradient paint
Thinker K.F. Li <thinker@branda.to>
parents: 54
diff changeset
130 paint_t *text_fill;
01ed2bc37eed Radial gradient paint
Thinker K.F. Li <thinker@branda.to>
parents: 54
diff changeset
131 grad_stop_t text_stops[2];
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
132 paint_t *stroke, *text_stroke;
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
133 shape_t *text;
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
134 grad_stop_t fill3_stops[3];
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
135 cairo_font_face_t *face;
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
136 struct timeval tv;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
137 mb_tman_t *tman;
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
138 mb_timeval_t mbtv, start, playing;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
139 mb_progm_t *progm;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
140 mb_word_t *word;
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
141 mb_action_t *act;
278
a90fd749af82 Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents: 186
diff changeset
142 PangoAttrList *attrs = pango_attr_list_new();
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 11
diff changeset
143
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
144 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
145 tmpcr = cairo_create(tmpsuf);
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
146
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
147 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
148 redraw_man_init(&rdman, tmpcr, cr);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
149 coord1 = rdman_coord_new(&rdman, rdman.root_coord);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
150 coord2 = rdman_coord_new(&rdman, rdman.root_coord);
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
151 coord3 = 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
152
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
153 fill1 = rdman_paint_color_new(&rdman, 1, 1, 0, 0.5);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
154 fill2 = rdman_paint_color_new(&rdman, 0, 1, 1, 0.5);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
155 stroke = rdman_paint_color_new(&rdman, 0.4, 0.4, 0.4, 1);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
156 text_stroke = rdman_paint_color_new(&rdman, 0.5, 0.5, 0.5, 1);
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
157
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
158 face = cairo_get_font_face(tmpcr);
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
159 text = rdman_shape_text_new(&rdman, "hello \xe6\xbc\xa2\xe5\xad\x97",
278
a90fd749af82 Implement the whole tspan attribute. Currently, we can accept font family/font style/font weight and font size.
wycc
parents: 186
diff changeset
160 10, h / 4, 36.0, face, attrs);
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
161 text_fill = rdman_paint_radial_new(&rdman, 100, h / 4, 70);
55
01ed2bc37eed Radial gradient paint
Thinker K.F. Li <thinker@branda.to>
parents: 54
diff changeset
162 grad_stop_init(text_stops, 0, 0.2, 0.9, 0.2, 1);
01ed2bc37eed Radial gradient paint
Thinker K.F. Li <thinker@branda.to>
parents: 54
diff changeset
163 grad_stop_init(text_stops + 1, 1, 0.9, 0.2, 0.2, 0.1);
56
e444a8c01735 Change interface of paint_radial_new()
Thinker K.F. Li <thinker@branda.to>
parents: 55
diff changeset
164 paint_radial_stops(text_fill, 2, text_stops);
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
165 rdman_paint_stroke(&rdman, text_stroke, text);
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
166 text->stroke_width = 0.5;
55
01ed2bc37eed Radial gradient paint
Thinker K.F. Li <thinker@branda.to>
parents: 54
diff changeset
167 rdman_paint_fill(&rdman, text_fill, text);
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
168 rdman_add_shape(&rdman, text, coord3);
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
169
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
170 path1 = rdman_shape_path_new(&rdman, "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 ");
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
171 rdman_paint_fill(&rdman, fill1, path1);
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 21
diff changeset
172 rdman_paint_stroke(&rdman, stroke, path1);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
173 coord1->matrix[0] = 0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
174 coord1->matrix[1] = 0;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
175 coord1->matrix[2] = 20;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
176 coord1->matrix[4] = 0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
177 coord1->matrix[5] = 20;
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
178
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
179 path2 = rdman_shape_path_new(&rdman, "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 ");
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
180 rdman_paint_fill(&rdman, fill2, path2);
22
8fcf2d878ecd shapes with stroke
Thinker K.F. Li <thinker@branda.to>
parents: 21
diff changeset
181 rdman_paint_stroke(&rdman, stroke, path2);
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
182 coord2->matrix[0] = -0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
183 coord2->matrix[1] = 0;
20
74d3d5dc9aaa rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents: 19
diff changeset
184 coord2->matrix[2] = 180;
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
185 coord2->matrix[4] = 0.8;
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
186 coord2->matrix[5] = 20;
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
187
19
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
188 rdman_coord_changed(&rdman, coord1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
189 rdman_coord_changed(&rdman, coord2);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
190 rdman_add_shape(&rdman, (shape_t *)path1, coord1);
cf6d65398619 More animation demo
Thinker K.F. Li <thinker@branda.to>
parents: 18
diff changeset
191 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
192
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
193
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
194 fill3 = rdman_paint_linear_new(&rdman, 50, 50, 150, 150);
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
195 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
196 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
197 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
198 paint_linear_stops(fill3, 3, fill3_stops);
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
199 rect = rdman_shape_rect_new(&rdman, 50, 50, 100, 100, 20, 20);
35
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
200 rdman_paint_fill(&rdman, fill3, rect);
581a03196093 Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents: 33
diff changeset
201 rdman_add_shape(&rdman, (shape_t *)rect, rdman.root_coord);
23
56f592f56ff7 Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 22
diff changeset
202
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
203 rdman_redraw_all(&rdman);
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
204
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
205 XFlush(display);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
206
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
207 tman = mb_tman_new();
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
208 if(tman) {
58
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
209 /* Prepare an animation program. */
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
210 progm = mb_progm_new(10, &rdman);
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
211
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
212 MB_TIMEVAL_SET(&start, 0, 0);
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
213 MB_TIMEVAL_SET(&playing, 1, 0);
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
214 word = mb_progm_next_word(progm, &start, &playing);
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
215
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
216 act = mb_shift_new(50, 50, coord1, word);
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
217 act = mb_shift_new(-50, 50, coord2, word);
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
218
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
219 MB_TIMEVAL_SET(&start, 1, 0);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
220 MB_TIMEVAL_SET(&playing, 2, 0);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
221 word = mb_progm_next_word(progm, &start, &playing);
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
222
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 44
diff changeset
223 act = mb_shift_new(0, 20, coord1, word);
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
224 act = mb_shift_new(0, -20, coord2, word);
57
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 56
diff changeset
225 act = mb_visibility_new(VIS_HIDDEN, coord3, word);
44
7d9af44f095b Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
226
7d9af44f095b Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
227 MB_TIMEVAL_SET(&start, 3, 0);
7d9af44f095b Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents: 42
diff changeset
228 MB_TIMEVAL_SET(&playing, 2, 0);
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
229 word = mb_progm_next_word(progm, &start, &playing);
53
ffed18510d55 Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents: 52
diff changeset
230
47
f3818d996f4f change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents: 44
diff changeset
231 act = mb_shift_new(0, -20, coord1, word);
48
bdf711cbf0fb Use absolute time to dispatch animation actions.
Thinker K.F. Li <thinker@branda.to>
parents: 47
diff changeset
232 act = mb_shift_new(0, 20, coord2, word);
52
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 49
diff changeset
233 act = mb_chgcolor_new(0, 0, 1, 0.5, fill1, word);
59a295651480 Add action mb_chgcolor_t to change color of paints.
Thinker K.F. Li <thinker@branda.to>
parents: 49
diff changeset
234 act = mb_chgcolor_new(1, 0, 0, 0.5, fill2, word);
57
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 56
diff changeset
235 act = mb_visibility_new(VIS_VISIBLE, coord3, word);
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
236
58
Thinker K.F. Li <thinker@branda.to>
parents: 57
diff changeset
237 /* Start playing the program. */
42
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
238 gettimeofday(&tv, NULL);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
239 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
240 mb_progm_start(progm, tman, &mbtv);
e3295c07faa9 mb_shift is work
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
241
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
242 handle_connection(display, tman, &rdman, w, h);
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
243
57
ab028c9f0930 Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents: 56
diff changeset
244 mb_progm_free(progm);
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
245 mb_tman_free(tman);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents: 37
diff changeset
246 }
30
e06a4a667ce2 Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents: 27
diff changeset
247
159
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
248 rdman_paint_free(&rdman, fill1);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
249 rdman_paint_free(&rdman, fill2);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
250 rdman_paint_free(&rdman, stroke);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
251 rdman_paint_free(&rdman, text_stroke);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
252 rdman_paint_free(&rdman, text_fill);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
253 rdman_shape_free(&rdman, path1);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
254 rdman_shape_free(&rdman, path2);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
255 rdman_shape_free(&rdman, rect);
b90abd31a281 Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents: 77
diff changeset
256 rdman_shape_free(&rdman, text);
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
257 redraw_man_destroy(&rdman);
24
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
258 cairo_destroy(tmpcr);
e598bc809c0f No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents: 23
diff changeset
259 cairo_surface_destroy(tmpsuf);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
260 }
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
261
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
262 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
263 cairo_t *cr;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
264
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
265 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
266 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
267 cairo_paint(cr);
5
9c331ec9e210 SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents: 3
diff changeset
268 draw_path(cr, w, h);
27
19c603dd6ff9 Add text shape.
Thinker K.F. Li <thinker@branda.to>
parents: 26
diff changeset
269 cairo_destroy(cr);
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270 }
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
271
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
272 int
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
273 main(int argc, char * const argv[]) {
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
274 Window root;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
275 Visual *visual;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
276 int screen;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
277 XSetWindowAttributes wattr;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
278 int depth;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
279 cairo_surface_t *surface;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
280 int w, h;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
281 int x, y;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
282 int r;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
283
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
284 display = XOpenDisplay(":0.0");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
285 if(display == NULL)
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
286 printf("XOpenDisplay\n");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
287 screen = DefaultScreen(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
288 root = DefaultRootWindow(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
289 visual = DefaultVisual(display, screen);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
290 depth = DefaultDepth(display, screen);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
291 wattr.override_redirect = False;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
292 x = 10;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
293 y = 10;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
294 w = 200;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
295 h = 200;
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
296 win = XCreateWindow(display, root,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
297 x, y,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
298 w, h,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299 1, depth, InputOutput, visual,
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
300 CWOverrideRedirect, &wattr);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301 r = XMapWindow(display, win);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
302
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
303 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
304 if(surface == NULL)
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
305 printf("cairo_xlib_surface_create\n");
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
306
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
307 drawing(surface, w, h);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
308
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
309 XFlush(display);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
310 sleep(10);
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
311
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
312 XCloseDisplay(display);
10
7cfecdce94cc Remove warning messages
Thinker K.F. Li <thinker@branda.to>
parents: 9
diff changeset
313 return 0;
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
314 }