@@ -31,21 +31,21 @@ | |||
static int caca_init_driver(caca_t *kk); | |||
/** \brief Attach a caca graphical context to a cucul backend context. | |||
/** \brief Attach a caca graphical context to a cucul canvas. | |||
* | |||
* Create a graphical context using device-dependent features (ncurses for | |||
* terminals, an X11 window, a DOS command window...) that attaches to a | |||
* libcucul canvas. Everything that gets drawn in the libcucul canvas can | |||
* then be displayed by the libcaca driver. | |||
* | |||
* \param qq The cucul backend context. | |||
* \param c The cucul cavas. | |||
* \return The caca graphical context or NULL if an error occurred. | |||
*/ | |||
caca_t * caca_attach(cucul_t * qq) | |||
caca_t * caca_attach(cucul_canvas_t * c) | |||
{ | |||
caca_t *kk = malloc(sizeof(caca_t)); | |||
kk->qq = qq; | |||
kk->c = c; | |||
if(caca_init_driver(kk)) | |||
{ | |||
@@ -60,7 +60,7 @@ caca_t * caca_attach(cucul_t * qq) | |||
} | |||
/* Attached! */ | |||
kk->qq->refcount++; | |||
kk->c->refcount++; | |||
/* Graphics stuff */ | |||
kk->delay = 0; | |||
@@ -83,8 +83,8 @@ caca_t * caca_attach(cucul_t * qq) | |||
kk->lastticks = 0; | |||
/* Mouse position */ | |||
kk->mouse.x = kk->qq->width / 2; | |||
kk->mouse.y = kk->qq->height / 2; | |||
kk->mouse.x = kk->c->width / 2; | |||
kk->mouse.y = kk->c->height / 2; | |||
/* Resize events */ | |||
kk->resize.resized = 0; | |||
@@ -103,7 +103,7 @@ caca_t * caca_attach(cucul_t * qq) | |||
void caca_detach(caca_t *kk) | |||
{ | |||
kk->drv.end_graphics(kk); | |||
kk->qq->refcount--; | |||
kk->c->refcount--; | |||
free(kk); | |||
} | |||
@@ -100,7 +100,7 @@ typedef struct caca_event caca_event_t; | |||
* | |||
* \li \b CACA_EVENT_NONE: no other field is valid. | |||
* | |||
* \li \b CACA_EVENT_KEY_PRESS, \b CACA_EVENT_KEY_RELEASE: the \e data.key.c | |||
* \li \b CACA_EVENT_KEY_PRESS, \b CACA_EVENT_KEY_RELEASE: the \e data.key.ch | |||
* field is valid and contains either the ASCII value for the key, or | |||
* an \e enum \e caca_key value. If the value is a printable ASCII | |||
* character, the \e data.key.ucs4 and \e data.key.utf8 fields are | |||
@@ -146,7 +146,7 @@ struct caca_event | |||
{ | |||
struct { unsigned int x, y, button; } mouse; | |||
struct { unsigned int w, h; } resize; | |||
struct { unsigned int c; unsigned long int ucs4; char utf8[8]; } key; | |||
struct { unsigned int ch; unsigned long int ucs4; char utf8[8]; } key; | |||
} data; | |||
}; | |||
@@ -203,14 +203,14 @@ enum caca_key | |||
* initialisation, system information retrieval and configuration. | |||
* | |||
* @{ */ | |||
caca_t * caca_attach(cucul_t *qq); | |||
void caca_detach(caca_t *kk); | |||
void caca_set_delay(caca_t *kk, unsigned int); | |||
void caca_display(caca_t *kk); | |||
unsigned int caca_get_rendertime(caca_t *kk); | |||
unsigned int caca_get_window_width(caca_t *kk); | |||
unsigned int caca_get_window_height(caca_t *kk); | |||
int caca_set_window_title(caca_t *kk, char const *); | |||
caca_t * caca_attach(cucul_canvas_t *); | |||
void caca_detach(caca_t *); | |||
void caca_set_delay(caca_t *, unsigned int); | |||
void caca_display(caca_t *); | |||
unsigned int caca_get_rendertime(caca_t *); | |||
unsigned int caca_get_window_width(caca_t *); | |||
unsigned int caca_get_window_height(caca_t *); | |||
int caca_set_window_title(caca_t *, char const *); | |||
/* @} */ | |||
/** \defgroup event Event handling | |||
@@ -219,10 +219,10 @@ int caca_set_window_title(caca_t *kk, char const *); | |||
* clicks. | |||
* | |||
* @{ */ | |||
int caca_get_event(caca_t *kk, unsigned int, caca_event_t *, int); | |||
unsigned int caca_get_mouse_x(caca_t *kk); | |||
unsigned int caca_get_mouse_y(caca_t *kk); | |||
void caca_set_mouse(caca_t *kk, int); | |||
int caca_get_event(caca_t *, unsigned int, caca_event_t *, int); | |||
unsigned int caca_get_mouse_x(caca_t *); | |||
unsigned int caca_get_mouse_y(caca_t *); | |||
void caca_set_mouse(caca_t *, int); | |||
/* @} */ | |||
#ifdef __cplusplus | |||
@@ -93,7 +93,7 @@ struct caca_timer | |||
struct caca | |||
{ | |||
/* A link to our cucul canvas */ | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
/* Device-specific functions */ | |||
struct drv | |||
@@ -56,8 +56,8 @@ static int conio_init_graphics(caca_t *kk) | |||
# else | |||
/* FIXME */ | |||
# endif | |||
_cucul_set_size(kk->qq, kk->drv.p->ti.screenwidth, | |||
kk->drv.p->ti.screenheight); | |||
_cucul_set_size(kk->c, kk->drv.p->ti.screenwidth, | |||
kk->drv.p->ti.screenheight); | |||
return 0; | |||
} | |||
@@ -66,7 +66,7 @@ static int conio_end_graphics(caca_t *kk) | |||
_wscroll = 1; | |||
textcolor((enum COLORS)WHITE); | |||
textbackground((enum COLORS)BLACK); | |||
gotoxy(kk->qq->width, kk->qq->height); | |||
gotoxy(kk->c->width, kk->c->height); | |||
cputs("\r\n"); | |||
_setcursortype(_NORMALCURSOR); | |||
@@ -84,23 +84,23 @@ static int conio_set_window_title(caca_t *kk, char const *title) | |||
static unsigned int conio_get_window_width(caca_t *kk) | |||
{ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->width * 6; | |||
return kk->c->width * 6; | |||
} | |||
static unsigned int conio_get_window_height(caca_t *kk) | |||
{ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->height * 10; | |||
return kk->c->height * 10; | |||
} | |||
static void conio_display(caca_t *kk) | |||
{ | |||
char *screen = kk->drv.p->screen; | |||
uint32_t *attr = kk->qq->attr; | |||
uint32_t *chars = kk->qq->chars; | |||
uint32_t *attr = kk->c->attr; | |||
uint32_t *chars = kk->c->chars; | |||
int n; | |||
for(n = kk->qq->height * kk->qq->width; n--; ) | |||
for(n = kk->c->height * kk->c->width; n--; ) | |||
{ | |||
*screen++ = _cucul_utf32_to_cp437(*chars++); | |||
*screen++ = _cucul_argb32_to_ansi8(*attr++); | |||
@@ -115,8 +115,8 @@ static void conio_display(caca_t *kk) | |||
static void conio_handle_resize(caca_t *kk) | |||
{ | |||
/* We know nothing about our window */ | |||
kk->resize.w = kk->qq->width; | |||
kk->resize.h = kk->qq->height; | |||
kk->resize.w = kk->c->width; | |||
kk->resize.h = kk->c->height; | |||
} | |||
static int conio_get_event(caca_t *kk, caca_event_t *ev) | |||
@@ -133,7 +133,7 @@ static int conio_get_event(caca_t *kk, caca_event_t *ev) | |||
ch = getch(); | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
ev->data.key.c = ch; | |||
ev->data.key.ch = ch; | |||
ev->data.key.ucs4 = (uint32_t)ch; | |||
ev->data.key.utf8[0] = ch; | |||
ev->data.key.utf8[1] = '\0'; | |||
@@ -96,13 +96,13 @@ static int gl_init_graphics(caca_t *kk) | |||
#endif | |||
if(width && height) | |||
_cucul_set_size(kk->qq, width, height); | |||
_cucul_set_size(kk->c, width, height); | |||
kk->drv.p->font_width = 9; | |||
kk->drv.p->font_height = 15; | |||
kk->drv.p->width = kk->qq->width * kk->drv.p->font_width; | |||
kk->drv.p->height = kk->qq->height * kk->drv.p->font_height; | |||
kk->drv.p->width = kk->c->width * kk->drv.p->font_width; | |||
kk->drv.p->height = kk->c->height * kk->drv.p->font_height; | |||
#ifdef HAVE_GLUTCLOSEFUNC | |||
kk->drv.p->close = 0; | |||
@@ -227,7 +227,7 @@ static void gl_display(caca_t *kk) | |||
line = 0; | |||
for(y = 0; y < kk->drv.p->height; y += kk->drv.p->font_height) | |||
{ | |||
uint32_t *attr = kk->qq->attr + line * kk->qq->width; | |||
uint32_t *attr = kk->c->attr + line * kk->c->width; | |||
for(x = 0; x < kk->drv.p->width; x += kk->drv.p->font_width) | |||
{ | |||
@@ -256,8 +256,8 @@ static void gl_display(caca_t *kk) | |||
line = 0; | |||
for(y = 0; y < kk->drv.p->height; y += kk->drv.p->font_height) | |||
{ | |||
uint32_t *attr = kk->qq->attr + line * kk->qq->width; | |||
uint32_t *chars = kk->qq->chars + line * kk->qq->width; | |||
uint32_t *attr = kk->c->attr + line * kk->c->width; | |||
uint32_t *chars = kk->c->chars + line * kk->c->width; | |||
for(x = 0; x < kk->drv.p->width; x += kk->drv.p->font_width) | |||
{ | |||
@@ -333,8 +333,8 @@ static int gl_get_event(caca_t *kk, caca_event_t *ev) | |||
if(kk->resize.resized) | |||
{ | |||
ev->type = CACA_EVENT_RESIZE; | |||
ev->data.resize.w = kk->qq->width; | |||
ev->data.resize.h = kk->qq->height; | |||
ev->data.resize.w = kk->c->width; | |||
ev->data.resize.h = kk->c->height; | |||
return 1; | |||
} | |||
@@ -359,7 +359,7 @@ static int gl_get_event(caca_t *kk, caca_event_t *ev) | |||
if(kk->drv.p->key != 0) | |||
{ | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
ev->data.key.c = kk->drv.p->key; | |||
ev->data.key.ch = kk->drv.p->key; | |||
ev->data.key.ucs4 = (uint32_t)kk->drv.p->key; | |||
ev->data.key.utf8[0] = kk->drv.p->key; | |||
ev->data.key.utf8[1] = '\0'; | |||
@@ -371,22 +371,22 @@ static int gl_get_event(caca_t *kk, caca_event_t *ev) | |||
{ | |||
switch(kk->drv.p->special_key) | |||
{ | |||
case GLUT_KEY_F1 : ev->data.key.c = CACA_KEY_F1; break; | |||
case GLUT_KEY_F2 : ev->data.key.c = CACA_KEY_F2; break; | |||
case GLUT_KEY_F3 : ev->data.key.c = CACA_KEY_F3; break; | |||
case GLUT_KEY_F4 : ev->data.key.c = CACA_KEY_F4; break; | |||
case GLUT_KEY_F5 : ev->data.key.c = CACA_KEY_F5; break; | |||
case GLUT_KEY_F6 : ev->data.key.c = CACA_KEY_F6; break; | |||
case GLUT_KEY_F7 : ev->data.key.c = CACA_KEY_F7; break; | |||
case GLUT_KEY_F8 : ev->data.key.c = CACA_KEY_F8; break; | |||
case GLUT_KEY_F9 : ev->data.key.c = CACA_KEY_F9; break; | |||
case GLUT_KEY_F10: ev->data.key.c = CACA_KEY_F10; break; | |||
case GLUT_KEY_F11: ev->data.key.c = CACA_KEY_F11; break; | |||
case GLUT_KEY_F12: ev->data.key.c = CACA_KEY_F12; break; | |||
case GLUT_KEY_LEFT : ev->data.key.c = CACA_KEY_LEFT; break; | |||
case GLUT_KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | |||
case GLUT_KEY_UP : ev->data.key.c = CACA_KEY_UP; break; | |||
case GLUT_KEY_DOWN : ev->data.key.c = CACA_KEY_DOWN; break; | |||
case GLUT_KEY_F1 : ev->data.key.ch = CACA_KEY_F1; break; | |||
case GLUT_KEY_F2 : ev->data.key.ch = CACA_KEY_F2; break; | |||
case GLUT_KEY_F3 : ev->data.key.ch = CACA_KEY_F3; break; | |||
case GLUT_KEY_F4 : ev->data.key.ch = CACA_KEY_F4; break; | |||
case GLUT_KEY_F5 : ev->data.key.ch = CACA_KEY_F5; break; | |||
case GLUT_KEY_F6 : ev->data.key.ch = CACA_KEY_F6; break; | |||
case GLUT_KEY_F7 : ev->data.key.ch = CACA_KEY_F7; break; | |||
case GLUT_KEY_F8 : ev->data.key.ch = CACA_KEY_F8; break; | |||
case GLUT_KEY_F9 : ev->data.key.ch = CACA_KEY_F9; break; | |||
case GLUT_KEY_F10: ev->data.key.ch = CACA_KEY_F10; break; | |||
case GLUT_KEY_F11: ev->data.key.ch = CACA_KEY_F11; break; | |||
case GLUT_KEY_F12: ev->data.key.ch = CACA_KEY_F12; break; | |||
case GLUT_KEY_LEFT : ev->data.key.ch = CACA_KEY_LEFT; break; | |||
case GLUT_KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break; | |||
case GLUT_KEY_UP : ev->data.key.ch = CACA_KEY_UP; break; | |||
case GLUT_KEY_DOWN : ev->data.key.ch = CACA_KEY_DOWN; break; | |||
default: ev->type = CACA_EVENT_NONE; return 0; | |||
} | |||
@@ -151,7 +151,7 @@ static int ncurses_init_graphics(caca_t *kk) | |||
} | |||
} | |||
_cucul_set_size(kk->qq, COLS, LINES); | |||
_cucul_set_size(kk->c, COLS, LINES); | |||
return 0; | |||
} | |||
@@ -176,24 +176,24 @@ static int ncurses_set_window_title(caca_t *kk, char const *title) | |||
static unsigned int ncurses_get_window_width(caca_t *kk) | |||
{ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->width * 6; | |||
return kk->c->width * 6; | |||
} | |||
static unsigned int ncurses_get_window_height(caca_t *kk) | |||
{ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->height * 10; | |||
return kk->c->height * 10; | |||
} | |||
static void ncurses_display(caca_t *kk) | |||
{ | |||
int x, y; | |||
uint32_t *attr = kk->qq->attr; | |||
uint32_t *chars = kk->qq->chars; | |||
for(y = 0; y < (int)kk->qq->height; y++) | |||
uint32_t *attr = kk->c->attr; | |||
uint32_t *chars = kk->c->chars; | |||
for(y = 0; y < (int)kk->c->height; y++) | |||
{ | |||
move(y, 0); | |||
for(x = kk->qq->width; x--; ) | |||
for(x = kk->c->width; x--; ) | |||
{ | |||
attrset(kk->drv.p->attr[_cucul_argb32_to_ansi8(*attr++)]); | |||
ncurses_write_utf32(*chars++); | |||
@@ -220,8 +220,8 @@ static void ncurses_handle_resize(caca_t *kk) | |||
} | |||
/* Fallback */ | |||
kk->resize.w = kk->qq->width; | |||
kk->resize.h = kk->qq->height; | |||
kk->resize.w = kk->c->width; | |||
kk->resize.h = kk->c->height; | |||
} | |||
static int ncurses_get_event(caca_t *kk, caca_event_t *ev) | |||
@@ -238,7 +238,7 @@ static int ncurses_get_event(caca_t *kk, caca_event_t *ev) | |||
if(intkey < 0x100) | |||
{ | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
ev->data.key.c = intkey; | |||
ev->data.key.ch = intkey; | |||
return 1; | |||
} | |||
@@ -396,30 +396,30 @@ static int ncurses_get_event(caca_t *kk, caca_event_t *ev) | |||
switch(intkey) | |||
{ | |||
case KEY_UP: ev->data.key.c = CACA_KEY_UP; break; | |||
case KEY_DOWN: ev->data.key.c = CACA_KEY_DOWN; break; | |||
case KEY_LEFT: ev->data.key.c = CACA_KEY_LEFT; break; | |||
case KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | |||
case KEY_IC: ev->data.key.c = CACA_KEY_INSERT; break; | |||
case KEY_DC: ev->data.key.c = CACA_KEY_DELETE; break; | |||
case KEY_HOME: ev->data.key.c = CACA_KEY_HOME; break; | |||
case KEY_END: ev->data.key.c = CACA_KEY_END; break; | |||
case KEY_PPAGE: ev->data.key.c = CACA_KEY_PAGEUP; break; | |||
case KEY_NPAGE: ev->data.key.c = CACA_KEY_PAGEDOWN; break; | |||
case KEY_F(1): ev->data.key.c = CACA_KEY_F1; break; | |||
case KEY_F(2): ev->data.key.c = CACA_KEY_F2; break; | |||
case KEY_F(3): ev->data.key.c = CACA_KEY_F3; break; | |||
case KEY_F(4): ev->data.key.c = CACA_KEY_F4; break; | |||
case KEY_F(5): ev->data.key.c = CACA_KEY_F5; break; | |||
case KEY_F(6): ev->data.key.c = CACA_KEY_F6; break; | |||
case KEY_F(7): ev->data.key.c = CACA_KEY_F7; break; | |||
case KEY_F(8): ev->data.key.c = CACA_KEY_F8; break; | |||
case KEY_F(9): ev->data.key.c = CACA_KEY_F9; break; | |||
case KEY_F(10): ev->data.key.c = CACA_KEY_F10; break; | |||
case KEY_F(11): ev->data.key.c = CACA_KEY_F11; break; | |||
case KEY_F(12): ev->data.key.c = CACA_KEY_F12; break; | |||
case KEY_UP: ev->data.key.ch = CACA_KEY_UP; break; | |||
case KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break; | |||
case KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break; | |||
case KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break; | |||
case KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break; | |||
case KEY_DC: ev->data.key.ch = CACA_KEY_DELETE; break; | |||
case KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break; | |||
case KEY_END: ev->data.key.ch = CACA_KEY_END; break; | |||
case KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break; | |||
case KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break; | |||
case KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break; | |||
case KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break; | |||
case KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break; | |||
case KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break; | |||
case KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break; | |||
case KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break; | |||
case KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break; | |||
case KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break; | |||
case KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break; | |||
case KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break; | |||
case KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break; | |||
case KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break; | |||
default: ev->type = CACA_EVENT_NONE; return 0; | |||
} | |||
@@ -53,19 +53,19 @@ static unsigned int raw_get_window_height(caca_t *kk) | |||
static void raw_display(caca_t *kk) | |||
{ | |||
uint32_t *attr = kk->qq->attr; | |||
uint32_t *chars = kk->qq->chars; | |||
uint32_t *attr = kk->c->attr; | |||
uint32_t *chars = kk->c->chars; | |||
uint32_t w, h; | |||
unsigned int n; | |||
w = kk->qq->width; | |||
h = kk->qq->height; | |||
w = kk->c->width; | |||
h = kk->c->height; | |||
fprintf(stdout, "CACA%c%c%c%c%c%c%c%c", | |||
(w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff, | |||
(h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff); | |||
for(n = kk->qq->height * kk->qq->width; n--; ) | |||
for(n = kk->c->height * kk->c->width; n--; ) | |||
{ | |||
uint32_t c = *chars++; | |||
uint32_t a = *attr++; | |||
@@ -164,7 +164,7 @@ static int slang_init_graphics(caca_t *kk) | |||
SLtt_utf8_enable(1); | |||
#endif | |||
_cucul_set_size(kk->qq, SLtt_Screen_Cols, SLtt_Screen_Rows); | |||
_cucul_set_size(kk->c, SLtt_Screen_Cols, SLtt_Screen_Rows); | |||
return 0; | |||
} | |||
@@ -188,24 +188,24 @@ static int slang_set_window_title(caca_t *kk, char const *title) | |||
static unsigned int slang_get_window_width(caca_t *kk) | |||
{ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->width * 6; | |||
return kk->c->width * 6; | |||
} | |||
static unsigned int slang_get_window_height(caca_t *kk) | |||
{ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->height * 10; | |||
return kk->c->height * 10; | |||
} | |||
static void slang_display(caca_t *kk) | |||
{ | |||
int x, y; | |||
uint32_t *attr = kk->qq->attr; | |||
uint32_t *chars = kk->qq->chars; | |||
for(y = 0; y < (int)kk->qq->height; y++) | |||
uint32_t *attr = kk->c->attr; | |||
uint32_t *chars = kk->c->chars; | |||
for(y = 0; y < (int)kk->c->height; y++) | |||
{ | |||
SLsmg_gotorc(y, 0); | |||
for(x = kk->qq->width; x--; ) | |||
for(x = kk->c->width; x--; ) | |||
{ | |||
uint32_t c = *chars++; | |||
@@ -248,7 +248,7 @@ static void slang_handle_resize(caca_t *kk) | |||
kk->resize.w = SLtt_Screen_Cols; | |||
kk->resize.h = SLtt_Screen_Rows; | |||
if(kk->resize.w != kk->qq->width || kk->resize.h != kk->qq->height) | |||
if(kk->resize.w != kk->c->width || kk->resize.h != kk->c->height) | |||
SLsmg_reinit_smg(); | |||
} | |||
@@ -277,7 +277,7 @@ static int slang_get_event(caca_t *kk, caca_event_t *ev) | |||
if(intkey < 0x100) | |||
{ | |||
ev->type = CACA_EVENT_KEY_PRESS; | |||
ev->data.key.c = intkey; | |||
ev->data.key.ch = intkey; | |||
return 1; | |||
} | |||
@@ -307,30 +307,30 @@ static int slang_get_event(caca_t *kk, caca_event_t *ev) | |||
switch(intkey) | |||
{ | |||
case SL_KEY_UP: ev->data.key.c = CACA_KEY_UP; break; | |||
case SL_KEY_DOWN: ev->data.key.c = CACA_KEY_DOWN; break; | |||
case SL_KEY_LEFT: ev->data.key.c = CACA_KEY_LEFT; break; | |||
case SL_KEY_RIGHT: ev->data.key.c = CACA_KEY_RIGHT; break; | |||
case SL_KEY_IC: ev->data.key.c = CACA_KEY_INSERT; break; | |||
case SL_KEY_DELETE: ev->data.key.c = CACA_KEY_DELETE; break; | |||
case SL_KEY_HOME: ev->data.key.c = CACA_KEY_HOME; break; | |||
case SL_KEY_END: ev->data.key.c = CACA_KEY_END; break; | |||
case SL_KEY_PPAGE: ev->data.key.c = CACA_KEY_PAGEUP; break; | |||
case SL_KEY_NPAGE: ev->data.key.c = CACA_KEY_PAGEDOWN; break; | |||
case SL_KEY_F(1): ev->data.key.c = CACA_KEY_F1; break; | |||
case SL_KEY_F(2): ev->data.key.c = CACA_KEY_F2; break; | |||
case SL_KEY_F(3): ev->data.key.c = CACA_KEY_F3; break; | |||
case SL_KEY_F(4): ev->data.key.c = CACA_KEY_F4; break; | |||
case SL_KEY_F(5): ev->data.key.c = CACA_KEY_F5; break; | |||
case SL_KEY_F(6): ev->data.key.c = CACA_KEY_F6; break; | |||
case SL_KEY_F(7): ev->data.key.c = CACA_KEY_F7; break; | |||
case SL_KEY_F(8): ev->data.key.c = CACA_KEY_F8; break; | |||
case SL_KEY_F(9): ev->data.key.c = CACA_KEY_F9; break; | |||
case SL_KEY_F(10): ev->data.key.c = CACA_KEY_F10; break; | |||
case SL_KEY_F(11): ev->data.key.c = CACA_KEY_F11; break; | |||
case SL_KEY_F(12): ev->data.key.c = CACA_KEY_F12; break; | |||
case SL_KEY_UP: ev->data.key.ch = CACA_KEY_UP; break; | |||
case SL_KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break; | |||
case SL_KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break; | |||
case SL_KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break; | |||
case SL_KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break; | |||
case SL_KEY_DELETE: ev->data.key.ch = CACA_KEY_DELETE; break; | |||
case SL_KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break; | |||
case SL_KEY_END: ev->data.key.ch = CACA_KEY_END; break; | |||
case SL_KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break; | |||
case SL_KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break; | |||
case SL_KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break; | |||
case SL_KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break; | |||
case SL_KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break; | |||
case SL_KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break; | |||
case SL_KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break; | |||
case SL_KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break; | |||
case SL_KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break; | |||
case SL_KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break; | |||
case SL_KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break; | |||
case SL_KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break; | |||
case SL_KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break; | |||
case SL_KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break; | |||
default: ev->type = CACA_EVENT_NONE; return 0; | |||
} | |||
@@ -74,7 +74,7 @@ static int vga_init_graphics(caca_t *kk) | |||
outb(tmp, 0x3d5); | |||
/* We don't have much choice */ | |||
_cucul_set_size(kk->qq, 80, 25); | |||
_cucul_set_size(kk->c, 80, 25); | |||
return 0; | |||
} | |||
@@ -114,11 +114,11 @@ static unsigned int vga_get_window_height(caca_t *kk) | |||
static void vga_display(caca_t *kk) | |||
{ | |||
char *screen = (char *)(intptr_t)0x000b8000; | |||
uint32_t *attr = kk->qq->attr; | |||
uint32_t *chars = kk->qq->chars; | |||
uint32_t *attr = kk->c->attr; | |||
uint32_t *chars = kk->c->chars; | |||
int n; | |||
for(n = kk->qq->height * kk->qq->width; n--; ) | |||
for(n = kk->c->height * kk->c->width; n--; ) | |||
{ | |||
*screen++ = _cucul_utf32_to_cp437(*chars++); | |||
*screen++ = _cucul_argb32_to_ansi8(*attr++); | |||
@@ -128,8 +128,8 @@ static void vga_display(caca_t *kk) | |||
static void vga_handle_resize(caca_t *kk) | |||
{ | |||
/* We know nothing about our window */ | |||
kk->resize.w = kk->qq->width; | |||
kk->resize.h = kk->qq->height; | |||
kk->resize.w = kk->c->width; | |||
kk->resize.h = kk->c->height; | |||
} | |||
static int vga_get_event(caca_t *kk, caca_event-t *ev) | |||
@@ -111,21 +111,21 @@ static int win32_init_graphics(caca_t *kk) | |||
return -1; | |||
/* Set the new console size */ | |||
size.X = kk->qq->width; | |||
size.Y = kk->qq->height; | |||
size.X = kk->c->width; | |||
size.Y = kk->c->height; | |||
SetConsoleScreenBufferSize(kk->drv.p->screen, size); | |||
rect.Left = rect.Top = 0; | |||
rect.Right = kk->qq->width - 1; | |||
rect.Bottom = kk->qq->height - 1; | |||
rect.Right = kk->c->width - 1; | |||
rect.Bottom = kk->c->height - 1; | |||
SetConsoleWindowInfo(kk->drv.p->screen, TRUE, &rect); | |||
/* Report our new size to libcucul */ | |||
if(!GetConsoleScreenBufferInfo(kk->drv.p->screen, &csbi)) | |||
return -1; | |||
_cucul_set_size(kk->qq, csbi.srWindow.Right - csbi.srWindow.Left + 1, | |||
csbi.srWindow.Bottom - csbi.srWindow.Top + 1); | |||
_cucul_set_size(kk->c, csbi.srWindow.Right - csbi.srWindow.Left + 1, | |||
csbi.srWindow.Bottom - csbi.srWindow.Top + 1); | |||
SetConsoleMode(kk->drv.p->screen, 0); | |||
@@ -136,7 +136,7 @@ static int win32_init_graphics(caca_t *kk) | |||
SetConsoleActiveScreenBuffer(kk->drv.p->screen); | |||
kk->drv.p->buffer = malloc(kk->qq->width * kk->qq->height | |||
kk->drv.p->buffer = malloc(kk->c->width * kk->c->height | |||
* sizeof(CHAR_INFO)); | |||
if(kk->drv.p->buffer == NULL) | |||
return -1; | |||
@@ -173,7 +173,7 @@ static unsigned int win32_get_window_width(caca_t *kk) | |||
/* FIXME */ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->width * 6; | |||
return kk->c->width * 6; | |||
} | |||
static unsigned int win32_get_window_height(caca_t *kk) | |||
@@ -181,7 +181,7 @@ static unsigned int win32_get_window_height(caca_t *kk) | |||
/* FIXME */ | |||
/* Fallback to a 6x10 font */ | |||
return kk->qq->height * 10; | |||
return kk->c->height * 10; | |||
} | |||
static void win32_display(caca_t *kk) | |||
@@ -191,9 +191,9 @@ static void win32_display(caca_t *kk) | |||
unsigned int i; | |||
/* Render everything to our screen buffer */ | |||
for(i = 0; i < kk->qq->width * kk->qq->height; i++) | |||
for(i = 0; i < kk->c->width * kk->c->height; i++) | |||
{ | |||
uint32_t c = kk->qq->chars[i]; | |||
uint32_t c = kk->c->chars[i]; | |||
#if 0 | |||
if(c > 0x00000020 && c < 0x00000080) | |||
@@ -208,17 +208,17 @@ static void win32_display(caca_t *kk) | |||
#endif | |||
kk->drv.p->buffer[i].Attributes = | |||
win32_fg_palette[_cucul_argb32_to_ansi4fg(kk->qq->attr[i])] | |||
| win32_bg_palette[_cucul_argb32_to_ansi4bg(kk->qq->attr[i])]; | |||
win32_fg_palette[_cucul_argb32_to_ansi4fg(kk->c->attr[i])] | |||
| win32_bg_palette[_cucul_argb32_to_ansi4bg(kk->c->attr[i])]; | |||
} | |||
/* Blit the screen buffer */ | |||
size.X = kk->qq->width; | |||
size.Y = kk->qq->height; | |||
size.X = kk->c->width; | |||
size.Y = kk->c->height; | |||
pos.X = pos.Y = 0; | |||
rect.Left = rect.Top = 0; | |||
rect.Right = kk->qq->width - 1; | |||
rect.Bottom = kk->qq->height - 1; | |||
rect.Right = kk->c->width - 1; | |||
rect.Bottom = kk->c->height - 1; | |||
#if 0 | |||
WriteConsoleOutput(kk->drv.p->screen, kk->drv.p->buffer, size, pos, &rect); | |||
#else | |||
@@ -229,8 +229,8 @@ static void win32_display(caca_t *kk) | |||
static void win32_handle_resize(caca_t *kk) | |||
{ | |||
/* FIXME: I don't know what to do here. */ | |||
kk->resize.w = kk->qq->width; | |||
kk->resize.h = kk->qq->height; | |||
kk->resize.w = kk->c->width; | |||
kk->resize.h = kk->c->height; | |||
} | |||
static int win32_get_event(caca_t *kk, caca_event_t *ev) | |||
@@ -256,9 +256,9 @@ static int win32_get_event(caca_t *kk, caca_event_t *ev) | |||
if(rec.Event.KeyEvent.uChar.AsciiChar) | |||
{ | |||
ev->data.key.c = rec.Event.KeyEvent.uChar.AsciiChar; | |||
ev->data.key.ucs4 = (uint32_t)ev->data.key.c; | |||
ev->data.key.utf8[0] = ev->data.key.c; | |||
ev->data.key.ch = rec.Event.KeyEvent.uChar.AsciiChar; | |||
ev->data.key.ucs4 = (uint32_t)ev->data.key.ch; | |||
ev->data.key.utf8[0] = ev->data.key.ch; | |||
ev->data.key.utf8[1] = '\0'; | |||
return 1; | |||
@@ -78,7 +78,7 @@ static int x11_init_graphics(caca_t *kk) | |||
#endif | |||
if(width && height) | |||
_cucul_set_size(kk->qq, width, height); | |||
_cucul_set_size(kk->c, width, height); | |||
kk->drv.p->dpy = XOpenDisplay(NULL); | |||
if(kk->drv.p->dpy == NULL) | |||
@@ -144,8 +144,8 @@ static int x11_init_graphics(caca_t *kk) | |||
kk->drv.p->window = | |||
XCreateWindow(kk->drv.p->dpy, DefaultRootWindow(kk->drv.p->dpy), 0, 0, | |||
kk->qq->width * kk->drv.p->font_width, | |||
kk->qq->height * kk->drv.p->font_height, | |||
kk->c->width * kk->drv.p->font_width, | |||
kk->c->height * kk->drv.p->font_height, | |||
0, 0, InputOutput, 0, | |||
CWBackingStore | CWBackPixel | CWEventMask, | |||
&x11_winattr); | |||
@@ -192,8 +192,8 @@ static int x11_init_graphics(caca_t *kk) | |||
XSync(kk->drv.p->dpy, False); | |||
kk->drv.p->pixmap = XCreatePixmap(kk->drv.p->dpy, kk->drv.p->window, | |||
kk->qq->width * kk->drv.p->font_width, | |||
kk->qq->height * kk->drv.p->font_height, | |||
kk->c->width * kk->drv.p->font_width, | |||
kk->c->height * kk->drv.p->font_height, | |||
DefaultDepth(kk->drv.p->dpy, | |||
DefaultScreen(kk->drv.p->dpy))); | |||
kk->drv.p->pointer = None; | |||
@@ -228,12 +228,12 @@ static int x11_set_window_title(caca_t *kk, char const *title) | |||
static unsigned int x11_get_window_width(caca_t *kk) | |||
{ | |||
return kk->qq->width * kk->drv.p->font_width; | |||
return kk->c->width * kk->drv.p->font_width; | |||
} | |||
static unsigned int x11_get_window_height(caca_t *kk) | |||
{ | |||
return kk->qq->height * kk->drv.p->font_height; | |||
return kk->c->height * kk->drv.p->font_height; | |||
} | |||
static void x11_display(caca_t *kk) | |||
@@ -242,15 +242,15 @@ static void x11_display(caca_t *kk) | |||
/* First draw the background colours. Splitting the process in two | |||
* loops like this is actually slightly faster. */ | |||
for(y = 0; y < kk->qq->height; y++) | |||
for(y = 0; y < kk->c->height; y++) | |||
{ | |||
for(x = 0; x < kk->qq->width; x += len) | |||
for(x = 0; x < kk->c->width; x += len) | |||
{ | |||
uint32_t *attr = kk->qq->attr + x + y * kk->qq->width; | |||
uint32_t *attr = kk->c->attr + x + y * kk->c->width; | |||
uint16_t bg = _cucul_argb32_to_rgb12bg(*attr); | |||
len = 1; | |||
while(x + len < kk->qq->width | |||
while(x + len < kk->c->width | |||
&& _cucul_argb32_to_rgb12bg(attr[len]) == bg) | |||
len++; | |||
@@ -263,15 +263,15 @@ static void x11_display(caca_t *kk) | |||
} | |||
/* Then print the foreground characters */ | |||
for(y = 0; y < kk->qq->height; y++) | |||
for(y = 0; y < kk->c->height; y++) | |||
{ | |||
unsigned int yoff = (y + 1) * kk->drv.p->font_height | |||
- kk->drv.p->font_offset; | |||
uint32_t *chars = kk->qq->chars + y * kk->qq->width; | |||
uint32_t *chars = kk->c->chars + y * kk->c->width; | |||
for(x = 0; x < kk->qq->width; x++, chars++) | |||
for(x = 0; x < kk->c->width; x++, chars++) | |||
{ | |||
uint32_t *attr = kk->qq->attr + x + y * kk->qq->width; | |||
uint32_t *attr = kk->c->attr + x + y * kk->c->width; | |||
/* Skip spaces */ | |||
if(*chars == 0x00000020) | |||
@@ -370,8 +370,8 @@ static void x11_display(caca_t *kk) | |||
XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->window, | |||
kk->drv.p->gc, 0, 0, | |||
kk->qq->width * kk->drv.p->font_width, | |||
kk->qq->height * kk->drv.p->font_height, | |||
kk->c->width * kk->drv.p->font_width, | |||
kk->c->height * kk->drv.p->font_height, | |||
0, 0); | |||
XFlush(kk->drv.p->dpy); | |||
} | |||
@@ -408,8 +408,8 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev) | |||
{ | |||
XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, | |||
kk->drv.p->window, kk->drv.p->gc, 0, 0, | |||
kk->qq->width * kk->drv.p->font_width, | |||
kk->qq->height * kk->drv.p->font_height, 0, 0); | |||
kk->c->width * kk->drv.p->font_width, | |||
kk->c->height * kk->drv.p->font_height, 0, 0); | |||
continue; | |||
} | |||
@@ -423,7 +423,7 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev) | |||
h = (xevent.xconfigure.height + kk->drv.p->font_height / 3) | |||
/ kk->drv.p->font_height; | |||
if(!w || !h || (w == kk->qq->width && h == kk->qq->height)) | |||
if(!w || !h || (w == kk->c->width && h == kk->c->height)) | |||
continue; | |||
kk->resize.w = w; | |||
@@ -439,10 +439,10 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev) | |||
unsigned int newx = xevent.xmotion.x / kk->drv.p->font_width; | |||
unsigned int newy = xevent.xmotion.y / kk->drv.p->font_height; | |||
if(newx >= kk->qq->width) | |||
newx = kk->qq->width - 1; | |||
if(newy >= kk->qq->height) | |||
newy = kk->qq->height - 1; | |||
if(newx >= kk->c->width) | |||
newx = kk->c->width - 1; | |||
if(newy >= kk->c->height) | |||
newy = kk->c->height - 1; | |||
if(kk->mouse.x == newx && kk->mouse.y == newy) | |||
continue; | |||
@@ -481,7 +481,7 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev) | |||
if(XLookupString(&xevent.xkey, &key, 1, NULL, NULL)) | |||
{ | |||
ev->data.key.c = key; | |||
ev->data.key.ch = key; | |||
ev->data.key.ucs4 = key; | |||
ev->data.key.utf8[0] = key; | |||
ev->data.key.utf8[1] = '\0'; | |||
@@ -491,25 +491,25 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev) | |||
keysym = XKeycodeToKeysym(kk->drv.p->dpy, xevent.xkey.keycode, 0); | |||
switch(keysym) | |||
{ | |||
case XK_F1: ev->data.key.c = CACA_KEY_F1; break; | |||
case XK_F2: ev->data.key.c = CACA_KEY_F2; break; | |||
case XK_F3: ev->data.key.c = CACA_KEY_F3; break; | |||
case XK_F4: ev->data.key.c = CACA_KEY_F4; break; | |||
case XK_F5: ev->data.key.c = CACA_KEY_F5; break; | |||
case XK_F6: ev->data.key.c = CACA_KEY_F6; break; | |||
case XK_F7: ev->data.key.c = CACA_KEY_F7; break; | |||
case XK_F8: ev->data.key.c = CACA_KEY_F8; break; | |||
case XK_F9: ev->data.key.c = CACA_KEY_F9; break; | |||
case XK_F10: ev->data.key.c = CACA_KEY_F10; break; | |||
case XK_F11: ev->data.key.c = CACA_KEY_F11; break; | |||
case XK_F12: ev->data.key.c = CACA_KEY_F12; break; | |||
case XK_F13: ev->data.key.c = CACA_KEY_F13; break; | |||
case XK_F14: ev->data.key.c = CACA_KEY_F14; break; | |||
case XK_F15: ev->data.key.c = CACA_KEY_F15; break; | |||
case XK_Left: ev->data.key.c = CACA_KEY_LEFT; break; | |||
case XK_Right: ev->data.key.c = CACA_KEY_RIGHT; break; | |||
case XK_Up: ev->data.key.c = CACA_KEY_UP; break; | |||
case XK_Down: ev->data.key.c = CACA_KEY_DOWN; break; | |||
case XK_F1: ev->data.key.ch = CACA_KEY_F1; break; | |||
case XK_F2: ev->data.key.ch = CACA_KEY_F2; break; | |||
case XK_F3: ev->data.key.ch = CACA_KEY_F3; break; | |||
case XK_F4: ev->data.key.ch = CACA_KEY_F4; break; | |||
case XK_F5: ev->data.key.ch = CACA_KEY_F5; break; | |||
case XK_F6: ev->data.key.ch = CACA_KEY_F6; break; | |||
case XK_F7: ev->data.key.ch = CACA_KEY_F7; break; | |||
case XK_F8: ev->data.key.ch = CACA_KEY_F8; break; | |||
case XK_F9: ev->data.key.ch = CACA_KEY_F9; break; | |||
case XK_F10: ev->data.key.ch = CACA_KEY_F10; break; | |||
case XK_F11: ev->data.key.ch = CACA_KEY_F11; break; | |||
case XK_F12: ev->data.key.ch = CACA_KEY_F12; break; | |||
case XK_F13: ev->data.key.ch = CACA_KEY_F13; break; | |||
case XK_F14: ev->data.key.ch = CACA_KEY_F14; break; | |||
case XK_F15: ev->data.key.ch = CACA_KEY_F15; break; | |||
case XK_Left: ev->data.key.ch = CACA_KEY_LEFT; break; | |||
case XK_Right: ev->data.key.ch = CACA_KEY_RIGHT; break; | |||
case XK_Up: ev->data.key.ch = CACA_KEY_UP; break; | |||
case XK_Down: ev->data.key.ch = CACA_KEY_DOWN; break; | |||
default: ev->type = CACA_EVENT_NONE; return 0; | |||
} | |||
@@ -113,8 +113,8 @@ int caca_get_event(caca_t *kk, unsigned int event_mask, | |||
*/ | |||
unsigned int caca_get_mouse_x(caca_t *kk) | |||
{ | |||
if(kk->mouse.x >= kk->qq->width) | |||
kk->mouse.x = kk->qq->width - 1; | |||
if(kk->mouse.x >= kk->c->width) | |||
kk->mouse.x = kk->c->width - 1; | |||
return kk->mouse.x; | |||
} | |||
@@ -131,8 +131,8 @@ unsigned int caca_get_mouse_x(caca_t *kk) | |||
*/ | |||
unsigned int caca_get_mouse_y(caca_t *kk) | |||
{ | |||
if(kk->mouse.y >= kk->qq->height) | |||
kk->mouse.y = kk->qq->height - 1; | |||
if(kk->mouse.y >= kk->c->height) | |||
kk->mouse.y = kk->c->height - 1; | |||
return kk->mouse.y; | |||
} | |||
@@ -154,8 +154,8 @@ static int _get_next_event(caca_t *kk, caca_event_t *ev) | |||
kk->resize.resized = 0; | |||
_caca_handle_resize(kk); | |||
ev->type = CACA_EVENT_RESIZE; | |||
ev->data.resize.w = kk->qq->width; | |||
ev->data.resize.h = kk->qq->height; | |||
ev->data.resize.w = kk->c->width; | |||
ev->data.resize.h = kk->c->height; | |||
return 1; | |||
} | |||
@@ -191,7 +191,7 @@ static int _get_next_event(caca_t *kk, caca_event_t *ev) | |||
* this event and return the next one by calling ourselves. */ | |||
if(ev->type == CACA_EVENT_KEY_PRESS | |||
&& kk->events.last_key_event.type | |||
&& ev->data.key.c == kk->events.last_key_event.data.key.c | |||
&& ev->data.key.ch == kk->events.last_key_event.data.key.ch | |||
&& ev->data.key.ucs4 == kk->events.last_key_event.data.key.ucs4) | |||
{ | |||
kk->events.last_key_ticks = 0; | |||
@@ -172,7 +172,7 @@ void _caca_handle_resize(caca_t *kk) | |||
kk->drv.handle_resize(kk); | |||
/* Tell libcucul we changed size */ | |||
if(kk->resize.w != kk->qq->width || kk->resize.h != kk->qq->height) | |||
_cucul_set_size(kk->qq, kk->resize.w, kk->resize.h); | |||
if(kk->resize.w != kk->c->width || kk->resize.h != kk->c->height) | |||
_cucul_set_size(kk->c, kk->resize.w, kk->resize.h); | |||
} | |||
@@ -25,18 +25,18 @@ Caca::Caca(void) | |||
{ | |||
} | |||
Caca::Caca(Cucul *qq) | |||
Caca::Caca(Cucul *c) | |||
{ | |||
kk = caca_attach(qq->get_cucul_t()); | |||
kk = caca_attach(c->get_cucul_canvas_t()); | |||
if(!kk) throw -1; | |||
} | |||
Caca::~Caca() | |||
{ | |||
caca_detach(kk); | |||
} | |||
void Caca::attach(Cucul *qq) | |||
void Caca::attach(Cucul *c) | |||
{ | |||
kk = caca_attach(qq->get_cucul_t()); | |||
kk = caca_attach(c->get_cucul_canvas_t()); | |||
if(!kk) throw -1; | |||
} | |||
void Caca::detach () | |||
@@ -20,55 +20,55 @@ | |||
Cucul::Cucul() | |||
{ | |||
qq = cucul_create(0,0); | |||
if(!qq) throw -1; | |||
c = cucul_create(0,0); | |||
if(!c) throw -1; | |||
} | |||
Cucul::Cucul(int width, int height) | |||
{ | |||
qq = cucul_create(width, height); | |||
if(!qq) throw -1; | |||
c = cucul_create(width, height); | |||
if(!c) throw -1; | |||
} | |||
Cucul::~Cucul() | |||
{ | |||
if(qq) { | |||
cucul_free(qq); | |||
if(c) { | |||
cucul_free(c); | |||
} | |||
} | |||
cucul_t *Cucul::get_cucul_t() | |||
cucul_canvas_t *Cucul::get_cucul_canvas_t() | |||
{ | |||
return qq; | |||
return c; | |||
} | |||
void Cucul::set_size(unsigned int width, unsigned int height) | |||
{ | |||
cucul_set_size (qq, width, height); | |||
cucul_set_size (c, width, height); | |||
} | |||
unsigned int Cucul::get_width(void) | |||
{ | |||
return cucul_get_width (qq); | |||
return cucul_get_width (c); | |||
} | |||
unsigned int Cucul::get_height(void) | |||
{ | |||
return cucul_get_height (qq); | |||
return cucul_get_height (c); | |||
} | |||
void Cucul::set_color(unsigned int f, unsigned int b) | |||
{ | |||
cucul_set_color (qq, f, b); | |||
cucul_set_color (c, f, b); | |||
} | |||
char const * Cucul::get_color_name (unsigned int color) | |||
{ | |||
return cucul_get_color_name (color); | |||
} | |||
void Cucul::putchar (int x, int y, char c) | |||
void Cucul::putchar (int x, int y, char ch) | |||
{ | |||
cucul_putchar (qq, x, y, c); | |||
cucul_putchar (c, x, y, ch); | |||
} | |||
void Cucul::putstr (int x, int y, char *str) | |||
{ | |||
cucul_putstr(qq, x, y, str); | |||
cucul_putstr(c, x, y, str); | |||
} | |||
void Cucul::printf ( int x , int y , char const * format,...) | |||
{ | |||
@@ -91,102 +91,102 @@ void Cucul::printf ( int x , int y , char const * format,...) | |||
void Cucul::clear () | |||
{ | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
} | |||
void Cucul::blit ( int x, int y, Cucul* c1, Cucul* c2) | |||
{ | |||
cucul_blit(qq, x, y, c1->get_cucul_t(), c2->get_cucul_t()); | |||
cucul_blit(c, x, y, c1->get_cucul_canvas_t(), c2->get_cucul_canvas_t()); | |||
} | |||
void Cucul::invert () | |||
{ | |||
cucul_invert(qq); | |||
cucul_invert(c); | |||
} | |||
void Cucul::flip () | |||
{ | |||
cucul_flip(qq); | |||
cucul_flip(c); | |||
} | |||
void Cucul::flop () | |||
{ | |||
cucul_flop(qq); | |||
cucul_flop(c); | |||
} | |||
void Cucul::rotate () | |||
{ | |||
cucul_rotate(qq); | |||
cucul_rotate(c); | |||
} | |||
void Cucul::draw_line (int x1 , int y1, int x2, int y2, char const *c) | |||
void Cucul::draw_line (int x1 , int y1, int x2, int y2, char const *ch) | |||
{ | |||
cucul_draw_line(qq, x1,y1,x2,y2, c); | |||
cucul_draw_line(c, x1,y1,x2,y2, ch); | |||
} | |||
void Cucul::draw_polyline (int const x[], int const y[], int f, char const *c) | |||
void Cucul::draw_polyline (int const x[], int const y[], int f, char const *ch) | |||
{ | |||
cucul_draw_polyline(qq, x, y, f, c); | |||
cucul_draw_polyline(c, x, y, f, ch); | |||
} | |||
void Cucul::draw_thin_line (int x1 , int y1, int x2, int y2) | |||
{ | |||
cucul_draw_thin_line(qq, x1, y1, x2, y2); | |||
cucul_draw_thin_line(c, x1, y1, x2, y2); | |||
} | |||
void Cucul::draw_thin_polyline ( int const x[], int const y[], int f) | |||
{ | |||
cucul_draw_thin_polyline(qq, x, y, f); | |||
cucul_draw_thin_polyline(c, x, y, f); | |||
} | |||
void Cucul::draw_circle ( int x, int y, int d, char const *c) | |||
void Cucul::draw_circle ( int x, int y, int d, char const *ch) | |||
{ | |||
cucul_draw_circle(qq, x, y, d, c); | |||
cucul_draw_circle(c, x, y, d, ch); | |||
} | |||
void Cucul::draw_ellipse ( int x, int y, int d1, int d2, char const *c) | |||
void Cucul::draw_ellipse ( int x, int y, int d1, int d2, char const *ch) | |||
{ | |||
cucul_draw_ellipse(qq, x, y, d1, d2, c); | |||
cucul_draw_ellipse(c, x, y, d1, d2, ch); | |||
} | |||
void Cucul::draw_thin_ellipse ( int x, int y, int d1, int d2) | |||
{ | |||
cucul_draw_thin_ellipse(qq, x, y, d1, d2); | |||
cucul_draw_thin_ellipse(c, x, y, d1, d2); | |||
} | |||
void Cucul::fill_ellipse ( int x, int y, int d1, int d2, char const *c) | |||
void Cucul::fill_ellipse ( int x, int y, int d1, int d2, char const *ch) | |||
{ | |||
cucul_fill_ellipse(qq, x, y, d1, d2, c); | |||
cucul_fill_ellipse(c, x, y, d1, d2, ch); | |||
} | |||
void Cucul::draw_box ( int x, int y, int w, int h, char const *c) | |||
void Cucul::draw_box ( int x, int y, int w, int h, char const *ch) | |||
{ | |||
cucul_draw_box(qq, x, y, w, h, c); | |||
cucul_draw_box(c, x, y, w, h, ch); | |||
} | |||
void Cucul::draw_thin_box ( int x, int y, int w, int h) | |||
{ | |||
cucul_draw_thin_box(qq, x, y, w, h); | |||
cucul_draw_thin_box(c, x, y, w, h); | |||
} | |||
void Cucul::fill_box ( int x, int y, int w, int h, char const *c) | |||
void Cucul::fill_box ( int x, int y, int w, int h, char const *ch) | |||
{ | |||
cucul_fill_box(qq, x, y, w, h, c); | |||
cucul_fill_box(c, x, y, w, h, ch); | |||
} | |||
void Cucul::draw_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, char const *c) | |||
void Cucul::draw_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, char const *ch) | |||
{ | |||
cucul_draw_triangle(qq, x1, y1, x2, y2, x3, y3, c); | |||
cucul_draw_triangle(c, x1, y1, x2, y2, x3, y3, ch); | |||
} | |||
void Cucul::draw_thin_triangle ( int x1, int y1, int x2, int y2, int x3, int y3) | |||
{ | |||
cucul_draw_thin_triangle(qq, x1, y1, x2, y2, x3, y3); | |||
cucul_draw_thin_triangle(c, x1, y1, x2, y2, x3, y3); | |||
} | |||
void Cucul::fill_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, const char *c) | |||
void Cucul::fill_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, const char *ch) | |||
{ | |||
cucul_fill_triangle(qq, x1, y1, x2, y2, x3, y3, c); | |||
cucul_fill_triangle(c, x1, y1, x2, y2, x3, y3, ch); | |||
} | |||
int Cucul::rand (int min, int max) | |||
@@ -228,7 +228,7 @@ int Cucul::get_sprite_dy (Cucul::Sprite const *s, int v) | |||
void Cucul::draw_sprite ( int x, int y, Cucul::Sprite const *s, int v) | |||
{ | |||
cucul_draw_sprite(qq, x, y, s->sprite, v); | |||
cucul_draw_sprite(c, x, y, s->sprite, v); | |||
} | |||
void Cucul::free_sprite (Cucul::Sprite *s) | |||
@@ -310,7 +310,7 @@ char const *const * Cucul::get_dither_mode_list ( Cucul::Dither const *d) | |||
void Cucul::dither_bitmap ( int x, int y, int w, int h, Cucul::Dither const *d, void *v) | |||
{ | |||
cucul_dither_bitmap(qq, x, y, w, h, d->dither, v); | |||
cucul_dither_bitmap(c, x, y, w, h, d->dither, v); | |||
} | |||
void Cucul::free_dither ( Cucul::Dither *d) | |||
@@ -340,9 +340,9 @@ unsigned int Cucul::get_font_height ( Cucul::Font *f) | |||
return cucul_get_font_height(f->font); | |||
} | |||
void Cucul::render_canvas (Cucul::Font *f, unsigned char *c, unsigned int x, unsigned int y, unsigned int w) | |||
void Cucul::render_canvas (Cucul::Font *f, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w) | |||
{ | |||
cucul_render_canvas(qq, f->font, c, x,y,w); | |||
cucul_render_canvas(c, f->font, buf, x,y,w); | |||
} | |||
void Cucul::free_font ( Cucul::Font *f) | |||
@@ -350,10 +350,10 @@ void Cucul::free_font ( Cucul::Font *f) | |||
cucul_free_font(f->font); | |||
} | |||
Cucul::Buffer * Cucul::create_export (char const *c) | |||
Cucul::Buffer * Cucul::create_export (char const *buf) | |||
{ | |||
Cucul::Buffer *b = new Cucul::Buffer(); | |||
b->buffer = cucul_create_export(qq, c); | |||
b->buffer = cucul_create_export(c, buf); | |||
return b; | |||
} | |||
@@ -123,10 +123,10 @@ class Cucul { | |||
protected: | |||
cucul_t *get_cucul_t(); | |||
cucul_canvas_t *get_cucul_canvas_t(); | |||
private: | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
}; | |||
@@ -26,7 +26,7 @@ | |||
/** \brief Draw a box on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the upper-left corner of the box. | |||
* \param y1 Y coordinate of the upper-left corner of the box. | |||
* \param x2 X coordinate of the lower-right corner of the box. | |||
@@ -34,25 +34,25 @@ | |||
* \param str UTF-8 string containing the character to use to draw the box. | |||
* \return void | |||
*/ | |||
void cucul_draw_box(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
void cucul_draw_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2, | |||
char const *str) | |||
{ | |||
cucul_draw_line(qq, x1, y1, x1, y2, str); | |||
cucul_draw_line(qq, x1, y2, x2, y2, str); | |||
cucul_draw_line(qq, x2, y2, x2, y1, str); | |||
cucul_draw_line(qq, x2, y1, x1, y1, str); | |||
cucul_draw_line(c, x1, y1, x1, y2, str); | |||
cucul_draw_line(c, x1, y2, x2, y2, str); | |||
cucul_draw_line(c, x2, y2, x2, y1, str); | |||
cucul_draw_line(c, x2, y1, x1, y1, str); | |||
} | |||
/** \brief Draw a thin box on the canvas. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the upper-left corner of the box. | |||
* \param y1 Y coordinate of the upper-left corner of the box. | |||
* \param x2 X coordinate of the lower-right corner of the box. | |||
* \param y2 Y coordinate of the lower-right corner of the box. | |||
* \return void | |||
*/ | |||
void cucul_draw_thin_box(cucul_t *qq, int x1, int y1, int x2, int y2) | |||
void cucul_draw_thin_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2) | |||
{ | |||
int x, y, xmax, ymax; | |||
@@ -68,8 +68,8 @@ void cucul_draw_thin_box(cucul_t *qq, int x1, int y1, int x2, int y2) | |||
y1 = y2; y2 = tmp; | |||
} | |||
xmax = qq->width - 1; | |||
ymax = qq->height - 1; | |||
xmax = c->width - 1; | |||
ymax = c->height - 1; | |||
if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | |||
return; | |||
@@ -77,37 +77,37 @@ void cucul_draw_thin_box(cucul_t *qq, int x1, int y1, int x2, int y2) | |||
/* Draw edges */ | |||
if(y1 >= 0) | |||
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) | |||
_cucul_putchar32(qq, x, y1, (uint32_t)'-'); | |||
_cucul_putchar32(c, x, y1, (uint32_t)'-'); | |||
if(y2 <= ymax) | |||
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) | |||
_cucul_putchar32(qq, x, y2, (uint32_t)'-'); | |||
_cucul_putchar32(c, x, y2, (uint32_t)'-'); | |||
if(x1 >= 0) | |||
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) | |||
_cucul_putchar32(qq, x1, y, (uint32_t)'|'); | |||
_cucul_putchar32(c, x1, y, (uint32_t)'|'); | |||
if(x2 <= xmax) | |||
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) | |||
_cucul_putchar32(qq, x2, y, (uint32_t)'|'); | |||
_cucul_putchar32(c, x2, y, (uint32_t)'|'); | |||
/* Draw corners */ | |||
if(x1 >= 0 && y1 >= 0) | |||
_cucul_putchar32(qq, x1, y1, (uint32_t)','); | |||
_cucul_putchar32(c, x1, y1, (uint32_t)','); | |||
if(x1 >= 0 && y2 <= ymax) | |||
_cucul_putchar32(qq, x1, y2, (uint32_t)'`'); | |||
_cucul_putchar32(c, x1, y2, (uint32_t)'`'); | |||
if(x2 <= xmax && y1 >= 0) | |||
_cucul_putchar32(qq, x2, y1, (uint32_t)'.'); | |||
_cucul_putchar32(c, x2, y1, (uint32_t)'.'); | |||
if(x2 <= xmax && y2 <= ymax) | |||
_cucul_putchar32(qq, x2, y2, (uint32_t)'\''); | |||
_cucul_putchar32(c, x2, y2, (uint32_t)'\''); | |||
} | |||
/** \brief Fill a box on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the upper-left corner of the box. | |||
* \param y1 Y coordinate of the upper-left corner of the box. | |||
* \param x2 X coordinate of the lower-right corner of the box. | |||
@@ -115,11 +115,11 @@ void cucul_draw_thin_box(cucul_t *qq, int x1, int y1, int x2, int y2) | |||
* \param str UTF-8 string containing the character to fill the box with. | |||
* \return void | |||
*/ | |||
void cucul_fill_box(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
void cucul_fill_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2, | |||
char const *str) | |||
{ | |||
int x, y, xmax, ymax; | |||
uint32_t c; | |||
uint32_t ch; | |||
if(x1 > x2) | |||
{ | |||
@@ -133,8 +133,8 @@ void cucul_fill_box(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
y1 = y2; y2 = tmp; | |||
} | |||
xmax = qq->width - 1; | |||
ymax = qq->height - 1; | |||
xmax = c->width - 1; | |||
ymax = c->height - 1; | |||
if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | |||
return; | |||
@@ -144,10 +144,10 @@ void cucul_fill_box(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
if(x2 > xmax) x2 = xmax; | |||
if(y2 > ymax) y2 = ymax; | |||
c = _cucul_utf8_to_utf32(str); | |||
ch = _cucul_utf8_to_utf32(str); | |||
for(y = y1; y <= y2; y++) | |||
for(x = x1; x <= x2; x++) | |||
_cucul_putchar32(qq, x, y, c); | |||
_cucul_putchar32(c, x, y, ch); | |||
} | |||
@@ -46,22 +46,22 @@ | |||
* replaced with a space. To print a sequence of bytes forming an UTF-8 | |||
* character, use cucul_putstr() instead. | |||
* | |||
* \param qq A handle to the libcucul canvas. | |||
* \param c A handle to the libcucul canvas. | |||
* \param x X coordinate. | |||
* \param y Y coordinate. | |||
* \param c The character to print. | |||
* \param ch The character to print. | |||
*/ | |||
void cucul_putchar(cucul_t *qq, int x, int y, char c) | |||
void cucul_putchar(cucul_canvas_t *c, int x, int y, char ch) | |||
{ | |||
if(x < 0 || x >= (int)qq->width || | |||
y < 0 || y >= (int)qq->height) | |||
if(x < 0 || x >= (int)c->width || | |||
y < 0 || y >= (int)c->height) | |||
return; | |||
if((unsigned char)c < 0x20 || (unsigned char)c > 0x7f) | |||
c = 0x20; | |||
if((unsigned char)ch < 0x20 || (unsigned char)ch > 0x7f) | |||
ch = 0x20; | |||
qq->chars[x + y * qq->width] = c; | |||
qq->attr[x + y * qq->width] = (qq->bgcolor << 16) | qq->fgcolor; | |||
c->chars[x + y * c->width] = ch; | |||
c->attr[x + y * c->width] = (c->bgcolor << 16) | c->fgcolor; | |||
} | |||
/** \brief Print a string. | |||
@@ -71,17 +71,17 @@ void cucul_putchar(cucul_t *qq, int x, int y, char c) | |||
* the canvas boundaries (eg. a negative Y coordinate) and the string will | |||
* be cropped accordingly if it is too long. | |||
* | |||
* \param qq A handle to the libcucul canvas. | |||
* \param c A handle to the libcucul canvas. | |||
* \param x X coordinate. | |||
* \param y Y coordinate. | |||
* \param s The string to print. | |||
*/ | |||
void cucul_putstr(cucul_t *qq, int x, int y, char const *s) | |||
void cucul_putstr(cucul_canvas_t *c, int x, int y, char const *s) | |||
{ | |||
uint32_t *chars, *attr; | |||
unsigned int len; | |||
if(y < 0 || y >= (int)qq->height || x >= (int)qq->width) | |||
if(y < 0 || y >= (int)c->height || x >= (int)c->width) | |||
return; | |||
len = _cucul_strlen_utf8(s); | |||
@@ -95,16 +95,16 @@ void cucul_putstr(cucul_t *qq, int x, int y, char const *s) | |||
x = 0; | |||
} | |||
chars = qq->chars + x + y * qq->width; | |||
attr = qq->attr + x + y * qq->width; | |||
chars = c->chars + x + y * c->width; | |||
attr = c->attr + x + y * c->width; | |||
if(x + len >= qq->width) | |||
len = qq->width - x; | |||
if(x + len >= c->width) | |||
len = c->width - x; | |||
while(len) | |||
{ | |||
*chars++ = _cucul_utf8_to_utf32(s); | |||
*attr++ = (qq->bgcolor << 16) | qq->fgcolor; | |||
*attr++ = (c->bgcolor << 16) | c->fgcolor; | |||
s = _cucul_skip_utf8(s, 1); | |||
len--; | |||
@@ -119,34 +119,34 @@ void cucul_putstr(cucul_t *qq, int x, int y, char const *s) | |||
* be cropped accordingly if it is too long. The syntax of the format | |||
* string is the same as for the C printf() function. | |||
* | |||
* \param qq A handle to the libcucul canvas. | |||
* \param c A handle to the libcucul canvas. | |||
* \param x X coordinate. | |||
* \param y Y coordinate. | |||
* \param format The format string to print. | |||
* \param ... Arguments to the format string. | |||
*/ | |||
void cucul_printf(cucul_t *qq, int x, int y, char const *format, ...) | |||
void cucul_printf(cucul_canvas_t *c, int x, int y, char const *format, ...) | |||
{ | |||
char tmp[BUFSIZ]; | |||
char *buf = tmp; | |||
va_list args; | |||
if(y < 0 || y >= (int)qq->height || x >= (int)qq->width) | |||
if(y < 0 || y >= (int)c->height || x >= (int)c->width) | |||
return; | |||
if(qq->width - x + 1 > BUFSIZ) | |||
buf = malloc(qq->width - x + 1); | |||
if(c->width - x + 1 > BUFSIZ) | |||
buf = malloc(c->width - x + 1); | |||
va_start(args, format); | |||
#if defined(HAVE_VSNPRINTF) | |||
vsnprintf(buf, qq->width - x + 1, format, args); | |||
vsnprintf(buf, c->width - x + 1, format, args); | |||
#else | |||
vsprintf(buf, format, args); | |||
#endif | |||
buf[qq->width - x] = '\0'; | |||
buf[c->width - x] = '\0'; | |||
va_end(args); | |||
cucul_putstr(qq, x, y, buf); | |||
cucul_putstr(c, x, y, buf); | |||
if(buf != tmp) | |||
free(buf); | |||
@@ -156,20 +156,20 @@ void cucul_printf(cucul_t *qq, int x, int y, char const *format, ...) | |||
* | |||
* This function clears the canvas using a black background. | |||
*/ | |||
void cucul_clear(cucul_t *qq) | |||
void cucul_clear(cucul_canvas_t *c) | |||
{ | |||
uint16_t oldfg = qq->fgcolor; | |||
uint16_t oldbg = qq->bgcolor; | |||
int y = qq->height; | |||
uint16_t oldfg = c->fgcolor; | |||
uint16_t oldbg = c->bgcolor; | |||
int y = c->height; | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
/* We could use SLsmg_cls() etc., but drawing empty lines is much faster */ | |||
while(y--) | |||
cucul_putstr(qq, 0, y, qq->empty_line); | |||
cucul_putstr(c, 0, y, c->empty_line); | |||
qq->fgcolor = oldfg; | |||
qq->bgcolor = oldbg; | |||
c->fgcolor = oldfg; | |||
c->bgcolor = oldbg; | |||
} | |||
/** \brief Blit a canvas onto another one. | |||
@@ -183,8 +183,8 @@ void cucul_clear(cucul_t *qq) | |||
* \param src The source canvas. | |||
* \param mask The mask canvas. | |||
*/ | |||
void cucul_blit(cucul_t *dst, int x, int y, | |||
cucul_t const *src, cucul_t const *mask) | |||
void cucul_blit(cucul_canvas_t *dst, int x, int y, | |||
cucul_canvas_t const *src, cucul_canvas_t const *mask) | |||
{ | |||
int i, j, starti, startj, endi, endj; | |||
@@ -230,13 +230,13 @@ void cucul_blit(cucul_t *dst, int x, int y, | |||
* XXX: The following functions are not exported | |||
*/ | |||
void _cucul_putchar32(cucul_t *qq, int x, int y, uint32_t c) | |||
void _cucul_putchar32(cucul_canvas_t *c, int x, int y, uint32_t ch) | |||
{ | |||
if(x < 0 || x >= (int)qq->width || | |||
y < 0 || y >= (int)qq->height) | |||
if(x < 0 || x >= (int)c->width || | |||
y < 0 || y >= (int)c->height) | |||
return; | |||
qq->chars[x + y * qq->width] = c; | |||
qq->attr[x + y * qq->width] = (qq->bgcolor << 16) | qq->fgcolor; | |||
c->chars[x + y * c->width] = ch; | |||
c->attr[x + y * c->width] = (c->bgcolor << 16) | c->fgcolor; | |||
} | |||
@@ -36,17 +36,17 @@ static const uint16_t ansitab[16] = | |||
* Color values are those defined in \e cucul.h, such as CUCUL_COLOR_RED | |||
* or CUCUL_COLOR_TRANSPARENT. | |||
* | |||
* \param qq A handle to the libcucul canvas. | |||
* \param c A handle to the libcucul canvas. | |||
* \param fg The requested foreground colour. | |||
* \param bg The requested background colour. | |||
*/ | |||
void cucul_set_color(cucul_t *qq, unsigned char fg, unsigned char bg) | |||
void cucul_set_color(cucul_canvas_t *c, unsigned char fg, unsigned char bg) | |||
{ | |||
if(fg > 0x20 || bg > 0x20) | |||
return; | |||
qq->fgcolor = fg; | |||
qq->bgcolor = bg; | |||
c->fgcolor = fg; | |||
c->bgcolor = bg; | |||
} | |||
/** \brief Set the default colour pair (truecolor version). | |||
@@ -59,11 +59,11 @@ void cucul_set_color(cucul_t *qq, unsigned char fg, unsigned char bg) | |||
* instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is | |||
* white with 50% alpha (A=8 R=15 G=15 B=15). | |||
* | |||
* \param qq A handle to the libcucul canvas. | |||
* \param c A handle to the libcucul canvas. | |||
* \param fg The requested foreground colour. | |||
* \param bg The requested background colour. | |||
*/ | |||
void cucul_set_truecolor(cucul_t *qq, unsigned int fg, unsigned int bg) | |||
void cucul_set_truecolor(cucul_canvas_t *c, unsigned int fg, unsigned int bg) | |||
{ | |||
if(fg > 0xffff || bg > 0xffff) | |||
return; | |||
@@ -74,8 +74,8 @@ void cucul_set_truecolor(cucul_t *qq, unsigned int fg, unsigned int bg) | |||
if(bg < 0x100) | |||
bg += 0x100; | |||
qq->fgcolor = fg; | |||
qq->bgcolor = bg; | |||
c->fgcolor = fg; | |||
c->bgcolor = bg; | |||
} | |||
/* | |||
@@ -124,28 +124,28 @@ static uint8_t nearest_ansi(uint16_t argb16, uint8_t def) | |||
return best; | |||
} | |||
uint8_t _cucul_argb32_to_ansi8(uint32_t c) | |||
uint8_t _cucul_argb32_to_ansi8(uint32_t ch) | |||
{ | |||
uint16_t fg = c & 0xffff; | |||
uint16_t bg = c >> 16; | |||
uint16_t fg = ch & 0xffff; | |||
uint16_t bg = ch >> 16; | |||
return nearest_ansi(fg, CUCUL_COLOR_LIGHTGRAY) | |||
| (nearest_ansi(bg, CUCUL_COLOR_BLACK) << 4); | |||
} | |||
uint8_t _cucul_argb32_to_ansi4fg(uint32_t c) | |||
uint8_t _cucul_argb32_to_ansi4fg(uint32_t ch) | |||
{ | |||
return nearest_ansi(c & 0xffff, CUCUL_COLOR_LIGHTGRAY); | |||
return nearest_ansi(ch & 0xffff, CUCUL_COLOR_LIGHTGRAY); | |||
} | |||
uint8_t _cucul_argb32_to_ansi4bg(uint32_t c) | |||
uint8_t _cucul_argb32_to_ansi4bg(uint32_t ch) | |||
{ | |||
return nearest_ansi(c >> 16, CUCUL_COLOR_BLACK); | |||
return nearest_ansi(ch >> 16, CUCUL_COLOR_BLACK); | |||
} | |||
uint16_t _cucul_argb32_to_rgb12fg(uint32_t c) | |||
uint16_t _cucul_argb32_to_rgb12fg(uint32_t ch) | |||
{ | |||
uint16_t fg = c & 0xffff; | |||
uint16_t fg = ch & 0xffff; | |||
if(fg < CUCUL_COLOR_DEFAULT) | |||
return ansitab[fg] & 0x0fff; | |||
@@ -159,9 +159,9 @@ uint16_t _cucul_argb32_to_rgb12fg(uint32_t c) | |||
return fg & 0x0fff; | |||
} | |||
uint16_t _cucul_argb32_to_rgb12bg(uint32_t c) | |||
uint16_t _cucul_argb32_to_rgb12bg(uint32_t ch) | |||
{ | |||
uint16_t bg = c >> 16; | |||
uint16_t bg = ch >> 16; | |||
if(bg < CUCUL_COLOR_DEFAULT) | |||
return ansitab[bg] & 0x0fff; | |||
@@ -180,20 +180,20 @@ uint16_t _cucul_argb32_to_rgb12bg(uint32_t c) | |||
| ((uint32_t)((i & 0x0f0) >> 4) * 0x001100) \ | |||
| ((uint32_t)(i & 0x00f) * 0x000011)) | |||
uint32_t _cucul_argb32_to_rgb24fg(uint32_t c) | |||
uint32_t _cucul_argb32_to_rgb24fg(uint32_t ch) | |||
{ | |||
return RGB12TO24(_cucul_argb32_to_rgb12fg(c)); | |||
return RGB12TO24(_cucul_argb32_to_rgb12fg(ch)); | |||
} | |||
uint32_t _cucul_argb32_to_rgb24bg(uint32_t c) | |||
uint32_t _cucul_argb32_to_rgb24bg(uint32_t ch) | |||
{ | |||
return RGB12TO24(_cucul_argb32_to_rgb12bg(c)); | |||
return RGB12TO24(_cucul_argb32_to_rgb12bg(ch)); | |||
} | |||
void _cucul_argb32_to_argb4(uint32_t c, uint8_t argb[8]) | |||
void _cucul_argb32_to_argb4(uint32_t ch, uint8_t argb[8]) | |||
{ | |||
uint16_t fg = c & 0xffff; | |||
uint16_t bg = c >> 16; | |||
uint16_t fg = ch & 0xffff; | |||
uint16_t bg = ch >> 16; | |||
if(fg < CUCUL_COLOR_DEFAULT) | |||
fg = ansitab[fg]; | |||
@@ -25,11 +25,11 @@ | |||
#include "cucul.h" | |||
#include "cucul_internals.h" | |||
static void ellipsepoints(cucul_t *, int, int, int, int, uint32_t); | |||
static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t); | |||
/** \brief Draw a circle on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x Center X coordinate. | |||
* \param y Center Y coordinate. | |||
* \param r Circle radius. | |||
@@ -37,16 +37,16 @@ static void ellipsepoints(cucul_t *, int, int, int, int, uint32_t); | |||
* to draw the circle outline. | |||
* \return void | |||
*/ | |||
void cucul_draw_circle(cucul_t *qq, int x, int y, int r, char const *str) | |||
void cucul_draw_circle(cucul_canvas_t *c, int x, int y, int r, char const *str) | |||
{ | |||
int test, dx, dy; | |||
uint32_t c = _cucul_utf8_to_utf32(str); | |||
uint32_t ch = _cucul_utf8_to_utf32(str); | |||
/* Optimized Bresenham. Kick ass. */ | |||
for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++) | |||
{ | |||
ellipsepoints(qq, x, y, dx, dy, c); | |||
ellipsepoints(qq, x, y, dy, dx, c); | |||
ellipsepoints(c, x, y, dx, dy, ch); | |||
ellipsepoints(c, x, y, dy, dx, ch); | |||
test += test > 0 ? dx - dy-- : dx; | |||
} | |||
@@ -54,7 +54,7 @@ void cucul_draw_circle(cucul_t *qq, int x, int y, int r, char const *str) | |||
/** \brief Fill an ellipse on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param xo Center X coordinate. | |||
* \param yo Center Y coordinate. | |||
* \param a Ellipse X radius. | |||
@@ -63,7 +63,7 @@ void cucul_draw_circle(cucul_t *qq, int x, int y, int r, char const *str) | |||
* to fill the ellipse. | |||
* \return void | |||
*/ | |||
void cucul_fill_ellipse(cucul_t *qq, int xo, int yo, int a, int b, | |||
void cucul_fill_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b, | |||
char const *str) | |||
{ | |||
int d2; | |||
@@ -80,15 +80,15 @@ void cucul_fill_ellipse(cucul_t *qq, int xo, int yo, int a, int b, | |||
else | |||
{ | |||
d1 += b*b*(2*x*1) + a*a*(-2*y+2); | |||
cucul_draw_line(qq, xo - x, yo - y, xo + x, yo - y, str); | |||
cucul_draw_line(qq, xo - x, yo + y, xo + x, yo + y, str); | |||
cucul_draw_line(c, xo - x, yo - y, xo + x, yo - y, str); | |||
cucul_draw_line(c, xo - x, yo + y, xo + x, yo + y, str); | |||
y--; | |||
} | |||
x++; | |||
} | |||
cucul_draw_line(qq, xo - x, yo - y, xo + x, yo - y, str); | |||
cucul_draw_line(qq, xo - x, yo + y, xo + x, yo + y, str); | |||
cucul_draw_line(c, xo - x, yo - y, xo + x, yo - y, str); | |||
cucul_draw_line(c, xo - x, yo + y, xo + x, yo + y, str); | |||
d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; | |||
while(y > 0) | |||
@@ -104,14 +104,14 @@ void cucul_fill_ellipse(cucul_t *qq, int xo, int yo, int a, int b, | |||
} | |||
y--; | |||
cucul_draw_line(qq, xo - x, yo - y, xo + x, yo - y, str); | |||
cucul_draw_line(qq, xo - x, yo + y, xo + x, yo + y, str); | |||
cucul_draw_line(c, xo - x, yo - y, xo + x, yo - y, str); | |||
cucul_draw_line(c, xo - x, yo + y, xo + x, yo + y, str); | |||
} | |||
} | |||
/** \brief Draw an ellipse on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param xo Center X coordinate. | |||
* \param yo Center Y coordinate. | |||
* \param a Ellipse X radius. | |||
@@ -120,16 +120,16 @@ void cucul_fill_ellipse(cucul_t *qq, int xo, int yo, int a, int b, | |||
* to draw the ellipse outline. | |||
* \return void | |||
*/ | |||
void cucul_draw_ellipse(cucul_t *qq, int xo, int yo, int a, int b, | |||
void cucul_draw_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b, | |||
char const *str) | |||
{ | |||
int d2; | |||
int x = 0; | |||
int y = b; | |||
int d1 = b*b - (a*a*b) + (a*a/4); | |||
uint32_t c = _cucul_utf8_to_utf32(str); | |||
uint32_t ch = _cucul_utf8_to_utf32(str); | |||
ellipsepoints(qq, xo, yo, x, y, c); | |||
ellipsepoints(c, xo, yo, x, y, ch); | |||
while(a*a*y - a*a/2 > b*b*(x+1)) | |||
{ | |||
@@ -143,7 +143,7 @@ void cucul_draw_ellipse(cucul_t *qq, int xo, int yo, int a, int b, | |||
y--; | |||
} | |||
x++; | |||
ellipsepoints(qq, xo, yo, x, y, c); | |||
ellipsepoints(c, xo, yo, x, y, ch); | |||
} | |||
d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; | |||
@@ -160,20 +160,20 @@ void cucul_draw_ellipse(cucul_t *qq, int xo, int yo, int a, int b, | |||
} | |||
y--; | |||
ellipsepoints(qq, xo, yo, x, y, c); | |||
ellipsepoints(c, xo, yo, x, y, ch); | |||
} | |||
} | |||
/** \brief Draw a thin ellipse on the canvas. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param xo Center X coordinate. | |||
* \param yo Center Y coordinate. | |||
* \param a Ellipse X radius. | |||
* \param b Ellipse Y radius. | |||
* \return void | |||
*/ | |||
void cucul_draw_thin_ellipse(cucul_t *qq, int xo, int yo, int a, int b) | |||
void cucul_draw_thin_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b) | |||
{ | |||
/* FIXME: this is not correct */ | |||
int d2; | |||
@@ -181,7 +181,7 @@ void cucul_draw_thin_ellipse(cucul_t *qq, int xo, int yo, int a, int b) | |||
int y = b; | |||
int d1 = b*b - (a*a*b) + (a*a/4); | |||
ellipsepoints(qq, xo, yo, x, y, '-'); | |||
ellipsepoints(c, xo, yo, x, y, '-'); | |||
while(a*a*y - a*a/2 > b*b*(x+1)) | |||
{ | |||
@@ -195,7 +195,7 @@ void cucul_draw_thin_ellipse(cucul_t *qq, int xo, int yo, int a, int b) | |||
y--; | |||
} | |||
x++; | |||
ellipsepoints(qq, xo, yo, x, y, '-'); | |||
ellipsepoints(c, xo, yo, x, y, '-'); | |||
} | |||
d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; | |||
@@ -212,33 +212,34 @@ void cucul_draw_thin_ellipse(cucul_t *qq, int xo, int yo, int a, int b) | |||
} | |||
y--; | |||
ellipsepoints(qq, xo, yo, x, y, '|'); | |||
ellipsepoints(c, xo, yo, x, y, '|'); | |||
} | |||
} | |||
static void ellipsepoints(cucul_t *qq, int xo, int yo, int x, int y, uint32_t c) | |||
static void ellipsepoints(cucul_canvas_t *c, int xo, int yo, int x, int y, | |||
uint32_t ch) | |||
{ | |||
uint8_t b = 0; | |||
if(xo + x >= 0 && xo + x < (int)qq->width) | |||
if(xo + x >= 0 && xo + x < (int)c->width) | |||
b |= 0x1; | |||
if(xo - x >= 0 && xo - x < (int)qq->width) | |||
if(xo - x >= 0 && xo - x < (int)c->width) | |||
b |= 0x2; | |||
if(yo + y >= 0 && yo + y < (int)qq->height) | |||
if(yo + y >= 0 && yo + y < (int)c->height) | |||
b |= 0x4; | |||
if(yo - y >= 0 && yo - y < (int)qq->height) | |||
if(yo - y >= 0 && yo - y < (int)c->height) | |||
b |= 0x8; | |||
if((b & (0x1|0x4)) == (0x1|0x4)) | |||
_cucul_putchar32(qq, xo + x, yo + y, c); | |||
_cucul_putchar32(c, xo + x, yo + y, ch); | |||
if((b & (0x2|0x4)) == (0x2|0x4)) | |||
_cucul_putchar32(qq, xo - x, yo + y, c); | |||
_cucul_putchar32(c, xo - x, yo + y, ch); | |||
if((b & (0x1|0x8)) == (0x1|0x8)) | |||
_cucul_putchar32(qq, xo + x, yo - y, c); | |||
_cucul_putchar32(c, xo + x, yo - y, ch); | |||
if((b & (0x2|0x8)) == (0x2|0x8)) | |||
_cucul_putchar32(qq, xo - x, yo - y, c); | |||
_cucul_putchar32(c, xo - x, yo - y, ch); | |||
} | |||
@@ -41,35 +41,35 @@ | |||
* \param height The desired canvas height | |||
* \return A libcucul canvas handle upon success, NULL if an error occurred. | |||
*/ | |||
cucul_t * cucul_create(unsigned int width, unsigned int height) | |||
cucul_canvas_t * cucul_create(unsigned int width, unsigned int height) | |||
{ | |||
cucul_t *qq = malloc(sizeof(cucul_t)); | |||
cucul_canvas_t *c = malloc(sizeof(cucul_canvas_t)); | |||
qq->refcount = 0; | |||
c->refcount = 0; | |||
qq->fgcolor = CUCUL_COLOR_LIGHTGRAY; | |||
qq->bgcolor = CUCUL_COLOR_BLACK; | |||
c->fgcolor = CUCUL_COLOR_LIGHTGRAY; | |||
c->bgcolor = CUCUL_COLOR_BLACK; | |||
qq->width = qq->height = 0; | |||
qq->chars = NULL; | |||
qq->attr = NULL; | |||
qq->empty_line = qq->scratch_line = NULL; | |||
c->width = c->height = 0; | |||
c->chars = NULL; | |||
c->attr = NULL; | |||
c->empty_line = c->scratch_line = NULL; | |||
/* Initialise to a default size. 80x32 is arbitrary but matches AAlib's | |||
* default X11 window. When a graphic driver attaches to us, it can set | |||
* a different size. */ | |||
if(width && height) | |||
_cucul_set_size(qq, width, height); | |||
_cucul_set_size(c, width, height); | |||
else | |||
_cucul_set_size(qq, 80, 32); | |||
_cucul_set_size(c, 80, 32); | |||
if(_cucul_init_dither()) | |||
{ | |||
free(qq); | |||
free(c); | |||
return NULL; | |||
} | |||
return qq; | |||
return c; | |||
} | |||
/** \brief Load a memory area into a canvas. | |||
@@ -81,9 +81,9 @@ cucul_t * cucul_create(unsigned int width, unsigned int height) | |||
* \param size The length of the memory area. | |||
* \return A libcucul canvas, or NULL in case of error. | |||
*/ | |||
cucul_t *cucul_load(void *data, unsigned int size) | |||
cucul_canvas_t *cucul_load(void *data, unsigned int size) | |||
{ | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
uint8_t *buf = (uint8_t *)data; | |||
unsigned int width, height, n; | |||
@@ -108,24 +108,24 @@ cucul_t *cucul_load(void *data, unsigned int size) | |||
|| buf[size - 2] != 'A' || buf[size - 1] != 'C') | |||
return NULL; | |||
qq = cucul_create(width, height); | |||
c = cucul_create(width, height); | |||
if(!qq) | |||
if(!c) | |||
return NULL; | |||
for(n = height * width; n--; ) | |||
{ | |||
qq->chars[n] = ((uint32_t)buf[12 + 8 * n] << 24) | |||
c->chars[n] = ((uint32_t)buf[12 + 8 * n] << 24) | |||
| ((uint32_t)buf[13 + 8 * n] << 16) | |||
| ((uint32_t)buf[14 + 8 * n] << 8) | |||
| (uint32_t)buf[15 + 8 * n]; | |||
qq->attr[n] = ((uint32_t)buf[16 + 8 * n] << 24) | |||
c->attr[n] = ((uint32_t)buf[16 + 8 * n] << 24) | |||
| ((uint32_t)buf[17 + 8 * n] << 16) | |||
| ((uint32_t)buf[18 + 8 * n] << 8) | |||
| (uint32_t)buf[19 + 8 * n]; | |||
} | |||
return qq; | |||
return c; | |||
} | |||
/** \brief Resize a canvas. | |||
@@ -143,40 +143,40 @@ cucul_t *cucul_load(void *data, unsigned int size) | |||
* resize through user interaction. See the caca_event() documentation | |||
* for more about this. | |||
* | |||
* \param qq A libcucul canvas | |||
* \param c A libcucul canvas | |||
* \param width The desired canvas width | |||
* \param height The desired canvas height | |||
*/ | |||
void cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height) | |||
void cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height) | |||
{ | |||
if(qq->refcount) | |||
if(c->refcount) | |||
return; | |||
_cucul_set_size(qq, width, height); | |||
_cucul_set_size(c, width, height); | |||
} | |||
/** \brief Get the canvas width. | |||
* | |||
* This function returns the current canvas width, in character cells. | |||
* | |||
* \param qq A libcucul canvas | |||
* \param c A libcucul canvas | |||
* \return The canvas width. | |||
*/ | |||
unsigned int cucul_get_width(cucul_t *qq) | |||
unsigned int cucul_get_width(cucul_canvas_t *c) | |||
{ | |||
return qq->width; | |||
return c->width; | |||
} | |||
/** \brief Get the canvas height. | |||
* | |||
* This function returns the current canvas height, in character cells. | |||
* | |||
* \param qq A libcucul canvas | |||
* \param c A libcucul canvas | |||
* \return The canvas height. | |||
*/ | |||
unsigned int cucul_get_height(cucul_t *qq) | |||
unsigned int cucul_get_height(cucul_canvas_t *c) | |||
{ | |||
return qq->height; | |||
return c->height; | |||
} | |||
/** \brief Translate a colour index into the colour's name. | |||
@@ -221,19 +221,19 @@ char const *cucul_get_color_name(unsigned int color) | |||
* cucul_free() has been called, no other \e libcucul functions may be used | |||
* unless a new call to cucul_create() is done. | |||
* | |||
* \param qq A libcucul canvas | |||
* \param c A libcucul canvas | |||
*/ | |||
void cucul_free(cucul_t *qq) | |||
void cucul_free(cucul_canvas_t *c) | |||
{ | |||
_cucul_end_dither(); | |||
free(qq->empty_line); | |||
free(qq->scratch_line); | |||
free(c->empty_line); | |||
free(c->scratch_line); | |||
free(qq->chars); | |||
free(qq->attr); | |||
free(c->chars); | |||
free(c->attr); | |||
free(qq); | |||
free(c); | |||
} | |||
/** \brief Generate a random integer within a range. | |||
@@ -290,23 +290,23 @@ void cucul_free_buffer(cucul_buffer_t *buf) | |||
* XXX: The following functions are local. | |||
*/ | |||
void _cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height) | |||
void _cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height) | |||
{ | |||
unsigned int x, y, old_width, old_height, new_size, old_size; | |||
old_width = qq->width; | |||
old_height = qq->height; | |||
old_width = c->width; | |||
old_height = c->height; | |||
old_size = old_width * old_height; | |||
qq->width = width; | |||
qq->height = height; | |||
c->width = width; | |||
c->height = height; | |||
new_size = width * height; | |||
/* Step 1: if new area is bigger, resize the memory area now. */ | |||
if(new_size > old_size) | |||
{ | |||
qq->chars = realloc(qq->chars, new_size * sizeof(uint32_t)); | |||
qq->attr = realloc(qq->attr, new_size * sizeof(uint32_t)); | |||
c->chars = realloc(c->chars, new_size * sizeof(uint32_t)); | |||
c->attr = realloc(c->attr, new_size * sizeof(uint32_t)); | |||
} | |||
/* Step 2: move line data if necessary. */ | |||
@@ -324,14 +324,14 @@ void _cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height) | |||
{ | |||
for(x = old_width; x--; ) | |||
{ | |||
qq->chars[y * width + x] = qq->chars[y * old_width + x]; | |||
qq->attr[y * width + x] = qq->attr[y * old_width + x]; | |||
c->chars[y * width + x] = c->chars[y * old_width + x]; | |||
c->attr[y * width + x] = c->attr[y * old_width + x]; | |||
} | |||
/* Zero the end of the line */ | |||
for(x = width - old_width; x--; ) | |||
qq->chars[y * width + old_width + x] = (uint32_t)' '; | |||
memset(qq->attr + y * width + old_width, 0, | |||
c->chars[y * width + old_width + x] = (uint32_t)' '; | |||
memset(c->attr + y * width + old_width, 0, | |||
(width - old_width) * 4); | |||
} | |||
} | |||
@@ -345,8 +345,8 @@ void _cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height) | |||
{ | |||
for(x = 0; x < width; x++) | |||
{ | |||
qq->chars[y * width + x] = qq->chars[y * old_width + x]; | |||
qq->attr[y * width + x] = qq->attr[y * old_width + x]; | |||
c->chars[y * width + x] = c->chars[y * old_width + x]; | |||
c->attr[y * width + x] = c->attr[y * old_width + x]; | |||
} | |||
} | |||
} | |||
@@ -356,26 +356,26 @@ void _cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height) | |||
{ | |||
/* Zero the bottom of the screen */ | |||
for(x = (height - old_height) * width; x--; ) | |||
qq->chars[old_height * width + x] = (uint32_t)' '; | |||
memset(qq->attr + old_height * width, 0, | |||
c->chars[old_height * width + x] = (uint32_t)' '; | |||
memset(c->attr + old_height * width, 0, | |||
(height - old_height) * width * 4); | |||
} | |||
/* Step 4: if new area is smaller, resize memory area now. */ | |||
if(new_size <= old_size) | |||
{ | |||
qq->chars = realloc(qq->chars, new_size * sizeof(uint32_t)); | |||
qq->attr = realloc(qq->attr, new_size * sizeof(uint32_t)); | |||
c->chars = realloc(c->chars, new_size * sizeof(uint32_t)); | |||
c->attr = realloc(c->attr, new_size * sizeof(uint32_t)); | |||
} | |||
/* Recompute the scratch line and the empty line */ | |||
if(width != old_width) | |||
{ | |||
qq->empty_line = realloc(qq->empty_line, width + 1); | |||
memset(qq->empty_line, ' ', width); | |||
qq->empty_line[width] = '\0'; | |||
c->empty_line = realloc(c->empty_line, width + 1); | |||
memset(c->empty_line, ' ', width); | |||
c->empty_line[width] = '\0'; | |||
qq->scratch_line = realloc(qq->scratch_line, width + 1); | |||
c->scratch_line = realloc(c->scratch_line, width + 1); | |||
} | |||
} | |||
@@ -32,7 +32,7 @@ extern "C" | |||
#endif | |||
/** \e libcucul context */ | |||
typedef struct cucul cucul_t; | |||
typedef struct cucul_canvas cucul_canvas_t; | |||
/** sprite structure */ | |||
typedef struct cucul_sprite cucul_sprite_t; | |||
/** dither structure */ | |||
@@ -73,12 +73,12 @@ typedef struct cucul_font cucul_font_t; | |||
* initialisation, system information retrieval and configuration. | |||
* | |||
* @{ */ | |||
cucul_t * cucul_create(unsigned int, unsigned int); | |||
cucul_t * cucul_load(void *, unsigned int); | |||
void cucul_set_size(cucul_t *, unsigned int, unsigned int); | |||
unsigned int cucul_get_width(cucul_t *); | |||
unsigned int cucul_get_height(cucul_t *); | |||
void cucul_free(cucul_t *); | |||
cucul_canvas_t * cucul_create(unsigned int, unsigned int); | |||
cucul_canvas_t * cucul_load(void *, unsigned int); | |||
void cucul_set_size(cucul_canvas_t *, unsigned int, unsigned int); | |||
unsigned int cucul_get_width(cucul_canvas_t *); | |||
unsigned int cucul_get_height(cucul_canvas_t *); | |||
void cucul_free(cucul_canvas_t *); | |||
int cucul_rand(int, int); | |||
/* @} */ | |||
@@ -98,14 +98,14 @@ void cucul_free_buffer(cucul_buffer_t *); | |||
* higher level graphics functions. | |||
* | |||
* @{ */ | |||
void cucul_set_color(cucul_t *, unsigned char, unsigned char); | |||
void cucul_set_truecolor(cucul_t *, unsigned int, unsigned int); | |||
void cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char); | |||
void cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int); | |||
char const *cucul_get_color_name(unsigned int); | |||
void cucul_putchar(cucul_t *, int, int, char); | |||
void cucul_putstr(cucul_t *, int, int, char const *); | |||
void cucul_printf(cucul_t *, int, int, char const *, ...); | |||
void cucul_clear(cucul_t *); | |||
void cucul_blit(cucul_t *, int, int, cucul_t const *, cucul_t const *); | |||
void cucul_putchar(cucul_canvas_t *, int, int, char); | |||
void cucul_putstr(cucul_canvas_t *, int, int, char const *); | |||
void cucul_printf(cucul_canvas_t *, int, int, char const *, ...); | |||
void cucul_clear(cucul_canvas_t *); | |||
void cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *, cucul_canvas_t const *); | |||
/* @} */ | |||
/** \defgroup transform Canvas transformation | |||
@@ -113,10 +113,10 @@ void cucul_blit(cucul_t *, int, int, cucul_t const *, cucul_t const *); | |||
* These functions perform horizontal and vertical canvas flipping. | |||
* | |||
* @{ */ | |||
void cucul_invert(cucul_t *); | |||
void cucul_flip(cucul_t *); | |||
void cucul_flop(cucul_t *); | |||
void cucul_rotate(cucul_t *); | |||
void cucul_invert(cucul_canvas_t *); | |||
void cucul_flip(cucul_canvas_t *); | |||
void cucul_flop(cucul_canvas_t *); | |||
void cucul_rotate(cucul_canvas_t *); | |||
/* @} */ | |||
/** \defgroup prim Primitives drawing | |||
@@ -125,23 +125,23 @@ void cucul_rotate(cucul_t *); | |||
* boxes, triangles and ellipses. | |||
* | |||
* @{ */ | |||
void cucul_draw_line(cucul_t *, int, int, int, int, char const *); | |||
void cucul_draw_polyline(cucul_t *, int const x[], int const y[], int, char const *); | |||
void cucul_draw_thin_line(cucul_t *, int, int, int, int); | |||
void cucul_draw_thin_polyline(cucul_t *, int const x[], int const y[], int); | |||
void cucul_draw_circle(cucul_t *, int, int, int, char const *); | |||
void cucul_draw_ellipse(cucul_t *, int, int, int, int, char const *); | |||
void cucul_draw_thin_ellipse(cucul_t *, int, int, int, int); | |||
void cucul_fill_ellipse(cucul_t *, int, int, int, int, char const *); | |||
void cucul_draw_box(cucul_t *, int, int, int, int, char const *); | |||
void cucul_draw_thin_box(cucul_t *, int, int, int, int); | |||
void cucul_fill_box(cucul_t *, int, int, int, int, char const *); | |||
void cucul_draw_triangle(cucul_t *, int, int, int, int, int, int, char const *); | |||
void cucul_draw_thin_triangle(cucul_t *, int, int, int, int, int, int); | |||
void cucul_fill_triangle(cucul_t *, int, int, int, int, int, int, char const *); | |||
void cucul_draw_line(cucul_canvas_t *, int, int, int, int, char const *); | |||
void cucul_draw_polyline(cucul_canvas_t *, int const x[], int const y[], int, char const *); | |||
void cucul_draw_thin_line(cucul_canvas_t *, int, int, int, int); | |||
void cucul_draw_thin_polyline(cucul_canvas_t *, int const x[], int const y[], int); | |||
void cucul_draw_circle(cucul_canvas_t *, int, int, int, char const *); | |||
void cucul_draw_ellipse(cucul_canvas_t *, int, int, int, int, char const *); | |||
void cucul_draw_thin_ellipse(cucul_canvas_t *, int, int, int, int); | |||
void cucul_fill_ellipse(cucul_canvas_t *, int, int, int, int, char const *); | |||
void cucul_draw_box(cucul_canvas_t *, int, int, int, int, char const *); | |||
void cucul_draw_thin_box(cucul_canvas_t *, int, int, int, int); | |||
void cucul_fill_box(cucul_canvas_t *, int, int, int, int, char const *); | |||
void cucul_draw_triangle(cucul_canvas_t *, int, int, int, int, int, int, char const *); | |||
void cucul_draw_thin_triangle(cucul_canvas_t *, int, int, int, int, int, int); | |||
void cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int, int, char const *); | |||
/* @} */ | |||
/** \defgroup sprite Sprite handling | |||
@@ -156,7 +156,7 @@ int cucul_get_sprite_width(cucul_sprite_t const *, int); | |||
int cucul_get_sprite_height(cucul_sprite_t const *, int); | |||
int cucul_get_sprite_dx(cucul_sprite_t const *, int); | |||
int cucul_get_sprite_dy(cucul_sprite_t const *, int); | |||
void cucul_draw_sprite(cucul_t *, int, int, cucul_sprite_t const *, int); | |||
void cucul_draw_sprite(cucul_canvas_t *, int, int, cucul_sprite_t const *, int); | |||
void cucul_free_sprite(cucul_sprite_t *); | |||
/* @} */ | |||
@@ -185,7 +185,7 @@ void cucul_set_dither_charset(cucul_dither_t *, char const *); | |||
char const * const * cucul_get_dither_charset_list(cucul_dither_t const *); | |||
void cucul_set_dither_mode(cucul_dither_t *, char const *); | |||
char const * const * cucul_get_dither_mode_list(cucul_dither_t const *); | |||
void cucul_dither_bitmap(cucul_t *, int, int, int, int, | |||
void cucul_dither_bitmap(cucul_canvas_t *, int, int, int, int, | |||
cucul_dither_t const *, void *); | |||
void cucul_free_dither(cucul_dither_t *); | |||
/* @} */ | |||
@@ -200,7 +200,7 @@ cucul_font_t *cucul_load_font(void const *, unsigned int); | |||
char const * const * cucul_get_font_list(void); | |||
unsigned int cucul_get_font_width(cucul_font_t *); | |||
unsigned int cucul_get_font_height(cucul_font_t *); | |||
void cucul_render_canvas(cucul_t *, cucul_font_t *, void *, | |||
void cucul_render_canvas(cucul_canvas_t *, cucul_font_t *, void *, | |||
unsigned int, unsigned int, unsigned int); | |||
void cucul_free_font(cucul_font_t *); | |||
/* @} */ | |||
@@ -211,7 +211,7 @@ void cucul_free_font(cucul_font_t *); | |||
* is necessary to call cucul_free_buffer() to dispose of the data. | |||
* | |||
* @{ */ | |||
cucul_buffer_t * cucul_create_export(cucul_t *, char const *); | |||
cucul_buffer_t * cucul_create_export(cucul_canvas_t *, char const *); | |||
char const * const * cucul_get_export_list(void); | |||
/* @} */ | |||
@@ -25,7 +25,7 @@ typedef long int intptr_t; | |||
typedef long unsigned int uintptr_t; | |||
#endif | |||
struct cucul | |||
struct cucul_canvas | |||
{ | |||
/* Context size */ | |||
unsigned int width, height; | |||
@@ -51,8 +51,8 @@ extern int _cucul_init_dither(void); | |||
extern int _cucul_end_dither(void); | |||
/* Canvas functions */ | |||
extern void _cucul_set_size(cucul_t *, unsigned int, unsigned int); | |||
extern void _cucul_putchar32(cucul_t *qq, int x, int y, uint32_t c); | |||
extern void _cucul_set_size(cucul_canvas_t *, unsigned int, unsigned int); | |||
extern void _cucul_putchar32(cucul_canvas_t *, int, int, uint32_t); | |||
/* Charset functions */ | |||
extern unsigned int _cucul_strlen_utf8(char const *); | |||
@@ -688,12 +688,12 @@ char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d) | |||
return list; | |||
} | |||
/** \brief Draw a dither on the screen. | |||
/** \brief Dither a bitmap on the canvas. | |||
* | |||
* Draw a dither at the given coordinates. The dither can be of any size and | |||
* will be stretched to the text area. | |||
* Dither a bitmap at the given coordinates. The dither can be of any size | |||
* and will be stretched to the text area. | |||
* | |||
* \param qq A handle to the libcucul canvas. | |||
* \param c A handle to the libcucul canvas. | |||
* \param x1 X coordinate of the upper-left corner of the drawing area. | |||
* \param y1 Y coordinate of the upper-left corner of the drawing area. | |||
* \param x2 X coordinate of the lower-right corner of the drawing area. | |||
@@ -701,7 +701,7 @@ char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d) | |||
* \param d Dither object to be drawn. | |||
* \param pixels Bitmap's pixels. | |||
*/ | |||
void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
void cucul_dither_bitmap(cucul_canvas_t *c, int x1, int y1, int x2, int y2, | |||
cucul_dither_t const *d, void *pixels) | |||
{ | |||
int *floyd_steinberg, *fs_r, *fs_g, *fs_b; | |||
@@ -730,19 +730,19 @@ void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
deltay = y2 - y1 + 1; | |||
dchmax = d->glyph_count; | |||
fs_length = ((int)qq->width <= x2 ? (int)qq->width : x2) + 1; | |||
fs_length = ((int)c->width <= x2 ? (int)c->width : x2) + 1; | |||
floyd_steinberg = malloc(3 * (fs_length + 2) * sizeof(int)); | |||
memset(floyd_steinberg, 0, 3 * (fs_length + 2) * sizeof(int)); | |||
fs_r = floyd_steinberg + 1; | |||
fs_g = fs_r + fs_length + 2; | |||
fs_b = fs_g + fs_length + 2; | |||
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)qq->height; y++) | |||
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)c->height; y++) | |||
{ | |||
int remain_r = 0, remain_g = 0, remain_b = 0; | |||
for(x = x1 > 0 ? x1 : 0, d->init_dither(y); | |||
x <= x2 && x <= (int)qq->width; | |||
x <= x2 && x <= (int)c->width; | |||
x++) | |||
{ | |||
unsigned int i; | |||
@@ -791,7 +791,7 @@ void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
tox = (x - x1 + 1) * w / deltax; | |||
toy = (y - y1 + 1) * h / deltay; | |||
/* tox and toy can overflow the screen, but they cannot overflow | |||
/* tox and toy can overflow the canvas, but they cannot overflow | |||
* when averaged with fromx and fromy because these are guaranteed | |||
* to be within the pixel boundaries. */ | |||
myx = (fromx + tox) / 2; | |||
@@ -936,8 +936,8 @@ void cucul_dither_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
} | |||
/* Now output the character */ | |||
cucul_set_color(qq, outfg, outbg); | |||
cucul_putstr(qq, x, y, outch); | |||
cucul_set_color(c, outfg, outbg); | |||
cucul_putstr(c, x, y, outch); | |||
d->increment_dither(); | |||
} | |||
@@ -27,13 +27,13 @@ | |||
#include "cucul.h" | |||
#include "cucul_internals.h" | |||
static void export_ansi(cucul_t *, cucul_buffer_t *); | |||
static void export_html(cucul_t *, cucul_buffer_t *); | |||
static void export_html3(cucul_t *, cucul_buffer_t *); | |||
static void export_irc(cucul_t *, cucul_buffer_t *); | |||
static void export_ps(cucul_t *, cucul_buffer_t *); | |||
static void export_svg(cucul_t *, cucul_buffer_t *); | |||
static void export_tga(cucul_t *, cucul_buffer_t *); | |||
static void export_ansi(cucul_canvas_t *, cucul_buffer_t *); | |||
static void export_html(cucul_canvas_t *, cucul_buffer_t *); | |||
static void export_html3(cucul_canvas_t *, cucul_buffer_t *); | |||
static void export_irc(cucul_canvas_t *, cucul_buffer_t *); | |||
static void export_ps(cucul_canvas_t *, cucul_buffer_t *); | |||
static void export_svg(cucul_canvas_t *, cucul_buffer_t *); | |||
static void export_tga(cucul_canvas_t *, cucul_buffer_t *); | |||
/** \brief Export a canvas into a foreign format. | |||
* | |||
@@ -59,10 +59,10 @@ static void export_tga(cucul_t *, cucul_buffer_t *); | |||
* | |||
* \li \e "tga": export a TGA image. | |||
* | |||
* \param qq A libcucul canvas | |||
* \param c A libcucul canvas | |||
* \param format A string describing the requested output format. | |||
*/ | |||
cucul_buffer_t * cucul_create_export(cucul_t *qq, char const *format) | |||
cucul_buffer_t * cucul_create_export(cucul_canvas_t *c, char const *format) | |||
{ | |||
cucul_buffer_t *ex; | |||
@@ -71,19 +71,19 @@ cucul_buffer_t * cucul_create_export(cucul_t *qq, char const *format) | |||
ex->data = NULL; | |||
if(!strcasecmp("ansi", format)) | |||
export_ansi(qq, ex); | |||
export_ansi(c, ex); | |||
else if(!strcasecmp("html", format)) | |||
export_html(qq, ex); | |||
export_html(c, ex); | |||
else if(!strcasecmp("html3", format)) | |||
export_html3(qq, ex); | |||
export_html3(c, ex); | |||
else if(!strcasecmp("irc", format)) | |||
export_irc(qq, ex); | |||
export_irc(c, ex); | |||
else if(!strcasecmp("ps", format)) | |||
export_ps(qq, ex); | |||
export_ps(c, ex); | |||
else if(!strcasecmp("svg", format)) | |||
export_svg(qq, ex); | |||
export_svg(c, ex); | |||
else if(!strcasecmp("tga", format)) | |||
export_tga(qq, ex); | |||
export_tga(c, ex); | |||
if(ex->size == 0) | |||
{ | |||
@@ -125,7 +125,7 @@ char const * const * cucul_get_export_list(void) | |||
*/ | |||
/* Generate ANSI representation of current canvas. */ | |||
static void export_ansi(cucul_t *qq, cucul_buffer_t *ex) | |||
static void export_ansi(cucul_canvas_t *c, cucul_buffer_t *ex) | |||
{ | |||
static uint8_t const palette[] = | |||
{ | |||
@@ -139,24 +139,24 @@ static void export_ansi(cucul_t *qq, cucul_buffer_t *ex) | |||
/* 23 bytes assumed for max length per pixel ('\e[5;1;3x;4y;9x;10ym' plus | |||
* 4 max bytes for a UTF-8 character). | |||
* Add height*9 to that (zeroes color at the end and jump to next line) */ | |||
ex->size = (qq->height * 9) + (qq->width * qq->height * 23); | |||
ex->size = (c->height * 9) + (c->width * c->height * 23); | |||
ex->data = malloc(ex->size); | |||
cur = ex->data; | |||
for(y = 0; y < qq->height; y++) | |||
for(y = 0; y < c->height; y++) | |||
{ | |||
uint32_t *lineattr = qq->attr + y * qq->width; | |||
uint32_t *linechar = qq->chars + y * qq->width; | |||
uint32_t *lineattr = c->attr + y * c->width; | |||
uint32_t *linechar = c->chars + y * c->width; | |||
uint8_t prevfg = -1; | |||
uint8_t prevbg = -1; | |||
for(x = 0; x < qq->width; x++) | |||
for(x = 0; x < c->width; x++) | |||
{ | |||
uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])]; | |||
uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])]; | |||
uint32_t c = linechar[x]; | |||
uint32_t ch = linechar[x]; | |||
if(fg != prevfg || bg != prevbg) | |||
{ | |||
@@ -177,7 +177,7 @@ static void export_ansi(cucul_t *qq, cucul_buffer_t *ex) | |||
fg - 8, bg - 8, fg - 8, bg - 8); | |||
} | |||
*cur++ = c & 0x7f; | |||
*cur++ = ch & 0x7f; | |||
prevfg = fg; | |||
prevbg = bg; | |||
@@ -192,7 +192,7 @@ static void export_ansi(cucul_t *qq, cucul_buffer_t *ex) | |||
} | |||
/* Generate HTML representation of current canvas. */ | |||
static void export_html(cucul_t *qq, cucul_buffer_t *ex) | |||
static void export_html(cucul_canvas_t *c, cucul_buffer_t *ex) | |||
{ | |||
char *cur; | |||
unsigned int x, y, len; | |||
@@ -202,7 +202,7 @@ static void export_html(cucul_t *qq, cucul_buffer_t *ex) | |||
* A glyph: 47 chars for "<span style="color:#xxx;background-color:#xxx">" | |||
* up to 9 chars for "&#xxxxxx;", far less for pure ASCII | |||
* 7 chars for "</span>" */ | |||
ex->size = 1000 + qq->height * (7 + qq->width * (47 + 9 + 7)); | |||
ex->size = 1000 + c->height * (7 + c->width * (47 + 9 + 7)); | |||
ex->data = malloc(ex->size); | |||
cur = ex->data; | |||
@@ -215,12 +215,12 @@ static void export_html(cucul_t *qq, cucul_buffer_t *ex) | |||
cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n", | |||
"font-family: monospace, fixed; font-weight: bold;"); | |||
for(y = 0; y < qq->height; y++) | |||
for(y = 0; y < c->height; y++) | |||
{ | |||
uint32_t *lineattr = qq->attr + y * qq->width; | |||
uint32_t *linechar = qq->chars + y * qq->width; | |||
uint32_t *lineattr = c->attr + y * c->width; | |||
uint32_t *linechar = c->chars + y * c->width; | |||
for(x = 0; x < qq->width; x += len) | |||
for(x = 0; x < c->width; x += len) | |||
{ | |||
cur += sprintf(cur, "<span style=\"color:#%.03x;" | |||
"background-color:#%.03x\">", | |||
@@ -228,7 +228,7 @@ static void export_html(cucul_t *qq, cucul_buffer_t *ex) | |||
_cucul_argb32_to_rgb12bg(lineattr[x])); | |||
for(len = 0; | |||
x + len < qq->width && lineattr[x + len] == lineattr[x]; | |||
x + len < c->width && lineattr[x + len] == lineattr[x]; | |||
len++) | |||
{ | |||
if(linechar[x + len] <= 0x00000020) | |||
@@ -255,7 +255,7 @@ static void export_html(cucul_t *qq, cucul_buffer_t *ex) | |||
* but permits viewing in old browsers (or limited ones such as links). It | |||
* will not work under gecko (mozilla rendering engine) unless you set a | |||
* correct header. */ | |||
static void export_html3(cucul_t *qq, cucul_buffer_t *ex) | |||
static void export_html3(cucul_canvas_t *c, cucul_buffer_t *ex) | |||
{ | |||
char *cur; | |||
unsigned int x, y, len; | |||
@@ -265,30 +265,30 @@ static void export_html3(cucul_t *qq, cucul_buffer_t *ex) | |||
* A glyph: 40 chars for "<td bgcolor=#xxxxxx><font color=#xxxxxx>" | |||
* up to 9 chars for "&#xxxxxx;", far less for pure ASCII | |||
* 12 chars for "</font></td>" */ | |||
ex->size = 1000 + qq->height * (10 + qq->width * (40 + 9 + 12)); | |||
ex->size = 1000 + c->height * (10 + c->width * (40 + 9 + 12)); | |||
ex->data = malloc(ex->size); | |||
cur = ex->data; | |||
/* Table */ | |||
cur += sprintf(cur, "<table cols='%d' cellpadding='0' cellspacing='0'>\n", | |||
qq->height); | |||
c->height); | |||
for(y = 0; y < qq->height; y++) | |||
for(y = 0; y < c->height; y++) | |||
{ | |||
uint32_t *lineattr = qq->attr + y * qq->width; | |||
uint32_t *linechar = qq->chars + y * qq->width; | |||
uint32_t *lineattr = c->attr + y * c->width; | |||
uint32_t *linechar = c->chars + y * c->width; | |||
cur += sprintf(cur, "<tr>"); | |||
for(x = 0; x < qq->width; x += len) | |||
for(x = 0; x < c->width; x += len) | |||
{ | |||
unsigned int i; | |||
/* Use colspan option to factor cells with same attributes | |||
* (see below) */ | |||
len = 1; | |||
while(x + len < qq->width && lineattr[x + len] == lineattr[x]) | |||
while(x + len < c->width && lineattr[x + len] == lineattr[x]) | |||
len++; | |||
cur += sprintf(cur, "<td bgcolor=#%.06x", | |||
@@ -324,7 +324,7 @@ static void export_html3(cucul_t *qq, cucul_buffer_t *ex) | |||
} | |||
/* Export a text file with IRC colours */ | |||
static void export_irc(cucul_t *qq, cucul_buffer_t *ex) | |||
static void export_irc(cucul_canvas_t *c, cucul_buffer_t *ex) | |||
{ | |||
static uint8_t const palette[] = | |||
{ | |||
@@ -343,35 +343,35 @@ static void export_irc(cucul_t *qq, cucul_buffer_t *ex) | |||
* In real life, the average bytes per pixel value will be around 5. | |||
*/ | |||
ex->size = 2 + (qq->width * qq->height * 11); | |||
ex->size = 2 + (c->width * c->height * 11); | |||
ex->data = malloc(ex->size); | |||
cur = ex->data; | |||
for(y = 0; y < qq->height; y++) | |||
for(y = 0; y < c->height; y++) | |||
{ | |||
uint32_t *lineattr = qq->attr + y * qq->width; | |||
uint32_t *linechar = qq->chars + y * qq->width; | |||
uint32_t *lineattr = c->attr + y * c->width; | |||
uint32_t *linechar = c->chars + y * c->width; | |||
uint8_t prevfg = -1; | |||
uint8_t prevbg = -1; | |||
for(x = 0; x < qq->width; x++) | |||
for(x = 0; x < c->width; x++) | |||
{ | |||
uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])]; | |||
uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])]; | |||
uint32_t c = linechar[x]; | |||
uint32_t ch = linechar[x]; | |||
if(bg == prevbg) | |||
{ | |||
if(fg == prevfg) | |||
; /* Same fg/bg, do nothing */ | |||
else if(c == (uint32_t)' ') | |||
else if(ch == (uint32_t)' ') | |||
fg = prevfg; /* Hackety hack */ | |||
else | |||
{ | |||
cur += sprintf(cur, "\x03%d", fg); | |||
if(c >= (uint32_t)'0' && c <= (uint32_t)'9') | |||
if(ch >= (uint32_t)'0' && ch <= (uint32_t)'9') | |||
cur += sprintf(cur, "\x02\x02"); | |||
} | |||
} | |||
@@ -382,10 +382,10 @@ static void export_irc(cucul_t *qq, cucul_buffer_t *ex) | |||
else | |||
cur += sprintf(cur, "\x03%d,%d", fg, bg); | |||
if(c >= (uint32_t)'0' && c <= (uint32_t)'9') | |||
if(ch >= (uint32_t)'0' && ch <= (uint32_t)'9') | |||
cur += sprintf(cur, "\x02\x02"); | |||
} | |||
*cur++ = c & 0x7f; | |||
*cur++ = ch & 0x7f; | |||
prevfg = fg; | |||
prevbg = bg; | |||
} | |||
@@ -399,7 +399,7 @@ static void export_irc(cucul_t *qq, cucul_buffer_t *ex) | |||
} | |||
/* Export a PostScript document. */ | |||
static void export_ps(cucul_t *qq, cucul_buffer_t *ex) | |||
static void export_ps(cucul_canvas_t *c, cucul_buffer_t *ex) | |||
{ | |||
static char const *ps_header = | |||
"%!\n" | |||
@@ -430,7 +430,7 @@ static void export_ps(cucul_t *qq, cucul_buffer_t *ex) | |||
unsigned int x, y; | |||
/* 200 is arbitrary but should be ok */ | |||
ex->size = strlen(ps_header) + (qq->width * qq->height * 200); | |||
ex->size = strlen(ps_header) + (c->width * c->height * 200); | |||
ex->data = malloc(ex->size); | |||
cur = ex->data; | |||
@@ -439,11 +439,11 @@ static void export_ps(cucul_t *qq, cucul_buffer_t *ex) | |||
cur += sprintf(cur, "%s", ps_header); | |||
/* Background, drawn using csquare macro defined in header */ | |||
for(y = qq->height; y--; ) | |||
for(y = c->height; y--; ) | |||
{ | |||
uint32_t *lineattr = qq->attr + y * qq->width; | |||
uint32_t *lineattr = c->attr + y * c->width; | |||
for(x = 0; x < qq->width; x++) | |||
for(x = 0; x < c->width; x++) | |||
{ | |||
uint8_t argb[8]; | |||
_cucul_argb32_to_argb4(*lineattr++, argb); | |||
@@ -454,20 +454,20 @@ static void export_ps(cucul_t *qq, cucul_buffer_t *ex) | |||
} | |||
/* Return to beginning of the line, and jump to the next one */ | |||
cur += sprintf(cur, "-%d 1 translate\n", qq->width); | |||
cur += sprintf(cur, "-%d 1 translate\n", c->width); | |||
} | |||
cur += sprintf(cur, "grestore\n"); /* Restore transformation matrix */ | |||
for(y = qq->height; y--; ) | |||
for(y = c->height; y--; ) | |||
{ | |||
uint32_t *lineattr = qq->attr + (qq->height - y - 1) * qq->width; | |||
uint32_t *linechar = qq->chars + (qq->height - y - 1) * qq->width; | |||
uint32_t *lineattr = c->attr + (c->height - y - 1) * c->width; | |||
uint32_t *linechar = c->chars + (c->height - y - 1) * c->width; | |||
for(x = 0; x < qq->width; x++) | |||
for(x = 0; x < c->width; x++) | |||
{ | |||
uint8_t argb[8]; | |||
uint32_t c = *linechar++; | |||
uint32_t ch = *linechar++; | |||
_cucul_argb32_to_argb4(*lineattr++, argb); | |||
@@ -478,19 +478,19 @@ static void export_ps(cucul_t *qq, cucul_buffer_t *ex) | |||
(float)argb[6] * (1.0 / 0xf), | |||
(float)argb[7] * (1.0 / 0xf)); | |||
if(c < 0x00000020) | |||
if(ch < 0x00000020) | |||
cur += sprintf(cur, "(?) show\n"); | |||
else if(c >= 0x00000080) | |||
else if(ch >= 0x00000080) | |||
cur += sprintf(cur, "(?) show\n"); | |||
else switch((uint8_t)(c & 0x7f)) | |||
else switch((uint8_t)(ch & 0x7f)) | |||
{ | |||
case '\\': | |||
case '(': | |||
case ')': | |||
cur += sprintf(cur, "(\\%c) show\n", c); | |||
cur += sprintf(cur, "(\\%c) show\n", ch); | |||
break; | |||
default: | |||
cur += sprintf(cur, "(%c) show\n", c); | |||
cur += sprintf(cur, "(%c) show\n", ch); | |||
break; | |||
} | |||
} | |||
@@ -504,7 +504,7 @@ static void export_ps(cucul_t *qq, cucul_buffer_t *ex) | |||
} | |||
/* Export an SVG vector image */ | |||
static void export_svg(cucul_t *qq, cucul_buffer_t *ex) | |||
static void export_svg(cucul_canvas_t *c, cucul_buffer_t *ex) | |||
{ | |||
static char const svg_header[] = | |||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |||
@@ -517,23 +517,23 @@ static void export_svg(cucul_t *qq, cucul_buffer_t *ex) | |||
unsigned int x, y; | |||
/* 200 is arbitrary but should be ok */ | |||
ex->size = strlen(svg_header) + (qq->width * qq->height * 200); | |||
ex->size = strlen(svg_header) + (c->width * c->height * 200); | |||
ex->data = malloc(ex->size); | |||
cur = ex->data; | |||
/* Header */ | |||
cur += sprintf(cur, svg_header, qq->width * 6, qq->height * 10, | |||
qq->width * 6, qq->height * 10); | |||
cur += sprintf(cur, svg_header, c->width * 6, c->height * 10, | |||
c->width * 6, c->height * 10); | |||
cur += sprintf(cur, " <g id=\"mainlayer\" font-size=\"12\">\n"); | |||
/* Background */ | |||
for(y = 0; y < qq->height; y++) | |||
for(y = 0; y < c->height; y++) | |||
{ | |||
uint32_t *lineattr = qq->attr + y * qq->width; | |||
uint32_t *lineattr = c->attr + y * c->width; | |||
for(x = 0; x < qq->width; x++) | |||
for(x = 0; x < c->width; x++) | |||
{ | |||
cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\"" | |||
" width=\"6\" height=\"10\"/>\n", | |||
@@ -543,22 +543,22 @@ static void export_svg(cucul_t *qq, cucul_buffer_t *ex) | |||
} | |||
/* Text */ | |||
for(y = 0; y < qq->height; y++) | |||
for(y = 0; y < c->height; y++) | |||
{ | |||
uint32_t *lineattr = qq->attr + y * qq->width; | |||
uint32_t *linechar = qq->chars + y * qq->width; | |||
uint32_t *lineattr = c->attr + y * c->width; | |||
uint32_t *linechar = c->chars + y * c->width; | |||
for(x = 0; x < qq->width; x++) | |||
for(x = 0; x < c->width; x++) | |||
{ | |||
uint32_t c = *linechar++; | |||
uint32_t ch = *linechar++; | |||
cur += sprintf(cur, "<text style=\"fill:#%.03x\" " | |||
"x=\"%d\" y=\"%d\">", | |||
_cucul_argb32_to_rgb12fg(*lineattr++), | |||
x * 6, (y * 10) + 10); | |||
if(c < 0x00000020) | |||
if(ch < 0x00000020) | |||
cur += sprintf(cur, "?"); | |||
else if(c > 0x0000007f) | |||
else if(ch > 0x0000007f) | |||
{ | |||
static const uint8_t mark[7] = | |||
{ | |||
@@ -566,27 +566,27 @@ static void export_svg(cucul_t *qq, cucul_buffer_t *ex) | |||
}; | |||
char buf[10], *parser; | |||
int bytes = (c < 0x800) ? 2 : (c < 0x10000) ? 3 : 4; | |||
int bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4; | |||
buf[bytes] = '\0'; | |||
parser = buf + bytes; | |||
switch(bytes) | |||
{ | |||
case 4: *--parser = (c | 0x80) & 0xbf; c >>= 6; | |||
case 3: *--parser = (c | 0x80) & 0xbf; c >>= 6; | |||
case 2: *--parser = (c | 0x80) & 0xbf; c >>= 6; | |||
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; | |||
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; | |||
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6; | |||
} | |||
*--parser = c | mark[bytes]; | |||
*--parser = ch | mark[bytes]; | |||
cur += sprintf(cur, "%s", buf); | |||
} | |||
else switch((uint8_t)c) | |||
else switch((uint8_t)ch) | |||
{ | |||
case '>': cur += sprintf(cur, ">"); break; | |||
case '<': cur += sprintf(cur, "<"); break; | |||
case '&': cur += sprintf(cur, "&"); break; | |||
default: cur += sprintf(cur, "%c", c); break; | |||
default: cur += sprintf(cur, "%c", ch); break; | |||
} | |||
cur += sprintf(cur, "</text>\n"); | |||
} | |||
@@ -601,7 +601,7 @@ static void export_svg(cucul_t *qq, cucul_buffer_t *ex) | |||
} | |||
/* Export a TGA image */ | |||
static void export_tga(cucul_t *qq, cucul_buffer_t *ex) | |||
static void export_tga(cucul_canvas_t *c, cucul_buffer_t *ex) | |||
{ | |||
char const * const * fontlist; | |||
char * cur; | |||
@@ -614,8 +614,8 @@ static void export_tga(cucul_t *qq, cucul_buffer_t *ex) | |||
f = cucul_load_font(fontlist[0], 0); | |||
w = cucul_get_width(qq) * cucul_get_font_width(f); | |||
h = cucul_get_height(qq) * cucul_get_font_height(f); | |||
w = cucul_get_width(c) * cucul_get_font_width(f); | |||
h = cucul_get_height(c) * cucul_get_font_height(f); | |||
ex->size = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */ | |||
ex->data = malloc(ex->size); | |||
@@ -643,7 +643,7 @@ static void export_tga(cucul_t *qq, cucul_buffer_t *ex) | |||
/* Color Map Data: no colormap */ | |||
/* Image Data */ | |||
cucul_render_canvas(qq, f, cur, w, h, 4 * w); | |||
cucul_render_canvas(c, f, cur, w, h, 4 * w); | |||
/* Swap bytes. What a waste of time. */ | |||
for(i = 0; i < w * h * 4; i += 4) | |||
@@ -259,21 +259,21 @@ void cucul_free_font(cucul_font_t *f) | |||
* This function renders the given canvas on an image buffer using a specific | |||
* font. The pixel format is fixed (32-bit ARGB, 8 bits for each component). | |||
* | |||
* The required image width can be computed using \e cucul_get_width(qq) and | |||
* The required image width can be computed using \e cucul_get_width(c) and | |||
* \e cucul_get_font_width(f). The required height can be computed using | |||
* \e cucul_get_height(qq) and \e cucul_get_font_height(f). | |||
* \e cucul_get_height(c) and \e cucul_get_font_height(f). | |||
* | |||
* Glyphs that do not fit in the image buffer are currently not rendered at | |||
* all. They may be cropped instead in future versions. | |||
* | |||
* \param qq The canvas to render | |||
* \param c The canvas to render | |||
* \param f The font, as returned by \e cucul_load_font() | |||
* \param buf The image buffer | |||
* \param width The width (in pixels) of the image buffer | |||
* \param height The height (in pixels) of the image buffer | |||
* \param pitch The pitch (in bytes) of an image buffer line. | |||
*/ | |||
void cucul_render_canvas(cucul_t *qq, cucul_font_t *f, | |||
void cucul_render_canvas(cucul_canvas_t *c, cucul_font_t *f, | |||
void *buf, unsigned int width, | |||
unsigned int height, unsigned int pitch) | |||
{ | |||
@@ -283,15 +283,15 @@ void cucul_render_canvas(cucul_t *qq, cucul_font_t *f, | |||
if(f->header.bpp != 8) | |||
glyph = malloc(f->header.width * f->header.height); | |||
if(width < qq->width * f->header.width) | |||
if(width < c->width * f->header.width) | |||
xmax = width / f->header.width; | |||
else | |||
xmax = qq->width; | |||
xmax = c->width; | |||
if(height < qq->height * f->header.height) | |||
if(height < c->height * f->header.height) | |||
ymax = height / f->header.height; | |||
else | |||
ymax = qq->height; | |||
ymax = c->height; | |||
for(y = 0; y < ymax; y++) | |||
{ | |||
@@ -300,8 +300,8 @@ void cucul_render_canvas(cucul_t *qq, cucul_font_t *f, | |||
uint8_t argb[8]; | |||
unsigned int starty = y * f->header.height; | |||
unsigned int startx = x * f->header.width; | |||
uint32_t ch = qq->chars[y * qq->width + x]; | |||
uint32_t attr = qq->attr[y * qq->width + x]; | |||
uint32_t ch = c->chars[y * c->width + x]; | |||
uint32_t attr = c->attr[y * c->width + x]; | |||
unsigned int b, i, j; | |||
struct glyph_info *g; | |||
@@ -30,19 +30,19 @@ struct line | |||
{ | |||
int x1, y1; | |||
int x2, y2; | |||
uint32_t c; | |||
void (*draw) (cucul_t *, struct line*); | |||
uint32_t ch; | |||
void (*draw) (cucul_canvas_t *, struct line*); | |||
}; | |||
#endif | |||
static void clip_line(cucul_t*, struct line*); | |||
static uint8_t clip_bits(cucul_t*, int, int); | |||
static void draw_solid_line(cucul_t*, struct line*); | |||
static void draw_thin_line(cucul_t*, struct line*); | |||
static void clip_line(cucul_canvas_t*, struct line*); | |||
static uint8_t clip_bits(cucul_canvas_t*, int, int); | |||
static void draw_solid_line(cucul_canvas_t*, struct line*); | |||
static void draw_thin_line(cucul_canvas_t*, struct line*); | |||
/** \brief Draw a line on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the first point. | |||
* \param y1 Y coordinate of the first point. | |||
* \param x2 X coordinate of the second point. | |||
@@ -50,7 +50,7 @@ static void draw_thin_line(cucul_t*, struct line*); | |||
* \param str UTF-8 string containing the character to use to draw the line. | |||
* \return void | |||
*/ | |||
void cucul_draw_line(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
void cucul_draw_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2, | |||
char const *str) | |||
{ | |||
struct line s; | |||
@@ -58,9 +58,9 @@ void cucul_draw_line(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
s.y1 = y1; | |||
s.x2 = x2; | |||
s.y2 = y2; | |||
s.c = _cucul_utf8_to_utf32(str); | |||
s.ch = _cucul_utf8_to_utf32(str); | |||
s.draw = draw_solid_line; | |||
clip_line(qq, &s); | |||
clip_line(c, &s); | |||
} | |||
/** \brief Draw a polyline. | |||
@@ -70,19 +70,19 @@ void cucul_draw_line(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
* draw a polygon you need to specify the starting point at the end of the | |||
* list as well. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x Array of X coordinates. Must have \p n + 1 elements. | |||
* \param y Array of Y coordinates. Must have \p n + 1 elements. | |||
* \param n Number of lines to draw. | |||
* \param str UTF-8 string containing the character to use to draw the lines. | |||
* \return void | |||
*/ | |||
void cucul_draw_polyline(cucul_t *qq, int const x[], int const y[], int n, | |||
void cucul_draw_polyline(cucul_canvas_t *c, int const x[], int const y[], int n, | |||
char const *str) | |||
{ | |||
int i; | |||
struct line s; | |||
s.c = _cucul_utf8_to_utf32(str); | |||
s.ch = _cucul_utf8_to_utf32(str); | |||
s.draw = draw_solid_line; | |||
for(i = 0; i < n; i++) | |||
@@ -91,20 +91,20 @@ void cucul_draw_polyline(cucul_t *qq, int const x[], int const y[], int n, | |||
s.y1 = y[i]; | |||
s.x2 = x[i+1]; | |||
s.y2 = y[i+1]; | |||
clip_line(qq, &s); | |||
clip_line(c, &s); | |||
} | |||
} | |||
/** \brief Draw a thin line on the canvas, using ASCII art. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the first point. | |||
* \param y1 Y coordinate of the first point. | |||
* \param x2 X coordinate of the second point. | |||
* \param y2 Y coordinate of the second point. | |||
* \return void | |||
*/ | |||
void cucul_draw_thin_line(cucul_t *qq, int x1, int y1, int x2, int y2) | |||
void cucul_draw_thin_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2) | |||
{ | |||
struct line s; | |||
s.x1 = x1; | |||
@@ -112,7 +112,7 @@ void cucul_draw_thin_line(cucul_t *qq, int x1, int y1, int x2, int y2) | |||
s.x2 = x2; | |||
s.y2 = y2; | |||
s.draw = draw_thin_line; | |||
clip_line(qq, &s); | |||
clip_line(c, &s); | |||
} | |||
/** \brief Draw an ASCII art thin polyline. | |||
@@ -122,13 +122,13 @@ void cucul_draw_thin_line(cucul_t *qq, int x1, int y1, int x2, int y2) | |||
* to draw a polygon you need to specify the starting point at the end of | |||
* the list as well. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x Array of X coordinates. Must have \p n + 1 elements. | |||
* \param y Array of Y coordinates. Must have \p n + 1 elements. | |||
* \param n Number of lines to draw. | |||
* \return void | |||
*/ | |||
void cucul_draw_thin_polyline(cucul_t *qq, int const x[], int const y[], int n) | |||
void cucul_draw_thin_polyline(cucul_canvas_t *c, int const x[], int const y[], int n) | |||
{ | |||
int i; | |||
struct line s; | |||
@@ -140,7 +140,7 @@ void cucul_draw_thin_polyline(cucul_t *qq, int const x[], int const y[], int n) | |||
s.y1 = y[i]; | |||
s.x2 = x[i+1]; | |||
s.y2 = y[i+1]; | |||
clip_line(qq, &s); | |||
clip_line(c, &s); | |||
} | |||
} | |||
@@ -149,12 +149,12 @@ void cucul_draw_thin_polyline(cucul_t *qq, int const x[], int const y[], int n) | |||
*/ | |||
/* Generic Cohen-Sutherland line clipping function. */ | |||
static void clip_line(cucul_t *qq, struct line* s) | |||
static void clip_line(cucul_canvas_t *c, struct line* s) | |||
{ | |||
uint8_t bits1, bits2; | |||
bits1 = clip_bits(qq, s->x1, s->y1); | |||
bits2 = clip_bits(qq, s->x2, s->y2); | |||
bits1 = clip_bits(c, s->x1, s->y1); | |||
bits2 = clip_bits(c, s->x2, s->y2); | |||
if(bits1 & bits2) | |||
return; | |||
@@ -162,13 +162,13 @@ static void clip_line(cucul_t *qq, struct line* s) | |||
if(bits1 == 0) | |||
{ | |||
if(bits2 == 0) | |||
s->draw(qq, s); | |||
s->draw(c, s); | |||
else | |||
{ | |||
int tmp; | |||
tmp = s->x1; s->x1 = s->x2; s->x2 = tmp; | |||
tmp = s->y1; s->y1 = s->y2; s->y2 = tmp; | |||
clip_line(qq, s); | |||
clip_line(c, s); | |||
} | |||
return; | |||
@@ -181,7 +181,7 @@ static void clip_line(cucul_t *qq, struct line* s) | |||
} | |||
else if(bits1 & (1<<1)) | |||
{ | |||
int xmax = qq->width - 1; | |||
int xmax = c->width - 1; | |||
s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1); | |||
s->x1 = xmax; | |||
} | |||
@@ -192,27 +192,27 @@ static void clip_line(cucul_t *qq, struct line* s) | |||
} | |||
else if(bits1 & (1<<3)) | |||
{ | |||
int ymax = qq->height - 1; | |||
int ymax = c->height - 1; | |||
s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1); | |||
s->y1 = ymax; | |||
} | |||
clip_line(qq, s); | |||
clip_line(c, s); | |||
} | |||
/* Helper function for clip_line(). */ | |||
static uint8_t clip_bits(cucul_t *qq, int x, int y) | |||
static uint8_t clip_bits(cucul_canvas_t *c, int x, int y) | |||
{ | |||
uint8_t b = 0; | |||
if(x < 0) | |||
b |= (1<<0); | |||
else if(x >= (int)qq->width) | |||
else if(x >= (int)c->width) | |||
b |= (1<<1); | |||
if(y < 0) | |||
b |= (1<<2); | |||
else if(y >= (int)qq->height) | |||
else if(y >= (int)c->height) | |||
b |= (1<<3); | |||
return b; | |||
@@ -220,7 +220,7 @@ static uint8_t clip_bits(cucul_t *qq, int x, int y) | |||
/* Solid line drawing function, using Bresenham's mid-point line | |||
* scan-conversion algorithm. */ | |||
static void draw_solid_line(cucul_t *qq, struct line* s) | |||
static void draw_solid_line(cucul_canvas_t *c, struct line* s) | |||
{ | |||
int x1, y1, x2, y2; | |||
int dx, dy; | |||
@@ -242,7 +242,7 @@ static void draw_solid_line(cucul_t *qq, struct line* s) | |||
for(; dx>=0; dx--) | |||
{ | |||
_cucul_putchar32(qq, x1, y1, s->c); | |||
_cucul_putchar32(c, x1, y1, s->ch); | |||
if(delta > 0) | |||
{ | |||
x1 += xinc; | |||
@@ -264,7 +264,7 @@ static void draw_solid_line(cucul_t *qq, struct line* s) | |||
for(; dy >= 0; dy--) | |||
{ | |||
_cucul_putchar32(qq, x1, y1, s->c); | |||
_cucul_putchar32(c, x1, y1, s->ch); | |||
if(delta > 0) | |||
{ | |||
x1 += xinc; | |||
@@ -282,7 +282,7 @@ static void draw_solid_line(cucul_t *qq, struct line* s) | |||
/* Thin line drawing function, using Bresenham's mid-point line | |||
* scan-conversion algorithm and ASCII art graphics. */ | |||
static void draw_thin_line(cucul_t *qq, struct line* s) | |||
static void draw_thin_line(cucul_canvas_t *c, struct line* s) | |||
{ | |||
uint32_t charmapx[2], charmapy[2]; | |||
int x1, y1, x2, y2; | |||
@@ -329,7 +329,7 @@ static void draw_thin_line(cucul_t *qq, struct line* s) | |||
{ | |||
if(delta > 0) | |||
{ | |||
_cucul_putchar32(qq, x1, y1, charmapy[1]); | |||
_cucul_putchar32(c, x1, y1, charmapy[1]); | |||
x1++; | |||
y1 += yinc; | |||
delta += dpru; | |||
@@ -338,9 +338,9 @@ static void draw_thin_line(cucul_t *qq, struct line* s) | |||
else | |||
{ | |||
if(prev) | |||
_cucul_putchar32(qq, x1, y1, charmapy[0]); | |||
_cucul_putchar32(c, x1, y1, charmapy[0]); | |||
else | |||
_cucul_putchar32(qq, x1, y1, (uint32_t)'-'); | |||
_cucul_putchar32(c, x1, y1, (uint32_t)'-'); | |||
x1++; | |||
delta += dpr; | |||
prev = 0; | |||
@@ -357,15 +357,15 @@ static void draw_thin_line(cucul_t *qq, struct line* s) | |||
{ | |||
if(delta > 0) | |||
{ | |||
_cucul_putchar32(qq, x1, y1, charmapx[0]); | |||
_cucul_putchar32(qq, x1 + 1, y1, charmapx[1]); | |||
_cucul_putchar32(c, x1, y1, charmapx[0]); | |||
_cucul_putchar32(c, x1 + 1, y1, charmapx[1]); | |||
x1++; | |||
y1 += yinc; | |||
delta += dpru; | |||
} | |||
else | |||
{ | |||
_cucul_putchar32(qq, x1, y1, (uint32_t)'|'); | |||
_cucul_putchar32(c, x1, y1, (uint32_t)'|'); | |||
y1 += yinc; | |||
delta += dpr; | |||
} | |||
@@ -246,14 +246,14 @@ int cucul_get_sprite_dy(cucul_sprite_t const *sprite, int f) | |||
/** \brief Draw a sprite's specific frame at the given coordinates. If the | |||
* frame does not exist, nothing is displayed. | |||
* | |||
* \param qq A libcucul canvas | |||
* \param c A libcucul canvas | |||
* \param x The X coordinate. | |||
* \param y The Y coordinate. | |||
* \param sprite The sprite. | |||
* \param f The frame index. | |||
* \return void | |||
*/ | |||
void cucul_draw_sprite(cucul_t *qq, int x, int y, cucul_sprite_t const *sprite, int f) | |||
void cucul_draw_sprite(cucul_canvas_t *c, int x, int y, cucul_sprite_t const *sprite, int f) | |||
{ | |||
int i, j; | |||
unsigned int oldfg, oldbg; | |||
@@ -267,8 +267,8 @@ void cucul_draw_sprite(cucul_t *qq, int x, int y, cucul_sprite_t const *sprite, | |||
frame = &sprite->frames[f]; | |||
oldfg = qq->fgcolor; | |||
oldbg = qq->bgcolor; | |||
oldfg = c->fgcolor; | |||
oldbg = c->bgcolor; | |||
for(j = 0; j < frame->h; j++) | |||
{ | |||
@@ -277,14 +277,14 @@ void cucul_draw_sprite(cucul_t *qq, int x, int y, cucul_sprite_t const *sprite, | |||
int col = frame->color[frame->w * j + i]; | |||
if(col >= 0) | |||
{ | |||
cucul_set_color(qq, col, CUCUL_COLOR_BLACK); | |||
cucul_putchar(qq, x + i - frame->dx, y + j - frame->dy, | |||
cucul_set_color(c, col, CUCUL_COLOR_BLACK); | |||
cucul_putchar(c, x + i - frame->dx, y + j - frame->dy, | |||
frame->chars[frame->w * j + i]); | |||
} | |||
} | |||
} | |||
cucul_set_color(qq, oldfg, oldbg); | |||
cucul_set_color(c, oldfg, oldbg); | |||
} | |||
/** \brief Free the memory associated with a sprite. | |||
@@ -32,14 +32,14 @@ static uint32_t rotatechar(uint32_t ch); | |||
* This function inverts a canvas' colours (black becomes white, red | |||
* becomes cyan, etc.) without changing the characters in it. | |||
* | |||
* \param qq The canvas to invert. | |||
* \param c The canvas to invert. | |||
*/ | |||
void cucul_invert(cucul_t *qq) | |||
void cucul_invert(cucul_canvas_t *c) | |||
{ | |||
uint32_t *attr = qq->attr; | |||
uint32_t *attr = c->attr; | |||
unsigned int i; | |||
for(i = qq->height * qq->width; i--; ) | |||
for(i = c->height * c->width; i--; ) | |||
{ | |||
*attr = *attr ^ 0x000f000f; | |||
attr++; | |||
@@ -51,18 +51,18 @@ void cucul_invert(cucul_t *qq) | |||
* This function flips a canvas horizontally, choosing characters that | |||
* look like the mirrored version wherever possible. | |||
* | |||
* \param qq The canvas to flip. | |||
* \param c The canvas to flip. | |||
*/ | |||
void cucul_flip(cucul_t *qq) | |||
void cucul_flip(cucul_canvas_t *c) | |||
{ | |||
unsigned int y; | |||
for(y = 0; y < qq->height; y++) | |||
for(y = 0; y < c->height; y++) | |||
{ | |||
uint32_t *cleft = qq->chars + y * qq->width; | |||
uint32_t *cright = cleft + qq->width - 1; | |||
uint32_t *aleft = qq->attr + y * qq->width; | |||
uint32_t *aright = aleft + qq->width - 1; | |||
uint32_t *cleft = c->chars + y * c->width; | |||
uint32_t *cright = cleft + c->width - 1; | |||
uint32_t *aleft = c->attr + y * c->width; | |||
uint32_t *aright = aleft + c->width - 1; | |||
while(cleft < cright) | |||
{ | |||
@@ -88,18 +88,18 @@ void cucul_flip(cucul_t *qq) | |||
* This function flips a canvas vertically, choosing characters that | |||
* look like the mirrored version wherever possible. | |||
* | |||
* \param qq The canvas to flop. | |||
* \param c The canvas to flop. | |||
*/ | |||
void cucul_flop(cucul_t *qq) | |||
void cucul_flop(cucul_canvas_t *c) | |||
{ | |||
unsigned int x; | |||
for(x = 0; x < qq->width; x++) | |||
for(x = 0; x < c->width; x++) | |||
{ | |||
uint32_t *ctop = qq->chars + x; | |||
uint32_t *cbottom = ctop + qq->width * (qq->height - 1); | |||
uint32_t *atop = qq->attr + x; | |||
uint32_t *abottom = atop + qq->width * (qq->height - 1); | |||
uint32_t *ctop = c->chars + x; | |||
uint32_t *cbottom = ctop + c->width * (c->height - 1); | |||
uint32_t *atop = c->attr + x; | |||
uint32_t *abottom = atop + c->width * (c->height - 1); | |||
while(ctop < cbottom) | |||
{ | |||
@@ -112,8 +112,8 @@ void cucul_flop(cucul_t *qq) | |||
/* Swap characters */ | |||
ch = *cbottom; *cbottom = flopchar(*ctop); *ctop = flopchar(ch); | |||
ctop += qq->width; cbottom -= qq->width; | |||
atop += qq->width; abottom -= qq->width; | |||
ctop += c->width; cbottom -= c->width; | |||
atop += c->width; abottom -= c->width; | |||
} | |||
if(ctop == cbottom) | |||
@@ -127,14 +127,14 @@ void cucul_flop(cucul_t *qq) | |||
* choosing characters that look like the mirrored version wherever | |||
* possible. | |||
* | |||
* \param qq The canvas to rotate. | |||
* \param c The canvas to rotate. | |||
*/ | |||
void cucul_rotate(cucul_t *qq) | |||
void cucul_rotate(cucul_canvas_t *c) | |||
{ | |||
uint32_t *cbegin = qq->chars; | |||
uint32_t *cend = cbegin + qq->width * qq->height - 1; | |||
uint32_t *abegin = qq->attr; | |||
uint32_t *aend = abegin + qq->width * qq->height - 1; | |||
uint32_t *cbegin = c->chars; | |||
uint32_t *cend = cbegin + c->width * c->height - 1; | |||
uint32_t *abegin = c->attr; | |||
uint32_t *aend = abegin + c->width * c->height - 1; | |||
while(cbegin < cend) | |||
{ | |||
@@ -26,7 +26,7 @@ | |||
/** \brief Draw a triangle on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the first point. | |||
* \param y1 Y coordinate of the first point. | |||
* \param x2 X coordinate of the second point. | |||
@@ -37,17 +37,17 @@ | |||
* to draw the triangle outline. | |||
* \return void | |||
*/ | |||
void cucul_draw_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
void cucul_draw_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2, | |||
int x3, int y3, char const *str) | |||
{ | |||
cucul_draw_line(qq, x1, y1, x2, y2, str); | |||
cucul_draw_line(qq, x2, y2, x3, y3, str); | |||
cucul_draw_line(qq, x3, y3, x1, y1, str); | |||
cucul_draw_line(c, x1, y1, x2, y2, str); | |||
cucul_draw_line(c, x2, y2, x3, y3, str); | |||
cucul_draw_line(c, x3, y3, x1, y1, str); | |||
} | |||
/** \brief Draw a thin triangle on the canvas. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the first point. | |||
* \param y1 Y coordinate of the first point. | |||
* \param x2 X coordinate of the second point. | |||
@@ -56,17 +56,17 @@ void cucul_draw_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
* \param y3 Y coordinate of the third point. | |||
* \return void | |||
*/ | |||
void cucul_draw_thin_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
void cucul_draw_thin_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2, | |||
int x3, int y3) | |||
{ | |||
cucul_draw_thin_line(qq, x1, y1, x2, y2); | |||
cucul_draw_thin_line(qq, x2, y2, x3, y3); | |||
cucul_draw_thin_line(qq, x3, y3, x1, y1); | |||
cucul_draw_thin_line(c, x1, y1, x2, y2); | |||
cucul_draw_thin_line(c, x2, y2, x3, y3); | |||
cucul_draw_thin_line(c, x3, y3, x1, y1); | |||
} | |||
/** \brief Fill a triangle on the canvas using the given character. | |||
* | |||
* \param qq The handle to the libcucul canvas. | |||
* \param c The handle to the libcucul canvas. | |||
* \param x1 X coordinate of the first point. | |||
* \param y1 Y coordinate of the first point. | |||
* \param x2 X coordinate of the second point. | |||
@@ -77,22 +77,22 @@ void cucul_draw_thin_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
* to fill the triangle. | |||
* \return void | |||
*/ | |||
void cucul_fill_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
void cucul_fill_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2, | |||
int x3, int y3, char const *str) | |||
{ | |||
int x, y, xa, xb, xmax, ymax; | |||
uint32_t c; | |||
uint32_t ch; | |||
/* Bubble-sort y1 <= y2 <= y3 */ | |||
if(y1 > y2) | |||
{ | |||
cucul_fill_triangle(qq, x2, y2, x1, y1, x3, y3, str); | |||
cucul_fill_triangle(c, x2, y2, x1, y1, x3, y3, str); | |||
return; | |||
} | |||
if(y2 > y3) | |||
{ | |||
cucul_fill_triangle(qq, x1, y1, x3, y3, x2, y2, str); | |||
cucul_fill_triangle(c, x1, y1, x3, y3, x2, y2, str); | |||
return; | |||
} | |||
@@ -101,10 +101,10 @@ void cucul_fill_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
x2 *= 4; | |||
x3 *= 4; | |||
xmax = qq->width - 1; | |||
ymax = qq->height - 1; | |||
xmax = c->width - 1; | |||
ymax = c->height - 1; | |||
c = _cucul_utf8_to_utf32(str); | |||
ch = _cucul_utf8_to_utf32(str); | |||
/* Rasterize our triangle */ | |||
for(y = y1 < 0 ? 0 : y1; y <= y3 && y <= ymax; y++) | |||
@@ -136,7 +136,7 @@ void cucul_fill_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, | |||
if(xb > xmax) xb = xmax; | |||
for(x = xa; x <= xb; x++) | |||
_cucul_putchar32(qq, x, y, c); | |||
_cucul_putchar32(c, x, y, ch); | |||
} | |||
} | |||
@@ -39,7 +39,7 @@ | |||
#endif | |||
#define MAXTABLE (256*5) | |||
#ifdef LIBCACA | |||
static cucul_t *qq; | |||
static cucul_canvas_t *c; | |||
static caca_t *kk; | |||
static int XSIZ, YSIZ; | |||
static cucul_dither_t *cucul_dither; | |||
@@ -100,21 +100,21 @@ initialize (void) | |||
#endif | |||
#ifdef LIBCACA | |||
qq = cucul_create(80, 32); | |||
if (!qq) | |||
c = cucul_create(80, 32); | |||
if (!c) | |||
{ | |||
printf ("Failed to initialize libcucul\n"); | |||
exit (1); | |||
} | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if (!kk) | |||
{ | |||
printf ("Failed to initialize libcaca\n"); | |||
exit (1); | |||
} | |||
caca_set_delay(kk, 10000); | |||
XSIZ = cucul_get_width(qq) * 2; | |||
YSIZ = cucul_get_height(qq) * 2 - 4; | |||
XSIZ = cucul_get_width(c) * 2; | |||
YSIZ = cucul_get_height(c) * 2 - 4; | |||
#else | |||
context = aa_autoinit (&aa_defparams); | |||
if (context == NULL) | |||
@@ -142,8 +142,8 @@ initialize (void) | |||
#ifdef LIBCACA | |||
cucul_dither = cucul_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0); | |||
cucul_set_dither_palette(cucul_dither, r, g, b, a); | |||
bitmap = malloc(4 * cucul_get_width(qq) * cucul_get_height(qq) * sizeof(char)); | |||
memset(bitmap, 0, 4 * cucul_get_width(qq) * cucul_get_height(qq)); | |||
bitmap = malloc(4 * cucul_get_width(c) * cucul_get_height(c) * sizeof(char)); | |||
memset(bitmap, 0, 4 * cucul_get_width(c) * cucul_get_height(c)); | |||
#else | |||
aa_hidecursor (context); | |||
#endif | |||
@@ -153,7 +153,7 @@ uninitialize (void) | |||
{ | |||
#ifdef LIBCACA | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
#else | |||
aa_close (context); | |||
#endif | |||
@@ -235,11 +235,11 @@ drawfire (void) | |||
firemain (); | |||
#ifdef LIBCACA | |||
paused: | |||
cucul_dither_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, | |||
cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
cucul_dither, bitmap); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, cucul_get_width(qq) - 30, cucul_get_height(qq) - 2, | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2, | |||
" -=[ Powered by libcaca ]=- "); | |||
caca_display(kk); | |||
@@ -268,7 +268,7 @@ game (void) | |||
caca_event_t ev; | |||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) | |||
{ | |||
switch(ev.data.key.c) | |||
switch(ev.data.key.ch) | |||
{ | |||
case CACA_KEY_ESCAPE: return; | |||
case ' ': pause = !pause; | |||
@@ -42,7 +42,7 @@ static unsigned char metaball[METASIZE * METASIZE]; | |||
int main(int argc, char **argv) | |||
{ | |||
cucul_t *qq; caca_t *kk; | |||
cucul_canvas_t *c; caca_t *kk; | |||
unsigned int r[256], g[256], b[256], a[256]; | |||
float d[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS]; | |||
unsigned int x[METABALLS], y[METABALLS]; | |||
@@ -53,10 +53,10 @@ int main(int argc, char **argv) | |||
double frameOffset40[360]; | |||
double frameOffset80[360]; | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
return 1; | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
return 1; | |||
@@ -95,7 +95,7 @@ int main(int argc, char **argv) | |||
caca_event_t ev; | |||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) | |||
{ | |||
switch(ev.data.key.c) | |||
switch(ev.data.key.ch) | |||
{ | |||
case CACA_KEY_ESCAPE: goto end; | |||
case ' ': pause = !pause; | |||
@@ -153,11 +153,11 @@ int main(int argc, char **argv) | |||
paused: | |||
/* Draw our virtual buffer to screen, letting libcucul resize it */ | |||
cucul_dither_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, | |||
cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
cucul_dither, pixels + (METASIZE / 2) * (1 + XSIZ)); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, cucul_get_width(qq) - 30, cucul_get_height(qq) - 2, | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2, | |||
" -=[ Powered by libcaca ]=- "); | |||
caca_display(kk); | |||
@@ -167,7 +167,7 @@ paused: | |||
end: | |||
cucul_free_dither(cucul_dither); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -37,15 +37,15 @@ static void draw_line(int, int, char); | |||
int main (int argc, char **argv) | |||
{ | |||
cucul_t *qq; caca_t *kk; | |||
cucul_canvas_t *c; caca_t *kk; | |||
unsigned int red[256], green[256], blue[256], alpha[256]; | |||
cucul_dither_t *dither; | |||
int i, x, y, frame = 0, pause = 0; | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
return 1; | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
return 1; | |||
@@ -71,7 +71,7 @@ int main (int argc, char **argv) | |||
caca_event_t ev; | |||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) | |||
{ | |||
switch(ev.data.key.c) | |||
switch(ev.data.key.ch) | |||
{ | |||
case CACA_KEY_ESCAPE: goto end; | |||
case ' ': pause = !pause; | |||
@@ -106,11 +106,11 @@ int main (int argc, char **argv) | |||
frame++; | |||
paused: | |||
cucul_dither_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, | |||
cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
dither, screen); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, cucul_get_width(qq) - 30, cucul_get_height(qq) - 2, | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2, | |||
" -=[ Powered by libcaca ]=- "); | |||
caca_display(kk); | |||
} | |||
@@ -118,7 +118,7 @@ paused: | |||
end: | |||
cucul_free_dither(dither); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -40,23 +40,23 @@ static void do_plasma(unsigned char *, | |||
int main (int argc, char **argv) | |||
{ | |||
cucul_t *qq, *qq2, *mask; caca_t *kk; | |||
cucul_canvas_t *c, *c2, *mask; caca_t *kk; | |||
unsigned int red[256], green[256], blue[256], alpha[256]; | |||
double r[3], R[6]; | |||
cucul_dither_t *dither; | |||
int i, x, y, frame = 0, pause = 0; | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
return 1; | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
return 1; | |||
caca_set_delay(kk, 20000); | |||
qq2 = cucul_create(cucul_get_width(qq), cucul_get_height(qq)); | |||
mask = cucul_create(cucul_get_width(qq), cucul_get_height(qq)); | |||
c2 = cucul_create(cucul_get_width(c), cucul_get_height(c)); | |||
mask = cucul_create(cucul_get_width(c), cucul_get_height(c)); | |||
/* Fill various tables */ | |||
for(i = 0 ; i < 256; i++) | |||
@@ -87,7 +87,7 @@ int main (int argc, char **argv) | |||
caca_event_t ev; | |||
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) | |||
{ | |||
switch(ev.data.key.c) | |||
switch(ev.data.key.ch) | |||
{ | |||
case CACA_KEY_ESCAPE: goto end; | |||
case ' ': pause = !pause; | |||
@@ -119,18 +119,18 @@ int main (int argc, char **argv) | |||
frame++; | |||
paused: | |||
cucul_dither_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, | |||
cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
dither, screen); | |||
cucul_blit(qq2, 0, 0, qq, NULL); | |||
cucul_invert(qq2); | |||
cucul_blit(c2, 0, 0, c, NULL); | |||
cucul_invert(c2); | |||
cucul_blit(qq, 0, 0, qq2, mask); | |||
cucul_blit(c, 0, 0, c2, mask); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, cucul_get_width(qq) - 30, cucul_get_height(qq) - 2, | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2, | |||
" -=[ Powered by libcaca ]=- "); | |||
caca_display(kk); | |||
} | |||
@@ -138,7 +138,7 @@ paused: | |||
end: | |||
cucul_free_dither(dither); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -27,7 +27,7 @@ int main(int argc, char **argv) | |||
{ | |||
struct stat statbuf; | |||
caca_event_t ev; | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
void *buffer; | |||
int fd; | |||
@@ -53,28 +53,28 @@ int main(int argc, char **argv) | |||
buffer = malloc(statbuf.st_size); | |||
read(fd, buffer, statbuf.st_size); | |||
qq = cucul_load(buffer, statbuf.st_size); | |||
c = cucul_load(buffer, statbuf.st_size); | |||
free(buffer); | |||
if(!qq) | |||
if(!c) | |||
{ | |||
fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]); | |||
return 1; | |||
} | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
caca_display(kk); | |||
while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1)) | |||
{ | |||
if(ev.data.key.c == CACA_KEY_ESCAPE) | |||
if(ev.data.key.ch == CACA_KEY_ESCAPE) | |||
break; | |||
} | |||
/* Clean up */ | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -104,7 +104,7 @@ struct server | |||
char prefix[sizeof(INIT_PREFIX)]; | |||
cucul_t *qq; | |||
cucul_canvas_t *canvas; | |||
cucul_buffer_t *buffer; | |||
unsigned long int buflen; | |||
void *bufdata; | |||
@@ -184,7 +184,7 @@ int main(void) | |||
return -1; | |||
} | |||
server->qq = NULL; | |||
server->canvas = NULL; | |||
server->buffer = NULL; | |||
/* Ignore SIGPIPE */ | |||
@@ -223,12 +223,12 @@ int main(void) | |||
read(0, buf + 12, size - 12); | |||
/* Free the previous canvas, if any */ | |||
if(server->qq) | |||
cucul_free(server->qq); | |||
if(server->canvas) | |||
cucul_free(server->canvas); | |||
server->qq = cucul_load(buf, size); | |||
server->canvas = cucul_load(buf, size); | |||
if(!server->qq) | |||
if(!server->canvas) | |||
continue; /* Load error */ | |||
/* Free the previous export buffer, if any */ | |||
@@ -240,7 +240,7 @@ int main(void) | |||
/* Get ANSI representation of the image and skip the end-of buffer | |||
* linefeed ("\r\n\0", 3 bytes) */ | |||
server->buffer = cucul_create_export(server->qq, "ansi"); | |||
server->buffer = cucul_create_export(server->canvas, "ansi"); | |||
server->buflen -= 3; | |||
for(i = 0; i < server->client_count; i++) | |||
@@ -41,7 +41,7 @@ | |||
#define PAD_STEP 0.15 | |||
/* libcucul/libcaca contexts */ | |||
cucul_t *qq; caca_t *kk; | |||
cucul_canvas_t *c; caca_t *kk; | |||
/* Local functions */ | |||
static void print_status(void); | |||
@@ -68,14 +68,14 @@ int main(int argc, char **argv) | |||
int i; | |||
/* Initialise libcucul */ | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
{ | |||
fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); | |||
return 1; | |||
} | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
{ | |||
fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]); | |||
@@ -85,8 +85,8 @@ int main(int argc, char **argv) | |||
/* Set the window title */ | |||
caca_set_window_title(kk, "cacaview"); | |||
ww = cucul_get_width(qq); | |||
wh = cucul_get_height(qq); | |||
ww = cucul_get_width(c); | |||
wh = cucul_get_height(c); | |||
/* Fill the zoom table */ | |||
zoomtab[0] = 1.0; | |||
@@ -150,7 +150,7 @@ int main(int argc, char **argv) | |||
reload = 1; | |||
} | |||
} | |||
else if(ev.type & CACA_EVENT_KEY_PRESS) switch(ev.data.key.c) | |||
else if(ev.type & CACA_EVENT_KEY_PRESS) switch(ev.data.key.ch) | |||
{ | |||
case 'n': | |||
case 'N': | |||
@@ -170,44 +170,44 @@ int main(int argc, char **argv) | |||
break; | |||
#if 0 /* FIXME */ | |||
case 'b': | |||
i = 1 + cucul_get_feature(qq, CUCUL_BACKGROUND); | |||
i = 1 + cucul_get_feature(c, CUCUL_BACKGROUND); | |||
if(i > CUCUL_BACKGROUND_MAX) i = CUCUL_BACKGROUND_MIN; | |||
cucul_set_feature(qq, i); | |||
cucul_set_feature(c, i); | |||
new_status = STATUS_BACKGROUND; | |||
update = 1; | |||
break; | |||
case 'B': | |||
i = -1 + cucul_get_feature(qq, CUCUL_BACKGROUND); | |||
i = -1 + cucul_get_feature(c, CUCUL_BACKGROUND); | |||
if(i < CUCUL_BACKGROUND_MIN) i = CUCUL_BACKGROUND_MAX; | |||
cucul_set_feature(qq, i); | |||
cucul_set_feature(c, i); | |||
new_status = STATUS_BACKGROUND; | |||
update = 1; | |||
break; | |||
case 'a': | |||
i = 1 + cucul_get_feature(qq, CUCUL_ANTIALIASING); | |||
i = 1 + cucul_get_feature(c, CUCUL_ANTIALIASING); | |||
if(i > CUCUL_ANTIALIASING_MAX) i = CUCUL_ANTIALIASING_MIN; | |||
cucul_set_feature(qq, i); | |||
cucul_set_feature(c, i); | |||
new_status = STATUS_ANTIALIASING; | |||
update = 1; | |||
break; | |||
case 'A': | |||
i = -1 + cucul_get_feature(qq, CUCUL_ANTIALIASING); | |||
i = -1 + cucul_get_feature(c, CUCUL_ANTIALIASING); | |||
if(i < CUCUL_ANTIALIASING_MIN) i = CUCUL_ANTIALIASING_MAX; | |||
cucul_set_feature(qq, i); | |||
cucul_set_feature(c, i); | |||
new_status = STATUS_ANTIALIASING; | |||
update = 1; | |||
break; | |||
case 'd': | |||
i = 1 + cucul_get_feature(qq, CUCUL_DITHERING); | |||
i = 1 + cucul_get_feature(c, CUCUL_DITHERING); | |||
if(i > CUCUL_DITHERING_MAX) i = CUCUL_DITHERING_MIN; | |||
cucul_set_feature(qq, i); | |||
cucul_set_feature(c, i); | |||
new_status = STATUS_DITHERING; | |||
update = 1; | |||
break; | |||
case 'D': | |||
i = -1 + cucul_get_feature(qq, CUCUL_DITHERING); | |||
i = -1 + cucul_get_feature(c, CUCUL_DITHERING); | |||
if(i < CUCUL_DITHERING_MIN) i = CUCUL_DITHERING_MAX; | |||
cucul_set_feature(qq, i); | |||
cucul_set_feature(c, i); | |||
new_status = STATUS_DITHERING; | |||
update = 1; | |||
break; | |||
@@ -301,11 +301,11 @@ int main(int argc, char **argv) | |||
sprintf(buffer, " Loading `%s'... ", list[current]); | |||
buffer[ww] = '\0'; | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, (ww - strlen(buffer)) / 2, wh / 2, buffer); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, (ww - strlen(buffer)) / 2, wh / 2, buffer); | |||
caca_display(kk); | |||
ww = cucul_get_width(qq); | |||
wh = cucul_get_height(qq); | |||
ww = cucul_get_width(c); | |||
wh = cucul_get_height(c); | |||
if(im) | |||
unload_image(im); | |||
@@ -321,12 +321,12 @@ int main(int argc, char **argv) | |||
free(buffer); | |||
} | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
if(!items) | |||
{ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_printf(qq, ww / 2 - 5, wh / 2, " No image. "); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_printf(c, ww / 2 - 5, wh / 2, " No image. "); | |||
} | |||
else if(!im) | |||
{ | |||
@@ -345,8 +345,8 @@ int main(int argc, char **argv) | |||
sprintf(buffer, ERROR_STRING, list[current]); | |||
buffer[ww] = '\0'; | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, (ww - strlen(buffer)) / 2, wh / 2, buffer); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, (ww - strlen(buffer)) / 2, wh / 2, buffer); | |||
free(buffer); | |||
} | |||
else | |||
@@ -365,7 +365,7 @@ int main(int argc, char **argv) | |||
ww * (1.0 + xfactor) / 2, | |||
y + height * (1.0 + yfactor) / 2); | |||
cucul_dither_bitmap(qq, ww * (1.0 - xfactor) * xdelta, | |||
cucul_dither_bitmap(c, ww * (1.0 - xfactor) * xdelta, | |||
y + height * (1.0 - yfactor) * ydelta, | |||
ww * (xdelta + (1.0 - xdelta) * xfactor), | |||
y + height * (ydelta + (1.0 - ydelta) * yfactor), | |||
@@ -377,20 +377,20 @@ int main(int argc, char **argv) | |||
print_status(); | |||
#if 0 /* FIXME */ | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
switch(status) | |||
{ | |||
case STATUS_ANTIALIASING: | |||
cucul_printf(qq, 0, wh - 1, "Antialiasing: %s", | |||
cucul_get_feature_name(cucul_get_feature(qq, CUCUL_ANTIALIASING))); | |||
cucul_printf(c, 0, wh - 1, "Antialiasing: %s", | |||
cucul_get_feature_name(cucul_get_feature(c, CUCUL_ANTIALIASING))); | |||
break; | |||
case STATUS_DITHERING: | |||
cucul_printf(qq, 0, wh - 1, "Dithering: %s", | |||
cucul_get_feature_name(cucul_get_feature(qq, CUCUL_DITHERING))); | |||
cucul_printf(c, 0, wh - 1, "Dithering: %s", | |||
cucul_get_feature_name(cucul_get_feature(c, CUCUL_DITHERING))); | |||
break; | |||
case STATUS_BACKGROUND: | |||
cucul_printf(qq, 0, wh - 1, "Background: %s", | |||
cucul_get_feature_name(cucul_get_feature(qq, CUCUL_BACKGROUND))); | |||
cucul_printf(c, 0, wh - 1, "Background: %s", | |||
cucul_get_feature_name(cucul_get_feature(c, CUCUL_BACKGROUND))); | |||
break; | |||
} | |||
#endif | |||
@@ -409,25 +409,25 @@ int main(int argc, char **argv) | |||
if(im) | |||
unload_image(im); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
static void print_status(void) | |||
{ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_draw_line(qq, 0, 0, ww - 1, 0, " "); | |||
cucul_draw_line(qq, 0, wh - 2, ww - 1, wh - 2, "-"); | |||
cucul_putstr(qq, 0, 0, "q:Quit np:Next/Prev +-x:Zoom gG:Gamma " | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_draw_line(c, 0, 0, ww - 1, 0, " "); | |||
cucul_draw_line(c, 0, wh - 2, ww - 1, wh - 2, "-"); | |||
cucul_putstr(c, 0, 0, "q:Quit np:Next/Prev +-x:Zoom gG:Gamma " | |||
"hjkl:Move d:Dither a:Antialias"); | |||
cucul_putstr(qq, ww - strlen("?:Help"), 0, "?:Help"); | |||
cucul_printf(qq, 3, wh - 2, "cacaview %s", VERSION); | |||
cucul_printf(qq, ww - 30, wh - 2, "(gamma: %#.3g)", GAMMA(g)); | |||
cucul_printf(qq, ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); | |||
cucul_putstr(c, ww - strlen("?:Help"), 0, "?:Help"); | |||
cucul_printf(c, 3, wh - 2, "cacaview %s", VERSION); | |||
cucul_printf(c, ww - 30, wh - 2, "(gamma: %#.3g)", GAMMA(g)); | |||
cucul_printf(c, ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_line(qq, 0, wh - 1, ww - 1, wh - 1, " "); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_line(c, 0, wh - 1, ww - 1, wh - 1, " "); | |||
} | |||
static void print_help(int x, int y) | |||
@@ -454,10 +454,10 @@ static void print_help(int x, int y) | |||
int i; | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
for(i = 0; help[i]; i++) | |||
cucul_putstr(qq, x, y + i, help[i]); | |||
cucul_putstr(c, x, y + i, help[i]); | |||
} | |||
static void set_zoom(int new_zoom) | |||
@@ -472,12 +472,12 @@ static void set_zoom(int new_zoom) | |||
if(zoom > ZOOM_MAX) zoom = ZOOM_MAX; | |||
if(zoom < -ZOOM_MAX) zoom = -ZOOM_MAX; | |||
ww = cucul_get_width(qq); | |||
ww = cucul_get_width(c); | |||
height = fullscreen ? wh : wh - 3; | |||
xfactor = (zoom < 0) ? 1.0 / zoomtab[-zoom] : zoomtab[zoom]; | |||
yfactor = xfactor * ww / height * im->h / im->w | |||
* cucul_get_height(qq) / cucul_get_width(qq) | |||
* cucul_get_height(c) / cucul_get_width(c) | |||
* caca_get_window_width(kk) / caca_get_window_height(kk); | |||
if(yfactor > xfactor) | |||
@@ -506,17 +506,17 @@ static void draw_checkers(int x1, int y1, int x2, int y2) | |||
{ | |||
int xn, yn; | |||
if(x2 + 1 > (int)cucul_get_width(qq)) x2 = cucul_get_width(qq) - 1; | |||
if(y2 + 1 > (int)cucul_get_height(qq)) y2 = cucul_get_height(qq) - 1; | |||
if(x2 + 1 > (int)cucul_get_width(c)) x2 = cucul_get_width(c) - 1; | |||
if(y2 + 1 > (int)cucul_get_height(c)) y2 = cucul_get_height(c) - 1; | |||
for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++) | |||
for(xn = x1 > 0 ? x1 : 0; xn <= x2; xn++) | |||
{ | |||
if((((xn - x1) / 5) ^ ((yn - y1) / 3)) & 1) | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY); | |||
else | |||
cucul_set_color(qq, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY); | |||
cucul_putchar(qq, xn, yn, ' '); | |||
cucul_set_color(c, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY); | |||
cucul_putchar(c, xn, yn, ' '); | |||
} | |||
} | |||
@@ -23,7 +23,7 @@ | |||
int main(int argc, char **argv) | |||
{ | |||
/* libcucul context */ | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
cucul_buffer_t *export; | |||
struct image *i; | |||
int cols = 56, lines; | |||
@@ -34,8 +34,8 @@ int main(int argc, char **argv) | |||
return 1; | |||
} | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
{ | |||
fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); | |||
return 1; | |||
@@ -45,25 +45,25 @@ int main(int argc, char **argv) | |||
if(!i) | |||
{ | |||
fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 1; | |||
} | |||
/* Assume a 6×10 font */ | |||
lines = cols * i->h * 6 / i->w / 10; | |||
cucul_set_size(qq, cols, lines); | |||
cucul_clear(qq); | |||
cucul_dither_bitmap(qq, 0, 0, cols - 1, lines - 1, i->dither, i->pixels); | |||
cucul_set_size(c, cols, lines); | |||
cucul_clear(c); | |||
cucul_dither_bitmap(c, 0, 0, cols - 1, lines - 1, i->dither, i->pixels); | |||
unload_image(i); | |||
export = cucul_create_export(qq, "irc"); | |||
export = cucul_create_export(c, "irc"); | |||
fwrite(cucul_get_buffer_data(export), | |||
cucul_get_buffer_size(export), 1, stdout); | |||
cucul_free_buffer(export); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -22,29 +22,29 @@ | |||
int main(int argc, char **argv) | |||
{ | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
caca_event_t ev; | |||
int i, j; | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
return 1; | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
return 1; | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
for(i = 0; i < 16; i++) | |||
{ | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_printf(qq, 4, i + (i >= 8 ? 4 : 3), "'%c': %i (%s)", | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_printf(c, 4, i + (i >= 8 ? 4 : 3), "'%c': %i (%s)", | |||
'a' + i, i, cucul_get_color_name(i)); | |||
for(j = 0; j < 16; j++) | |||
{ | |||
cucul_set_color(qq, i, j); | |||
cucul_putstr(qq, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), | |||
cucul_set_color(c, i, j); | |||
cucul_putstr(c, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), | |||
"# "); | |||
} | |||
} | |||
@@ -53,7 +53,7 @@ int main(int argc, char **argv) | |||
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -37,7 +37,7 @@ int outline = 0; | |||
int dithering = 0; | |||
cucul_sprite_t *sprite = NULL; | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
int main(int argc, char **argv) | |||
@@ -45,10 +45,10 @@ int main(int argc, char **argv) | |||
void (*demo)(void) = NULL; | |||
int quit = 0; | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
return 1; | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
return 1; | |||
@@ -83,7 +83,7 @@ int main(int argc, char **argv) | |||
} | |||
else if(ev.type & CACA_EVENT_KEY_PRESS) | |||
{ | |||
switch(ev.data.key.c) | |||
switch(ev.data.key.ch) | |||
{ | |||
case 'q': | |||
case 'Q': | |||
@@ -104,7 +104,7 @@ int main(int argc, char **argv) | |||
case 'd': | |||
case 'D': | |||
dithering = (dithering + 1) % 5; | |||
cucul_set_feature(qq, dithering); | |||
cucul_set_feature(c, dithering); | |||
display_menu(); | |||
break; | |||
#endif | |||
@@ -142,7 +142,7 @@ int main(int argc, char **argv) | |||
} | |||
if(demo) | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
} | |||
else if(ev.type & CACA_EVENT_MOUSE_MOTION) | |||
{ | |||
@@ -161,9 +161,9 @@ int main(int argc, char **argv) | |||
display_menu(); | |||
if(mouse && !demo) | |||
{ | |||
cucul_set_color(qq, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, xmouse, ymouse, "."); | |||
cucul_putstr(qq, xmouse, ymouse + 1, "|\\"); | |||
cucul_set_color(c, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, xmouse, ymouse, "."); | |||
cucul_putstr(c, xmouse, ymouse + 1, "|\\"); | |||
} | |||
caca_display(kk); | |||
mouse = menu = 0; | |||
@@ -173,9 +173,9 @@ int main(int argc, char **argv) | |||
{ | |||
demo(); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(qq, 1, 1, cucul_get_width(qq) - 2, cucul_get_height(qq) - 2); | |||
cucul_printf(qq, 4, 1, "[%i.%i fps]----", | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(c, 1, 1, cucul_get_width(c) - 2, cucul_get_height(c) - 2); | |||
cucul_printf(c, 4, 1, "[%i.%i fps]----", | |||
1000000 / caca_get_rendertime(kk), | |||
(10000000 / caca_get_rendertime(kk)) % 10); | |||
caca_display(kk); | |||
@@ -185,44 +185,44 @@ int main(int argc, char **argv) | |||
/* Clean up */ | |||
cucul_free_sprite(sprite); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
static void display_menu(void) | |||
{ | |||
int xo = cucul_get_width(qq) - 2; | |||
int yo = cucul_get_height(qq) - 2; | |||
cucul_clear(qq); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(qq, 1, 1, xo, yo); | |||
cucul_putstr(qq, (xo - strlen("libcaca demo")) / 2, 3, "libcaca demo"); | |||
cucul_putstr(qq, (xo - strlen("==============")) / 2, 4, "=============="); | |||
cucul_putstr(qq, 4, 6, "demos:"); | |||
cucul_putstr(qq, 4, 7, "'f': full"); | |||
cucul_putstr(qq, 4, 8, "'1': dots"); | |||
cucul_putstr(qq, 4, 9, "'2': lines"); | |||
cucul_putstr(qq, 4, 10, "'3': boxes"); | |||
cucul_putstr(qq, 4, 11, "'4': triangles"); | |||
cucul_putstr(qq, 4, 12, "'5': ellipses"); | |||
cucul_putstr(qq, 4, 13, "'c': colour"); | |||
cucul_putstr(qq, 4, 14, "'r': render"); | |||
int xo = cucul_get_width(c) - 2; | |||
int yo = cucul_get_height(c) - 2; | |||
cucul_clear(c); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(c, 1, 1, xo, yo); | |||
cucul_putstr(c, (xo - strlen("libcaca demo")) / 2, 3, "libcaca demo"); | |||
cucul_putstr(c, (xo - strlen("==============")) / 2, 4, "=============="); | |||
cucul_putstr(c, 4, 6, "demos:"); | |||
cucul_putstr(c, 4, 7, "'f': full"); | |||
cucul_putstr(c, 4, 8, "'1': dots"); | |||
cucul_putstr(c, 4, 9, "'2': lines"); | |||
cucul_putstr(c, 4, 10, "'3': boxes"); | |||
cucul_putstr(c, 4, 11, "'4': triangles"); | |||
cucul_putstr(c, 4, 12, "'5': ellipses"); | |||
cucul_putstr(c, 4, 13, "'c': colour"); | |||
cucul_putstr(c, 4, 14, "'r': render"); | |||
if(sprite) | |||
cucul_putstr(qq, 4, 15, "'s': sprites"); | |||
cucul_putstr(c, 4, 15, "'s': sprites"); | |||
cucul_putstr(qq, 4, 16, "settings:"); | |||
cucul_printf(qq, 4, 17, "'o': outline: %s", | |||
cucul_putstr(c, 4, 16, "settings:"); | |||
cucul_printf(c, 4, 17, "'o': outline: %s", | |||
outline == 0 ? "none" : outline == 1 ? "solid" : "thin"); | |||
cucul_printf(qq, 4, 18, "'b': drawing boundaries: %s", | |||
cucul_printf(c, 4, 18, "'b': drawing boundaries: %s", | |||
bounds == 0 ? "screen" : "infinite"); | |||
//cucul_printf(qq, 4, 19, "'d': dithering (%s)", | |||
//cucul_printf(c, 4, 19, "'d': dithering (%s)", | |||
// cucul_get_feature_name(dithering)); | |||
cucul_putstr(qq, 4, yo - 2, "'q': quit"); | |||
cucul_putstr(c, 4, yo - 2, "'q': quit"); | |||
caca_display(kk); | |||
} | |||
@@ -235,99 +235,99 @@ static void demo_all(void) | |||
i++; | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
/* Draw the sun */ | |||
cucul_set_color(qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
xo = cucul_get_width(qq) / 4; | |||
yo = cucul_get_height(qq) / 4 + 5 * sin(0.03*i); | |||
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
xo = cucul_get_width(c) / 4; | |||
yo = cucul_get_height(c) / 4 + 5 * sin(0.03*i); | |||
for(j = 0; j < 16; j++) | |||
{ | |||
xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8); | |||
ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8); | |||
cucul_draw_thin_line(qq, xo, yo, xa, ya); | |||
cucul_draw_thin_line(c, xo, yo, xa, ya); | |||
} | |||
j = 15 + sin(0.03*i) * 8; | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
cucul_fill_ellipse(qq, xo, yo, j, j / 2, "#"); | |||
cucul_set_color(qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_ellipse(qq, xo, yo, j, j / 2, "#"); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
cucul_fill_ellipse(c, xo, yo, j, j / 2, "#"); | |||
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_ellipse(c, xo, yo, j, j / 2, "#"); | |||
/* Draw the pyramid */ | |||
xo = cucul_get_width(qq) * 5 / 8; | |||
xo = cucul_get_width(c) * 5 / 8; | |||
yo = 2; | |||
xa = cucul_get_width(qq) / 8 + sin(0.03*i) * 5; | |||
ya = cucul_get_height(qq) / 2 + cos(0.03*i) * 5; | |||
xa = cucul_get_width(c) / 8 + sin(0.03*i) * 5; | |||
ya = cucul_get_height(c) / 2 + cos(0.03*i) * 5; | |||
xb = cucul_get_width(qq) - 10 - cos(0.02*i) * 10; | |||
yb = cucul_get_height(qq) * 3 / 4 - 5 + sin(0.02*i) * 5; | |||
xb = cucul_get_width(c) - 10 - cos(0.02*i) * 10; | |||
yb = cucul_get_height(c) * 3 / 4 - 5 + sin(0.02*i) * 5; | |||
xc = cucul_get_width(qq) / 4 - sin(0.02*i) * 5; | |||
yc = cucul_get_height(qq) * 3 / 4 + cos(0.02*i) * 5; | |||
xc = cucul_get_width(c) / 4 - sin(0.02*i) * 5; | |||
yc = cucul_get_height(c) * 3 / 4 + cos(0.02*i) * 5; | |||
cucul_set_color(qq, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK); | |||
cucul_fill_triangle(qq, xo, yo, xb, yb, xa, ya, "%"); | |||
cucul_set_color(qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(qq, xo, yo, xb, yb, xa, ya); | |||
cucul_set_color(c, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK); | |||
cucul_fill_triangle(c, xo, yo, xb, yb, xa, ya, "%"); | |||
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(c, xo, yo, xb, yb, xa, ya); | |||
cucul_set_color(qq, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK); | |||
cucul_fill_triangle(qq, xa, ya, xb, yb, xc, yc, "#"); | |||
cucul_set_color(qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(qq, xa, ya, xb, yb, xc, yc); | |||
cucul_set_color(c, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK); | |||
cucul_fill_triangle(c, xa, ya, xb, yb, xc, yc, "#"); | |||
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(c, xa, ya, xb, yb, xc, yc); | |||
cucul_set_color(qq, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK); | |||
cucul_fill_triangle(qq, xo, yo, xb, yb, xc, yc, "%"); | |||
cucul_set_color(qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(qq, xo, yo, xb, yb, xc, yc); | |||
cucul_set_color(c, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK); | |||
cucul_fill_triangle(c, xo, yo, xb, yb, xc, yc, "%"); | |||
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(c, xo, yo, xb, yb, xc, yc); | |||
/* Draw a background triangle */ | |||
xa = 2; | |||
ya = 2; | |||
xb = cucul_get_width(qq) - 3; | |||
yb = cucul_get_height(qq) / 2; | |||
xb = cucul_get_width(c) - 3; | |||
yb = cucul_get_height(c) / 2; | |||
xc = cucul_get_width(qq) / 3; | |||
yc = cucul_get_height(qq) - 3; | |||
xc = cucul_get_width(c) / 3; | |||
yc = cucul_get_height(c) - 3; | |||
cucul_set_color(qq, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(qq, xa, ya, xb, yb, xc, yc); | |||
cucul_set_color(c, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_triangle(c, xa, ya, xb, yb, xc, yc); | |||
xo = cucul_get_width(qq) / 2 + cos(0.027*i) * cucul_get_width(qq) / 3; | |||
yo = cucul_get_height(qq) / 2 - sin(0.027*i) * cucul_get_height(qq) / 2; | |||
xo = cucul_get_width(c) / 2 + cos(0.027*i) * cucul_get_width(c) / 3; | |||
yo = cucul_get_height(c) / 2 - sin(0.027*i) * cucul_get_height(c) / 2; | |||
cucul_draw_thin_line(qq, xa, ya, xo, yo); | |||
cucul_draw_thin_line(qq, xb, yb, xo, yo); | |||
cucul_draw_thin_line(qq, xc, yc, xo, yo); | |||
cucul_draw_thin_line(c, xa, ya, xo, yo); | |||
cucul_draw_thin_line(c, xb, yb, xo, yo); | |||
cucul_draw_thin_line(c, xc, yc, xo, yo); | |||
/* Draw a sprite on the pyramid */ | |||
cucul_draw_sprite(qq, xo, yo, sprite, 0); | |||
cucul_draw_sprite(c, xo, yo, sprite, 0); | |||
/* Draw a trail behind the foreground sprite */ | |||
for(j = i - 60; j < i; j++) | |||
{ | |||
int delta = cucul_rand(-5, 5); | |||
cucul_set_color(qq, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_putchar(qq, cucul_get_width(qq) / 2 | |||
+ cos(0.02*j) * (delta + cucul_get_width(qq) / 4), | |||
cucul_get_height(qq) / 2 | |||
+ sin(0.02*j) * (delta + cucul_get_height(qq) / 3), | |||
cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_putchar(c, cucul_get_width(c) / 2 | |||
+ cos(0.02*j) * (delta + cucul_get_width(c) / 4), | |||
cucul_get_height(c) / 2 | |||
+ sin(0.02*j) * (delta + cucul_get_height(c) / 3), | |||
'#'); | |||
} | |||
/* Draw foreground sprite */ | |||
cucul_draw_sprite(qq, cucul_get_width(qq) / 2 + cos(0.02*i) * cucul_get_width(qq) / 4, | |||
cucul_get_height(qq) / 2 + sin(0.02*i) * cucul_get_height(qq) / 3, | |||
cucul_draw_sprite(c, cucul_get_width(c) / 2 + cos(0.02*i) * cucul_get_width(c) / 4, | |||
cucul_get_height(c) / 2 + sin(0.02*i) * cucul_get_height(c) / 3, | |||
sprite, 0); | |||
} | |||
static void demo_dots(void) | |||
{ | |||
int xmax = cucul_get_width(qq) - 1; | |||
int ymax = cucul_get_height(qq) - 1; | |||
int xmax = cucul_get_width(c) - 1; | |||
int ymax = cucul_get_height(c) - 1; | |||
int i; | |||
static char chars[10] = | |||
{ | |||
@@ -337,8 +337,8 @@ static void demo_dots(void) | |||
for(i = 1000; i--;) | |||
{ | |||
/* Putpixel */ | |||
cucul_set_color(qq, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_putchar(qq, cucul_rand(0, xmax), cucul_rand(0, ymax), | |||
cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_putchar(c, cucul_rand(0, xmax), cucul_rand(0, ymax), | |||
chars[cucul_rand(0, 9)]); | |||
} | |||
} | |||
@@ -348,24 +348,24 @@ static void demo_color(void) | |||
int i, j; | |||
char buf[BUFSIZ]; | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
for(i = 0; i < 16; i++) | |||
{ | |||
sprintf(buf, "'%c': %i (%s)", 'a' + i, i, cucul_get_color_name(i)); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 4, i + (i >= 8 ? 4 : 3), buf); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 4, i + (i >= 8 ? 4 : 3), buf); | |||
for(j = 0; j < 16; j++) | |||
{ | |||
cucul_set_color(qq, i, j); | |||
cucul_putstr(qq, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# "); | |||
cucul_set_color(c, i, j); | |||
cucul_putstr(c, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# "); | |||
} | |||
} | |||
} | |||
static void demo_lines(void) | |||
{ | |||
int w = cucul_get_width(qq); | |||
int h = cucul_get_height(qq); | |||
int w = cucul_get_width(c); | |||
int h = cucul_get_height(c); | |||
int xa, ya, xb, yb; | |||
if(bounds) | |||
@@ -379,17 +379,17 @@ static void demo_lines(void) | |||
xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1); | |||
} | |||
cucul_set_color(qq, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
if(outline > 1) | |||
cucul_draw_thin_line(qq, xa, ya, xb, yb); | |||
cucul_draw_thin_line(c, xa, ya, xb, yb); | |||
else | |||
cucul_draw_line(qq, xa, ya, xb, yb, "#"); | |||
cucul_draw_line(c, xa, ya, xb, yb, "#"); | |||
} | |||
static void demo_boxes(void) | |||
{ | |||
int w = cucul_get_width(qq); | |||
int h = cucul_get_height(qq); | |||
int w = cucul_get_width(c); | |||
int h = cucul_get_height(c); | |||
int xa, ya, xb, yb; | |||
if(bounds) | |||
@@ -403,20 +403,20 @@ static void demo_boxes(void) | |||
xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1); | |||
} | |||
cucul_set_color(qq, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_fill_box(qq, xa, ya, xb, yb, "#"); | |||
cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_fill_box(c, xa, ya, xb, yb, "#"); | |||
cucul_set_color(qq, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
if(outline == 2) | |||
cucul_draw_thin_box(qq, xa, ya, xb, yb); | |||
cucul_draw_thin_box(c, xa, ya, xb, yb); | |||
else if(outline == 1) | |||
cucul_draw_box(qq, xa, ya, xb, yb, "#"); | |||
cucul_draw_box(c, xa, ya, xb, yb, "#"); | |||
} | |||
static void demo_ellipses(void) | |||
{ | |||
int w = cucul_get_width(qq); | |||
int h = cucul_get_height(qq); | |||
int w = cucul_get_width(c); | |||
int h = cucul_get_height(c); | |||
int x, y, a, b; | |||
if(bounds) | |||
@@ -434,20 +434,20 @@ static void demo_ellipses(void) | |||
} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h); | |||
} | |||
cucul_set_color(qq, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_fill_ellipse(qq, x, y, a, b, "#"); | |||
cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_fill_ellipse(c, x, y, a, b, "#"); | |||
cucul_set_color(qq, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
if(outline == 2) | |||
cucul_draw_thin_ellipse(qq, x, y, a, b); | |||
cucul_draw_thin_ellipse(c, x, y, a, b); | |||
else if(outline == 1) | |||
cucul_draw_ellipse(qq, x, y, a, b, "#"); | |||
cucul_draw_ellipse(c, x, y, a, b, "#"); | |||
} | |||
static void demo_triangles(void) | |||
{ | |||
int w = cucul_get_width(qq); | |||
int h = cucul_get_height(qq); | |||
int w = cucul_get_width(c); | |||
int h = cucul_get_height(c); | |||
int xa, ya, xb, yb, xc, yc; | |||
if(bounds) | |||
@@ -464,20 +464,20 @@ static void demo_triangles(void) | |||
xc = cucul_rand(0, w - 1); yc = cucul_rand(0, h - 1); | |||
} | |||
cucul_set_color(qq, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_fill_triangle(qq, xa, ya, xb, yb, xc, yc, "#"); | |||
cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15)); | |||
cucul_fill_triangle(c, xa, ya, xb, yb, xc, yc, "#"); | |||
cucul_set_color(qq, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK); | |||
if(outline == 2) | |||
cucul_draw_thin_triangle(qq, xa, ya, xb, yb, xc, yc); | |||
cucul_draw_thin_triangle(c, xa, ya, xb, yb, xc, yc); | |||
else if(outline == 1) | |||
cucul_draw_triangle(qq, xa, ya, xb, yb, xc, yc, "#"); | |||
cucul_draw_triangle(c, xa, ya, xb, yb, xc, yc, "#"); | |||
} | |||
static void demo_sprites(void) | |||
{ | |||
cucul_draw_sprite(qq, cucul_rand(0, cucul_get_width(qq) - 1), | |||
cucul_rand(0, cucul_get_height(qq) - 1), sprite, 0); | |||
cucul_draw_sprite(c, cucul_rand(0, cucul_get_width(c) - 1), | |||
cucul_rand(0, cucul_get_height(c) - 1), sprite, 0); | |||
} | |||
#if 0 | |||
@@ -503,7 +503,7 @@ static void demo_render(void) | |||
cucul_set_dither_invert(dither, 1); | |||
//dither = cucul_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000); | |||
dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); | |||
cucul_dither_bitmap(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
dither, buffer); | |||
cucul_free_dither(dither); | |||
} | |||
@@ -548,7 +548,7 @@ static void demo_render(void) | |||
dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); | |||
cucul_set_dither_invert(dither, 1); | |||
cucul_dither_bitmap(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, dither, (char *)buffer); | |||
cucul_dither_bitmap(c, 0, 0, cucul_get_width(c) - 1, cucul_get_height(c) - 1, dither, (char *)buffer); | |||
cucul_free_dither(dither); | |||
} | |||
@@ -35,13 +35,13 @@ char density[] = " ',+:;o&%w$W@#"; | |||
int main(void) | |||
{ | |||
caca_event_t ev; | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
int neara, dista, nearb, distb, dist; | |||
int x, y; | |||
qq = cucul_create(0, 0); | |||
kk = caca_attach(qq); | |||
c = cucul_create(0, 0); | |||
kk = caca_attach(c); | |||
for(x = 0; x < 100; x++) | |||
for(y = 0; y < 100; y++) | |||
@@ -116,10 +116,10 @@ int main(void) | |||
ch = density[distb * 2 * 13 / (dista + distb)]; | |||
else | |||
ch = density[dista * 2 * 13 / (dista + distb)]; | |||
cucul_set_color(qq, points[nearb], points[neara]); | |||
cucul_set_color(c, points[nearb], points[neara]); | |||
cucul_putchar(qq, x * cucul_get_width(qq) / 100, | |||
(100 - y) * cucul_get_height(qq) / 100, ch); | |||
cucul_putchar(c, x * cucul_get_width(c) / 100, | |||
(100 - y) * cucul_get_height(c) / 100, ch); | |||
} | |||
caca_display(kk); | |||
@@ -127,7 +127,7 @@ int main(void) | |||
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -20,7 +20,7 @@ | |||
#include "cucul.h" | |||
#include "caca.h" | |||
static cucul_t *qq; | |||
static cucul_canvas_t *c; | |||
static caca_t *kk; | |||
static void print_event(int, int, caca_event_t *); | |||
@@ -30,20 +30,20 @@ int main(int argc, char **argv) | |||
caca_event_t *events; | |||
int i, h, quit; | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
return 1; | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
return 1; | |||
h = cucul_get_height(qq) - 1; | |||
h = cucul_get_height(c) - 1; | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_draw_line(qq, 0, 0, cucul_get_width(qq) - 1, 0, " "); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_draw_line(c, 0, 0, cucul_get_width(c) - 1, 0, " "); | |||
cucul_draw_line(qq, 0, h, cucul_get_width(qq) - 1, h, " "); | |||
cucul_putstr(qq, 0, h, "type \"quit\" to exit"); | |||
cucul_draw_line(c, 0, h, cucul_get_width(c) - 1, h, " "); | |||
cucul_putstr(c, 0, h, "type \"quit\" to exit"); | |||
caca_display(kk); | |||
@@ -64,7 +64,7 @@ int main(int argc, char **argv) | |||
/* "quit" quits */ | |||
if(ev.type & CACA_EVENT_KEY_PRESS) | |||
{ | |||
int key = ev.data.key.c; | |||
int key = ev.data.key.ch; | |||
if((key == 'q' && quit == 0) || (key == 'u' && quit == 1) | |||
|| (key == 'i' && quit == 2) || (key == 't' && quit == 3)) | |||
quit++; | |||
@@ -81,18 +81,18 @@ int main(int argc, char **argv) | |||
} | |||
while(ret); | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
/* Print current event */ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_draw_line(qq, 0, 0, cucul_get_width(qq) - 1, 0, " "); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_draw_line(c, 0, 0, cucul_get_width(c) - 1, 0, " "); | |||
print_event(0, 0, events); | |||
cucul_draw_line(qq, 0, h, cucul_get_width(qq) - 1, h, " "); | |||
cucul_printf(qq, 0, h, "type \"quit\" to exit: %s", quit_string[quit]); | |||
cucul_draw_line(c, 0, h, cucul_get_width(c) - 1, h, " "); | |||
cucul_printf(c, 0, h, "type \"quit\" to exit: %s", quit_string[quit]); | |||
/* Print previous events */ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
for(i = 1; i < h && events[i].type; i++) | |||
print_event(0, i, events + i); | |||
@@ -101,7 +101,7 @@ int main(int argc, char **argv) | |||
/* Clean up */ | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -113,39 +113,39 @@ static void print_event(int x, int y, caca_event_t *ev) | |||
switch(ev->type) | |||
{ | |||
case CACA_EVENT_NONE: | |||
cucul_printf(qq, x, y, "CACA_EVENT_NONE"); | |||
cucul_printf(c, x, y, "CACA_EVENT_NONE"); | |||
break; | |||
case CACA_EVENT_KEY_PRESS: | |||
character = ev->data.key.c; | |||
cucul_printf(qq, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character, | |||
character = ev->data.key.ch; | |||
cucul_printf(c, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character, | |||
(character > 0x1f && character < 0x80) ? character : '?'); | |||
break; | |||
case CACA_EVENT_KEY_RELEASE: | |||
character = ev->data.key.c; | |||
cucul_printf(qq, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character, | |||
character = ev->data.key.ch; | |||
cucul_printf(c, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character, | |||
(character > 0x1f && character < 0x80) ? character : '?'); | |||
break; | |||
case CACA_EVENT_MOUSE_MOTION: | |||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_MOTION %u %u", | |||
cucul_printf(c, x, y, "CACA_EVENT_MOUSE_MOTION %u %u", | |||
ev->data.mouse.x, ev->data.mouse.y); | |||
break; | |||
case CACA_EVENT_MOUSE_PRESS: | |||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_PRESS %u", | |||
cucul_printf(c, x, y, "CACA_EVENT_MOUSE_PRESS %u", | |||
ev->data.mouse.button); | |||
break; | |||
case CACA_EVENT_MOUSE_RELEASE: | |||
cucul_printf(qq, x, y, "CACA_EVENT_MOUSE_RELEASE %u", | |||
cucul_printf(c, x, y, "CACA_EVENT_MOUSE_RELEASE %u", | |||
ev->data.mouse.button); | |||
break; | |||
case CACA_EVENT_RESIZE: | |||
cucul_printf(qq, x, y, "CACA_EVENT_RESIZE %u %u", | |||
cucul_printf(c, x, y, "CACA_EVENT_RESIZE %u %u", | |||
ev->data.resize.w, ev->data.resize.h); | |||
break; | |||
case CACA_EVENT_QUIT: | |||
cucul_printf(qq, x, y, "CACA_EVENT_QUIT"); | |||
cucul_printf(c, x, y, "CACA_EVENT_QUIT"); | |||
break; | |||
default: | |||
cucul_printf(qq, x, y, "CACA_EVENT_UNKNOWN"); | |||
cucul_printf(c, x, y, "CACA_EVENT_UNKNOWN"); | |||
} | |||
} | |||
@@ -34,7 +34,7 @@ uint32_t pixels[256*256]; | |||
int main(int argc, char *argv[]) | |||
{ | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
cucul_dither_t *dither; | |||
cucul_buffer_t *buffer; | |||
char const * const * exports, * const * p; | |||
@@ -65,7 +65,7 @@ int main(int argc, char *argv[]) | |||
exit(-1); | |||
} | |||
qq = cucul_create(WIDTH, HEIGHT); | |||
c = cucul_create(WIDTH, HEIGHT); | |||
for(y = 0; y < 256; y++) | |||
{ | |||
@@ -80,34 +80,34 @@ int main(int argc, char *argv[]) | |||
dither = cucul_create_dither(32, 256, 256, 4 * 256, | |||
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); | |||
cucul_dither_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, | |||
cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
dither, pixels); | |||
cucul_free_dither(dither); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(qq, 0, 0, WIDTH - 1, HEIGHT - 1); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(c, 0, 0, WIDTH - 1, HEIGHT - 1); | |||
cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE); | |||
cucul_fill_ellipse(qq, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " "); | |||
cucul_putstr(qq, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>"); | |||
cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); | |||
cucul_set_color(c, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE); | |||
cucul_fill_ellipse(c, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " "); | |||
cucul_putstr(c, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>"); | |||
cucul_putstr(c, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); | |||
cucul_putstr(qq, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); | |||
cucul_putstr(c, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); | |||
for(x = 0; x < 16; x++) | |||
{ | |||
cucul_set_truecolor(qq, 0xff00 | x, 0xf00f | (x << 4)); | |||
cucul_putstr(qq, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#"); | |||
cucul_set_truecolor(c, 0xff00 | x, 0xf00f | (x << 4)); | |||
cucul_putstr(c, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#"); | |||
} | |||
buffer = cucul_create_export(qq, argv[1]); | |||
buffer = cucul_create_export(c, argv[1]); | |||
fwrite(cucul_get_buffer_data(buffer), | |||
cucul_get_buffer_size(buffer), 1, stdout); | |||
cucul_free_buffer(buffer); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -34,7 +34,7 @@ typedef unsigned int uint32_t; | |||
int main(int argc, char *argv[]) | |||
{ | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
cucul_font_t *f; | |||
cucul_dither_t *d; | |||
@@ -44,15 +44,15 @@ int main(int argc, char *argv[]) | |||
char const * const * fonts; | |||
/* Create a canvas */ | |||
qq = cucul_create(8, 2); | |||
c = cucul_create(8, 2); | |||
/* Draw stuff on our canvas */ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 0, 0, "ABcde"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 5, 0, "\\o/"); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, 0, 1, "&$âøÿØ?!"); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 0, 0, "ABcde"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 5, 0, "\\o/"); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, 0, 1, "&$âøÿØ?!"); | |||
/* Load a libcucul internal font */ | |||
fonts = cucul_get_font_list(); | |||
@@ -69,16 +69,16 @@ int main(int argc, char *argv[]) | |||
} | |||
/* Create our bitmap buffer (32-bit ARGB) */ | |||
w = cucul_get_width(qq) * cucul_get_font_width(f); | |||
h = cucul_get_height(qq) * cucul_get_font_height(f); | |||
w = cucul_get_width(c) * cucul_get_font_width(f); | |||
h = cucul_get_height(c) * cucul_get_font_height(f); | |||
buf = malloc(4 * w * h); | |||
/* Render the canvas onto our image buffer */ | |||
cucul_render_canvas(qq, f, buf, w, h, 4 * w); | |||
cucul_render_canvas(c, f, buf, w, h, 4 * w); | |||
/* Just for fun, render the image using libcaca */ | |||
cucul_set_size(qq, 80, 32); | |||
kk = caca_attach(qq); | |||
cucul_set_size(c, 80, 32); | |||
kk = caca_attach(c); | |||
#if defined(HAVE_ENDIAN_H) | |||
if(__BYTE_ORDER == __BIG_ENDIAN) | |||
@@ -93,8 +93,8 @@ int main(int argc, char *argv[]) | |||
d = cucul_create_dither(32, w, h, 4 * w, | |||
0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff); | |||
cucul_dither_bitmap(qq, 0, 0, cucul_get_width(qq) - 1, | |||
cucul_get_height(qq) - 1, d, buf); | |||
cucul_dither_bitmap(c, 0, 0, cucul_get_width(c) - 1, | |||
cucul_get_height(c) - 1, d, buf); | |||
caca_display(kk); | |||
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1); | |||
@@ -104,7 +104,7 @@ int main(int argc, char *argv[]) | |||
free(buf); | |||
cucul_free_dither(d); | |||
cucul_free_font(f); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -34,17 +34,17 @@ uint32_t buffer[256 * 4]; | |||
int main(void) | |||
{ | |||
caca_event_t ev; | |||
cucul_t *qq, *gg, *mask; | |||
cucul_canvas_t *c, *gg, *mask; | |||
caca_t *kk; | |||
cucul_dither_t *left, *right; | |||
float gam = 1.0; | |||
int x; | |||
qq = cucul_create(0, 0); | |||
kk = caca_attach(qq); | |||
c = cucul_create(0, 0); | |||
kk = caca_attach(c); | |||
gg = cucul_create(cucul_get_width(qq), cucul_get_height(qq)); | |||
mask = cucul_create(cucul_get_width(qq), cucul_get_height(qq)); | |||
gg = cucul_create(cucul_get_width(c), cucul_get_height(c)); | |||
mask = cucul_create(cucul_get_width(c), cucul_get_height(c)); | |||
for(x = 0; x < 256; x++) | |||
{ | |||
@@ -66,23 +66,23 @@ int main(void) | |||
if(ret) | |||
{ | |||
if(ev.data.key.c == CACA_KEY_LEFT) | |||
if(ev.data.key.ch == CACA_KEY_LEFT) | |||
gam /= 1.03; | |||
else if(ev.data.key.c == CACA_KEY_RIGHT) | |||
else if(ev.data.key.ch == CACA_KEY_RIGHT) | |||
gam *= 1.03; | |||
else if(ev.data.key.c == CACA_KEY_DOWN) | |||
else if(ev.data.key.ch == CACA_KEY_DOWN) | |||
gam = 1.0; | |||
else if(ev.data.key.c == CACA_KEY_ESCAPE) | |||
else if(ev.data.key.ch == CACA_KEY_ESCAPE) | |||
break; | |||
} | |||
/* Resize the spare canvas, just in case the main one changed */ | |||
cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq)); | |||
cucul_set_size(mask, cucul_get_width(qq), cucul_get_height(qq)); | |||
cucul_set_size(gg, cucul_get_width(c), cucul_get_height(c)); | |||
cucul_set_size(mask, cucul_get_width(c), cucul_get_height(c)); | |||
/* Draw the regular dither on the main canvas */ | |||
cucul_dither_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, | |||
cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
left, buffer); | |||
/* Draw the gamma-modified dither on the spare canvas */ | |||
@@ -102,10 +102,10 @@ int main(void) | |||
cucul_get_height(mask) / 2, "#"); | |||
/* Blit the spare canvas onto the first one */ | |||
cucul_blit(qq, 0, 0, gg, mask); | |||
cucul_blit(c, 0, 0, gg, mask); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_printf(qq, 2, 1, | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_printf(c, 2, 1, | |||
"gamma=%g - use arrows to change, Esc to quit", gam); | |||
caca_display(kk); | |||
@@ -115,7 +115,7 @@ int main(void) | |||
cucul_free_dither(right); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -29,14 +29,14 @@ uint32_t buffer[256*256]; | |||
int main(void) | |||
{ | |||
caca_event_t ev; | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
cucul_dither_t *dither; | |||
int x, y; | |||
qq = cucul_create(0, 0); | |||
kk = caca_attach(qq); | |||
c = cucul_create(0, 0); | |||
kk = caca_attach(c); | |||
for(y = 0; y < 256; y++) | |||
for(x = 0; x < 256; x++) | |||
@@ -46,8 +46,8 @@ int main(void) | |||
dither = cucul_create_dither(32, 256, 256, 4 * 256, | |||
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); | |||
cucul_dither_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_dither_bitmap(c, 0, 0, | |||
cucul_get_width(c) - 1, cucul_get_height(c) - 1, | |||
dither, buffer); | |||
cucul_free_dither(dither); | |||
@@ -56,7 +56,7 @@ int main(void) | |||
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -22,7 +22,7 @@ | |||
int main(int argc, char **argv) | |||
{ | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
int quit = 0; | |||
@@ -37,10 +37,10 @@ int main(int argc, char **argv) | |||
return 1; | |||
} | |||
qq = cucul_create(0, 0); | |||
if(!qq) | |||
c = cucul_create(0, 0); | |||
if(!c) | |||
return 1; | |||
kk = caca_attach(qq); | |||
kk = caca_attach(c); | |||
if(!kk) | |||
return 1; | |||
@@ -49,7 +49,7 @@ int main(int argc, char **argv) | |||
if(!sprite) | |||
{ | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); | |||
return 1; | |||
} | |||
@@ -63,7 +63,7 @@ int main(int argc, char **argv) | |||
while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0)) | |||
{ | |||
switch(ev.data.key.c) | |||
switch(ev.data.key.ch) | |||
{ | |||
case 0: | |||
break; | |||
@@ -100,43 +100,43 @@ int main(int argc, char **argv) | |||
} | |||
cucul_clear(qq); | |||
cucul_clear(c); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(qq, 0, 0, cucul_get_width(qq) - 1, cucul_get_height(qq) - 1); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(c, 0, 0, cucul_get_width(c) - 1, cucul_get_height(c) - 1); | |||
cucul_putstr(qq, 3, 0, "[ Sprite editor for libcaca ]"); | |||
cucul_putstr(c, 3, 0, "[ Sprite editor for libcaca ]"); | |||
sprintf(buf, "sprite `%s'", argv[1]); | |||
cucul_putstr(qq, 3, 2, buf); | |||
cucul_putstr(c, 3, 2, buf); | |||
sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(sprite) - 1); | |||
cucul_putstr(qq, 3, 3, buf); | |||
cucul_putstr(c, 3, 3, buf); | |||
/* Crosshair */ | |||
cucul_draw_thin_line(qq, 57, 2, 57, 18); | |||
cucul_draw_thin_line(qq, 37, 10, 77, 10); | |||
cucul_putchar(qq, 57, 10, '+'); | |||
cucul_draw_thin_line(c, 57, 2, 57, 18); | |||
cucul_draw_thin_line(c, 37, 10, 77, 10); | |||
cucul_putchar(c, 57, 10, '+'); | |||
/* Boxed sprite */ | |||
xa = -1 - cucul_get_sprite_dx(sprite, frame); | |||
ya = -1 - cucul_get_sprite_dy(sprite, frame); | |||
xb = xa + 1 + cucul_get_sprite_width(sprite, frame); | |||
yb = ya + 1 + cucul_get_sprite_height(sprite, frame); | |||
cucul_set_color(qq, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK); | |||
cucul_fill_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " "); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(qq, 57 + xa, 10 + ya, 57 + xb, 10 + yb); | |||
cucul_draw_sprite(qq, 57, 10, sprite, frame); | |||
cucul_set_color(c, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK); | |||
cucul_fill_box(c, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " "); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_draw_thin_box(c, 57 + xa, 10 + ya, 57 + xb, 10 + yb); | |||
cucul_draw_sprite(c, 57, 10, sprite, frame); | |||
/* Free sprite */ | |||
cucul_draw_sprite(qq, 20, 10, sprite, frame); | |||
cucul_draw_sprite(c, 20, 10, sprite, frame); | |||
caca_display(kk); | |||
} | |||
/* Clean up */ | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -50,12 +50,12 @@ static char const *duck[] = | |||
int main(void) | |||
{ | |||
caca_event_t ev; | |||
cucul_t *qq, *normal, *flip, *flop, *rotate; | |||
cucul_canvas_t *c, *normal, *flip, *flop, *rotate; | |||
caca_t *kk; | |||
int i; | |||
qq = cucul_create(0, 0); | |||
kk = caca_attach(qq); | |||
c = cucul_create(0, 0); | |||
kk = caca_attach(c); | |||
normal = cucul_create(70, 6); | |||
flip = cucul_create(70, 6); | |||
@@ -96,15 +96,15 @@ int main(void) | |||
cucul_rotate(rotate); | |||
/* Blit the transformed canvas onto the main canvas */ | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, 0, 0, "normal"); | |||
cucul_blit(qq, 10, 0, normal, NULL); | |||
cucul_putstr(qq, 0, 6, "flip"); | |||
cucul_blit(qq, 10, 6, flip, NULL); | |||
cucul_putstr(qq, 0, 12, "flop"); | |||
cucul_blit(qq, 10, 12, flop, NULL); | |||
cucul_putstr(qq, 0, 18, "rotate"); | |||
cucul_blit(qq, 10, 18, rotate, NULL); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, 0, 0, "normal"); | |||
cucul_blit(c, 10, 0, normal, NULL); | |||
cucul_putstr(c, 0, 6, "flip"); | |||
cucul_blit(c, 10, 6, flip, NULL); | |||
cucul_putstr(c, 0, 12, "flop"); | |||
cucul_blit(c, 10, 12, flop, NULL); | |||
cucul_putstr(c, 0, 18, "rotate"); | |||
cucul_blit(c, 10, 18, rotate, NULL); | |||
caca_display(kk); | |||
@@ -115,7 +115,7 @@ int main(void) | |||
cucul_free(flop); | |||
cucul_free(flip); | |||
cucul_free(normal); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -27,13 +27,13 @@ typedef unsigned int uint32_t; | |||
int main(void) | |||
{ | |||
caca_event_t ev; | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
int x, y; | |||
qq = cucul_create(32, 16); | |||
kk = caca_attach(qq); | |||
c = cucul_create(32, 16); | |||
kk = caca_attach(c); | |||
for(y = 0; y < 16; y++) | |||
for(x = 0; x < 16; x++) | |||
@@ -41,19 +41,19 @@ int main(void) | |||
uint16_t bgcolor = 0xff00 | (y << 4) | x; | |||
uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8); | |||
cucul_set_truecolor(qq, fgcolor, bgcolor); | |||
cucul_putstr(qq, x * 2, y, "CA"); | |||
cucul_set_truecolor(c, fgcolor, bgcolor); | |||
cucul_putstr(c, x * 2, y, "CA"); | |||
} | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); | |||
cucul_putstr(qq, 2, 1, " truecolor libcaca "); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE); | |||
cucul_putstr(c, 2, 1, " truecolor libcaca "); | |||
caca_display(kk); | |||
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||
@@ -27,70 +27,70 @@ typedef unsigned int uint32_t; | |||
int main(void) | |||
{ | |||
caca_event_t ev; | |||
cucul_t *qq; | |||
cucul_canvas_t *c; | |||
caca_t *kk; | |||
qq = cucul_create(0, 0); | |||
kk = caca_attach(qq); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, 1, 1, "Basic Unicode support"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 1, 2, "This is ASCII: | abc DEF 123 !@# |"); | |||
cucul_putstr(qq, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |"); | |||
cucul_putstr(qq, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |"); | |||
cucul_putstr(qq, 1, 5, "If the three lines do not have the same length, there is a bug somewhere."); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, 1, 7, "Gradient glyphs"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 31, 8, " 0%"); | |||
cucul_putstr(qq, 31, 9, " 25%"); | |||
cucul_putstr(qq, 31, 10, " 50%"); | |||
cucul_putstr(qq, 31, 11, " 75%"); | |||
cucul_putstr(qq, 31, 12, "100%"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_LIGHTGREEN); | |||
cucul_putstr(qq, 1, 8, " "); | |||
cucul_putstr(qq, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); | |||
cucul_putstr(qq, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"); | |||
cucul_putstr(qq, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); | |||
cucul_putstr(qq, 1, 12, "█████████████████████████████"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGREEN, CUCUL_COLOR_LIGHTRED); | |||
cucul_putstr(qq, 36, 8, "█████████████████████████████"); | |||
cucul_putstr(qq, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); | |||
cucul_putstr(qq, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"); | |||
cucul_putstr(qq, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); | |||
cucul_putstr(qq, 36, 12, " "); | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, 1, 14, "Double width characters"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 1, 15, "| ドラゴン ボーレ |"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 1, 16, "| ()()()() ()()() |"); | |||
cucul_set_color(qq, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 1, 17, "| ドラゴン"); | |||
cucul_putstr(qq, 10, 17, "ボーレ |"); | |||
cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, 1, 18, "If the three lines do not have the same length, there is a bug somewhere."); | |||
cucul_putstr(qq, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼"); | |||
cucul_putstr(qq, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■"); | |||
cucul_putstr(qq, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟"); | |||
c = cucul_create(0, 0); | |||
kk = caca_attach(c); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, 1, 1, "Basic Unicode support"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 1, 2, "This is ASCII: | abc DEF 123 !@# |"); | |||
cucul_putstr(c, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |"); | |||
cucul_putstr(c, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |"); | |||
cucul_putstr(c, 1, 5, "If the three lines do not have the same length, there is a bug somewhere."); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, 1, 7, "Gradient glyphs"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 31, 8, " 0%"); | |||
cucul_putstr(c, 31, 9, " 25%"); | |||
cucul_putstr(c, 31, 10, " 50%"); | |||
cucul_putstr(c, 31, 11, " 75%"); | |||
cucul_putstr(c, 31, 12, "100%"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_LIGHTGREEN); | |||
cucul_putstr(c, 1, 8, " "); | |||
cucul_putstr(c, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); | |||
cucul_putstr(c, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"); | |||
cucul_putstr(c, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); | |||
cucul_putstr(c, 1, 12, "█████████████████████████████"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGREEN, CUCUL_COLOR_LIGHTRED); | |||
cucul_putstr(c, 36, 8, "█████████████████████████████"); | |||
cucul_putstr(c, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓"); | |||
cucul_putstr(c, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"); | |||
cucul_putstr(c, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); | |||
cucul_putstr(c, 36, 12, " "); | |||
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(c, 1, 14, "Double width characters"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 1, 15, "| ドラゴン ボーレ |"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 1, 16, "| ()()()() ()()() |"); | |||
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 1, 17, "| ドラゴン"); | |||
cucul_putstr(c, 10, 17, "ボーレ |"); | |||
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK); | |||
cucul_putstr(c, 1, 18, "If the three lines do not have the same length, there is a bug somewhere."); | |||
cucul_putstr(c, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼"); | |||
cucul_putstr(c, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■"); | |||
cucul_putstr(c, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟"); | |||
caca_display(kk); | |||
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1); | |||
caca_detach(kk); | |||
cucul_free(qq); | |||
cucul_free(c); | |||
return 0; | |||
} | |||