Changeset 226
- Timestamp:
- Nov 27, 2003, 10:56:30 PM (19 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/NOTES
r225 r226 4 4 many terminal emulators and tried to summarise which combinations 5 5 worked properly and which ones did not. 6 7 From termcap(5): 8 9 set_a_background setab AB Set background 10 color to #1, using 11 ANSI escape 12 set_a_foreground setaf AF Set foreground 13 color to #1, using 14 ANSI escape 15 From the xterm terminfo: 16 17 setab=\E[4%p1%dm, setaf=\E[3%p1%dm 18 19 From the xterm-16color terminfo: 20 21 setab=\E[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm, 22 setaf=\E[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm, 23 24 (http://www.sct.gu.edu.au/~anthony/info/X/Xterm_xf86.terminfo) 6 25 7 26 o I tested the following terminals: … … 21 40 22 41 o In most terminals, \e[3xm and \[4xm respectively set the foreground 23 and background colours. x is a ncolour between 0 and 7 or the value24 9 for default value.42 and background colours. x is a colour between 0 and 7 or the value 43 9 for default colour (may be transparent). 25 44 26 45 \e[0m sets everything to normal, \e[1m sets bold, \e[5m sets blink … … 36 55 for blink in '' '\e[5m'; do 37 56 for bold in '' '\e[1m'; do 38 echo -ne "$bold$blink$invert"'\e[3 4m\e[43m'hop'\e[0m '57 echo -ne "$bold$blink$invert"'\e[33m\e[44m'hop'\e[0m ' 39 58 echo "($bold$blink$invert)" 40 59 done … … 49 68 50 69 Almost works on: 51 + xterm (bright bg works for blue, but not for red or yellow) 70 + xterm (bright bg only works when fg is bright and then inverted, 71 but then fg is not bright) 52 72 53 73 Fails on: … … 75 95 + pterm 76 96 77 Failed (\e[9x and \e[10x don't work) on:97 Failed (\e[9x and \e[10x don't do anything) on: 78 98 + Eterm 79 99 + aterm, wterm, rxvt 80 100 + mlterm 81 + linux 101 + Linux console 102 103 o How to draw bright colours on any terminal? 104 105 '\e[93;104m' -> bright yellow on bright blue 106 doesn't work on mlterm, gnome-terminal, konsole 107 108 '\e[5;1;33;44m' -> bright yellow on bright blue 109 doesn't work on mlterm, aterm/wterm/rxvt, Eterm, console 110 111 '\e[5;1;33;44;93;104m' -> bright yellow on bright blue 112 works on gnome-terminal, xterm, pterm, aterm/wterm/rxvt, console 113 doesn't work on konsole 82 114 83 115 o S-Lang: -
libcaca/trunk/examples/demo.c
r217 r226 63 63 if(!sprite) 64 64 sprite = caca_load_sprite("examples/caca.txt"); 65 if(!sprite)66 return 1;67 65 68 66 /* Main menu */ … … 133 131 case 's': 134 132 case 'S': 135 demo = demo_sprites; 133 if(sprite) 134 demo = demo_sprites; 136 135 break; 137 136 } 138 139 if(demo)140 caca_clear();141 137 142 138 handle_event: … … 148 144 149 145 caca_refresh(); 146 147 if(demo) 148 caca_clear(); 150 149 } 151 150 else if(event & CACA_EVENT_MOUSE_CLICK) 152 151 { 153 152 display_menu(); 154 caca_set_color(CACA_COLOR_RED );153 caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK); 155 154 caca_putstr((event & 0xff00) >> 8, event & 0xff, "|\\"); 156 155 caca_refresh(); … … 161 160 demo(); 162 161 163 caca_set_color(CACA_COLOR_ WHITE);162 caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); 164 163 caca_draw_thin_box(1, 1, caca_get_width() - 2, caca_get_height() - 2); 165 164 caca_printf(4, 1, "[%i.%i fps]----", … … 183 182 184 183 caca_clear(); 185 caca_set_color(CACA_COLOR_ WHITE);184 caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); 186 185 caca_draw_thin_box(1, 1, xo, yo); 187 186 … … 196 195 caca_putstr(4, 11, "'4': triangles"); 197 196 caca_putstr(4, 12, "'5': ellipses"); 198 caca_putstr(4, 13, "'s': sprites"); 199 caca_putstr(4, 14, "'c': color"); 200 201 caca_putstr(4, 17, "settings:"); 202 caca_printf(4, 18, "'o': outline: %s", 197 caca_putstr(4, 13, "'c': colour"); 198 if(sprite) 199 caca_putstr(4, 14, "'s': sprites"); 200 201 caca_putstr(4, 16, "settings:"); 202 caca_printf(4, 17, "'o': outline: %s", 203 203 outline == 0 ? "none" : outline == 1 ? "solid" : "thin"); 204 caca_printf(4, 1 9, "'b': drawing boundaries: %s",204 caca_printf(4, 18, "'b': drawing boundaries: %s", 205 205 bounds == 0 ? "screen" : "infinite"); 206 caca_printf(4, 20, "'d': %s dithering",206 caca_printf(4, 19, "'d': %s dithering", 207 207 dithering == 0 ? "no" : dithering == 1 ? "ordered" : "random"); 208 208 … … 221 221 222 222 /* Draw the sun */ 223 caca_set_color(CACA_COLOR_YELLOW );223 caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK); 224 224 xo = caca_get_width() / 4; 225 225 yo = caca_get_height() / 4 + 5 * sin(0.03*i); … … 233 233 234 234 j = 15 + sin(0.03*i) * 8; 235 caca_set_color(CACA_COLOR_WHITE );235 caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK); 236 236 caca_fill_ellipse(xo, yo, j, j / 2, '#'); 237 caca_set_color(CACA_COLOR_YELLOW );237 caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK); 238 238 caca_draw_ellipse(xo, yo, j, j / 2, '#'); 239 239 … … 251 251 yc = caca_get_height() * 3 / 4 + cos(0.02*i) * 5; 252 252 253 caca_set_color(CACA_COLOR_GREEN );253 caca_set_color(CACA_COLOR_GREEN, CACA_COLOR_BLACK); 254 254 caca_fill_triangle(xo, yo, xb, yb, xa, ya, '%'); 255 caca_set_color(CACA_COLOR_YELLOW );255 caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK); 256 256 caca_draw_thin_triangle(xo, yo, xb, yb, xa, ya); 257 257 258 caca_set_color(CACA_COLOR_RED );258 caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK); 259 259 caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#'); 260 caca_set_color(CACA_COLOR_YELLOW );260 caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK); 261 261 caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc); 262 262 263 caca_set_color(CACA_COLOR_BLUE );263 caca_set_color(CACA_COLOR_BLUE, CACA_COLOR_BLACK); 264 264 caca_fill_triangle(xo, yo, xb, yb, xc, yc, '%'); 265 caca_set_color(CACA_COLOR_YELLOW );265 caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK); 266 266 caca_draw_thin_triangle(xo, yo, xb, yb, xc, yc); 267 267 … … 276 276 yc = caca_get_height() - 3; 277 277 278 caca_set_color(CACA_COLOR_CYAN );278 caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK); 279 279 caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc); 280 280 … … 293 293 { 294 294 int delta = caca_rand(-5, 5); 295 caca_set_color(caca_rand(0, 15) );295 caca_set_color(caca_rand(0, 15), caca_rand(0, 15)); 296 296 caca_putchar(caca_get_width() / 2 297 297 + cos(0.02*j) * (delta + caca_get_width() / 4), … … 312 312 int ymax = caca_get_height() - 1; 313 313 int i; 314 static char chars[10] = 315 { 316 '+', '-', '*', '#', 'X', '@', '%', '$', 'M', 'W' 317 }; 314 318 315 319 for(i = 1000; i--;) 316 320 { 317 321 /* Putpixel */ 318 caca_set_color(caca_rand(0, 15)); 319 caca_putchar(caca_rand(0, xmax), caca_rand(0, ymax), '#'); 322 caca_set_color(caca_rand(0, 15), caca_rand(0, 15)); 323 caca_putchar(caca_rand(0, xmax), caca_rand(0, ymax), 324 chars[caca_rand(0, 9)]); 320 325 } 321 326 } … … 323 328 static void demo_color(void) 324 329 { 325 int i ;330 int i, j; 326 331 char buf[BUFSIZ]; 327 332 … … 330 335 { 331 336 sprintf(buf, "'%c': %i (%s)", 'a' + i, i, caca_get_color_name(i)); 332 caca_set_color(CACA_COLOR_WHITE); 333 caca_putstr(4, i + 3, buf); 334 caca_set_color(i); 335 caca_putstr(40, i + 3, "XXXXXXXXXX-XX--X----------"); 337 caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); 338 caca_putstr(4, i + (i >= 8 ? 4 : 3), buf); 339 for(j = 0; j < 16; j++) 340 { 341 caca_set_color(i, j); 342 caca_putstr((j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# "); 343 } 336 344 } 337 345 } … … 354 362 } 355 363 356 caca_set_color(caca_rand(0, 15) );364 caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK); 357 365 if(outline > 1) 358 366 caca_draw_thin_line(xa, ya, xb, yb); … … 378 386 } 379 387 380 caca_set_color(caca_rand(0, 15) );388 caca_set_color(caca_rand(0, 15), caca_rand(0, 15)); 381 389 caca_fill_box(xa, ya, xb, yb, '#'); 382 390 383 caca_set_color(caca_rand(0, 15) );391 caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK); 384 392 if(outline == 2) 385 393 caca_draw_thin_box(xa, ya, xb, yb); … … 409 417 } 410 418 411 caca_set_color(caca_rand(0, 15) );419 caca_set_color(caca_rand(0, 15), caca_rand(0, 15)); 412 420 caca_fill_ellipse(x, y, a, b, '#'); 413 421 414 caca_set_color(caca_rand(0, 15) );422 caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK); 415 423 if(outline == 2) 416 424 caca_draw_thin_ellipse(x, y, a, b); … … 439 447 } 440 448 441 caca_set_color(caca_rand(0, 15) );449 caca_set_color(caca_rand(0, 15), caca_rand(0, 15)); 442 450 caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#'); 443 451 444 caca_set_color(caca_rand(0, 15) );452 caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK); 445 453 if(outline == 2) 446 454 caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc); -
libcaca/trunk/examples/spritedit.c
r199 r226 82 82 caca_clear(); 83 83 84 caca_set_color(CACA_COLOR_ WHITE);84 caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); 85 85 caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1); 86 86 … … 102 102 xb = xa + 1 + caca_get_sprite_width(sprite, frame); 103 103 yb = ya + 1 + caca_get_sprite_height(sprite, frame); 104 caca_set_color(CACA_COLOR_BLACK );104 caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_BLACK); 105 105 caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' '); 106 caca_set_color(CACA_COLOR_ WHITE);106 caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); 107 107 caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb); 108 108 caca_draw_sprite(57, 10, sprite, frame); -
libcaca/trunk/src/bitmap.c
r221 r226 34 34 #else 35 35 typedef unsigned char uint8_t; 36 typedef unsigned short uint16_t; 37 typedef unsigned int uint32_t; 36 38 #endif 37 39 -
libcaca/trunk/src/caca.c
r213 r226 62 62 #if defined(USE_NCURSES) 63 63 static mmask_t oldmask; 64 int _caca_attr[16 ];64 int _caca_attr[16*16]; 65 65 #endif 66 66 … … 73 73 { 74 74 #if defined(USE_SLANG) 75 /* See SLang ref., 5.4.4. */ 75 76 static char *slang_colors[16] = 76 77 { … … 93 94 }; 94 95 95 int i;96 int fg, bg; 96 97 97 98 /* Initialize slang library */ … … 121 122 SLsmg_refresh(); 122 123 123 for(i = 0; i < 16; i++) 124 SLtt_set_color(i + 1, NULL, slang_colors[i], "black"); 125 126 #elif defined(USE_NCURSES) 127 int i; 124 for(bg = 0; bg < 16; bg++) 125 for(fg = 0; fg < 16; fg++) 126 { 127 int i = fg + 16 * bg; 128 SLtt_set_color(i, NULL, slang_colors[fg], slang_colors[bg]); 129 } 130 131 #elif defined(USE_NCURSES) 132 static int curses_colors[] = 133 { 134 COLOR_BLACK, 135 COLOR_BLUE, 136 COLOR_GREEN, 137 COLOR_CYAN, 138 COLOR_RED, 139 COLOR_MAGENTA, 140 COLOR_YELLOW, 141 COLOR_WHITE, 142 /* Extra values for xterm-16color */ 143 COLOR_BLACK + 8, 144 COLOR_BLUE + 8, 145 COLOR_GREEN + 8, 146 COLOR_CYAN + 8, 147 COLOR_RED + 8, 148 COLOR_MAGENTA + 8, 149 COLOR_YELLOW + 8, 150 COLOR_WHITE + 8 151 }; 152 153 int fg, bg, max; 128 154 mmask_t newmask; 129 155 … … 136 162 curs_set(0); 137 163 164 /* Activate mouse */ 138 165 newmask = ALL_MOUSE_EVENTS; 139 166 mousemask(newmask, &oldmask); 140 167 168 /* Activate colour */ 141 169 start_color(); 142 170 143 init_pair(1 + CACA_COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);144 init_pair(1 + CACA_COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); 145 init_pair(1 + CACA_COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);146 init_pair(1 + CACA_COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);147 init_pair(1 + CACA_COLOR_RED, COLOR_RED, COLOR_BLACK);148 init_pair(1 + CACA_COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);149 init_pair(1 + CACA_COLOR_BROWN, COLOR_YELLOW, COLOR_BLACK);150 init_pair(1 + CACA_COLOR_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK);151 init_pair(1 + CACA_COLOR_DARKGRAY, COLOR_BLACK, COLOR_BLACK);152 init_pair(1 + CACA_COLOR_LIGHTBLUE, COLOR_BLUE, COLOR_BLACK);153 init_pair(1 + CACA_COLOR_LIGHTGREEN, COLOR_GREEN, COLOR_BLACK);154 init_pair(1 + CACA_COLOR_LIGHTCYAN, COLOR_CYAN, COLOR_BLACK); 155 init_pair(1 + CACA_COLOR_LIGHTRED, COLOR_RED, COLOR_BLACK);156 init_pair(1 + CACA_COLOR_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK);157 init_pair(1 + CACA_COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);158 init_pair(1 + CACA_COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);159 160 for(i = 0; i < 8; i++)161 {162 _caca_attr[i] = COLOR_PAIR(1 + i);163 _caca_attr[i + 8] = A_BOLD | COLOR_PAIR(1 + i);164 }171 max = COLORS >= 16 ? 16 : 8; 172 173 for(bg = 0; bg < max; bg++) 174 for(fg = 0; fg < max; fg++) 175 { 176 /* Use ((max + 7 - fg) % max) instead of fg so that colour 0 177 * is light gray on black, since some terminals don't like 178 * this colour pair to be redefined. */ 179 int col = ((max + 7 - fg) % max) + max * bg; 180 init_pair(col, curses_colors[fg], curses_colors[bg]); 181 _caca_attr[fg + 16 * bg] = COLOR_PAIR(col); 182 183 if(max == 8) 184 { 185 /* Bright fg on simple bg */ 186 _caca_attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col); 187 /* Simple fg on bright bg */ 188 _caca_attr[fg + 16 * (bg + 8)] = A_BLINK | COLOR_PAIR(col); 189 /* Bright fg on bright bg */ 190 _caca_attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD | COLOR_PAIR(col); 191 } 192 } 165 193 166 194 #elif defined(USE_CONIO) -
libcaca/trunk/src/caca.h
r213 r226 151 151 * Character graphics 152 152 */ 153 void caca_set_color(enum caca_color); 154 enum caca_color caca_get_color(void); 153 void caca_set_color(enum caca_color, enum caca_color); 154 enum caca_color caca_get_fg_color(void); 155 enum caca_color caca_get_bg_color(void); 155 156 void caca_putchar(int, int, char); 156 157 void caca_putstr(int, int, const char *); … … 203 204 struct caca_bitmap; 204 205 struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int); 206 void caca_set_bitmap_palette(struct caca_bitmap *, int[], int[], int[]); 205 207 void caca_draw_bitmap(int, int, int, int, struct caca_bitmap *, char *); 206 208 void caca_free_bitmap(struct caca_bitmap *); -
libcaca/trunk/src/graphics.c
r205 r226 40 40 #endif 41 41 42 #include <stdio.h> /* BUFSIZ */ 42 43 #include <string.h> 43 44 #include <stdlib.h> … … 47 48 #include "caca_internals.h" 48 49 49 static enum caca_color _caca_color = CACA_COLOR_WHITE; 50 static enum caca_color _caca_fgcolor = CACA_COLOR_LIGHTGRAY; 51 static enum caca_color _caca_bgcolor = CACA_COLOR_BLACK; 50 52 51 void caca_set_color(enum caca_color color)53 void caca_set_color(enum caca_color fgcolor, enum caca_color bgcolor) 52 54 { 53 if( color < 0 ||color > 15)55 if(fgcolor < 0 || fgcolor > 15 || bgcolor < 0 || bgcolor > 15) 54 56 return; 55 57 56 _caca_color = color; 58 _caca_fgcolor = fgcolor; 59 _caca_bgcolor = bgcolor; 57 60 #if defined(USE_SLANG) 58 SLsmg_set_color( color + 1);61 SLsmg_set_color(fgcolor + 16 * bgcolor); 59 62 #elif defined(USE_NCURSES) 60 attrset(_caca_attr[ color]);63 attrset(_caca_attr[fgcolor + 16 * bgcolor]); 61 64 #elif defined(USE_CONIO) 62 textcolor(color); 65 textbackground(bgcolor); 66 textcolor(fgcolor); 63 67 #endif 64 68 } 65 69 66 enum caca_color caca_get_ color(void)70 enum caca_color caca_get_fg_color(void) 67 71 { 68 return _caca_color; 72 return _caca_fgcolor; 73 } 74 75 enum caca_color caca_get_bg_color(void) 76 { 77 return _caca_bgcolor; 69 78 } 70 79 71 80 void caca_putchar(int x, int y, char c) 72 81 { 82 #if defined(USE_CONIO) 83 char *data; 84 #endif 73 85 if(x < 0 || x >= (int)caca_get_width() || 74 86 y < 0 || y >= (int)caca_get_height()) … … 82 94 addch(c); 83 95 #elif defined(USE_CONIO) 84 _caca_screen[2 * (x + y * caca_get_width())] = c; 85 _caca_screen[2 * (x + y * caca_get_width()) + 1] = _caca_color; 96 data = _caca_screen + 2 * (x + y * caca_get_width()); 97 data[0] = c; 98 data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; 86 99 // gotoxy(x + 1, y + 1); 87 100 // putch(c); … … 125 138 { 126 139 *buf++ = *s++; 127 *buf++ = _caca_color;140 *buf++ = (_caca_bgcolor << 4) | _caca_fgcolor; 128 141 } 129 142 // gotoxy(x + 1, y + 1); … … 145 158 146 159 va_start(args, format); 160 #if defined(HAVE_VSNPRINTF) 147 161 vsnprintf(buf, caca_get_width() - x + 1, format, args); 162 #else 163 vsprintf(buf, format, args); 164 #endif 148 165 buf[caca_get_width() - x] = '\0'; 149 166 va_end(args); … … 157 174 void caca_clear(void) 158 175 { 159 /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */ 176 enum caca_color oldfg = caca_get_fg_color(); 177 enum caca_color oldbg = caca_get_bg_color(); 160 178 int y = caca_get_height(); 161 179 180 caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK); 181 182 /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */ 162 183 while(y--) 163 184 caca_putstr(0, y, _caca_empty_line); 185 186 caca_set_color(oldfg, oldbg); 164 187 } 165 188 -
libcaca/trunk/src/sprite.c
r205 r226 220 220 void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f) 221 221 { 222 int i, j, oldcol; 222 int i, j; 223 enum caca_color oldfg, oldbg; 223 224 struct caca_frame *frame; 224 225 … … 231 232 frame = &sprite->frames[f]; 232 233 233 oldcol = caca_get_color(); 234 oldfg = caca_get_fg_color(); 235 oldbg = caca_get_bg_color(); 234 236 235 237 for(j = 0; j < frame->h; j++) … … 240 242 if(col >= 0) 241 243 { 242 caca_set_color(col );244 caca_set_color(col, CACA_COLOR_BLACK); 243 245 caca_putchar(x + i - frame->dx, y + j - frame->dy, 244 246 frame->chars[frame->w * j + i]); … … 247 249 } 248 250 249 caca_set_color(old col);251 caca_set_color(oldfg, oldbg); 250 252 } 251 253
Note: See TracChangeset
for help on using the changeset viewer.