Changeset 3447 for libcaca/trunk
 Timestamp:
 May 14, 2009, 2:18:13 AM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/caca/box.c
r2826 r3447 26 26 #include "caca_internals.h" 27 27 28 static int draw_box(caca_canvas_t *cv, int x, int y, int w, int h, 29 uint32_t const *chars); 30 28 31 /** \brief Draw a box on the canvas using the given character. 29 32 * … … 64 67 int caca_draw_thin_box(caca_canvas_t *cv, int x, int y, int w, int h) 65 68 { 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; 81 } 82 83 xmax = cv>width  1; 84 ymax = cv>height  1; 85 86 if(x2 < 0  y2 < 0  x > xmax  y > ymax) 87 return 0; 88 89 /* Draw edges */ 90 if(y >= 0) 91 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 92 caca_put_char(cv, i, y, ''); 93 94 if(y2 <= ymax) 95 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 96 caca_put_char(cv, i, y2, ''); 97 98 if(x >= 0) 99 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 100 caca_put_char(cv, x, j, ''); 101 102 if(x2 <= xmax) 103 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 104 caca_put_char(cv, x2, j, ''); 105 106 /* Draw corners */ 107 caca_put_char(cv, x, y, ','); 108 caca_put_char(cv, x, y2, '`'); 109 caca_put_char(cv, x2, y, '.'); 110 caca_put_char(cv, x2, y2, '\''); 111 112 return 0; 69 static uint32_t const ascii_chars[] = 70 { 71 '', '', ',', '`', '.', '\'' 72 }; 73 74 return draw_box(cv, x, y, w, h, ascii_chars); 113 75 } 114 76 … … 126 88 int caca_draw_cp437_box(caca_canvas_t *cv, int x, int y, int w, int h) 127 89 { 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; 143 } 144 145 xmax = cv>width  1; 146 ymax = cv>height  1; 147 148 if(x2 < 0  y2 < 0  x > xmax  y > ymax) 149 return 0; 150 151 /* Draw edges */ 152 if(y >= 0) 153 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 154 caca_put_char(cv, i, y, 0x2500); /* ─ */ 155 156 if(y2 <= ymax) 157 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 158 caca_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 caca_put_char(cv, x, j, 0x2502); /* │ */ 163 164 if(x2 <= xmax) 165 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 166 caca_put_char(cv, x2, j, 0x2502); /* │ */ 167 168 /* Draw corners */ 169 caca_put_char(cv, x, y, 0x250c); /* ┌ */ 170 caca_put_char(cv, x, y2, 0x2514); /* └ */ 171 caca_put_char(cv, x2, y, 0x2510); /* ┐ */ 172 caca_put_char(cv, x2, y2, 0x2518); /* ┘ */ 173 174 return 0; 90 static uint32_t const cp437_chars[] = 91 { 92 /* ─ │ ┌ └ ┐ ┘ */ 93 0x2500, 0x2502, 0x250c, 0x2514, 0x2510, 0x2518 94 }; 95 96 return draw_box(cv, x, y, w, h, cp437_chars); 175 97 } 176 98 … … 221 143 for(i = x; i <= x2; i++) 222 144 caca_put_char(cv, i, j, ch); 145 146 return 0; 147 } 148 149 /* 150 * XXX: The following functions are local. 151 */ 152 153 static int draw_box(caca_canvas_t *cv, int x, int y, int w, int h, 154 uint32_t const *chars) 155 { 156 int i, j, xmax, ymax; 157 158 int x2 = x + w  1; 159 int y2 = y + h  1; 160 161 if(x > x2) 162 { 163 int tmp = x; 164 x = x2; x2 = tmp; 165 } 166 167 if(y > y2) 168 { 169 int tmp = y; 170 y = y2; y2 = tmp; 171 } 172 173 xmax = cv>width  1; 174 ymax = cv>height  1; 175 176 if(x2 < 0  y2 < 0  x > xmax  y > ymax) 177 return 0; 178 179 /* Draw edges */ 180 if(y >= 0) 181 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 182 caca_put_char(cv, i, y, chars[0]); 183 184 if(y2 <= ymax) 185 for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++) 186 caca_put_char(cv, i, y2, chars[0]); 187 188 if(x >= 0) 189 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 190 caca_put_char(cv, x, j, chars[1]); 191 192 if(x2 <= xmax) 193 for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++) 194 caca_put_char(cv, x2, j, chars[1]); 195 196 /* Draw corners */ 197 caca_put_char(cv, x, y, chars[2]); 198 caca_put_char(cv, x, y2, chars[3]); 199 caca_put_char(cv, x2, y, chars[4]); 200 caca_put_char(cv, x2, y2, chars[5]); 223 201 224 202 return 0;
Note: See TracChangeset
for help on using the changeset viewer.