Changeset 263
- Timestamp:
- Dec 20, 2003, 1:07:56 PM (17 years ago)
- Location:
- libcaca/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/caca_internals.h
r251 r263 45 45 #if defined(USE_X11) 46 46 #include <X11/Xlib.h> 47 extern Display * _caca_dpy;48 extern Window _caca_window;47 extern Display *x11_dpy; 48 extern Window x11_window; 49 49 #endif 50 50 -
libcaca/trunk/src/graphics.c
r261 r263 63 63 * Global variables 64 64 */ 65 unsigned int _caca_width ;66 unsigned int _caca_height ;65 unsigned int _caca_width = 0; 66 unsigned int _caca_height = 0; 67 67 68 68 /* … … 70 70 */ 71 71 #if defined(USE_NCURSES) 72 static int _caca_attr[16*16];72 static int ncurses_attr[16*16]; 73 73 #endif 74 74 75 75 #if defined(USE_CONIO) 76 static struct text_info ti;77 static char * _caca_screen;76 static struct text_info conio_ti; 77 static char *conio_screen; 78 78 #endif 79 79 80 80 #if defined(USE_X11) 81 Display *_caca_dpy; 82 Window _caca_window; 83 GC _caca_gc; 84 XImage _caca_image; 85 static int *_caca_screen; 86 int _caca_colors[16]; 81 Display *x11_dpy; 82 Window x11_window; 83 static GC x11_gc; 84 static Pixmap x11_pixmap; 85 static int *x11_screen; 86 static int x11_colors[16]; 87 static Font x11_font; 88 static XFontStruct *x11_font_struct; 89 static int x11_font_width, x11_font_height, x11_font_offset; 87 90 #endif 88 91 … … 113 116 SLsmg_set_color((bgcolor + 16 * fgcolor) /*% 128*/); 114 117 #elif defined(USE_NCURSES) 115 attrset( _caca_attr[fgcolor + 16 * bgcolor]);118 attrset(ncurses_attr[fgcolor + 16 * bgcolor]); 116 119 #elif defined(USE_CONIO) 117 120 textbackground(bgcolor); … … 166 169 addch(c); 167 170 #elif defined(USE_CONIO) 168 data = _caca_screen + 2 * (x + y * _caca_width);171 data = conio_screen + 2 * (x + y * _caca_width); 169 172 data[0] = c; 170 173 data[1] = (_caca_bgcolor << 4) | _caca_fgcolor; … … 172 175 // putch(c); 173 176 #elif defined(USE_X11) 174 _caca_screen[x + y * _caca_width] =177 x11_screen[x + y * _caca_width] = 175 178 ((int)c << 8) | ((int)_caca_bgcolor << 4) | (int)_caca_fgcolor; 176 179 #endif … … 222 225 addstr(s); 223 226 #elif defined(USE_CONIO) 224 buf = _caca_screen + 2 * (x + y * _caca_width);227 buf = conio_screen + 2 * (x + y * _caca_width); 225 228 while(*s) 226 229 { … … 231 234 // cputs(s); 232 235 #elif defined(USE_X11) 233 buf = _caca_screen + x + y * _caca_width;236 buf = x11_screen + x + y * _caca_width; 234 237 while(*s) 235 238 *buf++ = ((int)*s++ << 8) | ((int)_caca_bgcolor << 4) | (int)_caca_fgcolor; … … 378 381 int col = ((max + 7 - fg) % max) + max * bg; 379 382 init_pair(col, curses_colors[fg], curses_colors[bg]); 380 _caca_attr[fg + 16 * bg] = COLOR_PAIR(col);383 ncurses_attr[fg + 16 * bg] = COLOR_PAIR(col); 381 384 382 385 if(max == 8) 383 386 { 384 387 /* Bright fg on simple bg */ 385 _caca_attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);388 ncurses_attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col); 386 389 /* Simple fg on bright bg */ 387 _caca_attr[fg + 16 * (bg + 8)] = A_BLINK | COLOR_PAIR(col);390 ncurses_attr[fg + 16 * (bg + 8)] = A_BLINK | COLOR_PAIR(col); 388 391 /* Bright fg on bright bg */ 389 _caca_attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD390 392 ncurses_attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD 393 | COLOR_PAIR(col); 391 394 } 392 395 } … … 396 399 397 400 #elif defined(USE_CONIO) 398 gettextinfo(&ti); 399 _caca_screen = malloc(2 * ti.screenwidth * ti.screenheight * sizeof(char)); 400 if(_caca_screen == NULL) 401 gettextinfo(&conio_ti); 402 conio_screen = malloc(2 * conio_ti.screenwidth 403 * conio_ti.screenheight * sizeof(char)); 404 if(conio_screen == NULL) 401 405 return -1; 402 406 # if defined(SCREENUPDATE_IN_PC_H) 403 ScreenRetrieve( _caca_screen);407 ScreenRetrieve(conio_screen); 404 408 # else 405 409 /* FIXME */ 406 410 # endif 407 _caca_width = ti.screenwidth;408 _caca_height = ti.screenheight;409 410 #elif defined(USE_X11) 411 static int x11_ colors[] =411 _caca_width = conio_ti.screenwidth; 412 _caca_height = conio_ti.screenheight; 413 414 #elif defined(USE_X11) 415 static int x11_palette[] = 412 416 { 413 417 /* Standard curses colours */ … … 431 435 }; 432 436 437 Colormap colormap; 438 const char *font_name = "8x13bold"; 433 439 int i; 434 Colormap colormap; 435 436 /* FIXME */ 437 _caca_width = 80; 438 _caca_height = 30; 439 440 _caca_screen = malloc(_caca_width * _caca_height * sizeof(int)); 441 if(_caca_screen == NULL) 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 = 25; 450 451 x11_screen = malloc(_caca_width * _caca_height * sizeof(int)); 452 if(x11_screen == NULL) 442 453 return -1; 443 454 444 _caca_dpy = XOpenDisplay(NULL);445 if( _caca_dpy == NULL)446 { 447 free( _caca_screen);455 x11_dpy = XOpenDisplay(NULL); 456 if(x11_dpy == NULL) 457 { 458 free(x11_screen); 448 459 return -1; 449 460 } 450 461 451 colormap = DefaultColormap(_caca_dpy, DefaultScreen(_caca_dpy)); 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)); 452 488 for(i = 0; i < 16; i++) 453 489 { 454 490 XColor color; 455 color.red = x11_colors[i * 3]; 456 color.green = x11_colors[i * 3 + 1]; 457 color.blue = x11_colors[i * 3 + 2]; 458 XAllocColor(_caca_dpy, colormap, &color); 459 _caca_colors[i] = color.pixel; 460 } 461 462 _caca_window = XCreateSimpleWindow(_caca_dpy, DefaultRootWindow(_caca_dpy), 463 0, 0, 400, 300, 0, 464 _caca_colors[0], _caca_colors[0]); 465 XSelectInput(_caca_dpy, _caca_window, StructureNotifyMask); 466 XMapWindow(_caca_dpy, _caca_window); 467 468 _caca_gc = XCreateGC(_caca_dpy, _caca_window, 0, NULL); 469 XSetForeground(_caca_dpy, _caca_gc, _caca_colors[15]); 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); 470 508 471 509 for(;;) 472 510 { 473 511 XEvent event; 474 XNextEvent( _caca_dpy, &event);512 XNextEvent(x11_dpy, &event); 475 513 if (event.type == MapNotify) 476 514 break; 477 515 } 478 516 479 XSelectInput(_caca_dpy, _caca_window, KeyPressMask); 480 481 XSync(_caca_dpy, False); 482 483 //_caca_image = 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))); 484 525 #endif 485 526 _caca_empty_line = malloc(_caca_width + 1); … … 502 543 /* Nothing to do */ 503 544 #elif defined(USE_CONIO) 504 free(_caca_screen); 505 #elif defined(USE_X11) 506 XSync(_caca_dpy, False); 507 XFreeGC(_caca_dpy, _caca_gc); 508 XUnmapWindow(_caca_dpy, _caca_window); 509 XDestroyWindow(_caca_dpy, _caca_window); 510 XCloseDisplay(_caca_dpy); 511 free(_caca_screen); 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); 512 555 #endif 513 556 free(_caca_empty_line); … … 574 617 #elif defined(USE_CONIO) 575 618 # if defined(SCREENUPDATE_IN_PC_H) 576 ScreenUpdate( _caca_screen);619 ScreenUpdate(conio_screen); 577 620 # else 578 621 /* FIXME */ 579 622 # endif 580 623 #elif defined(USE_X11) 581 int x, y;624 unsigned int x, y; 582 625 583 626 for(y = 0; y < _caca_height; y++) 584 627 for(x = 0; x < _caca_width; x++) 585 628 { 586 int item = _caca_screen[x + y * _caca_width];629 int item = x11_screen[x + y * _caca_width]; 587 630 char data = item >> 8; 588 XSetForeground(_caca_dpy, _caca_gc, _caca_colors[(item >> 4) & 0xf]); 589 XFillRectangle(_caca_dpy, _caca_window, _caca_gc, 590 x * 6, y * 12, 6, 12); 591 XSetForeground(_caca_dpy, _caca_gc, _caca_colors[item & 0xf]); 592 XDrawString(_caca_dpy, _caca_window, _caca_gc, 593 x * 6, y * 12 + 10, &data, 1); 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); 594 638 } 595 XFlush(_caca_dpy); 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); 596 643 #endif 597 644 -
libcaca/trunk/src/io.c
r257 r263 217 217 char key; 218 218 219 while(XCheckWindowEvent( _caca_dpy, _caca_window, KeyPressMask, &event)219 while(XCheckWindowEvent(x11_dpy, x11_window, KeyPressMask, &event) 220 220 == True) 221 221 {
Note: See TracChangeset
for help on using the changeset viewer.