Changeset 265
- Timestamp:
- Dec 22, 2003, 4:26:12 PM (17 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/configure.ac
r253 r265 38 38 Define if <pc.h> defines ScreenUpdate.)],[ 39 39 AC_MSG_RESULT(no)]) 40 AC_DEFINE(USE_CONIO, 1, Define if the backend driver is conio.h) 41 elif test "${enable_slang}" = "yes"; then 40 AC_DEFINE(USE_CONIO, 1, Define to activate the conio.h backend driver) 41 fi 42 43 if test "${enable_slang}" = "yes"; then 42 44 AC_CHECK_HEADERS(slang.h,:,AC_MSG_ERROR([cannot find slang headers])) 43 45 AC_CHECK_LIB(slang,SLkp_init,:,AC_MSG_ERROR([cannot find slang library])) 44 AC_DEFINE(USE_SLANG, 1, Define if the backend driver is slang)46 AC_DEFINE(USE_SLANG, 1, Define to activate the slang backend driver) 45 47 CACA_LIBS="${CACA_LIBS} -lslang" 46 elif test "${enable_x11}" = "yes"; then 48 fi 49 50 if test "${enable_x11}" = "yes"; then 47 51 AC_PATH_X 48 52 AC_CHECK_LIB(X11, XOpenDisplay, … … 55 59 AC_MSG_ERROR([cannot find X11 development files]) 56 60 fi 57 AC_DEFINE(USE_X11, 1, Define if the backend driver is X11)61 AC_DEFINE(USE_X11, 1, Define to activate the X11 backend driver) 58 62 CPPFLAGS="${CPPFLAGS} ${X_CFLAGS}" 59 63 CACA_LIBS="${CACA_LIBS} ${X_LIBS}" 60 elif test "${enable_ncurses}" != "no"; then 64 fi 65 66 if test "${enable_ncurses}" != "no"; then 61 67 AC_CHECK_HEADERS(ncurses.h,:,AC_MSG_ERROR([cannot find ncurses headers])) 62 68 AC_CHECK_LIB(ncurses,initscr,:,AC_MSG_ERROR([cannot find ncurses library])) 63 AC_DEFINE(USE_NCURSES, 1, Define if the backend driver is ncurses)69 AC_DEFINE(USE_NCURSES, 1, Define to activate the ncurses backend driver) 64 70 CACA_LIBS="${CACA_LIBS} -lncurses" 65 else66 AC_MSG_ERROR([could not find any terminal graphics interface])67 71 fi 68 72 -
libcaca/trunk/src/bitmap.c
r257 r265 30 30 #include "config.h" 31 31 32 #if def HAVE_INTTYPES_H32 #if defined(HAVE_INTTYPES_H) 33 33 # include <inttypes.h> 34 34 #else … … 38 38 #endif 39 39 40 #if def HAVE_ENDIAN_H40 #if defined(HAVE_ENDIAN_H) 41 41 # include <endian.h> 42 42 #endif … … 257 257 case 3: 258 258 { 259 #if def HAVE_ENDIAN_H259 #if defined(HAVE_ENDIAN_H) 260 260 if(__BYTE_ORDER == __BIG_ENDIAN) 261 261 #else -
libcaca/trunk/src/caca.c
r257 r265 34 34 #if defined(USE_SLANG) 35 35 # include <slang.h> 36 #elif defined(USE_NCURSES) 36 #endif 37 #if defined(USE_NCURSES) 37 38 # include <curses.h> 38 #elif defined(USE_CONIO) 39 #endif 40 #if defined(USE_CONIO) 39 41 # include <dos.h> 40 42 # include <conio.h> 41 #elif defined(USE_X11) 43 #endif 44 #if defined(USE_X11) 42 45 # include <X11/Xlib.h> 43 #else44 # error "no graphics library detected"45 46 #endif 46 47 … … 51 52 #include "caca_internals.h" 52 53 54 static void caca_init_driver(void); 53 55 static void caca_init_features(void); 54 56 static void caca_init_terminal(void); 55 57 58 enum caca_driver _caca_driver; 59 56 60 #if defined(USE_NCURSES) 57 61 static mmask_t oldmask; … … 68 72 mmask_t newmask; 69 73 #endif 74 75 caca_init_driver(); 76 77 if(_caca_driver == CACA_DRIVER_NONE) 78 return -1; 70 79 71 80 caca_init_features(); … … 73 82 74 83 #if defined(USE_SLANG) 75 /* Initialize slang library */ 76 SLsig_block_signals(); 77 SLtt_get_terminfo(); 78 79 if(SLkp_init() == -1) 80 { 84 if(_caca_driver == CACA_DRIVER_SLANG) 85 { 86 /* Initialise slang library */ 87 SLsig_block_signals(); 88 SLtt_get_terminfo(); 89 90 if(SLkp_init() == -1) 91 { 92 SLsig_unblock_signals(); 93 return -1; 94 } 95 96 SLang_init_tty(-1, 0, 1); 97 98 if(SLsmg_init_smg() == -1) 99 { 100 SLsig_unblock_signals(); 101 return -1; 102 } 103 81 104 SLsig_unblock_signals(); 82 return -1; 83 }84 85 SLang_init_tty(-1, 0,1);86 87 if(SLsmg_init_smg() == -1)88 { 89 SLsig_unblock_signals();90 return -1;91 }92 93 SLsig_unblock_signals();94 95 SLsmg_cls(); 96 SLtt_set_cursor_visibility(0);97 SLkp_define_keysym("\e[M", 1001);98 SLtt_set_mouse_mode(1, 0);99 SLsmg_refresh();100 101 /* Disable scrolling so that hashmap scrolling optimization code102 * does not cause ugly refreshes due to slow terminals */103 SLtt_Term_Cannot_Scroll = 1;104 105 #elif defined(USE_NCURSES) 106 initscr();107 keypad(stdscr, TRUE);108 nonl();109 cbreak();110 noecho();111 nodelay(stdscr, TRUE); 112 curs_set(0); 113 114 /* Activate mouse */115 newmask = ALL_MOUSE_EVENTS;116 mousemask(newmask, &oldmask);117 118 #elif defined(USE_CONIO) 119 _wscroll = 0;120 _setcursortype(_NOCURSOR); 121 clrscr(); 122 123 #elif defined(USE_X11) 124 /* Nothing to do */125 126 #endif 105 106 SLsmg_cls(); 107 SLtt_set_cursor_visibility(0); 108 SLkp_define_keysym("\e[M", 1001); 109 SLtt_set_mouse_mode(1, 0); 110 SLsmg_refresh(); 111 112 /* Disable scrolling so that hashmap scrolling optimization code 113 * does not cause ugly refreshes due to slow terminals */ 114 SLtt_Term_Cannot_Scroll = 1; 115 } 116 else 117 #endif 118 #if defined(USE_NCURSES) 119 if(_caca_driver == CACA_DRIVER_NCURSES) 120 { 121 initscr(); 122 keypad(stdscr, TRUE); 123 nonl(); 124 cbreak(); 125 noecho(); 126 nodelay(stdscr, TRUE); 127 curs_set(0); 128 129 /* Activate mouse */ 130 newmask = ALL_MOUSE_EVENTS; 131 mousemask(newmask, &oldmask); 132 } 133 else 134 #endif 135 #if defined(USE_CONIO) 136 if(_caca_driver == CACA_DRIVER_CONIO) 137 { 138 _wscroll = 0; 139 _setcursortype(_NOCURSOR); 140 clrscr(); 141 } 142 else 143 #endif 144 #if defined(USE_X11) 145 { 146 /* Nothing to do */ 147 } 148 #endif 149 127 150 if(_caca_init_graphics()) 128 151 return -1; … … 282 305 283 306 #if defined(USE_SLANG) 284 SLtt_set_mouse_mode(0, 0); 285 SLtt_set_cursor_visibility(1); 286 SLang_reset_tty(); 287 SLsmg_reset_smg(); 288 #elif defined(USE_NCURSES) 289 mousemask(oldmask, NULL); 290 curs_set(1); 291 endwin(); 292 #elif defined(USE_CONIO) 293 _wscroll = 1; 294 textcolor((enum COLORS)WHITE); 295 textbackground((enum COLORS)BLACK); 296 gotoxy(_caca_width, _caca_height); 297 cputs("\r\n"); 298 _setcursortype(_NORMALCURSOR); 299 #elif defined(USE_X11) 300 /* Nothing to do */ 301 #endif 307 if(_caca_driver == CACA_DRIVER_SLANG) 308 { 309 SLtt_set_mouse_mode(0, 0); 310 SLtt_set_cursor_visibility(1); 311 SLang_reset_tty(); 312 SLsmg_reset_smg(); 313 } 314 else 315 #endif 316 #if defined(USE_NCURSES) 317 if(_caca_driver == CACA_DRIVER_NCURSES) 318 { 319 mousemask(oldmask, NULL); 320 curs_set(1); 321 endwin(); 322 } 323 else 324 #endif 325 #if defined(USE_CONIO) 326 if(_caca_driver == USE_CONIO) 327 { 328 _wscroll = 1; 329 textcolor((enum COLORS)WHITE); 330 textbackground((enum COLORS)BLACK); 331 gotoxy(_caca_width, _caca_height); 332 cputs("\r\n"); 333 _setcursortype(_NORMALCURSOR); 334 } 335 else 336 #endif 337 #if defined(USE_X11) 338 if(_caca_driver == USE_X11) 339 { 340 /* Nothing to do */ 341 } 342 #endif 343 } 344 345 static void caca_init_driver(void) 346 { 347 #if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP) 348 char *var = getenv("CACA_DRIVER"); 349 350 /* If the environment variable was set, use it */ 351 if(var && *var) 352 { 353 #if defined(USE_CONIO) 354 if(!strcasecmp(var, "conio")) 355 _caca_driver = CACA_DRIVER_CONIO; 356 else 357 #endif 358 #if defined(USE_NCURSES) 359 if(!strcasecmp(var, "ncurses")) 360 _caca_driver = CACA_DRIVER_NCURSES; 361 else 362 #endif 363 #if defined(USE_SLANG) 364 if(!strcasecmp(var, "slang")) 365 _caca_driver = CACA_DRIVER_SLANG; 366 else 367 #endif 368 #if defined(USE_X11) 369 if(!strcasecmp(var, "x11")) 370 _caca_driver = CACA_DRIVER_X11; 371 else 372 #endif 373 _caca_driver = CACA_DRIVER_NONE; 374 375 return; 376 } 377 #endif 378 379 #if defined(USE_CONIO) 380 _caca_driver = CACA_DRIVER_CONIO; 381 return; 382 #endif 383 #if defined(USE_NCURSES) 384 _caca_driver = CACA_DRIVER_NCURSES; 385 return; 386 #endif 387 #if defined(USE_SLANG) 388 _caca_driver = CACA_DRIVER_SLANG; 389 return; 390 #endif 391 #if defined(USE_X11) 392 _caca_driver = CACA_DRIVER_X11; 393 return; 394 #endif 395 _caca_driver = CACA_DRIVER_NONE; 396 return; 302 397 } 303 398 … … 352 447 char *term, *colorterm, *other; 353 448 449 if(_caca_driver != CACA_DRIVER_NCURSES && 450 _caca_driver != CACA_DRIVER_SLANG) 451 return; 452 354 453 term = getenv("TERM"); 355 454 colorterm = getenv("COLORTERM"); … … 361 460 { 362 461 #if defined(USE_NCURSES) 363 SCREEN *screen; 364 screen = newterm("xterm-16color", stdout, stdin); 365 if(screen == NULL) 366 return; 367 endwin(); 462 if(_caca_driver == USE_NCURSES) 463 { 464 SCREEN *screen; 465 screen = newterm("xterm-16color", stdout, stdin); 466 if(screen == NULL) 467 return; 468 endwin(); 469 } 368 470 #endif 369 471 (void)putenv("TERM=xterm-16color"); … … 376 478 { 377 479 #if defined(USE_NCURSES) 378 SCREEN *screen; 379 screen = newterm("xterm-16color", stdout, stdin); 380 if(screen == NULL) 381 return; 382 endwin(); 480 if(_caca_driver == USE_NCURSES) 481 { 482 SCREEN *screen; 483 screen = newterm("xterm-16color", stdout, stdin); 484 if(screen == NULL) 485 return; 486 endwin(); 487 } 383 488 #endif 384 489 (void)putenv("TERM=xterm-16color"); -
libcaca/trunk/src/caca.h
r257 r265 55 55 * \e libcaca without having to modify the program which uses it. These 56 56 * variables are: 57 * 58 * \li \b CACA_DRIVER: set the backend video driver. In order of preference: 59 * - \c conio uses the DOS conio.h interface. 60 * - \c ncurses uses the ncurses library. 61 * - \c slang uses the S-Lang library. 62 * - \c x11 uses the native X11 driver. 57 63 * 58 64 * \li \b CACA_BACKGROUND: set the background type. -
libcaca/trunk/src/caca_internals.h
r263 r265 31 31 #define __CACA_INTERNALS_H__ 32 32 33 /* Graphics driver */ 34 enum caca_driver 35 { 36 #if defined(USE_CONIO) 37 CACA_DRIVER_CONIO = 1, 38 #endif 39 #if defined(USE_NCURSES) 40 CACA_DRIVER_NCURSES = 2, 41 #endif 42 #if defined(USE_SLANG) 43 CACA_DRIVER_SLANG = 3, 44 #endif 45 #if defined(USE_X11) 46 CACA_DRIVER_X11 = 4, 47 #endif 48 CACA_DRIVER_NONE = 0 49 }; 50 51 extern enum caca_driver _caca_driver; 52 53 /* Initialisation functions */ 33 54 extern int _caca_init_graphics(void); 34 55 extern int _caca_end_graphics(void); -
libcaca/trunk/src/conic.c
r257 r265 31 31 #include "config.h" 32 32 33 #if def HAVE_INTTYPES_H33 #if defined(HAVE_INTTYPES_H) 34 34 # include <inttypes.h> 35 35 #else -
libcaca/trunk/src/graphics.c
r264 r265 32 32 #if defined(USE_SLANG) 33 33 # include <slang.h> 34 #elif defined(USE_NCURSES) 34 #endif 35 #if defined(USE_NCURSES) 35 36 # include <curses.h> 36 #elif defined(USE_CONIO) 37 #endif 38 #if defined(USE_CONIO) 37 39 # include <conio.h> 38 40 # if defined(SCREENUPDATE_IN_PC_H) 39 41 # include <pc.h> 40 42 # endif 41 #elif defined(USE_X11) 43 #endif 44 #if defined(USE_X11) 42 45 # include <X11/Xlib.h> 43 #else 44 # error "no graphics library detected" 45 #endif 46 47 #ifdef HAVE_INTTYPES_H 46 #endif 47 48 #if defined(HAVE_INTTYPES_H) 48 49 # include <inttypes.h> 49 50 #endif … … 113 114 _caca_fgcolor = fgcolor; 114 115 _caca_bgcolor = bgcolor; 116 switch(_caca_driver) 117 { 115 118 #if defined(USE_SLANG) 116 SLsmg_set_color((bgcolor + 16 * fgcolor) /*% 128*/); 117 #elif defined(USE_NCURSES) 118 attrset(ncurses_attr[fgcolor + 16 * bgcolor]); 119 #elif defined(USE_CONIO) 120 textbackground(bgcolor); 121 textcolor(fgcolor); 122 #elif defined(USE_X11) 123 /* FIXME */ 124 #endif 119 case CACA_DRIVER_SLANG: 120 SLsmg_set_color((bgcolor + 16 * fgcolor) /*% 128*/); 121 break; 122 #endif 123 #if defined(USE_NCURSES) 124 case CACA_DRIVER_NCURSES: 125 attrset(ncurses_attr[fgcolor + 16 * bgcolor]); 126 break; 127 #endif 128 #if defined(USE_CONIO) 129 case CACA_DRIVER_CONIO: 130 textbackground(bgcolor); 131 textcolor(fgcolor); 132 break; 133 #endif 134 #if defined(USE_X11) 135 case CACA_DRIVER_X11: 136 /* FIXME */ 137 break; 138 #endif 139 default: 140 break; 141 } 125 142 } 126 143 … … 162 179 return; 163 180 181 switch(_caca_driver) 182 { 164 183 #if defined(USE_SLANG) 165 SLsmg_gotorc(y, x); 166 SLsmg_write_char(c); 167 #elif defined(USE_NCURSES) 168 move(y, x); 169 addch(c); 170 #elif defined(USE_CONIO) 171 data = conio_screen + 2 * (x + y * _caca_width); 172 data[0] = c; 173 data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; 174 // gotoxy(x + 1, y + 1); 175 // putch(c); 176 #elif defined(USE_X11) 177 x11_screen[x + y * _caca_width] = 178 ((int)c << 8) | ((int)_caca_bgcolor << 4) | (int)_caca_fgcolor; 179 #endif 184 case CACA_DRIVER_SLANG: 185 SLsmg_gotorc(y, x); 186 SLsmg_write_char(c); 187 break; 188 #endif 189 #if defined(USE_NCURSES) 190 case CACA_DRIVER_NCURSES: 191 move(y, x); 192 addch(c); 193 break; 194 #endif 195 #if defined(USE_CONIO) 196 case CACA_DRIVER_CONIO: 197 data = conio_screen + 2 * (x + y * _caca_width); 198 data[0] = c; 199 data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; 200 // gotoxy(x + 1, y + 1); 201 // putch(c); 202 break; 203 #endif 204 #if defined(USE_X11) 205 case CACA_DRIVER_X11: 206 x11_screen[x + y * _caca_width] = 207 ((int)c << 8) | ((int)_caca_bgcolor << 4) | (int)_caca_fgcolor; 208 break; 209 #endif 210 default: 211 break; 212 } 180 213 } 181 214 … … 191 224 { 192 225 #if defined(USE_CONIO) 193 char *buf; 194 #elif defined(USE_X11) 195 int *buf; 226 char *charbuf; 227 #endif 228 #if defined(USE_X11) 229 int *intbuf; 196 230 #endif 197 231 unsigned int len; … … 218 252 } 219 253 254 switch(_caca_driver) 255 { 220 256 #if defined(USE_SLANG) 221 SLsmg_gotorc(y, x); 222 SLsmg_write_string((char *)(intptr_t)s); 223 #elif defined(USE_NCURSES) 224 move(y, x); 225 addstr(s); 226 #elif defined(USE_CONIO) 227 buf = conio_screen + 2 * (x + y * _caca_width); 228 while(*s) 229 { 230 *buf++ = *s++; 231 *buf++ = (_caca_bgcolor << 4) | _caca_fgcolor; 232 } 233 // gotoxy(x + 1, y + 1); 234 // cputs(s); 235 #elif defined(USE_X11) 236 buf = x11_screen + x + y * _caca_width; 237 while(*s) 238 *buf++ = ((int)*s++ << 8) | ((int)_caca_bgcolor << 4) | (int)_caca_fgcolor; 239 #endif 257 case CACA_DRIVER_SLANG: 258 SLsmg_gotorc(y, x); 259 SLsmg_write_string((char *)(intptr_t)s); 260 break; 261 #endif 262 #if defined(USE_NCURSES) 263 case CACA_DRIVER_NCURSES: 264 move(y, x); 265 addstr(s); 266 break; 267 #endif 268 #if defined(USE_CONIO) 269 case CACA_DRIVER_CONIO: 270 charbuf = conio_screen + 2 * (x + y * _caca_width); 271 while(*s) 272 { 273 *charbuf++ = *s++; 274 *charbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor; 275 } 276 // gotoxy(x + 1, y + 1); 277 // cputs(s); 278 break; 279 #endif 280 #if defined(USE_X11) 281 case CACA_DRIVER_X11: 282 intbuf = x11_screen + x + y * _caca_width; 283 while(*s) 284 *intbuf++ = ((int)*s++ << 8) 285 | ((int)_caca_bgcolor << 4) | (int)_caca_fgcolor; 286 break; 287 #endif 288 default: 289 break; 290 } 240 291 } 241 292 … … 299 350 { 300 351 #if defined(USE_SLANG) 301 /* See SLang ref., 5.4.4. */ 302 static char *slang_colors[16] = 303 { 304 /* Standard colours */ 305 "black", 306 "blue", 307 "green", 308 "cyan", 309 "red", 310 "magenta", 311 "brown", 312 "lightgray", 313 /* Bright colours */ 314 "gray", 315 "brightblue", 316 "brightgreen", 317 "brightcyan", 318 "brightred", 319 "brightmagenta", 320 "yellow", 321 "white", 322 }; 323 324 int fg, bg; 325 326 for(fg = 0; fg < 16; fg++) 327 for(bg = 0; bg < 16; bg++) 328 { 329 int i = bg + 16 * fg; 330 SLtt_set_color(i, NULL, slang_colors[fg], slang_colors[bg]); 352 if(_caca_driver == CACA_DRIVER_SLANG) 353 { 354 /* See SLang ref., 5.4.4. */ 355 static char *slang_colors[16] = 356 { 357 /* Standard colours */ 358 "black", 359 "blue", 360 "green", 361 "cyan", 362 "red", 363 "magenta", 364 "brown", 365 "lightgray", 366 /* Bright colours */ 367 "gray", 368 "brightblue", 369 "brightgreen", 370 "brightcyan", 371 "brightred", 372 "brightmagenta", 373 "yellow", 374 "white", 375 }; 376 377 int fg, bg; 378 379 for(fg = 0; fg < 16; fg++) 380 for(bg = 0; bg < 16; bg++) 381 { 382 int i = bg + 16 * fg; 383 SLtt_set_color(i, NULL, slang_colors[fg], slang_colors[bg]); 384 } 385 386 /* Disable alt charset support so that we get all 256 colour pairs */ 387 SLtt_Has_Alt_Charset = 0; 388 389 _caca_width = SLtt_Screen_Cols; 390 _caca_height = SLtt_Screen_Rows; 391 } 392 else 393 #endif 394 #if defined(USE_NCURSES) 395 if(_caca_driver == CACA_DRIVER_NCURSES) 396 { 397 static int curses_colors[] = 398 { 399 /* Standard curses colours */ 400 COLOR_BLACK, 401 COLOR_BLUE, 402 COLOR_GREEN, 403 COLOR_CYAN, 404 COLOR_RED, 405 COLOR_MAGENTA, 406 COLOR_YELLOW, 407 COLOR_WHITE, 408 /* Extra values for xterm-16color */ 409 COLOR_BLACK + 8, 410 COLOR_BLUE + 8, 411 COLOR_GREEN + 8, 412 COLOR_CYAN + 8, 413 COLOR_RED + 8, 414 COLOR_MAGENTA + 8, 415 COLOR_YELLOW + 8, 416 COLOR_WHITE + 8 417 }; 418 419 int fg, bg, max; 420 421 /* Activate colour */ 422 start_color(); 423 424 /* If COLORS == 16, it means the terminal supports full bright colours 425 * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8), 426 * we can build 16*16 colour pairs. 427 * If COLORS == 8, it means the terminal does not know about bright 428 * colours and we need to get them through A_BOLD and A_BLINK (\e[1m 429 * and \e[5m). We can only build 8*8 colour pairs. */ 430 max = COLORS >= 16 ? 16 : 8; 431 432 for(bg = 0; bg < max; bg++) 433 for(fg = 0; fg < max; fg++) 434 { 435 /* Use ((max + 7 - fg) % max) instead of fg so that colour 0 436 * is light gray on black, since some terminals don't like 437 * this colour pair to be redefined. */ 438 int col = ((max + 7 - fg) % max) + max * bg; 439 init_pair(col, curses_colors[fg], curses_colors[bg]); 440 ncurses_attr[fg + 16 * bg] = COLOR_PAIR(col); 441 442 if(max == 8) 443 { 444 /* Bright fg on simple bg */ 445 ncurses_attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col); 446 /* Simple fg on bright bg */ 447 ncurses_attr[fg + 16 * (bg + 8)] = A_BLINK 448 | COLOR_PAIR(col); 449 /* Bright fg on bright bg */ 450 ncurses_attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD 451 | COLOR_PAIR(col); 452 } 453 } 454 455 _caca_width = COLS; 456 _caca_height = LINES; 457 } 458 else 459 #endif 460 #if defined(USE_CONIO) 461 if(_caca_driver == CACA_DRIVER_CONIO) 462 { 463 gettextinfo(&conio_ti); 464 conio_screen = malloc(2 * conio_ti.screenwidth 465 * conio_ti.screenheight * sizeof(char)); 466 if(conio_screen == NULL) 467 return -1; 468 # if defined(SCREENUPDATE_IN_PC_H) 469 ScreenRetrieve(conio_screen); 470 # else 471 /* FIXME */ 472 # endif 473 _caca_width = conio_ti.screenwidth; 474 _caca_height = conio_ti.screenheight; 475 } 476 else 477 #endif 478 #if defined(USE_X11) 479 if(_caca_driver == CACA_DRIVER_X11) 480 { 481 static int x11_palette[] = 482 { 483 /* Standard curses colours */ 484 0, 0, 0, 485 0, 0, 32768, 486 0, 32768, 0, 487 0, 32768, 32768, 488 32768, 0, 0, 489 32768, 0, 32768, 490 32768, 32768, 0, 491 32768, 32768, 32768, 492 /* Extra values for xterm-16color */ 493 16384, 16384, 16384, 494 16384, 16384, 65535, 495 16384, 65535, 16384, 496 16384, 65535, 65535, 497 65535, 16384, 16384, 498 65535, 16384, 65535, 499 65535, 65535, 16384, 500 65535, 65535, 65535, 501 }; 502 503 Colormap colormap; 504 const char *font_name = "8x13bold"; 505 int i; 506 507 if(getenv("CACA_WIDTH")) 508 _caca_width = atoi(getenv("CACA_WIDTH")); 509 if(!_caca_width) 510 _caca_width = 80; 511 512 if(getenv("CACA_HEIGHT")) 513 _caca_height = atoi(getenv("CACA_HEIGHT")); 514 if(!_caca_height) 515 _caca_height = 32; 516 517 x11_screen = malloc(_caca_width * _caca_height * sizeof(int)); 518 if(x11_screen == NULL) 519 return -1; 520 521 x11_dpy = XOpenDisplay(NULL); 522 if(x11_dpy == NULL) 523 { 524 free(x11_screen); 525 return -1; 331 526 } 332 527 333 /* Disable alt charset support so that we get all 256 colour pairs */ 334 SLtt_Has_Alt_Charset = 0; 335 336 _caca_width = SLtt_Screen_Cols; 337 _caca_height = SLtt_Screen_Rows; 338 339 #elif defined(USE_NCURSES) 340 static int curses_colors[] = 341 { 342 /* Standard curses colours */ 343 COLOR_BLACK, 344 COLOR_BLUE, 345 COLOR_GREEN, 346 COLOR_CYAN, 347 COLOR_RED, 348 COLOR_MAGENTA, 349 COLOR_YELLOW, 350 COLOR_WHITE, 351 /* Extra values for xterm-16color */ 352 COLOR_BLACK + 8, 353 COLOR_BLUE + 8, 354 COLOR_GREEN + 8, 355 COLOR_CYAN + 8, 356 COLOR_RED + 8, 357 COLOR_MAGENTA + 8, 358 COLOR_YELLOW + 8, 359 COLOR_WHITE + 8 360 }; 361 362 int fg, bg, max; 363 364 /* Activate colour */ 365 start_color(); 366 367 /* If COLORS == 16, it means the terminal supports full bright colours 368 * using setab and setaf (will use \e[90m \e[91m etc. for colours >= 8), 369 * we can build 16*16 colour pairs. 370 * If COLORS == 8, it means the terminal does not know about bright 371 * colours and we need to get them through A_BOLD and A_BLINK (\e[1m 372 * and \e[5m). We can only build 8*8 colour pairs. */ 373 max = COLORS >= 16 ? 16 : 8; 374 375 for(bg = 0; bg < max; bg++) 376 for(fg = 0; fg < max; fg++) 377 { 378 /* Use ((max + 7 - fg) % max) instead of fg so that colour 0 379 * is light gray on black, since some terminals don't like 380 * this colour pair to be redefined. */ 381 int col = ((max + 7 - fg) % max) + max * bg; 382 init_pair(col, curses_colors[fg], curses_colors[bg]); 383 ncurses_attr[fg + 16 * bg] = COLOR_PAIR(col); 384 385 if(max == 8) 386 { 387 /* Bright fg on simple bg */ 388 ncurses_attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col); 389 /* Simple fg on bright bg */ 390 ncurses_attr[fg + 16 * (bg + 8)] = A_BLINK | COLOR_PAIR(col); 391 /* Bright fg on bright bg */ 392 ncurses_attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD 393 | COLOR_PAIR(col); 394 } 528 if(getenv("CACA_FONT")) 529 font_name = getenv("CACA_FONT"); 530 531 x11_font = XLoadFont(x11_dpy, font_name); 532 if(!x11_font) 533 { 534 XCloseDisplay(x11_dpy); 535 free(x11_screen); 536 return -1; 395 537 } 396 538 397 _caca_width = COLS; 398 _caca_height = LINES; 399 400 #elif defined(USE_CONIO) 401 gettextinfo(&conio_ti); 402 conio_screen = malloc(2 * conio_ti.screenwidth 403 * conio_ti.screenheight * sizeof(char)); 404 if(conio_screen == NULL) 405 return -1; 406 # if defined(SCREENUPDATE_IN_PC_H) 407 ScreenRetrieve(conio_screen); 408 # else 409 /* FIXME */ 410 # endif 411 _caca_width = conio_ti.screenwidth; 412 _caca_height = conio_ti.screenheight; 413 414 #elif defined(USE_X11) 415 static int x11_palette[] = 416 { 417 /* Standard curses colours */ 418 0, 0, 0, 419 0, 0, 32768, 420 0, 32768, 0, 421 0, 32768, 32768, 422 32768, 0, 0, 423 32768, 0, 32768, 424 32768, 32768, 0, 425 32768, 32768, 32768, 426 /* Extra values for xterm-16color */ 427 16384, 16384, 16384, 428 16384, 16384, 65535, 429 16384, 65535, 16384, 430 16384, 65535, 65535, 431 65535, 16384, 16384, 432 65535, 16384, 65535, 433 65535, 65535, 16384, 434 65535, 65535, 65535, 435 }; 436 437 Colormap colormap; 438 const char *font_name = "8x13bold"; 439 int i; 440 441 if(getenv("CACA_WIDTH")) 442 _caca_width = atoi(getenv("CACA_WIDTH")); 443 if(!_caca_width) 444 _caca_width = 80; 445 446 if(getenv("CACA_HEIGHT")) 447 _caca_height = atoi(getenv("CACA_HEIGHT")); 448 if(!_caca_height) 449 _caca_height = 32; 450 451 x11_screen = malloc(_caca_width * _caca_height * sizeof(int)); 452 if(x11_screen == NULL) 453 return -1; 454 455 x11_dpy = XOpenDisplay(NULL); 456 if(x11_dpy == NULL) 457 { 458 free(x11_screen); 459 return -1; 460 } 461 462 if(getenv("CACA_FONT")) 463 font_name = getenv("CACA_FONT"); 464 465 x11_font = XLoadFont(x11_dpy, font_name); 466 if(!x11_font) 467 { 468 XCloseDisplay(x11_dpy); 469 free(x11_screen); 470 return -1; 471 } 472 473 x11_font_struct = XQueryFont(x11_dpy, x11_font); 474 if(!x11_font_struct) 475 { 476 XUnloadFont(x11_dpy, x11_font); 477 XCloseDisplay(x11_dpy); 478 free(x11_screen); 479 return -1; 480 } 481 482 x11_font_width = x11_font_struct->max_bounds.width; 483 x11_font_height = x11_font_struct->max_bounds.ascent 484 + x11_font_struct->max_bounds.descent; 485 x11_font_offset = x11_font_struct->max_bounds.descent; 486 487 colormap = DefaultColormap(x11_dpy, DefaultScreen(x11_dpy)); 488 for(i = 0; i < 16; i++) 489 { 490 XColor color; 491 color.red = x11_palette[i * 3]; 492 color.green = x11_palette[i * 3 + 1]; 493 color.blue = x11_palette[i * 3 + 2]; 494 XAllocColor(x11_dpy, colormap, &color); 495 x11_colors[i] = color.pixel; 496 } 497 498 x11_window = XCreateSimpleWindow(x11_dpy, DefaultRootWindow(x11_dpy), 499 0, 0, _caca_width * x11_font_width, 500 _caca_height * x11_font_height, 0, 501 x11_colors[0], x11_colors[0]); 502 XSelectInput(x11_dpy, x11_window, StructureNotifyMask); 503 XMapWindow(x11_dpy, x11_window); 504 505 x11_gc = XCreateGC(x11_dpy, x11_window, 0, NULL); 506 XSetForeground(x11_dpy, x11_gc, x11_colors[15]); 507 XSetFont(x11_dpy, x11_gc, x11_font); 508 509 for(;;) 510 { 511 XEvent event; 512 XNextEvent(x11_dpy, &event); 513 if (event.type == MapNotify) 514 break; 515 } 516 517 XSelectInput(x11_dpy, x11_window, KeyPressMask); 518 519 XSync(x11_dpy, False); 520 521 x11_pixmap = XCreatePixmap(x11_dpy, x11_window, 522 _caca_width * x11_font_width, 523 _caca_height * x11_font_height, 524 DefaultDepth(x11_dpy, DefaultScreen(x11_dpy))); 525 #endif 539 x11_font_struct = XQueryFont(x11_dpy, x11_font); 540 if(!x11_font_struct) 541 { 542 XUnloadFont(x11_dpy, x11_font); 543 XCloseDisplay(x11_dpy); 544 free(x11_screen); 545 return -1; 546 } 547 548 x11_font_width = x11_font_struct->max_bounds.width; 549 x11_font_height = x11_font_struct->max_bounds.ascent 550 + x11_font_struct->max_bounds.descent; 551 x11_font_offset = x11_font_struct->max_bounds.descent; 552 553 colormap = DefaultColormap(x11_dpy, DefaultScreen(x11_dpy)); 554 for(i = 0; i < 16; i++) 555 { 556 XColor color; 557 color.red = x11_palette[i * 3]; 558 color.green = x11_palette[i * 3 + 1]; 559 color.blue = x11_palette[i * 3 + 2]; 560 XAllocColor(x11_dpy, colormap, &color); 561 x11_colors[i] = color.pixel; 562 } 563 564 x11_window = XCreateSimpleWindow(x11_dpy, DefaultRootWindow(x11_dpy), 565 0, 0, _caca_width * x11_font_width, 566 _caca_height * x11_font_height, 0, 567 x11_colors[0], x11_colors[0]); 568 XSelectInput(x11_dpy, x11_window, StructureNotifyMask); 569 XMapWindow(x11_dpy, x11_window); 570 571 x11_gc = XCreateGC(x11_dpy, x11_window, 0, NULL); 572 XSetForeground(x11_dpy, x11_gc, x11_colors[15]); 573 XSetFont(x11_dpy, x11_gc, x11_font); 574 575 for(;;) 576 { 577 XEvent event; 578 XNextEvent(x11_dpy, &event); 579 if (event.type == MapNotify) 580 break; 581 } 582 583 XSelectInput(x11_dpy, x11_window, KeyPressMask); 584 585 XSync(x11_dpy, False); 586 587 x11_pixmap = XCreatePixmap(x11_dpy, x11_window, 588 _caca_width * x11_font_width, 589 _caca_height * x11_font_height, 590 DefaultDepth(x11_dpy, 591 DefaultScreen(x11_dpy))); 592 } 593 #endif 594 526 595 _caca_empty_line = malloc(_caca_width + 1); 527 596 memset(_caca_empty_line, ' ', _caca_width); … … 540 609 #if defined(USE_SLANG) 541 610 /* Nothing to do */ 542 #elif defined(USE_NCURSES) 611 #endif 612 #if defined(USE_NCURSES) 543 613 /* Nothing to do */ 544 #elif defined(USE_CONIO) 545 free(conio_screen); 546 #elif defined(USE_X11) 547 XSync(x11_dpy, False); 548 XFreePixmap(x11_dpy, x11_pixmap); 549 XFreeFont(x11_dpy, x11_font_struct); 550 XFreeGC(x11_dpy, x11_gc); 551 XUnmapWindow(x11_dpy, x11_window); 552 XDestroyWindow(x11_dpy, x11_window); 553 XCloseDisplay(x11_dpy); 554 free(x11_screen); 614 #endif 615 #if defined(USE_CONIO) 616 if(_caca_driver == CACA_DRIVER_CONIO) 617 { 618 free(conio_screen); 619 } 620 else 621 #endif 622 #if defined(USE_X11) 623 if(_caca_driver == CACA_DRIVER_X11) 624 { 625 XSync(x11_dpy, False); 626 XFreePixmap(x11_dpy, x11_pixmap); 627 XFreeFont(x11_dpy, x11_font_struct); 628 XFreeGC(x11_dpy, x11_gc); 629 XUnmapWindow(x11_dpy, x11_window); 630 XDestroyWindow(x11_dpy, x11_window); 631 XCloseDisplay(x11_dpy); 632 free(x11_screen); 633 } 555 634 #endif 556 635 free(_caca_empty_line); … … 612 691 613 692 #if defined(USE_SLANG) 614 SLsmg_refresh(); 615 #elif defined(USE_NCURSES) 616 refresh(); 617 #elif defined(USE_CONIO) 693 if(_caca_driver == CACA_DRIVER_SLANG) 694 { 695 SLsmg_refresh(); 696 } 697 else 698 #endif 699 #if defined(USE_NCURSES) 700 if(_caca_driver == CACA_DRIVER_NCURSES) 701 { 702 refresh(); 703 } 704 else 705 #endif 706 #if defined(USE_CONIO) 707 if(_caca_driver == CACA_DRIVER_CONIO) 708 { 618 709 # if defined(SCREENUPDATE_IN_PC_H) 619 ScreenUpdate(conio_screen);710 ScreenUpdate(conio_screen); 620 711 # else 621 /* FIXME */712 /* FIXME */ 622 713 # endif 623 #elif defined(USE_X11) 624 unsigned int x, y; 625 626 for(y = 0; y < _caca_height; y++) 627 for(x = 0; x < _caca_width; x++) 628 { 629 int item = x11_screen[x + y * _caca_width]; 630 char data = item >> 8; 631 XSetForeground(x11_dpy, x11_gc, x11_colors[(item >> 4) & 0xf]); 632 XFillRectangle(x11_dpy, x11_pixmap, x11_gc, 633 x * x11_font_width, y * x11_font_height, 634 x11_font_width, x11_font_height); 635 XSetForeground(x11_dpy, x11_gc, x11_colors[item & 0xf]); 636 XDrawString(x11_dpy, x11_pixmap, x11_gc, x * x11_font_width, 637 (y + 1) * x11_font_height - x11_font_offset, &data, 1); 638 } 639 XCopyArea(x11_dpy, x11_pixmap, x11_window, x11_gc, 0, 0, 640 _caca_width * x11_font_width, _caca_height * x11_font_height, 641 0, 0); 642 XFlush(x11_dpy); 714 } 715 else 716 #endif 717 #if defined(USE_X11) 718 if(_caca_driver == CACA_DRIVER_X11) 719 { 720 unsigned int x, y; 721 722 for(y = 0; y < _caca_height; y++) 723 for(x = 0; x < _caca_width; x++) 724 { 725 int item = x11_screen[x + y * _caca_width]; 726 char data = item >> 8; 727 XSetForeground(x11_dpy, x11_gc, x11_colors[(item >> 4) & 0xf]); 728 XFillRectangle(x11_dpy, x11_pixmap, x11_gc, 729 x * x11_font_width, y * x11_font_height, 730 x11_font_width, x11_font_height); 731 XSetForeground(x11_dpy, x11_gc, x11_colors[item & 0xf]); 732 XDrawString(x11_dpy, x11_pixmap, x11_gc, x * x11_font_width, 733 (y + 1) * x11_font_height - x11_font_offset, 734 &data, 1); 735 } 736 XCopyArea(x11_dpy, x11_pixmap, x11_window, x11_gc, 0, 0, 737 _caca_width * x11_font_width, _caca_height * x11_font_height, 738 0, 0); 739 XFlush(x11_dpy); 740 } 643 741 #endif 644 742 -
libcaca/trunk/src/io.c
r263 r265 32 32 #if defined(USE_SLANG) 33 33 # include <slang.h> 34 #elif defined(USE_NCURSES) 34 #endif 35 #if defined(USE_NCURSES) 35 36 # include <curses.h> 36 #elif defined(USE_CONIO) 37 #endif 38 #if defined(USE_CONIO) 37 39 # include <conio.h> 38 #elif defined(USE_X11) 40 #endif 41 #if defined(USE_X11) 39 42 # include <X11/Xlib.h> 40 43 # include <X11/Xutil.h> 41 #else42 # error "no graphics library detected"43 44 #endif 44 45 … … 76 77 77 78 #if defined(USE_NCURSES) 78 if(keybuf[0] == KEY_MOUSE) 79 { 80 MEVENT mevent; 81 _pop_key(); 82 getmouse(&mevent); 83 84 event |= (1) << 16; 85 event |= (mevent.x) << 8; 86 event |= (mevent.y) << 0; 87 88 return CACA_EVENT_MOUSE_CLICK | event; 89 } 90 91 switch(keybuf[0]) 92 { 93 case KEY_UP: event = CACA_EVENT_KEY_PRESS | CACA_KEY_UP; break; 94 case KEY_DOWN: event = CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN; break; 95 case KEY_LEFT: event = CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT; break; 96 case KEY_RIGHT: event = CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT; break; 97 98 case KEY_F(1): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F1; break; 99 case KEY_F(2): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F2; break; 100 case KEY_F(3): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F3; break; 101 case KEY_F(4): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F4; break; 102 case KEY_F(5): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F5; break; 103 case KEY_F(6): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F6; break; 104 case KEY_F(7): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F7; break; 105 case KEY_F(8): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F8; break; 106 case KEY_F(9): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F9; break; 107 case KEY_F(10): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F10; break; 108 case KEY_F(11): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F11; break; 109 case KEY_F(12): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F12; break; 110 } 111 112 if(event) 113 { 114 _pop_key(); 115 return event; 79 if(_caca_driver == CACA_DRIVER_NCURSES) 80 { 81 if(keybuf[0] == KEY_MOUSE) 82 { 83 MEVENT mevent; 84 _pop_key(); 85 getmouse(&mevent); 86 87 event |= (1) << 16; 88 event |= (mevent.x) << 8; 89 event |= (mevent.y) << 0; 90 91 return CACA_EVENT_MOUSE_CLICK | event; 92 } 93 94 switch(keybuf[0]) 95 { 96 case KEY_UP: event = CACA_EVENT_KEY_PRESS | CACA_KEY_UP; break; 97 case KEY_DOWN: event = CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN; break; 98 case KEY_LEFT: event = CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT; break; 99 case KEY_RIGHT: event = CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT; break; 100 101 case KEY_F(1): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F1; break; 102 case KEY_F(2): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F2; break; 103 case KEY_F(3): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F3; break; 104 case KEY_F(4): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F4; break; 105 case KEY_F(5): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F5; break; 106 case KEY_F(6): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F6; break; 107 case KEY_F(7): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F7; break; 108 case KEY_F(8): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F8; break; 109 case KEY_F(9): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F9; break; 110 case KEY_F(10): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F10; break; 111 case KEY_F(11): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F11; break; 112 case KEY_F(12): event = CACA_EVENT_KEY_PRESS | CACA_KEY_F12; break; 113 } 114 115 if(event) 116 { 117 _pop_key(); 118 return event; 119 } 116 120 } 117 121 #endif … … 206 210 static unsigned int _read_key(void) 207 211 { 208 #if defined(USE_SLANG) 209 return SLang_input_pending(0) ? SLang_getkey() : 0; 210 #elif defined(USE_NCURSES) 211 int key = getch(); 212 return (key == ERR) ? 0 : key; 213 #elif defined(USE_CONIO) 214 return _conio_kbhit() ? getch() : 0; 215 #elif defined(USE_X11) 212 #if defined(USE_NCURSES) 213 int intkey; 214 #endif 215 #if defined(USE_X11) 216 216 XEvent event; 217 217 char key; 218 219 while(XCheckWindowEvent(x11_dpy, x11_window, KeyPressMask, &event) 220 == True) 221 { 222 if(event.type == KeyPress) 223 { 224 //KeySym keysym; 225 //keysym = XKeycodeToKeysym(_caca_dpy, event.xkey.keycode, 0); 226 if(XLookupString(&event.xkey, &key, 1, NULL, NULL)) 227 return key; 228 } 218 #endif 219 220 switch(_caca_driver) 221 { 222 #if defined(USE_SLANG) 223 case CACA_DRIVER_SLANG: 224 return SLang_input_pending(0) ? SLang_getkey() : 0; 225 #endif 226 #if defined(USE_NCURSES) 227 case CACA_DRIVER_NCURSES: 228 intkey = getch(); 229 return (intkey == ERR) ? 0 : intkey; 230 #endif 231 #if defined(USE_CONIO) 232 case CACA_DRIVER_CONIO: 233 return _conio_kbhit() ? getch() : 0; 234 #endif 235 #if defined(USE_X11) 236 case CACA_DRIVER_X11: 237 while(XCheckWindowEvent(x11_dpy, x11_window, KeyPressMask, &event) 238 == True) 239 { 240 if(event.type == KeyPress) 241 { 242 //KeySym keysym; 243 //keysym = XKeycodeToKeysym(_caca_dpy, event.xkey.keycode, 0); 244 if(XLookupString(&event.xkey, &key, 1, NULL, NULL)) 245 return key; 246 } 247 } 248 249 return 0; 250 #endif 251 default: 252 break; 229 253 } 230 254 231 255 return 0; 232 #endif 233 } 234 256 } 257 -
libcaca/trunk/src/line.c
r257 r265 31 31 #include "config.h" 32 32 33 #if def HAVE_INTTYPES_H33 #if defined(HAVE_INTTYPES_H) 34 34 # include <inttypes.h> 35 35 #else
Note: See TracChangeset
for help on using the changeset viewer.