浏览代码

* Got rid of cucul_ansi_to_str(), it's really useless.

* Partial update of the C++ bindings.
  * Updated documentation.
tags/v0.99.beta14
Sam Hocevar sam 18 年前
父节点
当前提交
67ff5d5b1d
共有 11 个文件被更改,包括 60 次插入101 次删除
  1. +28
    -0
      caca/caca0.c
  2. +2
    -1
      caca/caca0.h
  3. +0
    -45
      cucul/cucul.c
  4. +1
    -2
      cucul/cucul.h
  5. +11
    -11
      cxx/cucul++.cpp
  6. +4
    -4
      cxx/cucul++.h
  7. +3
    -3
      cxx/cxxtest.cpp
  8. +7
    -6
      doc/migrating.dox
  9. +1
    -1
      doc/tutorial.dox
  10. +3
    -4
      test/colors.c
  11. +0
    -24
      test/demo.c

+ 28
- 0
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];
}


+ 2
- 1
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)


+ 0
- 45
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


+ 1
- 2
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


+ 11
- 11
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,


+ 4
- 4
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);


+ 3
- 3
cxx/cxxtest.cpp 查看文件

@@ -3,7 +3,7 @@
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* 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 */


+ 7
- 6
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().


+ 1
- 1
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 */


+ 3
- 4
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");
}
}



+ 0
- 24
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);


正在加载...
取消
保存