Explorar el Código

* NOTES:

+ Added setab/setaf quotes from the XTerm terminfo.
    + Proposed a workaround for bright colours on any terminal.
  * src/caca.c:
    + 16 colour support for ncurses and conio.
  * src/graphics.c:
    + Ported to 16 colour support.
    + Added a missing <stdio.h> for BUFSIZ.
    + Disabled vsnprintf under DOS (only vsprintf exists).
  * examples/:
    + Don't abort if the caca.txt sprite was not found.
    + Ported to 16 colour support.
tags/v0.99.beta14
Sam Hocevar sam hace 21 años
padre
commit
83d606583e
Se han modificado 8 ficheros con 192 adiciones y 95 borrados
  1. +38
    -6
      NOTES
  2. +48
    -40
      examples/demo.c
  3. +3
    -3
      examples/spritedit.c
  4. +2
    -0
      src/bitmap.c
  5. +55
    -27
      src/caca.c
  6. +4
    -2
      src/caca.h
  7. +36
    -13
      src/graphics.c
  8. +6
    -4
      src/sprite.c

+ 38
- 6
NOTES Ver fichero

@@ -4,6 +4,25 @@ $Id$
many terminal emulators and tried to summarise which combinations
worked properly and which ones did not.

From termcap(5):

set_a_background setab AB Set background
color to #1, using
ANSI escape
set_a_foreground setaf AF Set foreground
color to #1, using
ANSI escape
From the xterm terminfo:

setab=\E[4%p1%dm, setaf=\E[3%p1%dm

From the xterm-16color terminfo:

setab=\E[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm,
setaf=\E[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm,

(http://www.sct.gu.edu.au/~anthony/info/X/Xterm_xf86.terminfo)

o I tested the following terminals:

name $TERM $COLORTERM
@@ -20,8 +39,8 @@ $Id$
uxterm xterm

o In most terminals, \e[3xm and \[4xm respectively set the foreground
and background colours. x is an colour between 0 and 7 or the value
9 for default value.
and background colours. x is a colour between 0 and 7 or the value
9 for default colour (may be transparent).

\e[0m sets everything to normal, \e[1m sets bold, \e[5m sets blink
and \e[7m sets inverse video.
@@ -35,7 +54,7 @@ $Id$
for invert in '' '\e[7m'; do
for blink in '' '\e[5m'; do
for bold in '' '\e[1m'; do
echo -ne "$bold$blink$invert"'\e[34m\e[43m'hop'\e[0m '
echo -ne "$bold$blink$invert"'\e[33m\e[44m'hop'\e[0m '
echo "($bold$blink$invert)"
done
done
@@ -48,7 +67,8 @@ $Id$
+ aterm, wterm, rxvt

Almost works on:
+ xterm (bright bg works for blue, but not for red or yellow)
+ xterm (bright bg only works when fg is bright and then inverted,
but then fg is not bright)

Fails on:
+ mlterm (no bright colours, neither fg nor bg)
@@ -74,11 +94,23 @@ $Id$
+ xterm
+ pterm

Failed (\e[9x and \e[10x don't work) on:
Failed (\e[9x and \e[10x don't do anything) on:
+ Eterm
+ aterm, wterm, rxvt
+ mlterm
+ linux
+ Linux console

o How to draw bright colours on any terminal?

'\e[93;104m' -> bright yellow on bright blue
doesn't work on mlterm, gnome-terminal, konsole

'\e[5;1;33;44m' -> bright yellow on bright blue
doesn't work on mlterm, aterm/wterm/rxvt, Eterm, console

'\e[5;1;33;44;93;104m' -> bright yellow on bright blue
works on gnome-terminal, xterm, pterm, aterm/wterm/rxvt, console
doesn't work on konsole

o S-Lang:



+ 48
- 40
examples/demo.c Ver fichero

@@ -62,8 +62,6 @@ int main(int argc, char **argv)
sprite = caca_load_sprite("caca.txt");
if(!sprite)
sprite = caca_load_sprite("examples/caca.txt");
if(!sprite)
return 1;

/* Main menu */
display_menu();
@@ -132,13 +130,11 @@ int main(int argc, char **argv)
break;
case 's':
case 'S':
demo = demo_sprites;
if(sprite)
demo = demo_sprites;
break;
}

if(demo)
caca_clear();

handle_event:
event = caca_get_event();
if(event & CACA_EVENT_KEY_PRESS)
@@ -147,11 +143,14 @@ int main(int argc, char **argv)
goto handle_event;

caca_refresh();

if(demo)
caca_clear();
}
else if(event & CACA_EVENT_MOUSE_CLICK)
{
display_menu();
caca_set_color(CACA_COLOR_RED);
caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
caca_putstr((event & 0xff00) >> 8, event & 0xff, "|\\");
caca_refresh();
}
@@ -160,7 +159,7 @@ int main(int argc, char **argv)
{
demo();

caca_set_color(CACA_COLOR_WHITE);
caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
caca_draw_thin_box(1, 1, caca_get_width() - 2, caca_get_height() - 2);
caca_printf(4, 1, "[%i.%i fps]----",
1000000 / caca_get_rendertime(),
@@ -182,7 +181,7 @@ static void display_menu(void)
int yo = caca_get_height() - 2;

caca_clear();
caca_set_color(CACA_COLOR_WHITE);
caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
caca_draw_thin_box(1, 1, xo, yo);

caca_putstr((xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
@@ -195,15 +194,16 @@ static void display_menu(void)
caca_putstr(4, 10, "'3': boxes");
caca_putstr(4, 11, "'4': triangles");
caca_putstr(4, 12, "'5': ellipses");
caca_putstr(4, 13, "'s': sprites");
caca_putstr(4, 14, "'c': color");
caca_putstr(4, 13, "'c': colour");
if(sprite)
caca_putstr(4, 14, "'s': sprites");

caca_putstr(4, 17, "settings:");
caca_printf(4, 18, "'o': outline: %s",
caca_putstr(4, 16, "settings:");
caca_printf(4, 17, "'o': outline: %s",
outline == 0 ? "none" : outline == 1 ? "solid" : "thin");
caca_printf(4, 19, "'b': drawing boundaries: %s",
caca_printf(4, 18, "'b': drawing boundaries: %s",
bounds == 0 ? "screen" : "infinite");
caca_printf(4, 20, "'d': %s dithering",
caca_printf(4, 19, "'d': %s dithering",
dithering == 0 ? "no" : dithering == 1 ? "ordered" : "random");

caca_putstr(4, yo - 2, "'q': quit");
@@ -220,7 +220,7 @@ static void demo_all(void)
caca_clear();

/* Draw the sun */
caca_set_color(CACA_COLOR_YELLOW);
caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
xo = caca_get_width() / 4;
yo = caca_get_height() / 4 + 5 * sin(0.03*i);

@@ -232,9 +232,9 @@ static void demo_all(void)
}

j = 15 + sin(0.03*i) * 8;
caca_set_color(CACA_COLOR_WHITE);
caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLACK);
caca_fill_ellipse(xo, yo, j, j / 2, '#');
caca_set_color(CACA_COLOR_YELLOW);
caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
caca_draw_ellipse(xo, yo, j, j / 2, '#');

/* Draw the pyramid */
@@ -250,19 +250,19 @@ static void demo_all(void)
xc = caca_get_width() / 4 - sin(0.02*i) * 5;
yc = caca_get_height() * 3 / 4 + cos(0.02*i) * 5;

caca_set_color(CACA_COLOR_GREEN);
caca_set_color(CACA_COLOR_GREEN, CACA_COLOR_BLACK);
caca_fill_triangle(xo, yo, xb, yb, xa, ya, '%');
caca_set_color(CACA_COLOR_YELLOW);
caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
caca_draw_thin_triangle(xo, yo, xb, yb, xa, ya);

caca_set_color(CACA_COLOR_RED);
caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#');
caca_set_color(CACA_COLOR_YELLOW);
caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);

caca_set_color(CACA_COLOR_BLUE);
caca_set_color(CACA_COLOR_BLUE, CACA_COLOR_BLACK);
caca_fill_triangle(xo, yo, xb, yb, xc, yc, '%');
caca_set_color(CACA_COLOR_YELLOW);
caca_set_color(CACA_COLOR_YELLOW, CACA_COLOR_BLACK);
caca_draw_thin_triangle(xo, yo, xb, yb, xc, yc);

/* Draw a background triangle */
@@ -275,7 +275,7 @@ static void demo_all(void)
xc = caca_get_width() / 3;
yc = caca_get_height() - 3;

caca_set_color(CACA_COLOR_CYAN);
caca_set_color(CACA_COLOR_CYAN, CACA_COLOR_BLACK);
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);

xo = caca_get_width() / 2 + cos(0.027*i) * caca_get_width() / 3;
@@ -292,7 +292,7 @@ static void demo_all(void)
for(j = i - 60; j < i; j++)
{
int delta = caca_rand(-5, 5);
caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
caca_putchar(caca_get_width() / 2
+ cos(0.02*j) * (delta + caca_get_width() / 4),
caca_get_height() / 2
@@ -311,28 +311,36 @@ static void demo_dots(void)
int xmax = caca_get_width() - 1;
int ymax = caca_get_height() - 1;
int i;
static char chars[10] =
{
'+', '-', '*', '#', 'X', '@', '%', '$', 'M', 'W'
};

for(i = 1000; i--;)
{
/* Putpixel */
caca_set_color(caca_rand(0, 15));
caca_putchar(caca_rand(0, xmax), caca_rand(0, ymax), '#');
caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
caca_putchar(caca_rand(0, xmax), caca_rand(0, ymax),
chars[caca_rand(0, 9)]);
}
}

static void demo_color(void)
{
int i;
int i, j;
char buf[BUFSIZ];

caca_clear();
for(i = 0; i < 16; i++)
{
sprintf(buf, "'%c': %i (%s)", 'a' + i, i, caca_get_color_name(i));
caca_set_color(CACA_COLOR_WHITE);
caca_putstr(4, i + 3, buf);
caca_set_color(i);
caca_putstr(40, i + 3, "XXXXXXXXXX-XX--X----------");
caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
caca_putstr(4, i + (i >= 8 ? 4 : 3), buf);
for(j = 0; j < 16; j++)
{
caca_set_color(i, j);
caca_putstr((j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# ");
}
}
}

@@ -353,7 +361,7 @@ static void demo_lines(void)
xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
}

caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
if(outline > 1)
caca_draw_thin_line(xa, ya, xb, yb);
else
@@ -377,10 +385,10 @@ static void demo_boxes(void)
xb = caca_rand(0, w - 1); yb = caca_rand(0, h - 1);
}

caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
caca_fill_box(xa, ya, xb, yb, '#');

caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
if(outline == 2)
caca_draw_thin_box(xa, ya, xb, yb);
else if(outline == 1)
@@ -408,10 +416,10 @@ static void demo_ellipses(void)
} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
}

caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
caca_fill_ellipse(x, y, a, b, '#');

caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
if(outline == 2)
caca_draw_thin_ellipse(x, y, a, b);
else if(outline == 1)
@@ -438,10 +446,10 @@ static void demo_triangles(void)
xc = caca_rand(0, w - 1); yc = caca_rand(0, h - 1);
}

caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), caca_rand(0, 15));
caca_fill_triangle(xa, ya, xb, yb, xc, yc, '#');

caca_set_color(caca_rand(0, 15));
caca_set_color(caca_rand(0, 15), CACA_COLOR_BLACK);
if(outline == 2)
caca_draw_thin_triangle(xa, ya, xb, yb, xc, yc);
else if(outline == 1)


+ 3
- 3
examples/spritedit.c Ver fichero

@@ -81,7 +81,7 @@ int main(int argc, char **argv)

caca_clear();

caca_set_color(CACA_COLOR_WHITE);
caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
caca_draw_thin_box(0, 0, caca_get_width() - 1, caca_get_height() - 1);

caca_putstr(3, 0, "[ Sprite editor for libcaca ]");
@@ -101,9 +101,9 @@ int main(int argc, char **argv)
ya = -1 - caca_get_sprite_dy(sprite, frame);
xb = xa + 1 + caca_get_sprite_width(sprite, frame);
yb = ya + 1 + caca_get_sprite_height(sprite, frame);
caca_set_color(CACA_COLOR_BLACK);
caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_BLACK);
caca_fill_box(57 + xa, 10 + ya, 57 + xb, 10 + yb, ' ');
caca_set_color(CACA_COLOR_WHITE);
caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
caca_draw_thin_box(57 + xa, 10 + ya, 57 + xb, 10 + yb);
caca_draw_sprite(57, 10, sprite, frame);



+ 2
- 0
src/bitmap.c Ver fichero

@@ -33,6 +33,8 @@
# include <inttypes.h>
#else
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#endif

#include <stdlib.h>


+ 55
- 27
src/caca.c Ver fichero

@@ -61,7 +61,7 @@ char *_caca_scratch_line;

#if defined(USE_NCURSES)
static mmask_t oldmask;
int _caca_attr[16];
int _caca_attr[16*16];
#endif

#if defined(USE_CONIO)
@@ -72,6 +72,7 @@ char *_caca_screen;
int caca_init(void)
{
#if defined(USE_SLANG)
/* See SLang ref., 5.4.4. */
static char *slang_colors[16] =
{
"black",
@@ -92,7 +93,7 @@ int caca_init(void)
"white",
};

int i;
int fg, bg;

/* Initialize slang library */
SLsig_block_signals();
@@ -120,11 +121,36 @@ int caca_init(void)
SLtt_set_mouse_mode(1, 0);
SLsmg_refresh();

for(i = 0; i < 16; i++)
SLtt_set_color(i + 1, NULL, slang_colors[i], "black");
for(bg = 0; bg < 16; bg++)
for(fg = 0; fg < 16; fg++)
{
int i = fg + 16 * bg;
SLtt_set_color(i, NULL, slang_colors[fg], slang_colors[bg]);
}

#elif defined(USE_NCURSES)
int i;
static int curses_colors[] =
{
COLOR_BLACK,
COLOR_BLUE,
COLOR_GREEN,
COLOR_CYAN,
COLOR_RED,
COLOR_MAGENTA,
COLOR_YELLOW,
COLOR_WHITE,
/* Extra values for xterm-16color */
COLOR_BLACK + 8,
COLOR_BLUE + 8,
COLOR_GREEN + 8,
COLOR_CYAN + 8,
COLOR_RED + 8,
COLOR_MAGENTA + 8,
COLOR_YELLOW + 8,
COLOR_WHITE + 8
};

int fg, bg, max;
mmask_t newmask;

initscr();
@@ -135,33 +161,35 @@ int caca_init(void)
nodelay(stdscr, TRUE);
curs_set(0);

/* Activate mouse */
newmask = ALL_MOUSE_EVENTS;
mousemask(newmask, &oldmask);

/* Activate colour */
start_color();

init_pair(1 + CACA_COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
init_pair(1 + CACA_COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(1 + CACA_COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(1 + CACA_COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(1 + CACA_COLOR_RED, COLOR_RED, COLOR_BLACK);
init_pair(1 + CACA_COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(1 + CACA_COLOR_BROWN, COLOR_YELLOW, COLOR_BLACK);
init_pair(1 + CACA_COLOR_LIGHTGRAY, COLOR_WHITE, COLOR_BLACK);
init_pair(1 + CACA_COLOR_DARKGRAY, COLOR_BLACK, COLOR_BLACK);
init_pair(1 + CACA_COLOR_LIGHTBLUE, COLOR_BLUE, COLOR_BLACK);
init_pair(1 + CACA_COLOR_LIGHTGREEN, COLOR_GREEN, COLOR_BLACK);
init_pair(1 + CACA_COLOR_LIGHTCYAN, COLOR_CYAN, COLOR_BLACK);
init_pair(1 + CACA_COLOR_LIGHTRED, COLOR_RED, COLOR_BLACK);
init_pair(1 + CACA_COLOR_LIGHTMAGENTA, COLOR_MAGENTA, COLOR_BLACK);
init_pair(1 + CACA_COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
init_pair(1 + CACA_COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
for(i = 0; i < 8; i++)
{
_caca_attr[i] = COLOR_PAIR(1 + i);
_caca_attr[i + 8] = A_BOLD | COLOR_PAIR(1 + i);
}
max = COLORS >= 16 ? 16 : 8;
for(bg = 0; bg < max; bg++)
for(fg = 0; fg < max; fg++)
{
/* Use ((max + 7 - fg) % max) instead of fg so that colour 0
* is light gray on black, since some terminals don't like
* this colour pair to be redefined. */
int col = ((max + 7 - fg) % max) + max * bg;
init_pair(col, curses_colors[fg], curses_colors[bg]);
_caca_attr[fg + 16 * bg] = COLOR_PAIR(col);
if(max == 8)
{
/* Bright fg on simple bg */
_caca_attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
/* Simple fg on bright bg */
_caca_attr[fg + 16 * (bg + 8)] = A_BLINK | COLOR_PAIR(col);
/* Bright fg on bright bg */
_caca_attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD | COLOR_PAIR(col);
}
}

#elif defined(USE_CONIO)
gettextinfo(&ti);


+ 4
- 2
src/caca.h Ver fichero

@@ -150,8 +150,9 @@ unsigned int caca_get_event(void);
/*
* Character graphics
*/
void caca_set_color(enum caca_color);
enum caca_color caca_get_color(void);
void caca_set_color(enum caca_color, enum caca_color);
enum caca_color caca_get_fg_color(void);
enum caca_color caca_get_bg_color(void);
void caca_putchar(int, int, char);
void caca_putstr(int, int, const char *);
void caca_printf(int, int, const char *, ...);
@@ -202,6 +203,7 @@ void caca_free_sprite(struct caca_sprite *);
*/
struct caca_bitmap;
struct caca_bitmap *caca_create_bitmap(int, int, int, int, int, int, int);
void caca_set_bitmap_palette(struct caca_bitmap *, int[], int[], int[]);
void caca_draw_bitmap(int, int, int, int, struct caca_bitmap *, char *);
void caca_free_bitmap(struct caca_bitmap *);



+ 36
- 13
src/graphics.c Ver fichero

@@ -39,6 +39,7 @@
# error "no graphics library detected"
#endif

#include <stdio.h> /* BUFSIZ */
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -46,30 +47,41 @@
#include "caca.h"
#include "caca_internals.h"

static enum caca_color _caca_color = CACA_COLOR_WHITE;
static enum caca_color _caca_fgcolor = CACA_COLOR_LIGHTGRAY;
static enum caca_color _caca_bgcolor = CACA_COLOR_BLACK;

void caca_set_color(enum caca_color color)
void caca_set_color(enum caca_color fgcolor, enum caca_color bgcolor)
{
if(color < 0 || color > 15)
if(fgcolor < 0 || fgcolor > 15 || bgcolor < 0 || bgcolor > 15)
return;

_caca_color = color;
_caca_fgcolor = fgcolor;
_caca_bgcolor = bgcolor;
#if defined(USE_SLANG)
SLsmg_set_color(color + 1);
SLsmg_set_color(fgcolor + 16 * bgcolor);
#elif defined(USE_NCURSES)
attrset(_caca_attr[color]);
attrset(_caca_attr[fgcolor + 16 * bgcolor]);
#elif defined(USE_CONIO)
textcolor(color);
textbackground(bgcolor);
textcolor(fgcolor);
#endif
}

enum caca_color caca_get_color(void)
enum caca_color caca_get_fg_color(void)
{
return _caca_color;
return _caca_fgcolor;
}

enum caca_color caca_get_bg_color(void)
{
return _caca_bgcolor;
}

void caca_putchar(int x, int y, char c)
{
#if defined(USE_CONIO)
char *data;
#endif
if(x < 0 || x >= (int)caca_get_width() ||
y < 0 || y >= (int)caca_get_height())
return;
@@ -81,8 +93,9 @@ void caca_putchar(int x, int y, char c)
move(y, x);
addch(c);
#elif defined(USE_CONIO)
_caca_screen[2 * (x + y * caca_get_width())] = c;
_caca_screen[2 * (x + y * caca_get_width()) + 1] = _caca_color;
data = _caca_screen + 2 * (x + y * caca_get_width());
data[0] = c;
data[1] = (_caca_bgcolor << 4) | _caca_fgcolor;
// gotoxy(x + 1, y + 1);
// putch(c);
#endif
@@ -124,7 +137,7 @@ void caca_putstr(int x, int y, const char *s)
while(*s)
{
*buf++ = *s++;
*buf++ = _caca_color;
*buf++ = (_caca_bgcolor << 4) | _caca_fgcolor;
}
// gotoxy(x + 1, y + 1);
// cputs(s);
@@ -144,7 +157,11 @@ void caca_printf(int x, int y, const char *format, ...)
buf = malloc(caca_get_width() - x + 1);

va_start(args, format);
#if defined(HAVE_VSNPRINTF)
vsnprintf(buf, caca_get_width() - x + 1, format, args);
#else
vsprintf(buf, format, args);
#endif
buf[caca_get_width() - x] = '\0';
va_end(args);

@@ -156,10 +173,16 @@ void caca_printf(int x, int y, const char *format, ...)

void caca_clear(void)
{
/* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
enum caca_color oldfg = caca_get_fg_color();
enum caca_color oldbg = caca_get_bg_color();
int y = caca_get_height();

caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);

/* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
while(y--)
caca_putstr(0, y, _caca_empty_line);

caca_set_color(oldfg, oldbg);
}


+ 6
- 4
src/sprite.c Ver fichero

@@ -219,7 +219,8 @@ int caca_get_sprite_dy(struct caca_sprite *sprite, int f)

void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f)
{
int i, j, oldcol;
int i, j;
enum caca_color oldfg, oldbg;
struct caca_frame *frame;

if(sprite == NULL)
@@ -230,7 +231,8 @@ void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f)

frame = &sprite->frames[f];

oldcol = caca_get_color();
oldfg = caca_get_fg_color();
oldbg = caca_get_bg_color();

for(j = 0; j < frame->h; j++)
{
@@ -239,14 +241,14 @@ void caca_draw_sprite(int x, int y, struct caca_sprite *sprite, int f)
int col = frame->color[frame->w * j + i];
if(col >= 0)
{
caca_set_color(col);
caca_set_color(col, CACA_COLOR_BLACK);
caca_putchar(x + i - frame->dx, y + j - frame->dy,
frame->chars[frame->w * j + i]);
}
}
}

caca_set_color(oldcol);
caca_set_color(oldfg, oldbg);
}

void caca_free_sprite(struct caca_sprite *sprite)


Cargando…
Cancelar
Guardar