Mercurial > MadButterfly
annotate src/X_main.c @ 517:82c1ea2ba929 Android_Skia
Implement SurfaceHolder.Callback for waiting surface creature.
SurfaceView should wait for surface being created. After that, user
of SurfaceView can be used to draw graphics.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 01 Dec 2009 22:55:27 +0800 |
parents | e98ae1407ca2 |
children | 586e50f82c1f |
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 | 3 #include <sys/time.h> |
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> |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
7 #include "mb_graph_engine.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
|
8 #include <pango/pangocairo.h> |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
10 #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
|
11 #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
|
12 #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
|
13 #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
|
14 #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
|
15 #include "mb_animate.h" |
39 | 16 |
17 #define OK 0 | |
18 #define ERR -1 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
19 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
20 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
|
21 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
|
22 |
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 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 } |
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 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
|
31 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
|
32 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
|
33 } |
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 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
|
36 } |
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 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 |
39 | 47 while(XEventsQueued(display, QueuedAfterReading) > 0) { |
48 r = XNextEvent(display, &evt); | |
49 if(r == -1) | |
50 break; | |
51 | |
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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 break; |
37 | 60 case Expose: |
77 | 61 rdman_redraw_area(rdman, evt.xexpose.x, evt.xexpose.y, |
62 evt.xexpose.width, evt.xexpose.height); | |
37 | 63 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
|
64 } |
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 } |
53
ffed18510d55
Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents:
52
diff
changeset
|
66 rdman_redraw_changed(rdman); |
39 | 67 XFlush(display); |
68 } | |
69 | |
70 void handle_connection(Display *display, mb_tman_t *tman, | |
71 redraw_man_t *rdman, int w, int h) { | |
72 int xcon; | |
73 fd_set rds; | |
74 int nfds; | |
75 struct timeval tmo; | |
53
ffed18510d55
Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents:
52
diff
changeset
|
76 mb_timeval_t mb_tmo, next_mb_tmo; |
54 | 77 int r; |
39 | 78 |
79 XSelectInput(display, win, PointerMotionMask | ExposureMask); | |
80 XFlush(display); | |
81 | |
82 xcon = XConnectionNumber(display); | |
83 nfds = xcon + 1; | |
49
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
84 |
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
85 r = gettimeofday(&tmo, NULL); |
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
86 if(r == -1) { |
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
87 perror("gettimeofday"); |
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
88 return; |
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
89 } |
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
90 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
|
91 |
39 | 92 while(1) { |
93 FD_ZERO(&rds); | |
94 FD_SET(xcon, &rds); | |
95 | |
53
ffed18510d55
Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents:
52
diff
changeset
|
96 r = mb_tman_next_timeout(tman, &mb_tmo, &next_mb_tmo); |
39 | 97 if(r != OK) |
98 r = select(nfds, &rds, NULL, NULL, NULL); | |
41 | 99 else { |
53
ffed18510d55
Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents:
52
diff
changeset
|
100 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
|
101 tmo.tv_usec = MB_TIMEVAL_USEC(&next_mb_tmo); |
39 | 102 r = select(nfds, &rds, NULL, NULL, &tmo); |
41 | 103 } |
39 | 104 |
105 if(r == -1) { | |
106 perror("select"); | |
107 return; | |
108 } | |
49
6a3726fa7aad
Reduce times of invoking gettimeofday()
Thinker K.F. Li <thinker@branda.to>
parents:
48
diff
changeset
|
109 |
54 | 110 if(r == 0) { |
111 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
|
112 |
41 | 113 mb_tman_handle_timeout(tman, &mb_tmo); |
42 | 114 rdman_redraw_changed(rdman); |
39 | 115 XFlush(display); |
116 } else if(FD_ISSET(xcon, &rds)) { | |
117 event_interaction(display, rdman, w, h); | |
118 } | |
119 } | |
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
|
120 } |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
121 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
122 void draw_path(mbe_t *cr, int w, int h) { |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
123 mbe_t *tmpcr; |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
124 mbe_surface_t *tmpsuf; |
471
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
451
diff
changeset
|
125 mbe_pattern_t *tmpptn; |
12 | 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 | 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 | 130 paint_t *text_fill; |
131 grad_stop_t text_stops[2]; | |
27 | 132 paint_t *stroke, *text_stroke; |
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]; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
135 mbe_font_face_t *face; |
39 | 136 struct timeval tv; |
137 mb_tman_t *tman; | |
42 | 138 mb_timeval_t mbtv, start, playing; |
139 mb_progm_t *progm; | |
140 mb_word_t *word; | |
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 | 143 |
450
a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
144 tmpsuf = mbe_image_surface_create(MB_IFMT_ARGB32, w, h); |
471
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
451
diff
changeset
|
145 tmpptn = mbe_pattern_create_for_surface(tmpsuf); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
146 tmpcr = mbe_create(tmpsuf); |
27 | 147 |
471
e98ae1407ca2
Remove mbe_set_source_surface() from graphic engine.
Thinker K.F. Li <thinker@branda.to>
parents:
451
diff
changeset
|
148 mbe_set_source(cr, tmpptn); |
24
e598bc809c0f
No more flash when animation.
Thinker K.F. Li <thinker@branda.to>
parents:
23
diff
changeset
|
149 redraw_man_init(&rdman, tmpcr, cr); |
19 | 150 coord1 = rdman_coord_new(&rdman, rdman.root_coord); |
151 coord2 = rdman_coord_new(&rdman, rdman.root_coord); | |
27 | 152 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
|
153 |
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
|
154 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
|
155 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
|
156 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
|
157 text_stroke = rdman_paint_color_new(&rdman, 0.5, 0.5, 0.5, 1); |
27 | 158 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
159 face = mbe_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
|
160 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
|
161 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
|
162 text_fill = rdman_paint_radial_new(&rdman, 100, h / 4, 70); |
55 | 163 grad_stop_init(text_stops, 0, 0.2, 0.9, 0.2, 1); |
164 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
|
165 paint_radial_stops(text_fill, 2, text_stops); |
27 | 166 rdman_paint_stroke(&rdman, text_stroke, text); |
167 text->stroke_width = 0.5; | |
55 | 168 rdman_paint_fill(&rdman, text_fill, text); |
27 | 169 rdman_add_shape(&rdman, text, coord3); |
170 | |
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
|
171 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 | 172 rdman_paint_fill(&rdman, fill1, path1); |
22 | 173 rdman_paint_stroke(&rdman, stroke, path1); |
19 | 174 coord1->matrix[0] = 0.8; |
175 coord1->matrix[1] = 0; | |
176 coord1->matrix[2] = 20; | |
177 coord1->matrix[4] = 0.8; | |
178 coord1->matrix[5] = 20; | |
27 | 179 |
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
|
180 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 | 181 rdman_paint_fill(&rdman, fill2, path2); |
22 | 182 rdman_paint_stroke(&rdman, stroke, path2); |
19 | 183 coord2->matrix[0] = -0.8; |
184 coord2->matrix[1] = 0; | |
20
74d3d5dc9aaa
rename XXX_draw() to XXX_fill()
Thinker K.F. Li <thinker@branda.to>
parents:
19
diff
changeset
|
185 coord2->matrix[2] = 180; |
19 | 186 coord2->matrix[4] = 0.8; |
187 coord2->matrix[5] = 20; | |
27 | 188 |
19 | 189 rdman_coord_changed(&rdman, coord1); |
190 rdman_coord_changed(&rdman, coord2); | |
191 rdman_add_shape(&rdman, (shape_t *)path1, coord1); | |
192 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
|
193 |
23
56f592f56ff7
Fix bug and add linear gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
194 |
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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 rdman_paint_fill(&rdman, fill3, rect); |
581a03196093
Support rectangle tag of SVG.
Thinker K.F. Li <thinker@branda.to>
parents:
33
diff
changeset
|
202 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
|
203 |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
204 rdman_redraw_all(&rdman); |
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
205 |
16
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
206 XFlush(display); |
e17e12b112c4
A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents:
15
diff
changeset
|
207 |
39 | 208 tman = mb_tman_new(); |
209 if(tman) { | |
58 | 210 /* Prepare an animation program. */ |
53
ffed18510d55
Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents:
52
diff
changeset
|
211 progm = mb_progm_new(10, &rdman); |
42 | 212 |
53
ffed18510d55
Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents:
52
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 |
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, coord1, word); |
ffed18510d55
Use animate feacilities to demo all animation.
Thinker K.F. Li <thinker@branda.to>
parents:
52
diff
changeset
|
218 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
|
219 |
42 | 220 MB_TIMEVAL_SET(&start, 1, 0); |
221 MB_TIMEVAL_SET(&playing, 2, 0); | |
222 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
|
223 |
47
f3818d996f4f
change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents:
44
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 |
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
228 MB_TIMEVAL_SET(&start, 3, 0); |
7d9af44f095b
Demo of concurrent words
Thinker K.F. Li <thinker@branda.to>
parents:
42
diff
changeset
|
229 MB_TIMEVAL_SET(&playing, 2, 0); |
42 | 230 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
|
231 |
47
f3818d996f4f
change interface of creating a animation action
Thinker K.F. Li <thinker@branda.to>
parents:
44
diff
changeset
|
232 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
|
233 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
|
234 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
|
235 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
|
236 act = mb_visibility_new(VIS_VISIBLE, coord3, word); |
42 | 237 |
58 | 238 /* Start playing the program. */ |
42 | 239 gettimeofday(&tv, NULL); |
240 MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); | |
241 mb_progm_start(progm, tman, &mbtv); | |
242 | |
39 | 243 handle_connection(display, tman, &rdman, w, h); |
41 | 244 |
57
ab028c9f0930
Ability to hidden shapes and action of visibility.
Thinker K.F. Li <thinker@branda.to>
parents:
56
diff
changeset
|
245 mb_progm_free(progm); |
39 | 246 mb_tman_free(tman); |
247 } | |
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
|
248 |
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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 rdman_shape_free(&rdman, text); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
13
diff
changeset
|
258 redraw_man_destroy(&rdman); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
259 mbe_destroy(tmpcr); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
260 mbe_surface_destroy(tmpsuf); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
261 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
262 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
263 void drawing(mbe_surface_t *surface, int w, int h) { |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
264 mbe_t *cr; |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
265 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
266 cr = mbe_create(surface); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
267 mbe_set_source_rgb(cr, 0, 0, 0); |
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
268 mbe_paint(cr); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
3
diff
changeset
|
269 draw_path(cr, w, h); |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
270 mbe_destroy(cr); |
3
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 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
273 int |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
274 main(int argc, char * const argv[]) { |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
275 Window root; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
276 Visual *visual; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
277 int screen; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
278 XSetWindowAttributes wattr; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
279 int depth; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
280 mbe_surface_t *surface; |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
281 int w, h; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
282 int x, y; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
283 int r; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
284 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
285 display = XOpenDisplay(":0.0"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
286 if(display == NULL) |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
287 printf("XOpenDisplay\n"); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
288 screen = DefaultScreen(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
289 root = DefaultRootWindow(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
290 visual = DefaultVisual(display, screen); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
291 depth = DefaultDepth(display, screen); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
292 wattr.override_redirect = False; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
293 x = 10; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
294 y = 10; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
295 w = 200; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
296 h = 200; |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
297 win = XCreateWindow(display, root, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
298 x, y, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
299 w, h, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
300 1, depth, InputOutput, visual, |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
301 CWOverrideRedirect, &wattr); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
302 r = XMapWindow(display, win); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
303 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
304 surface = mbe_xlib_surface_create(display, win, visual, w, h); |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 if(surface == NULL) |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
278
diff
changeset
|
306 printf("mbe_xlib_surface_create\n"); |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
307 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
308 drawing(surface, w, h); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
309 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
310 XFlush(display); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
311 sleep(10); |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
312 |
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
313 XCloseDisplay(display); |
10 | 314 return 0; |
3
164162781a7a
Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
315 } |