diff --git a/caca/caca.c b/caca/caca.c index 4bcdcbf..7d3234e 100644 --- a/caca/caca.c +++ b/caca/caca.c @@ -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); } diff --git a/caca/caca.h b/caca/caca.h index 98a69d0..692c765 100644 --- a/caca/caca.h +++ b/caca/caca.h @@ -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 diff --git a/caca/caca_internals.h b/caca/caca_internals.h index fdeb11b..fc84b66 100644 --- a/caca/caca_internals.h +++ b/caca/caca_internals.h @@ -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 diff --git a/caca/driver_conio.c b/caca/driver_conio.c index ff34e96..747a201 100644 --- a/caca/driver_conio.c +++ b/caca/driver_conio.c @@ -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'; diff --git a/caca/driver_gl.c b/caca/driver_gl.c index 9a11483..1e3da56 100644 --- a/caca/driver_gl.c +++ b/caca/driver_gl.c @@ -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; } diff --git a/caca/driver_ncurses.c b/caca/driver_ncurses.c index 154f729..6db6585 100644 --- a/caca/driver_ncurses.c +++ b/caca/driver_ncurses.c @@ -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; } diff --git a/caca/driver_raw.c b/caca/driver_raw.c index ab1a760..f684214 100644 --- a/caca/driver_raw.c +++ b/caca/driver_raw.c @@ -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++; diff --git a/caca/driver_slang.c b/caca/driver_slang.c index 11b44c8..154e6fc 100644 --- a/caca/driver_slang.c +++ b/caca/driver_slang.c @@ -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; } diff --git a/caca/driver_vga.c b/caca/driver_vga.c index 0593422..9a1c515 100644 --- a/caca/driver_vga.c +++ b/caca/driver_vga.c @@ -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) diff --git a/caca/driver_win32.c b/caca/driver_win32.c index da976a3..604a0f7 100644 --- a/caca/driver_win32.c +++ b/caca/driver_win32.c @@ -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; diff --git a/caca/driver_x11.c b/caca/driver_x11.c index 75ec344..395a4a6 100644 --- a/caca/driver_x11.c +++ b/caca/driver_x11.c @@ -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; } diff --git a/caca/event.c b/caca/event.c index 478bf8b..e615e3f 100644 --- a/caca/event.c +++ b/caca/event.c @@ -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; diff --git a/caca/graphics.c b/caca/graphics.c index a7709d6..df03845 100644 --- a/caca/graphics.c +++ b/caca/graphics.c @@ -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); } diff --git a/cpp/caca++.cpp b/cpp/caca++.cpp index 4029ad1..c7141fc 100644 --- a/cpp/caca++.cpp +++ b/cpp/caca++.cpp @@ -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 () diff --git a/cpp/cucul++.cpp b/cpp/cucul++.cpp index 0cd3d04..95224e6 100644 --- a/cpp/cucul++.cpp +++ b/cpp/cucul++.cpp @@ -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; } diff --git a/cpp/cucul++.h b/cpp/cucul++.h index a425c72..4825704 100644 --- a/cpp/cucul++.h +++ b/cpp/cucul++.h @@ -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; }; diff --git a/cucul/box.c b/cucul/box.c index 3970769..6fb566d 100644 --- a/cucul/box.c +++ b/cucul/box.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); } diff --git a/cucul/canvas.c b/cucul/canvas.c index ee76dd0..8511204 100644 --- a/cucul/canvas.c +++ b/cucul/canvas.c @@ -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; } diff --git a/cucul/colour.c b/cucul/colour.c index 7d542e4..4306d1a 100644 --- a/cucul/colour.c +++ b/cucul/colour.c @@ -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]; diff --git a/cucul/conic.c b/cucul/conic.c index 8360b7b..d645300 100644 --- a/cucul/conic.c +++ b/cucul/conic.c @@ -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); } diff --git a/cucul/cucul.c b/cucul/cucul.c index 50f66b9..b5e30a0 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -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); } } diff --git a/cucul/cucul.h b/cucul/cucul.h index d1b5ce9..7241959 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -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); /* @} */ diff --git a/cucul/cucul_internals.h b/cucul/cucul_internals.h index 3bfc9f0..287500a 100644 --- a/cucul/cucul_internals.h +++ b/cucul/cucul_internals.h @@ -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 *); diff --git a/cucul/dither.c b/cucul/dither.c index ff903c9..02587f8 100644 --- a/cucul/dither.c +++ b/cucul/dither.c @@ -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(); } diff --git a/cucul/export.c b/cucul/export.c index 83a1815..7e0fdc9 100644 --- a/cucul/export.c +++ b/cucul/export.c @@ -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 "" * up to 9 chars for "xxxxx;", far less for pure ASCII * 7 chars for "" */ - 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, "
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[] =
"\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, " |