diff --git a/caca/caca0.c b/caca/caca0.c index 8caaa09..6cd880a 100644 --- a/caca/caca0.c +++ b/caca/caca0.c @@ -267,3 +267,31 @@ void __caca0_free_bitmap(cucul_dither_t *d) nbitmaps--; } +char const *__caca0_get_color_name(unsigned char color) +{ + static char const *color_names[] = + { + "black", + "blue", + "green", + "cyan", + "red", + "magenta", + "brown", + "light gray", + "dark gray", + "light blue", + "light green", + "light cyan", + "light red", + "light magenta", + "yellow", + "white", + }; + + if(color > 15) + return "unknown"; + + return color_names[(unsigned int)color]; +} + diff --git a/caca/caca0.h b/caca/caca0.h index e2e585a..828d56a 100644 --- a/caca/caca0.h +++ b/caca/caca0.h @@ -39,6 +39,7 @@ extern cucul_dither_t *__caca0_create_bitmap(unsigned int, unsigned int, unsigned int, unsigned int, unsigned long int, unsigned long int, unsigned long int, unsigned long int); extern void __caca0_free_bitmap(cucul_dither_t *); +extern char const *__caca0_get_color_name(unsigned char); /* These variables are needed to emulate old non-thread safe behaviour */ extern cucul_canvas_t *__caca0_cv; @@ -133,7 +134,7 @@ enum caca_feature (__caca0_fg = (x), __caca0_bg = (y), cucul_set_color_ansi(__caca0_cv, x, y)) #define caca_get_fg_color() __caca0_fg #define caca_get_bg_color() __caca0_bg -#define caca_get_color_name cucul_ansi_to_str +#define caca_get_color_name __caca0_get_color_name #define caca_putchar(x, y, c) cucul_putchar(__caca0_cv, x, y, c) #define caca_putstr(x, y, s) cucul_putstr(__caca0_cv, x, y, s) #define caca_printf(x, y, f, z...) cucul_printf(__caca0_cv, x, y, f, ##z) diff --git a/cucul/cucul.c b/cucul/cucul.c index bb68d3f..eef8ee2 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -176,51 +176,6 @@ unsigned int cucul_get_canvas_height(cucul_canvas_t *cv) return cv->height; } -/** \brief Translate an ANSI colour index into the colour's name. - * - * Translate an ANSI colour index such as \e CUCUL_RED or \e CUCUL_WHITE - * into a human-readable string describing the corresponding colour. - * - * This function never fails. - * - * \param color The colour value. - * \return A static string containing the colour's name, or \c "unknown" if - * the colour is unknown. - */ -char const *cucul_ansi_to_str(unsigned char color) -{ - static char const *color_names[] = - { - "black", - "blue", - "green", - "cyan", - "red", - "magenta", - "brown", - "light gray", - "dark gray", - "light blue", - "light green", - "light cyan", - "light red", - "light magenta", - "yellow", - "white", - }; - - if(color > 15) - return "unknown"; - - return color_names[(unsigned int)color]; -} - -/* Legacy function for old programs */ -char const *cucul_get_color_name(unsigned int color) -{ - return cucul_ansi_to_str(color > 15 ? 15 : color); -} - /** \brief Uninitialise \e libcucul. * * Free all resources allocated by cucul_create_canvas(). After diff --git a/cucul/cucul.h b/cucul/cucul.h index c0ecf8c..fe87483 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -238,7 +238,7 @@ char const * const * cucul_get_import_list(void); /* @} */ #if !defined(_DOXYGEN_SKIP_ME) -/* Legacy stuff from beta versions */ +/* Legacy stuff from beta versions, will probably disappear in 1.0 */ # ifdef __GNUC__ # define CUCUL_DEPRECATED __attribute__ ((deprecated)) # else @@ -248,7 +248,6 @@ int cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char) CUCUL_DEPRECATED; int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int) CUCUL_DEPRECATED; -char const *cucul_get_color_name(unsigned int) CUCUL_DEPRECATED; # define CUCUL_COLOR_BLACK CUCUL_BLACK # define CUCUL_COLOR_BLUE CUCUL_BLUE # define CUCUL_COLOR_GREEN CUCUL_GREEN diff --git a/cxx/cucul++.cpp b/cxx/cucul++.cpp index d8b9170..cb02e9d 100644 --- a/cxx/cucul++.cpp +++ b/cxx/cucul++.cpp @@ -87,19 +87,14 @@ unsigned int Cucul::getHeight(void) return cucul_get_canvas_height(cv); } -void Cucul::setColor(unsigned int f, unsigned int b) +int Cucul::setColorANSI(unsigned char f, unsigned char b) { - cucul_set_color(cv, f, b); + return cucul_set_color_ansi(cv, f, b); } -int Cucul::setTruecolor(unsigned int f, unsigned int b) +int Cucul::setColorARGB(unsigned int f, unsigned int b) { - return cucul_set_truecolor(cv, f, b); -} - -char const * Cucul::getColorName(unsigned int color) -{ - return cucul_get_color_name(color); + return cucul_set_color_argb(cv, f, b); } void Cucul::putChar(int x, int y, char ch) @@ -235,9 +230,14 @@ int Cucul::Rand(int min, int max) return cucul_rand(min, max); } -unsigned long int Cucul::getColor(int x, int y) +int Cucul::setAttr(unsigned long int attr) +{ + return cucul_set_attr(cv, attr); +} + +unsigned long int Cucul::getAttr(int x, int y) { - return cucul_get_color(cv, x, y); + return cucul_get_attr(cv, x, y); } int Cucul::setBoundaries(cucul_canvas_t *, int x, int y, diff --git a/cxx/cucul++.h b/cxx/cucul++.h index 84dfab9..a1d9b63 100644 --- a/cxx/cucul++.h +++ b/cxx/cucul++.h @@ -120,10 +120,10 @@ class Cucul void setSize(unsigned int w, unsigned int h); unsigned int getWidth(void); unsigned int getHeight(void); - void setColor(unsigned int f, unsigned int b); - int setTruecolor(unsigned int f, unsigned int b); - unsigned long int getColor(int, int); - char const * getColorName(unsigned int color); + unsigned long int getAttr(int, int); + int setAttr(unsigned long int); + int setColorANSI(unsigned char f, unsigned char b); + int setColorARGB(unsigned int f, unsigned int b); void Printf(int x , int y , char const * format,...); void putChar(int x, int y, char ch); unsigned long int getChar(cucul_canvas_t *, int, int); diff --git a/cxx/cxxtest.cpp b/cxx/cxxtest.cpp index 7b9dfc5..c3c57b5 100644 --- a/cxx/cxxtest.cpp +++ b/cxx/cxxtest.cpp @@ -3,7 +3,7 @@ * Copyright (c) 2006 Jean-Yves Lamoureux * All Rights Reserved * - * $Id$ + * $Id: cpptest.cpp 784 2006-06-10 11:35:18Z jylam $ * * This program is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To @@ -72,13 +72,13 @@ int main(int argc, char *argv[]) while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) { /* Draw pig */ - qq->setColor(CUCUL_LIGHTMAGENTA, CUCUL_BLACK); + qq->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_BLACK); for(int i = 0; pig[i]; i++) qq->putStr(x, y+i, (char*)pig[i]); /* printf works */ - qq->setColor(CUCUL_LIGHTBLUE, CUCUL_BLACK); + qq->setColorANSI(CUCUL_LIGHTBLUE, CUCUL_BLACK); qq->Printf(30,15, "Powered by libcaca %s", VERSION); /* Blit */ diff --git a/doc/migrating.dox b/doc/migrating.dox index b02ac89..086a335 100644 --- a/doc/migrating.dox +++ b/doc/migrating.dox @@ -53,8 +53,8 @@ int main(void) /* Set window title */ caca_set_display_title(dp, "Window"); /* Choose drawing colours */ - cucul_set_color(cv, CUCUL_COLOR_BLACK, - CUCUL_COLOR_WHITE); + cucul_set_color_ansi(cv, CUCUL_BLACK, + CUCUL_WHITE); /* Draw a string at (0, 0) */ cucul_putstr(cv, 0, 0, "Hello world!"); /* Refresh display */ @@ -141,10 +141,11 @@ int main(void) \subsection bar3 Character printing - - \b caca_set_color(): use cucul_set_color() or cucul_set_truecolor(). - - \b caca_get_fg_color(): deprecated. - - \b caca_get_bg_color(): deprecated. - - \b caca_get_color_name(): use cucul_get_color_name(). + - \b caca_set_color(): use cucul_set_color_ansi() or cucul_set_color_argb(). + - \b caca_get_fg_color(): use cucul_get_attr(). + - \b caca_get_bg_color(): use cucul_get_attr(). + - \b caca_get_color_name(): this function is now deprecated due to major + uselessness. - \b caca_putchar(): use cucul_putchar(). - \b caca_putstr(): use cucul_putstr(). - \b caca_printf(): use cucul_printf(). diff --git a/doc/tutorial.dox b/doc/tutorial.dox index 632e6b9..d630fa9 100644 --- a/doc/tutorial.dox +++ b/doc/tutorial.dox @@ -17,7 +17,7 @@ int main(void) /* Set window title */ caca_set_display_title(dp, "Hello!"); /* Choose drawing colours */ - cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE); + cucul_set_color_ansi(cv, CUCUL_BLACK, CUCUL_WHITE); /* Draw a string at coordinates (0, 0) */ cucul_putstr(cv, 0, 0, "This is a message"); /* Refresh display */ diff --git a/test/colors.c b/test/colors.c index 732b596..aaab7e7 100644 --- a/test/colors.c +++ b/test/colors.c @@ -40,13 +40,12 @@ int main(int argc, char **argv) for(i = 0; i < 16; i++) { cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK); - cucul_printf(cv, 3, i + (i >= 8 ? 3 : 2), "'%cv': %i (%s)", - 'a' + i, i, cucul_ansi_to_str(i)); + cucul_printf(cv, 3, i + (i >= 8 ? 3 : 2), "ANSI %i", i); for(j = 0; j < 16; j++) { cucul_set_color_ansi(cv, i, j); - cucul_putstr(cv, (j >= 8 ? 40 : 39) + j * 2, i + (i >= 8 ? 3 : 2), - "Aa"); + cucul_putstr(cv, (j >= 8 ? 13 : 12) + j * 4, i + (i >= 8 ? 3 : 2), + "Aaホ"); } } diff --git a/test/demo.c b/test/demo.c index d322037..500fb9c 100644 --- a/test/demo.c +++ b/test/demo.c @@ -24,7 +24,6 @@ static void display_menu(void); static void demo_all(void); -static void demo_color(void); static void demo_dots(void); static void demo_lines(void); static void demo_boxes(void); @@ -113,9 +112,6 @@ int main(int argc, char **argv) display_menu(); break; #endif - case 'c': - demo = demo_color; - break; case 'f': case 'F': demo = demo_all; @@ -363,26 +359,6 @@ static void demo_dots(void) } } -static void demo_color(void) -{ - int i, j; - char buf[BUFSIZ]; - - cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK); - cucul_clear_canvas(cv); - for(i = 0; i < 16; i++) - { - sprintf(buf, "'%c': %i (%s)", 'a' + i, i, cucul_ansi_to_str(i)); - cucul_set_color_ansi(cv, CUCUL_LIGHTGRAY, CUCUL_BLACK); - cucul_putstr(cv, 4, i + (i >= 8 ? 4 : 3), buf); - for(j = 0; j < 16; j++) - { - cucul_set_color_ansi(cv, i, j); - cucul_putstr(cv, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# "); - } - } -} - static void demo_lines(void) { int w = cucul_get_canvas_width(cv);