Mercurial > MadButterfly
comparison src/shape_rect.c @ 35:581a03196093
Support rectangle tag of SVG.
- Change rectangle in X_main to sh_rect_t.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 06 Aug 2008 02:11:53 +0800 |
parents | 07c523c799f4 |
children | 51a20f240ce3 |
comparison
equal
deleted
inserted
replaced
34:07c523c799f4 | 35:581a03196093 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
2 #include "mb_types.h" | 4 #include "mb_types.h" |
3 #include "shapes.h" | 5 #include "shapes.h" |
4 | 6 |
5 typedef struct _sh_rect { | 7 typedef struct _sh_rect { |
6 shape_t shape; | 8 shape_t shape; |
7 co_aix x, y; | 9 co_aix x, y; |
10 co_aix w, h; | |
8 co_aix rx, ry; | 11 co_aix rx, ry; |
9 co_aix d_x, d_y; | 12 co_aix poses[12][2]; |
10 co_aix d_rx, d_ry; | |
11 } sh_rect_t; | 13 } sh_rect_t; |
12 | 14 |
13 extern void sh_rect_transform(shape_t *shape) { | 15 shape_t *sh_rect_new(co_aix x, co_aix y, co_aix w, co_aix h, |
16 co_aix rx, co_aix ry) { | |
17 sh_rect_t *rect; | |
18 | |
19 rect = (sh_rect_t *)malloc(sizeof(sh_rect_t)); | |
20 if(rect == NULL) | |
21 return NULL; | |
22 | |
23 memset(rect, 0, sizeof(sh_rect_t)); | |
24 | |
25 rect->shape.sh_type = SHT_RECT; | |
26 rect->x = x; | |
27 rect->y = y; | |
28 rect->w = w; | |
29 rect->h = h; | |
30 rect->rx = rx; | |
31 rect->ry = ry; | |
32 | |
33 return (shape_t *)rect; | |
34 } | |
35 | |
36 void sh_rect_free(shape_t *shape) { | |
37 free(shape); | |
38 } | |
39 | |
40 void sh_rect_transform(shape_t *shape) { | |
14 sh_rect_t *rect = (sh_rect_t *)shape; | 41 sh_rect_t *rect = (sh_rect_t *)shape; |
42 co_aix x, y, w, h, rx, ry; | |
43 co_aix (*poses)[2]; | |
44 co_aix width; | |
45 area_t *area; | |
46 int i; | |
15 | 47 |
48 x = rect->x; | |
49 y = rect->y; | |
50 w = rect->w; | |
51 h = rect->h; | |
52 rx = rect->rx; | |
53 ry = rect->ry; | |
54 | |
55 poses = rect->poses; | |
56 | |
57 poses[0][0] = x + w - rx; | |
58 poses[0][1] = y; | |
59 poses[1][0] = x + w; | |
60 poses[1][1] = y; | |
61 poses[2][0] = x + w; | |
62 poses[2][1] = y + ry; | |
63 | |
64 poses[3][0] = x + w; | |
65 poses[3][1] = y + h - ry; | |
66 poses[4][0] = x + w; | |
67 poses[4][1] = y + h; | |
68 poses[5][0] = x + w - rx; | |
69 poses[5][1] = y + h; | |
70 | |
71 poses[6][0] = x + rx; | |
72 poses[6][1] = y + h; | |
73 poses[7][0] = x; | |
74 poses[7][1] = y + h; | |
75 poses[8][0] = x; | |
76 poses[8][1] = y + h - ry; | |
77 | |
78 poses[9][0] = x; | |
79 poses[9][1] = y + ry; | |
80 poses[10][0] = x; | |
81 poses[10][1] = y; | |
82 poses[11][0] = x + rx; | |
83 poses[11][1] = y; | |
84 | |
85 for(i = 0; i < 12; i++) | |
86 coord_trans_pos(shape->coord, &poses[i][0], &poses[i][1]); | |
87 | |
88 geo_from_positions(shape->geo, 12, poses); | |
89 | |
90 if(shape->stroke) { | |
91 area = shape->geo->cur_area; | |
92 width = shape->stroke_width; | |
93 area->x -= width / 2 + 1; | |
94 area->y -= width / 2 + 1; | |
95 area->w += width + 2; | |
96 area->h += width + 2; | |
97 } | |
16 } | 98 } |
99 | |
100 void sh_rect_draw(shape_t *shape, cairo_t *cr) { | |
101 sh_rect_t *rect = (sh_rect_t *)shape; | |
102 int i; | |
103 co_aix (*poses)[2]; | |
104 | |
105 poses = rect->poses; | |
106 cairo_move_to(cr, poses[11][0], poses[11][1]); | |
107 for(i = 0; i < 12; i += 3) { | |
108 cairo_line_to(cr, poses[i][0], poses[i][1]); | |
109 cairo_curve_to(cr, | |
110 poses[i + 1][0], poses[i + 1][1], | |
111 poses[i + 1][0], poses[i + 1][1], | |
112 poses[i + 2][0], poses[i + 2][1]); | |
113 } | |
114 cairo_close_path(cr); | |
115 } |