- Timestamp:
- Oct 31, 2006, 9:17:58 AM (16 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/colour.c
r1258 r1266 38 38 * or created using cucul_ansi_to_attr() and cucul_argb_to_attr(), optionally 39 39 * ORed with style values such as CUCUL_UNDERLINE or CUCUL_BLINK. 40 * 41 * Only changing the style does not affect the current colour value. 40 42 * 41 43 * If an error occurs, -1 is returned and \b errno is set accordingly: … … 56 58 } 57 59 60 if(attr < 0x00000010) 61 attr = (cv->curattr & 0xfffffff0) | attr; 62 58 63 cv->curattr = attr; 59 64 60 65 return 0; 61 }62 63 /** \brief Set the default colour pair and text style (ANSI version).64 *65 * Set the default ANSI colour pair and text style for drawing. String66 * functions such as caca_printf() and graphical primitive functions such as67 * caca_draw_line() will use these attributes.68 *69 * Color values are those defined in cucul.h, such as CUCUL_RED70 * or CUCUL_TRANSPARENT.71 *72 * Style values are those defined in cucul.h, such as CUCUL_UNDERLINE73 * or CUCUL_BLINK. The values can be ORed to set several styles at74 * the same time.75 *76 * If an error occurs, 0 is returned and \b errno is set accordingly:77 * - \c EINVAL The colour values and/or the style mask are invalid.78 *79 * \param cv A handle to the libcucul canvas.80 * \param fg The requested foreground colour.81 * \param bg The requested background colour.82 * \param style The requested text styles.83 * \return 0 in case of success, -1 if an error occurred.84 */85 unsigned long int cucul_ansi_to_attr(unsigned char fg, unsigned char bg)86 {87 if(fg > 0x20 || bg > 0x20)88 {89 #if defined(HAVE_ERRNO_H)90 errno = EINVAL;91 #endif92 return 0;93 }94 95 return ((unsigned long int)bg << 18) | ((unsigned long int)fg << 4);96 }97 98 /* Legacy function for old programs */99 int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)100 {101 return cucul_set_attr(cv, cucul_ansi_to_attr(fg, bg));102 }103 104 /** \brief Set the default colour pair and text style (truecolor version).105 *106 * Set the default colour pair and text style for drawing. String107 * functions such as caca_printf() and graphical primitive functions such as108 * caca_draw_line() will use these attributes.109 *110 * Colors are 16-bit ARGB values, each component being coded on 4 bits. For111 * instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is112 * white with 50% alpha (A=8 R=15 G=15 B=15).113 *114 * If an error occurs, 0 is returned and \b errno is set accordingly:115 * - \c EINVAL At least one of the colour values is invalid.116 *117 * \param cv A handle to the libcucul canvas.118 * \param fg The requested foreground colour.119 * \param bg The requested background colour.120 * \param style The requested text styles.121 * \return 0 in case of success, -1 if an error occurred.122 */123 unsigned long int cucul_argb_to_attr(unsigned int fg, unsigned int bg)124 {125 if(fg > 0xffff || bg > 0xffff)126 {127 #if defined(HAVE_ERRNO_H)128 errno = EINVAL;129 #endif130 return -1;131 }132 133 if(fg < 0x100)134 fg += 0x100;135 136 if(bg < 0x100)137 bg += 0x100;138 139 fg = ((fg >> 1) & 0x7ff) | ((fg >> 13) << 11);140 bg = ((bg >> 1) & 0x7ff) | ((bg >> 13) << 11);141 142 return ((unsigned long int)bg << 18) | ((unsigned long int)fg << 4);143 }144 145 /* Legacy function for old programs */146 int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)147 {148 return cucul_set_attr(cv, cucul_argb_to_attr(fg, bg));149 66 } 150 67 … … 182 99 } 183 100 101 /** \brief Set the default colour pair and text style (ANSI version). 102 * 103 * Set the default ANSI colour pair and text style for drawing. String 104 * functions such as caca_printf() and graphical primitive functions such as 105 * caca_draw_line() will use these attributes. 106 * 107 * Color values are those defined in cucul.h, such as CUCUL_RED 108 * or CUCUL_TRANSPARENT. 109 * 110 * Style values are those defined in cucul.h, such as CUCUL_UNDERLINE 111 * or CUCUL_BLINK. The values can be ORed to set several styles at 112 * the same time. 113 * 114 * If an error occurs, 0 is returned and \b errno is set accordingly: 115 * - \c EINVAL The colour values and/or the style mask are invalid. 116 * 117 * \param cv A handle to the libcucul canvas. 118 * \param fg The requested foreground colour. 119 * \param bg The requested background colour. 120 * \param style The requested text styles. 121 * \return 0 in case of success, -1 if an error occurred. 122 */ 123 unsigned long int cucul_ansi_to_attr(unsigned char fg, unsigned char bg) 124 { 125 if(fg > 0x20 || bg > 0x20) 126 { 127 #if defined(HAVE_ERRNO_H) 128 errno = EINVAL; 129 #endif 130 return 0; 131 } 132 133 fg |= 0x40; 134 bg |= 0x40; 135 136 return ((unsigned long int)bg << 18) | ((unsigned long int)fg << 4); 137 } 138 139 /* Legacy function for old programs */ 140 int cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg) 141 { 142 return cucul_set_attr(cv, cucul_ansi_to_attr(fg, bg)); 143 } 144 145 /** \brief Set the default colour pair and text style (truecolor version). 146 * 147 * Set the default colour pair and text style for drawing. String 148 * functions such as caca_printf() and graphical primitive functions such as 149 * caca_draw_line() will use these attributes. 150 * 151 * Colors are 16-bit ARGB values, each component being coded on 4 bits. For 152 * instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is 153 * white with 50% alpha (A=8 R=15 G=15 B=15). 154 * 155 * If an error occurs, 0 is returned and \b errno is set accordingly: 156 * - \c EINVAL At least one of the colour values is invalid. 157 * 158 * \param cv A handle to the libcucul canvas. 159 * \param fg The requested foreground colour. 160 * \param bg The requested background colour. 161 * \param style The requested text styles. 162 * \return 0 in case of success, -1 if an error occurred. 163 */ 164 unsigned long int cucul_argb_to_attr(unsigned int fg, unsigned int bg) 165 { 166 if(fg > 0xffff || bg > 0xffff) 167 { 168 #if defined(HAVE_ERRNO_H) 169 errno = EINVAL; 170 #endif 171 return -1; 172 } 173 174 if(fg < 0x100) 175 fg += 0x100; 176 177 if(bg < 0x100) 178 bg += 0x100; 179 180 fg = ((fg >> 1) & 0x7ff) | ((fg >> 13) << 11); 181 bg = ((bg >> 1) & 0x7ff) | ((bg >> 13) << 11); 182 183 return ((unsigned long int)bg << 18) | ((unsigned long int)fg << 4); 184 } 185 186 /* Legacy function for old programs */ 187 int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg) 188 { 189 return cucul_set_attr(cv, cucul_argb_to_attr(fg, bg)); 190 } 191 184 192 /* 185 193 * XXX: the following functions are local … … 206 214 unsigned int i, best, dist; 207 215 208 if(argb14 < 0x00 10)209 return argb14 ;210 211 if(argb14 == CUCUL_DEFAULT || argb14 == CUCUL_TRANSPARENT)216 if(argb14 < 0x0050) 217 return argb14 ^ 0x40; 218 219 if(argb14 == (CUCUL_DEFAULT | 0x40) || argb14 == (CUCUL_TRANSPARENT | 0x40)) 212 220 return def; 213 221 … … 267 275 uint16_t fg = (attr >> 4) & 0x3fff; 268 276 269 if(fg < 0x00 10)270 return ansitab16[fg ] & 0x0fff;271 272 if(fg == CUCUL_DEFAULT)277 if(fg < 0x0050) 278 return ansitab16[fg ^ 0x40] & 0x0fff; 279 280 if(fg == (CUCUL_DEFAULT | 0x40)) 273 281 return ansitab16[CUCUL_LIGHTGRAY] & 0x0fff; 274 282 275 if(fg == CUCUL_TRANSPARENT)283 if(fg == (CUCUL_TRANSPARENT | 0x40)) 276 284 return ansitab16[CUCUL_LIGHTGRAY] & 0x0fff; 277 285 … … 283 291 uint16_t bg = attr >> 18; 284 292 285 if(bg < 0x00 10)286 return ansitab16[bg ] & 0x0fff;287 288 if(bg == CUCUL_DEFAULT)293 if(bg < 0x0050) 294 return ansitab16[bg ^ 0x40] & 0x0fff; 295 296 if(bg == (CUCUL_DEFAULT | 0x40)) 289 297 return ansitab16[CUCUL_BLACK] & 0x0fff; 290 298 291 if(bg == CUCUL_TRANSPARENT)299 if(bg == (CUCUL_TRANSPARENT | 0x40)) 292 300 return ansitab16[CUCUL_BLACK] & 0x0fff; 293 301 … … 315 323 uint16_t bg = attr >> 18; 316 324 317 if(bg < 0x00 10)318 bg = ansitab16[bg ];319 else if(bg == CUCUL_DEFAULT)325 if(bg < 0x0050) 326 bg = ansitab16[bg ^ 0x40]; 327 else if(bg == (CUCUL_DEFAULT | 0x40)) 320 328 bg = ansitab16[CUCUL_BLACK]; 321 else if(bg == CUCUL_TRANSPARENT)329 else if(bg == (CUCUL_TRANSPARENT | 0x40)) 322 330 bg = 0x0fff; 323 331 else … … 329 337 argb[3] = bg & 0xf; 330 338 331 if(fg < 0x00 10)332 fg = ansitab16[fg ];333 else if(fg == CUCUL_DEFAULT)339 if(fg < 0x0050) 340 fg = ansitab16[fg ^ 0x40]; 341 else if(fg == (CUCUL_DEFAULT | 0x40)) 334 342 fg = ansitab16[CUCUL_LIGHTGRAY]; 335 else if(fg == CUCUL_TRANSPARENT)343 else if(fg == (CUCUL_TRANSPARENT | 0x40)) 336 344 fg = 0x0fff; 337 345 else -
libcaca/trunk/cucul/export.c
r1264 r1266 231 231 continue; 232 232 233 fg = (((attr >> 4) & 0x3fff) == CUCUL_DEFAULT) ?233 fg = (((attr >> 4) & 0x3fff) == (CUCUL_DEFAULT | 0x40)) ? 234 234 0x10 : palette[_cucul_attr_to_ansi4fg(attr)]; 235 bg = (((attr >> 18) & 0x3fff) == CUCUL_TRANSPARENT) ?235 bg = (((attr >> 18) & 0x3fff) == (CUCUL_TRANSPARENT | 0x40)) ? 236 236 0x10 : palette[_cucul_attr_to_ansi4bg(attr)]; 237 237 … … 567 567 continue; 568 568 569 if(((attr >> 4) & 0x3fff) == CUCUL_DEFAULT)569 if(((attr >> 4) & 0x3fff) == (CUCUL_DEFAULT | 0x40)) 570 570 fg = 0x10; 571 571 572 if(((attr >> 18) & 0x3fff) == CUCUL_TRANSPARENT)572 if(((attr >> 18) & 0x3fff) == (CUCUL_TRANSPARENT | 0x40)) 573 573 bg = 0x10; 574 574 -
libcaca/trunk/test/colors.c
r1263 r1266 53 53 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK)); 54 54 cucul_putstr(cv, 3, 20, "This is bold This is blink This is italics This is underline"); 55 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK) |CUCUL_BOLD);55 cucul_set_attr(cv, CUCUL_BOLD); 56 56 cucul_putstr(cv, 3 + 8, 20, "bold"); 57 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK) |CUCUL_BLINK);57 cucul_set_attr(cv, CUCUL_BLINK); 58 58 cucul_putstr(cv, 3 + 24, 20, "blink"); 59 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK) |CUCUL_ITALICS);59 cucul_set_attr(cv, CUCUL_ITALICS); 60 60 cucul_putstr(cv, 3 + 41, 20, "italics"); 61 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_LIGHTGRAY, CUCUL_BLACK) |CUCUL_UNDERLINE);61 cucul_set_attr(cv, CUCUL_UNDERLINE); 62 62 cucul_putstr(cv, 3 + 60, 20, "underline"); 63 63 -
libcaca/trunk/test/export.c
r1263 r1266 127 127 cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); 128 128 129 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_WHITE) 130 | CUCUL_BOLD); 129 cucul_set_attr(cv, CUCUL_BOLD); 131 130 cucul_putstr(cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold"); 132 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_WHITE) 133 | CUCUL_BLINK); 131 cucul_set_attr(cv, CUCUL_BLINK); 134 132 cucul_putstr(cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink"); 135 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_WHITE) 136 | CUCUL_ITALICS); 133 cucul_set_attr(cv, CUCUL_ITALICS); 137 134 cucul_putstr(cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics"); 138 cucul_set_attr(cv, cucul_ansi_to_attr(CUCUL_BLACK, CUCUL_WHITE) 139 | CUCUL_UNDERLINE); 135 cucul_set_attr(cv, CUCUL_UNDERLINE); 140 136 cucul_putstr(cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline"); 141 137
Note: See TracChangeset
for help on using the changeset viewer.