Changeset 783 for libcaca/trunk/cpp


Ignore:
Timestamp:
Apr 17, 2006, 1:00:10 PM (14 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Fixed C++ printf(), added it in example
Location:
libcaca/trunk/cpp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cpp/cpptest.cpp

    r782 r783  
    4747    }
    4848
     49   
     50    /* Draw pig */
    4951    qq->set_color(CUCUL_COLOR_LIGHTMAGENTA, CUCUL_COLOR_BLACK);
    50 
     52   
    5153    for(int i = 0; pig[i]; i++)
    5254        qq->putstr(0, i, (char*)pig[i]);
    53 
     55   
     56    /* printf works */
     57    qq->set_color(CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLACK); 
     58    qq->printf(7,15, "Powered by libcaca %s", VERSION);
     59   
    5460
    5561    kk->display();
  • libcaca/trunk/cpp/cucul++.cpp

    r781 r783  
    5353    cucul_putstr(qq, x, y, str);
    5454}
    55 //void  Cucul::printf ( int, int, char const *,...)
     55void    Cucul::printf ( int x , int y , char const * format,...)
     56{
     57    char tmp[BUFSIZ];
     58    char *buf = tmp;
     59    va_list args;
     60
     61    va_start(args, format);
     62#if defined(HAVE_VSNPRINTF)
     63    vsnprintf(buf, get_width() - x + 1, format, args);
     64#else
     65    vsprintf(buf, format, args);
     66#endif
     67    buf[get_width() - x] = '\0';
     68    va_end(args);
     69
     70    putstr(x, y, buf);
     71
     72}
    5673
    5774void    Cucul::clear ()
  • libcaca/trunk/cpp/cucul++.h

    r781 r783  
    11#ifndef _CUCUL_PP_H
    22#define _CUCUL_PP_H
    3 
    4 
     3#include <stdio.h> // BUFSIZ
     4#include <stdarg.h> // va_*
     5#include "config.h"
    56#include "cucul.h"
    67
     
    4243    void set_color(unsigned int f, unsigned int b);
    4344    char const * get_color_name (unsigned int color);
     45    void        printf ( int x , int y , char const * format,...);
    4446    void putchar (int x, int y, char c);
    4547    void putstr (int x, int y, char *str);
Note: See TracChangeset for help on using the changeset viewer.