Changeset 2306 for libcaca/trunk/cucul/box.c
 Timestamp:
 Apr 19, 2008, 9:40:25 PM (12 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/cucul/box.c
r2303 r2306 38 38 * \return This function always returns 0. 39 39 */ 40 int cucul_draw_box(cucul_canvas_t *cv, int x1, int y1, int w, int h, 41 uint32_t ch) 42 { 43 int x2 = x1 + w  1; 44 int y2 = y1 + h  1; 45 46 cucul_draw_line(cv, x1, y1, x1, y2, ch); 47 cucul_draw_line(cv, x1, y2, x2, y2, ch); 48 cucul_draw_line(cv, x2, y2, x2, y1, ch); 49 cucul_draw_line(cv, x2, y1, x1, y1, ch); 40 int cucul_draw_box(cucul_canvas_t *cv, int x, int y, int w, int h, uint32_t ch) 41 { 42 int x2 = x + w  1; 43 int y2 = y + h  1; 44 45 cucul_draw_line(cv, x, y, x, y2, ch); 46 cucul_draw_line(cv, x, y2, x2, y2, ch); 47 cucul_draw_line(cv, x2, y2, x2, y, ch); 48 cucul_draw_line(cv, x2, y, x, y, ch); 50 49 51 50 return 0; … … 63 62 * \return This function always returns 0. 64 63 */ 65 int cucul_draw_thin_box(cucul_canvas_t *cv, int x 1, int y1, int w, int h)66 { 67 int x, y, xmax, ymax;68 69 int x2 = x 1+ w  1;70 int y2 = y 1+ h  1;71 72 if(x 1> x2)73 { 74 int tmp = x 1;75 x 1= x2; x2 = tmp;76 } 77 78 if(y 1> y2)79 { 80 int tmp = y 1;81 y 1= y2; y2 = tmp;64 int cucul_draw_thin_box(cucul_canvas_t *cv, int x, int y, int w, int h) 65 { 66 int i, j, xmax, ymax; 67 68 int x2 = x + w  1; 69 int y2 = y + h  1; 70 71 if(x > x2) 72 { 73 int tmp = x; 74 x = x2; x2 = tmp; 75 } 76 77 if(y > y2) 78 { 79 int tmp = y; 80 y = y2; y2 = tmp; 82 81 } 83 82 … … 85 84 ymax = cv>height  1; 86 85 87 if(x2 < 0  y2 < 0  x 1 > xmax  y1> ymax)86 if(x2 < 0  y2 < 0  x > xmax  y > ymax) 88 87 return 0; 89 88 90 89 /* Draw edges */ 91 if(y 1>= 0)92 for( x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)93 cucul_put_char(cv, x, y1, '');90 if(y >= 0) 91 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 92 cucul_put_char(cv, i, y, ''); 94 93 95 94 if(y2 <= ymax) 96 for( x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)97 cucul_put_char(cv, x, y2, '');98 99 if(x 1>= 0)100 for( y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)101 cucul_put_char(cv, x 1, y, '');95 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 96 cucul_put_char(cv, i, y2, ''); 97 98 if(x >= 0) 99 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 100 cucul_put_char(cv, x, j, ''); 102 101 103 102 if(x2 <= xmax) 104 for( y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)105 cucul_put_char(cv, x2, y, '');103 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 104 cucul_put_char(cv, x2, j, ''); 106 105 107 106 /* Draw corners */ 108 cucul_put_char(cv, x 1, y1, ',');109 cucul_put_char(cv, x 1, y2, '`');110 cucul_put_char(cv, x2, y 1, '.');107 cucul_put_char(cv, x, y, ','); 108 cucul_put_char(cv, x, y2, '`'); 109 cucul_put_char(cv, x2, y, '.'); 111 110 cucul_put_char(cv, x2, y2, '\''); 112 111 … … 125 124 * \return This function always returns 0. 126 125 */ 127 int cucul_draw_cp437_box(cucul_canvas_t *cv, int x 1, int y1, int w, int h)128 { 129 int x, y, xmax, ymax;130 131 int x2 = x 1+ w  1;132 int y2 = y 1+ h  1;133 134 if(x 1> x2)135 { 136 int tmp = x 1;137 x 1= x2; x2 = tmp;138 } 139 140 if(y 1> y2)141 { 142 int tmp = y 1;143 y 1= y2; y2 = tmp;126 int cucul_draw_cp437_box(cucul_canvas_t *cv, int x, int y, int w, int h) 127 { 128 int i, j, xmax, ymax; 129 130 int x2 = x + w  1; 131 int y2 = y + h  1; 132 133 if(x > x2) 134 { 135 int tmp = x; 136 x = x2; x2 = tmp; 137 } 138 139 if(y > y2) 140 { 141 int tmp = y; 142 y = y2; y2 = tmp; 144 143 } 145 144 … … 147 146 ymax = cv>height  1; 148 147 149 if(x2 < 0  y2 < 0  x 1 > xmax  y1> ymax)148 if(x2 < 0  y2 < 0  x > xmax  y > ymax) 150 149 return 0; 151 150 152 151 /* Draw edges */ 153 if(y 1>= 0)154 for( x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)155 cucul_put_char(cv, x, y1, 0x2500); /* ─ */152 if(y >= 0) 153 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 154 cucul_put_char(cv, i, y, 0x2500); /* ─ */ 156 155 157 156 if(y2 <= ymax) 158 for( x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)159 cucul_put_char(cv, x, y2, 0x2500); /* ─ */160 161 if(x 1>= 0)162 for( y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)163 cucul_put_char(cv, x 1, y, 0x2502); /* │ */157 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 158 cucul_put_char(cv, i, y2, 0x2500); /* ─ */ 159 160 if(x >= 0) 161 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 162 cucul_put_char(cv, x, j, 0x2502); /* │ */ 164 163 165 164 if(x2 <= xmax) 166 for( y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)167 cucul_put_char(cv, x2, y, 0x2502); /* │ */165 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 166 cucul_put_char(cv, x2, j, 0x2502); /* │ */ 168 167 169 168 /* Draw corners */ 170 cucul_put_char(cv, x 1, y1, 0x250c); /* ┌ */171 cucul_put_char(cv, x 1, y2, 0x2514); /* └ */172 cucul_put_char(cv, x2, y 1, 0x2510); /* ┐ */169 cucul_put_char(cv, x, y, 0x250c); /* ┌ */ 170 cucul_put_char(cv, x, y2, 0x2514); /* └ */ 171 cucul_put_char(cv, x2, y, 0x2510); /* ┐ */ 173 172 cucul_put_char(cv, x2, y2, 0x2518); /* ┘ */ 174 173 … … 188 187 * \return This function always returns 0. 189 188 */ 190 int cucul_fill_box(cucul_canvas_t *cv, int x 1, int y1, int w, int h,189 int cucul_fill_box(cucul_canvas_t *cv, int x, int y, int w, int h, 191 190 uint32_t ch) 192 191 { 193 int x, y, xmax, ymax;194 195 int x2 = x 1+ w  1;196 int y2 = y 1+ h  1;197 198 if(x 1> x2)199 { 200 int tmp = x 1;201 x 1= x2; x2 = tmp;202 } 203 204 if(y 1> y2)205 { 206 int tmp = y 1;207 y 1= y2; y2 = tmp;192 int i, j, xmax, ymax; 193 194 int x2 = x + w  1; 195 int y2 = y + h  1; 196 197 if(x > x2) 198 { 199 int tmp = x; 200 x = x2; x2 = tmp; 201 } 202 203 if(y > y2) 204 { 205 int tmp = y; 206 y = y2; y2 = tmp; 208 207 } 209 208 … … 211 210 ymax = cv>height  1; 212 211 213 if(x2 < 0  y2 < 0  x 1 > xmax  y1> ymax)212 if(x2 < 0  y2 < 0  x > xmax  y > ymax) 214 213 return 0; 215 214 216 if(x 1 < 0) x1= 0;217 if(y 1 < 0) y1= 0;215 if(x < 0) x = 0; 216 if(y < 0) y = 0; 218 217 if(x2 > xmax) x2 = xmax; 219 218 if(y2 > ymax) y2 = ymax; 220 219 221 for( y = y1; y <= y2; y++)222 for( x = x1; x <= x2; x++)223 cucul_put_char(cv, x, y, ch);224 225 return 0; 226 } 227 220 for(j = y; j <= y2; j++) 221 for(i = x; i <= x2; i++) 222 cucul_put_char(cv, i, j, ch); 223 224 return 0; 225 } 226
Note: See TracChangeset
for help on using the changeset viewer.