Mercurial > MadButterfly
comparison src/shape_rect.c @ 36:51a20f240ce3
short-cut for no-rounded rectangle
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 06 Aug 2008 02:20:28 +0800 |
parents | 581a03196093 |
children | e292beec12d4 |
comparison
equal
deleted
inserted
replaced
35:581a03196093 | 36:51a20f240ce3 |
---|---|
52 rx = rect->rx; | 52 rx = rect->rx; |
53 ry = rect->ry; | 53 ry = rect->ry; |
54 | 54 |
55 poses = rect->poses; | 55 poses = rect->poses; |
56 | 56 |
57 poses[0][0] = x + w - rx; | 57 if(rect->rx != 0 && rect->ry != 0) { |
58 poses[0][1] = y; | 58 poses[0][0] = x + w - rx; |
59 poses[1][0] = x + w; | 59 poses[0][1] = y; |
60 poses[1][1] = y; | 60 poses[1][0] = x + w; |
61 poses[2][0] = x + w; | 61 poses[1][1] = y; |
62 poses[2][1] = y + ry; | 62 poses[2][0] = x + w; |
63 poses[2][1] = y + ry; | |
64 | |
65 poses[3][0] = x + w; | |
66 poses[3][1] = y + h - ry; | |
67 poses[4][0] = x + w; | |
68 poses[4][1] = y + h; | |
69 poses[5][0] = x + w - rx; | |
70 poses[5][1] = y + h; | |
71 | |
72 poses[6][0] = x + rx; | |
73 poses[6][1] = y + h; | |
74 poses[7][0] = x; | |
75 poses[7][1] = y + h; | |
76 poses[8][0] = x; | |
77 poses[8][1] = y + h - ry; | |
78 | |
79 poses[9][0] = x; | |
80 poses[9][1] = y + ry; | |
81 poses[10][0] = x; | |
82 poses[10][1] = y; | |
83 poses[11][0] = x + rx; | |
84 poses[11][1] = y; | |
63 | 85 |
64 poses[3][0] = x + w; | 86 for(i = 0; i < 12; i++) |
65 poses[3][1] = y + h - ry; | 87 coord_trans_pos(shape->coord, &poses[i][0], &poses[i][1]); |
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 | 88 |
71 poses[6][0] = x + rx; | 89 geo_from_positions(shape->geo, 12, poses); |
72 poses[6][1] = y + h; | 90 } else { |
73 poses[7][0] = x; | 91 poses[0][0] = x; |
74 poses[7][1] = y + h; | 92 poses[0][1] = y; |
75 poses[8][0] = x; | 93 poses[1][0] = x + w; |
76 poses[8][1] = y + h - ry; | 94 poses[1][1] = y; |
95 poses[2][0] = x + w; | |
96 poses[2][1] = y + h; | |
97 poses[3][0] = x; | |
98 poses[3][1] = y + h; | |
77 | 99 |
78 poses[9][0] = x; | 100 for(i = 0; i < 4; i++) |
79 poses[9][1] = y + ry; | 101 coord_trans_pos(shape->coord, &poses[i][0], &poses[i][1]); |
80 poses[10][0] = x; | |
81 poses[10][1] = y; | |
82 poses[11][0] = x + rx; | |
83 poses[11][1] = y; | |
84 | 102 |
85 for(i = 0; i < 12; i++) | 103 geo_from_positions(shape->geo, 4, poses); |
86 coord_trans_pos(shape->coord, &poses[i][0], &poses[i][1]); | 104 } |
87 | |
88 geo_from_positions(shape->geo, 12, poses); | |
89 | 105 |
90 if(shape->stroke) { | 106 if(shape->stroke) { |
91 area = shape->geo->cur_area; | 107 area = shape->geo->cur_area; |
92 width = shape->stroke_width; | 108 width = shape->stroke_width; |
93 area->x -= width / 2 + 1; | 109 area->x -= width / 2 + 1; |
101 sh_rect_t *rect = (sh_rect_t *)shape; | 117 sh_rect_t *rect = (sh_rect_t *)shape; |
102 int i; | 118 int i; |
103 co_aix (*poses)[2]; | 119 co_aix (*poses)[2]; |
104 | 120 |
105 poses = rect->poses; | 121 poses = rect->poses; |
106 cairo_move_to(cr, poses[11][0], poses[11][1]); | 122 if(rect->rx != 0 && rect->ry != 0) { |
107 for(i = 0; i < 12; i += 3) { | 123 cairo_move_to(cr, poses[11][0], poses[11][1]); |
108 cairo_line_to(cr, poses[i][0], poses[i][1]); | 124 for(i = 0; i < 12; i += 3) { |
109 cairo_curve_to(cr, | 125 cairo_line_to(cr, poses[i][0], poses[i][1]); |
110 poses[i + 1][0], poses[i + 1][1], | 126 cairo_curve_to(cr, |
111 poses[i + 1][0], poses[i + 1][1], | 127 poses[i + 1][0], poses[i + 1][1], |
112 poses[i + 2][0], poses[i + 2][1]); | 128 poses[i + 1][0], poses[i + 1][1], |
129 poses[i + 2][0], poses[i + 2][1]); | |
130 } | |
131 } else { | |
132 cairo_move_to(cr, poses[3][0], poses[3][1]); | |
133 for(i = 0; i < 4; i++) | |
134 cairo_line_to(cr, poses[i][0], poses[i][1]); | |
113 } | 135 } |
114 cairo_close_path(cr); | |
115 } | 136 } |