diff --git a/cpp/cpptest.cpp b/cpp/cpptest.cpp index e60b51e..8c8ef16 100644 --- a/cpp/cpptest.cpp +++ b/cpp/cpptest.cpp @@ -46,11 +46,17 @@ int main(int argc, char *argv[]) return -1; } + + /* Draw pig */ qq->set_color(CUCUL_COLOR_LIGHTMAGENTA, CUCUL_COLOR_BLACK); - + for(int i = 0; pig[i]; i++) qq->putstr(0, i, (char*)pig[i]); - + + /* printf works */ + qq->set_color(CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLACK); + qq->printf(7,15, "Powered by libcaca %s", VERSION); + kk->display(); kk->get_event(CACA_EVENT_KEY_PRESS, &ev, -1); diff --git a/cpp/cucul++.cpp b/cpp/cucul++.cpp index 3232608..e919e9c 100644 --- a/cpp/cucul++.cpp +++ b/cpp/cucul++.cpp @@ -52,7 +52,24 @@ void Cucul::putstr (int x, int y, char *str) { cucul_putstr(qq, x, y, str); } -//void Cucul::printf ( int, int, char const *,...) +void Cucul::printf ( int x , int y , char const * format,...) +{ + char tmp[BUFSIZ]; + char *buf = tmp; + va_list args; + + va_start(args, format); +#if defined(HAVE_VSNPRINTF) + vsnprintf(buf, get_width() - x + 1, format, args); +#else + vsprintf(buf, format, args); +#endif + buf[get_width() - x] = '\0'; + va_end(args); + + putstr(x, y, buf); + +} void Cucul::clear () { diff --git a/cpp/cucul++.h b/cpp/cucul++.h index 921efff..b4f4af2 100644 --- a/cpp/cucul++.h +++ b/cpp/cucul++.h @@ -1,7 +1,8 @@ #ifndef _CUCUL_PP_H #define _CUCUL_PP_H - - +#include // BUFSIZ +#include // va_* +#include "config.h" #include "cucul.h" @@ -41,6 +42,7 @@ class Cucul { unsigned int get_height(void); void set_color(unsigned int f, unsigned int b); char const * get_color_name (unsigned int color); + void printf ( int x , int y , char const * format,...); void putchar (int x, int y, char c); void putstr (int x, int y, char *str); void clear ();