comparison src/X_main.c @ 448:16116d84bc5e

Replace Cairo with a abstract layer mb_graph_engine. mb_graph_engine is a layer to separate MadButterfly from Cairo. It is only a set of macro mapping to cairo implementation, now. But, it provides a oppotunities to replace cairo with other engines; likes skia.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 04 Aug 2009 23:35:41 +0800
parents a90fd749af82
children a417fd980228
comparison
equal deleted inserted replaced
447:38aae921243f 448:16116d84bc5e
2 #include <unistd.h> 2 #include <unistd.h>
3 #include <sys/time.h> 3 #include <sys/time.h>
4 #include <sys/select.h> 4 #include <sys/select.h>
5 #include <X11/Xlib.h> 5 #include <X11/Xlib.h>
6 #include <X11/Xutil.h> 6 #include <X11/Xutil.h>
7 #include <cairo.h> 7 #include "mb_graph_engine.h"
8 #include <cairo-xlib.h> 8 #include <cairo-xlib.h>
9 #include <pango/pangocairo.h> 9 #include <pango/pangocairo.h>
10 10
11 #include <string.h> 11 #include <string.h>
12 #include "mb_shapes.h" 12 #include "mb_shapes.h"
118 event_interaction(display, rdman, w, h); 118 event_interaction(display, rdman, w, h);
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 void draw_path(cairo_t *cr, int w, int h) { 123 void draw_path(mbe_t *cr, int w, int h) {
124 cairo_t *tmpcr; 124 mbe_t *tmpcr;
125 cairo_surface_t *tmpsuf; 125 mbe_surface_t *tmpsuf;
126 redraw_man_t rdman; 126 redraw_man_t rdman;
127 shape_t *path1, *path2, *rect; 127 shape_t *path1, *path2, *rect;
128 coord_t *coord1, *coord2, *coord3; 128 coord_t *coord1, *coord2, *coord3;
129 paint_t *fill1, *fill2, *fill3; 129 paint_t *fill1, *fill2, *fill3;
130 paint_t *text_fill; 130 paint_t *text_fill;
131 grad_stop_t text_stops[2]; 131 grad_stop_t text_stops[2];
132 paint_t *stroke, *text_stroke; 132 paint_t *stroke, *text_stroke;
133 shape_t *text; 133 shape_t *text;
134 grad_stop_t fill3_stops[3]; 134 grad_stop_t fill3_stops[3];
135 cairo_font_face_t *face; 135 mbe_font_face_t *face;
136 struct timeval tv; 136 struct timeval tv;
137 mb_tman_t *tman; 137 mb_tman_t *tman;
138 mb_timeval_t mbtv, start, playing; 138 mb_timeval_t mbtv, start, playing;
139 mb_progm_t *progm; 139 mb_progm_t *progm;
140 mb_word_t *word; 140 mb_word_t *word;
141 mb_action_t *act; 141 mb_action_t *act;
142 PangoAttrList *attrs = pango_attr_list_new(); 142 PangoAttrList *attrs = pango_attr_list_new();
143 143
144 tmpsuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); 144 tmpsuf = mbe_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
145 tmpcr = cairo_create(tmpsuf); 145 tmpcr = mbe_create(tmpsuf);
146 146
147 cairo_set_source_surface(cr, tmpsuf, 0, 0); 147 mbe_set_source_surface(cr, tmpsuf, 0, 0);
148 redraw_man_init(&rdman, tmpcr, cr); 148 redraw_man_init(&rdman, tmpcr, cr);
149 coord1 = rdman_coord_new(&rdman, rdman.root_coord); 149 coord1 = rdman_coord_new(&rdman, rdman.root_coord);
150 coord2 = rdman_coord_new(&rdman, rdman.root_coord); 150 coord2 = rdman_coord_new(&rdman, rdman.root_coord);
151 coord3 = rdman_coord_new(&rdman, rdman.root_coord); 151 coord3 = rdman_coord_new(&rdman, rdman.root_coord);
152 152
153 fill1 = rdman_paint_color_new(&rdman, 1, 1, 0, 0.5); 153 fill1 = rdman_paint_color_new(&rdman, 1, 1, 0, 0.5);
154 fill2 = rdman_paint_color_new(&rdman, 0, 1, 1, 0.5); 154 fill2 = rdman_paint_color_new(&rdman, 0, 1, 1, 0.5);
155 stroke = rdman_paint_color_new(&rdman, 0.4, 0.4, 0.4, 1); 155 stroke = rdman_paint_color_new(&rdman, 0.4, 0.4, 0.4, 1);
156 text_stroke = rdman_paint_color_new(&rdman, 0.5, 0.5, 0.5, 1); 156 text_stroke = rdman_paint_color_new(&rdman, 0.5, 0.5, 0.5, 1);
157 157
158 face = cairo_get_font_face(tmpcr); 158 face = mbe_get_font_face(tmpcr);
159 text = rdman_shape_text_new(&rdman, "hello \xe6\xbc\xa2\xe5\xad\x97", 159 text = rdman_shape_text_new(&rdman, "hello \xe6\xbc\xa2\xe5\xad\x97",
160 10, h / 4, 36.0, face, attrs); 160 10, h / 4, 36.0, face, attrs);
161 text_fill = rdman_paint_radial_new(&rdman, 100, h / 4, 70); 161 text_fill = rdman_paint_radial_new(&rdman, 100, h / 4, 70);
162 grad_stop_init(text_stops, 0, 0.2, 0.9, 0.2, 1); 162 grad_stop_init(text_stops, 0, 0.2, 0.9, 0.2, 1);
163 grad_stop_init(text_stops + 1, 1, 0.9, 0.2, 0.2, 0.1); 163 grad_stop_init(text_stops + 1, 1, 0.9, 0.2, 0.2, 0.1);
253 rdman_shape_free(&rdman, path1); 253 rdman_shape_free(&rdman, path1);
254 rdman_shape_free(&rdman, path2); 254 rdman_shape_free(&rdman, path2);
255 rdman_shape_free(&rdman, rect); 255 rdman_shape_free(&rdman, rect);
256 rdman_shape_free(&rdman, text); 256 rdman_shape_free(&rdman, text);
257 redraw_man_destroy(&rdman); 257 redraw_man_destroy(&rdman);
258 cairo_destroy(tmpcr); 258 mbe_destroy(tmpcr);
259 cairo_surface_destroy(tmpsuf); 259 mbe_surface_destroy(tmpsuf);
260 } 260 }
261 261
262 void drawing(cairo_surface_t *surface, int w, int h) { 262 void drawing(mbe_surface_t *surface, int w, int h) {
263 cairo_t *cr; 263 mbe_t *cr;
264 264
265 cr = cairo_create(surface); 265 cr = mbe_create(surface);
266 cairo_set_source_rgb(cr, 0, 0, 0); 266 mbe_set_source_rgb(cr, 0, 0, 0);
267 cairo_paint(cr); 267 mbe_paint(cr);
268 draw_path(cr, w, h); 268 draw_path(cr, w, h);
269 cairo_destroy(cr); 269 mbe_destroy(cr);
270 } 270 }
271 271
272 int 272 int
273 main(int argc, char * const argv[]) { 273 main(int argc, char * const argv[]) {
274 Window root; 274 Window root;
275 Visual *visual; 275 Visual *visual;
276 int screen; 276 int screen;
277 XSetWindowAttributes wattr; 277 XSetWindowAttributes wattr;
278 int depth; 278 int depth;
279 cairo_surface_t *surface; 279 mbe_surface_t *surface;
280 int w, h; 280 int w, h;
281 int x, y; 281 int x, y;
282 int r; 282 int r;
283 283
284 display = XOpenDisplay(":0.0"); 284 display = XOpenDisplay(":0.0");
298 w, h, 298 w, h,
299 1, depth, InputOutput, visual, 299 1, depth, InputOutput, visual,
300 CWOverrideRedirect, &wattr); 300 CWOverrideRedirect, &wattr);
301 r = XMapWindow(display, win); 301 r = XMapWindow(display, win);
302 302
303 surface = cairo_xlib_surface_create(display, win, visual, w, h); 303 surface = mbe_xlib_surface_create(display, win, visual, w, h);
304 if(surface == NULL) 304 if(surface == NULL)
305 printf("cairo_xlib_surface_create\n"); 305 printf("mbe_xlib_surface_create\n");
306 306
307 drawing(surface, w, h); 307 drawing(surface, w, h);
308 308
309 XFlush(display); 309 XFlush(display);
310 sleep(10); 310 sleep(10);