Ignore:
Timestamp:
Nov 13, 2006, 10:42:15 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Updated C++ bindings so that they build, at least.
Location:
libcaca/trunk/cxx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cxx/cucul++.cpp

    r1277 r1388  
    5656}
    5757
    58 Cucul::Cucul(Buffer *b, char const *format)
    59 {
    60     cv = cucul_import_canvas(b->getBuffer(), format);
    61     if(!cv) throw -1;
    62 }
    63 
    6458Cucul::~Cucul()
    6559{
     
    10094void Cucul::putChar(int x, int y, unsigned long int ch)
    10195{
    102     cucul_putchar(cv, x, y, ch);
     96    cucul_put_char(cv, x, y, ch);
    10397}
    10498
    10599unsigned long int Cucul::getChar(int x, int y)
    106100{
    107     return cucul_getchar(cv, x, y);
     101    return cucul_get_char(cv, x, y);
    108102}
    109103
    110104void Cucul::putStr(int x, int y, char *str)
    111105{
    112     cucul_putstr(cv, x, y, str);
    113 }
    114 
    115 void Cucul::Printf(int x, int y, char const * format,...)
     106    cucul_put_str(cv, x, y, str);
     107}
     108
     109void Cucul::Printf(int x, int y, char const * format, ...)
    116110{
    117111    char tmp[BUFSIZ];
     
    162156}
    163157
    164 void Cucul::drawLine(int x1, int y1, int x2, int y2, char const *ch)
     158void Cucul::drawLine(int x1, int y1, int x2, int y2, unsigned long int ch)
    165159{
    166160    cucul_draw_line(cv, x1, y1, x2, y2, ch);
    167161}
    168162
    169 void Cucul::drawPolyline(int const x[], int const y[], int f, char const *ch)
     163void Cucul::drawPolyline(int const x[], int const y[], int f, unsigned long int ch)
    170164{
    171165    cucul_draw_polyline(cv, x, y, f, ch);
     
    182176}
    183177
    184 void Cucul::drawCircle(int x, int y, int d, char const *ch)
     178void Cucul::drawCircle(int x, int y, int d, unsigned long int ch)
    185179{
    186180    cucul_draw_circle(cv, x, y, d, ch);
    187181}
    188182
    189 void Cucul::drawEllipse(int x, int y, int d1, int d2, char const *ch)
     183void Cucul::drawEllipse(int x, int y, int d1, int d2, unsigned long int ch)
    190184{
    191185    cucul_draw_ellipse(cv, x, y, d1, d2, ch);
     
    197191}
    198192
    199 void Cucul::fillEllipse(int x, int y, int d1, int d2, char const *ch)
     193void Cucul::fillEllipse(int x, int y, int d1, int d2, unsigned long int ch)
    200194{
    201195    cucul_fill_ellipse(cv, x, y, d1, d2, ch);
    202196}
    203197
    204 void Cucul::drawBox(int x, int y, int w, int h, char const *ch)
     198void Cucul::drawBox(int x, int y, int w, int h, unsigned long int ch)
    205199{
    206200    cucul_draw_box(cv, x, y, w, h, ch);
     
    212206}
    213207
    214 void Cucul::fillBox(int x, int y, int w, int h, char const *ch)
     208void Cucul::drawCP437Box(int x, int y, int w, int h)
     209{
     210    cucul_draw_cp437_box(cv, x, y, w, h);
     211}
     212
     213void Cucul::fillBox(int x, int y, int w, int h, unsigned long int ch)
    215214{
    216215    cucul_fill_box(cv, x, y, w, h, ch);
    217216}
    218217
    219 void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, char const *ch)
     218void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned long int ch)
    220219{
    221220    cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
     
    227226}
    228227
    229 void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, const char *ch)
     228void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned long int ch)
    230229{
    231230    cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
     
    270269}
    271270
     271char const *const * Cucul::getImportList(void)
     272{
     273    return cucul_get_import_list();
     274}
     275
     276long int Cucul::importMemory(void const *buf, unsigned long int len, char const *fmt)
     277{
     278    return cucul_import_memory(cv, buf, len, fmt);
     279}
     280
     281long int Cucul::importFile(char const *file, char const *fmt)
     282{
     283    return cucul_import_file(cv, file, fmt);
     284}
     285
     286char const *const * Cucul::getExportList(void)
     287{
     288    return cucul_get_export_list();
     289}
     290
     291void *Cucul::exportMemory(char const *fmt, unsigned long int *len)
     292{
     293    return cucul_export_memory(cv, fmt, len);
     294}
     295
    272296Dither::Dither(unsigned int v1, unsigned int v2, unsigned int v3, unsigned int v4, unsigned int v5, unsigned int v6, unsigned int v7, unsigned int v8)
    273297{
     
    385409}
    386410
    387 Buffer::Buffer()
    388 {
    389     buffer_ = NULL;
    390 }
    391 
    392 Buffer::~Buffer()
    393 {
    394     if(buffer_)
    395         cucul_free_buffer(buffer_);
    396 }
    397 
    398 char const *const * Buffer::getExportList(void)
    399 {
    400     return cucul_get_export_list();
    401 }
    402 
    403 void *Buffer::getData(void)
    404 {
    405     return cucul_get_buffer_data(buffer_);
    406 }
    407 
    408 void Buffer::loadMemory(void *buf, unsigned long int size)
    409 {
    410     buffer_ = cucul_load_memory(buf, size);
    411     if(buffer_ == NULL)
    412         throw -1;
    413 }
    414 
    415 void Buffer::loadFile(char const *filename)
    416 {
    417     buffer_ = cucul_load_file(filename);
    418     if(buffer_ == NULL)
    419         throw -1;
    420 }
    421 
    422 unsigned long int Buffer::getSize()
    423 {
    424     return cucul_get_buffer_size(buffer_);
    425 }
    426 
    427 cucul_buffer *Buffer::getBuffer()
    428 {
    429     return buffer_;
    430 }
  • libcaca/trunk/cxx/cucul++.h

    r1278 r1388  
    2626#include <cucul.h>
    2727
    28 
    2928class Cucul;
    30 
    3129
    3230class Charset
     
    3735    unsigned long int cp437ToUtf32(unsigned char);
    3836};
    39 
    40 
    41 
    42 
    4337
    4438/* Ugly, I know */
     
    5145    unsigned int getWidth();
    5246    unsigned int getHeight();
    53     void renderCanvas(Cucul *, unsigned char *, unsigned int, unsigned int, unsigned int);
     47    void renderCanvas(Cucul *, unsigned char *, unsigned int,
     48                               unsigned int, unsigned int);
    5449    unsigned long int const *getBlocks();
    5550
    5651 private:
    5752    cucul_font *font;
    58 
    5953};
    6054
     
    6256{
    6357 public:
    64     Dither(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
     58    Dither(unsigned int, unsigned int, unsigned int, unsigned int,
     59           unsigned int, unsigned int, unsigned int, unsigned int);
    6560    ~Dither();
    6661
    67     void setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[]);
     62    void setPalette(unsigned int r[], unsigned int g[],
     63                    unsigned int b[], unsigned int a[]);
    6864    void setBrightness(float);
    6965    void setGamma(float);
     
    8278 private:
    8379    cucul_dither *dither;
    84 
    8580};
    86 
    87 class Buffer
    88 {
    89     friend class Cucul;
    90  public:
    91     Buffer();
    92     ~Buffer();
    93     char const *const * getExportList(void);
    94     void *getData(void);
    95     void loadMemory(void *buf, unsigned long int size);
    96     void loadFile(char const *filename);
    97     unsigned long int getSize();
    98 
    99  protected:
    100     cucul_buffer *get_buffer();
    101 
    102  private:
    103     cucul_buffer *buffer_;
    104     cucul_buffer *getBuffer();
    105 };
    106 
    10781
    10882class Cucul
     
    11185    friend class Dither;
    11286    friend class Font;
    113     friend class Buffer;
    11487 public:
    11588    Cucul();
    11689    Cucul(int width, int height);
    117     Cucul(Buffer *, char const *);
    11890    ~Cucul();
    11991
     
    12597    int setColorANSI(unsigned char f, unsigned char b);
    12698    int setColorARGB(unsigned int f, unsigned int b);
    127     void Printf(int x , int y , char const * format,...);
     99    void Printf(int x, int y , char const * format, ...);
    128100    void putChar(int x, int y, unsigned long int ch);
    129101    unsigned long int getChar(int, int);
     
    135107    void Flop();
    136108    void Rotate();
    137     void drawLine(int, int, int, int, char const *);
    138     void drawPolyline(int const x[], int const y[], int, char const *);
     109    void drawLine(int, int, int, int, unsigned long int);
     110    void drawPolyline(int const x[], int const y[], int, unsigned long int);
    139111    void drawThinLine(int, int, int, int);
    140112    void drawThinPolyline(int const x[], int const y[], int);
    141     void drawCircle(int, int, int, char const *);
    142     void drawEllipse(int, int, int, int, char const *);
     113    void drawCircle(int, int, int, unsigned long int);
     114    void drawEllipse(int, int, int, int, unsigned long int);
    143115    void drawThinEllipse(int, int, int, int);
    144     void fillEllipse(int, int, int, int, char const *);
    145     void drawBox(int, int, int, int, char const *);
     116    void fillEllipse(int, int, int, int, unsigned long int);
     117    void drawBox(int, int, int, int, unsigned long int);
    146118    void drawThinBox(int, int, int, int);
    147     void fillBox(int, int, int, int, char const *);
    148     void drawTriangle(int, int, int, int, int, int, char const *);
     119    void drawCP437Box(int, int, int, int);
     120    void fillBox(int, int, int, int, unsigned long int);
     121    void drawTriangle(int, int, int, int, int, int, unsigned long int);
    149122    void drawThinTriangle(int, int, int, int, int, int);
    150     void fillTriangle(int, int, int, int, int, int, char const *);
     123    void fillTriangle(int, int, int, int, int, int, unsigned long int);
    151124    int Rand(int, int);
    152     int setBoundaries(cucul_canvas_t *, int, int,
    153                                 unsigned int, unsigned int);
     125    int setBoundaries(cucul_canvas_t *, int, int, unsigned int, unsigned int);
    154126    unsigned int getFrameCount();
    155127    int setFrame(unsigned int);
    156128    int createFrame(unsigned int);
    157129    int freeFrame(unsigned int);
     130
     131    char const * const * getImportList(void);
     132    long int importMemory(void const *, unsigned long int, char const *);
     133    long int importFile(char const *, char const *);
     134    char const * const * getExportList(void);
     135    void *exportMemory(char const *, unsigned long int *);
    158136
    159137 protected:
     
    164142};
    165143
    166 
    167144#endif /* _CUCUL_PP_H */
  • libcaca/trunk/cxx/cxxtest.cpp

    r1310 r1388  
    6565    try {
    6666        // Import buffer into a canvas
    67         Buffer *buf = new Buffer();
    68         buf->loadMemory((void *)pigstring, strlen(pigstring));
    69         pig = new Cucul(buf, "text");
    70         delete buf;
    71         // Change colour to magenta
     67        pig = new Cucul();
    7268        pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
    73         for(int y = 0; y < pig->getHeight(); y++)
    74             for(int x = 0; x < pig->getWidth(); x++)
    75                 pig->putChar(x, y, pig->getChar(x, y));
     69        pig->importMemory(pigstring, strlen(pigstring), "text");
    7670    }
    7771    catch(int e) {
Note: See TracChangeset for help on using the changeset viewer.