Mercurial > MadButterfly
comparison src/shape_path.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 | cd6af7da32c9 |
children | bb4f651090bf |
comparison
equal
deleted
inserted
replaced
447:38aae921243f | 448:16116d84bc5e |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <ctype.h> | 3 #include <ctype.h> |
4 #include <string.h> | 4 #include <string.h> |
5 #include <cairo.h> | 5 #include "mb_graph_engine.h" |
6 #include "mb_types.h" | 6 #include "mb_types.h" |
7 #include "mb_redraw_man.h" | 7 #include "mb_redraw_man.h" |
8 | 8 |
9 /*! \brief Implement respective objects for SVG path tag. | 9 /*! \brief Implement respective objects for SVG path tag. |
10 * | 10 * |
233 #define INNER(x1, y1, x2, y2) ((x1) * (x2) + (y1) * (y2)) | 233 #define INNER(x1, y1, x2, y2) ((x1) * (x2) + (y1) * (y2)) |
234 #define CROSS(x1, y1, x2, y2) ((x1) * (y2) - (y1) * (x2)) | 234 #define CROSS(x1, y1, x2, y2) ((x1) * (y2) - (y1) * (x2)) |
235 | 235 |
236 /*! \brief Make path for arcs in a path. | 236 /*! \brief Make path for arcs in a path. |
237 */ | 237 */ |
238 void sh_path_arc_path(cairo_t *cr, const co_aix **args_p, | 238 void sh_path_arc_path(mbe_t *cr, const co_aix **args_p, |
239 const int **fix_args_p) { | 239 const int **fix_args_p) { |
240 co_aix cx, cy, x0, y0, x, y, xx, xy; | 240 co_aix cx, cy, x0, y0, x, y, xx, xy; |
241 co_aix dx, dy, dx0, dy0, dxx, dxy; | 241 co_aix dx, dy, dx0, dy0, dxx, dxy; |
242 co_aix xyratio; | 242 co_aix xyratio; |
243 co_aix rx; | 243 co_aix rx; |
293 if(cross < 0) | 293 if(cross < 0) |
294 angle = PI * 2 - angle; /* 3rd, 4th Quadrant */ | 294 angle = PI * 2 - angle; /* 3rd, 4th Quadrant */ |
295 | 295 |
296 /* Make a path for arc */ | 296 /* Make a path for arc */ |
297 rotate = acos(dxx / rx); | 297 rotate = acos(dxx / rx); |
298 cairo_save(cr); | 298 mbe_save(cr); |
299 cairo_translate(cr, cx, cy); | 299 mbe_translate(cr, cx, cy); |
300 cairo_rotate(cr, rotate); | 300 mbe_rotate(cr, rotate); |
301 cairo_scale(cr, 1.0, xyratio); | 301 mbe_scale(cr, 1.0, xyratio); |
302 if(sweep) | 302 if(sweep) |
303 cairo_arc(cr, 0, 0, rx, angle0, angle); | 303 mbe_arc(cr, 0, 0, rx, angle0, angle); |
304 else | 304 else |
305 cairo_arc_negative(cr, 0, 0, rx, angle0, angle); | 305 mbe_arc_negative(cr, 0, 0, rx, angle0, angle); |
306 cairo_restore(cr); | 306 mbe_restore(cr); |
307 | 307 |
308 *args_p = args; | 308 *args_p = args; |
309 *fix_args_p = fix_args; | 309 *fix_args_p = fix_args; |
310 } | 310 } |
311 | 311 |
793 area->w += shape->stroke_width + 1; | 793 area->w += shape->stroke_width + 1; |
794 area->h += shape->stroke_width + 1; | 794 area->h += shape->stroke_width + 1; |
795 } | 795 } |
796 } | 796 } |
797 | 797 |
798 static void sh_path_path(shape_t *shape, cairo_t *cr) { | 798 static void sh_path_path(shape_t *shape, mbe_t *cr) { |
799 sh_path_t *path; | 799 sh_path_t *path; |
800 int cmd_len; | 800 int cmd_len; |
801 char *cmds, cmd; | 801 char *cmds, cmd; |
802 const co_aix *args; | 802 const co_aix *args; |
803 const int *fix_args; | 803 const int *fix_args; |
819 cmd = *cmds++; | 819 cmd = *cmds++; |
820 switch(cmd) { | 820 switch(cmd) { |
821 case 'M': | 821 case 'M': |
822 x = *args++; | 822 x = *args++; |
823 y = *args++; | 823 y = *args++; |
824 cairo_move_to(cr, x, y); | 824 mbe_move_to(cr, x, y); |
825 break; | 825 break; |
826 case 'L': | 826 case 'L': |
827 x = *args++; | 827 x = *args++; |
828 y = *args++; | 828 y = *args++; |
829 cairo_line_to(cr, x, y); | 829 mbe_line_to(cr, x, y); |
830 break; | 830 break; |
831 case 'C': | 831 case 'C': |
832 x1 = *args++; | 832 x1 = *args++; |
833 y1 = *args++; | 833 y1 = *args++; |
834 x2 = *args++; | 834 x2 = *args++; |
835 y2 = *args++; | 835 y2 = *args++; |
836 x = *args++; | 836 x = *args++; |
837 y = *args++; | 837 y = *args++; |
838 cairo_curve_to(cr, x1, y1, x2, y2, x, y); | 838 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
839 break; | 839 break; |
840 case 'S': | 840 case 'S': |
841 x1 = x + x - x2; | 841 x1 = x + x - x2; |
842 y1 = y + y - y2; | 842 y1 = y + y - y2; |
843 x2 = *args++; | 843 x2 = *args++; |
844 y2 = *args++; | 844 y2 = *args++; |
845 x = *args++; | 845 x = *args++; |
846 y = *args++; | 846 y = *args++; |
847 cairo_curve_to(cr, x1, y1, x2, y2, x, y); | 847 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
848 break; | 848 break; |
849 case 'Q': | 849 case 'Q': |
850 x1 = *args++; | 850 x1 = *args++; |
851 y1 = *args++; | 851 y1 = *args++; |
852 x2 = x1; | 852 x2 = x1; |
853 y2 = y1; | 853 y2 = y1; |
854 x = *args++; | 854 x = *args++; |
855 y = *args++; | 855 y = *args++; |
856 cairo_curve_to(cr, x1, y1, x2, y2, x, y); | 856 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
857 break; | 857 break; |
858 case 'T': | 858 case 'T': |
859 x1 = x + x - x2; | 859 x1 = x + x - x2; |
860 y1 = y + y - y2; | 860 y1 = y + y - y2; |
861 x2 = x1; | 861 x2 = x1; |
862 y2 = y1; | 862 y2 = y1; |
863 x = *args++; | 863 x = *args++; |
864 y = *args++; | 864 y = *args++; |
865 cairo_curve_to(cr, x1, y1, x2, y2, x, y); | 865 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
866 break; | 866 break; |
867 case 'A': | 867 case 'A': |
868 sh_path_arc_path(cr, &args, &fix_args); | 868 sh_path_arc_path(cr, &args, &fix_args); |
869 break; | 869 break; |
870 case 'Z': | 870 case 'Z': |
871 cairo_close_path(cr); | 871 mbe_close_path(cr); |
872 break; | 872 break; |
873 case '\x0': | 873 case '\x0': |
874 i = cmd_len; /* padding! Skip remain ones. */ | 874 i = cmd_len; /* padding! Skip remain ones. */ |
875 break; | 875 break; |
876 } | 876 } |
877 } | 877 } |
878 } | 878 } |
879 | 879 |
880 void sh_path_draw(shape_t *shape, cairo_t *cr) { | 880 void sh_path_draw(shape_t *shape, mbe_t *cr) { |
881 sh_path_path(shape, cr); | 881 sh_path_path(shape, cr); |
882 } | 882 } |
883 | 883 |
884 #ifdef UNITTEST | 884 #ifdef UNITTEST |
885 | 885 |