Kaynağa Gözat

* Updated C++ bindings so that they build, at least.

tags/v0.99.beta14
Sam Hocevar sam 18 yıl önce
ebeveyn
işleme
243ca40d7d
3 değiştirilmiş dosya ile 69 ekleme ve 118 silme
  1. +43
    -63
      cxx/cucul++.cpp
  2. +24
    -47
      cxx/cucul++.h
  3. +2
    -8
      cxx/cxxtest.cpp

+ 43
- 63
cxx/cucul++.cpp Dosyayı Görüntüle

@@ -55,12 +55,6 @@ Cucul::Cucul(int width, int height)
if(!cv) throw -1;
}

Cucul::Cucul(Buffer *b, char const *format)
{
cv = cucul_import_canvas(b->getBuffer(), format);
if(!cv) throw -1;
}

Cucul::~Cucul()
{
if(cv)
@@ -99,20 +93,20 @@ int Cucul::setColorARGB(unsigned int f, unsigned int b)

void Cucul::putChar(int x, int y, unsigned long int ch)
{
cucul_putchar(cv, x, y, ch);
cucul_put_char(cv, x, y, ch);
}

unsigned long int Cucul::getChar(int x, int y)
{
return cucul_getchar(cv, x, y);
return cucul_get_char(cv, x, y);
}

void Cucul::putStr(int x, int y, char *str)
{
cucul_putstr(cv, x, y, str);
cucul_put_str(cv, x, y, str);
}

void Cucul::Printf(int x, int y, char const * format,...)
void Cucul::Printf(int x, int y, char const * format, ...)
{
char tmp[BUFSIZ];
char *buf = tmp;
@@ -161,12 +155,12 @@ void Cucul::Rotate()
cucul_rotate(cv);
}

void Cucul::drawLine(int x1, int y1, int x2, int y2, char const *ch)
void Cucul::drawLine(int x1, int y1, int x2, int y2, unsigned long int ch)
{
cucul_draw_line(cv, x1, y1, x2, y2, ch);
}

void Cucul::drawPolyline(int const x[], int const y[], int f, char const *ch)
void Cucul::drawPolyline(int const x[], int const y[], int f, unsigned long int ch)
{
cucul_draw_polyline(cv, x, y, f, ch);
}
@@ -181,12 +175,12 @@ void Cucul::drawThinPolyline(int const x[], int const y[], int f)
cucul_draw_thin_polyline(cv, x, y, f);
}

void Cucul::drawCircle(int x, int y, int d, char const *ch)
void Cucul::drawCircle(int x, int y, int d, unsigned long int ch)
{
cucul_draw_circle(cv, x, y, d, ch);
}

void Cucul::drawEllipse(int x, int y, int d1, int d2, char const *ch)
void Cucul::drawEllipse(int x, int y, int d1, int d2, unsigned long int ch)
{
cucul_draw_ellipse(cv, x, y, d1, d2, ch);
}
@@ -196,12 +190,12 @@ void Cucul::drawThinEllipse(int x, int y, int d1, int d2)
cucul_draw_thin_ellipse(cv, x, y, d1, d2);
}

void Cucul::fillEllipse(int x, int y, int d1, int d2, char const *ch)
void Cucul::fillEllipse(int x, int y, int d1, int d2, unsigned long int ch)
{
cucul_fill_ellipse(cv, x, y, d1, d2, ch);
}

void Cucul::drawBox(int x, int y, int w, int h, char const *ch)
void Cucul::drawBox(int x, int y, int w, int h, unsigned long int ch)
{
cucul_draw_box(cv, x, y, w, h, ch);
}
@@ -211,12 +205,17 @@ void Cucul::drawThinBox(int x, int y, int w, int h)
cucul_draw_thin_box(cv, x, y, w, h);
}

void Cucul::fillBox(int x, int y, int w, int h, char const *ch)
void Cucul::drawCP437Box(int x, int y, int w, int h)
{
cucul_draw_cp437_box(cv, x, y, w, h);
}

void Cucul::fillBox(int x, int y, int w, int h, unsigned long int ch)
{
cucul_fill_box(cv, x, y, w, h, ch);
}

void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, char const *ch)
void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned long int ch)
{
cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
}
@@ -226,7 +225,7 @@ void Cucul::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
}

void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, const char *ch)
void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned long int ch)
{
cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
}
@@ -269,6 +268,31 @@ int Cucul::freeFrame(unsigned int f)
return cucul_create_canvas_frame(cv, f);
}

char const *const * Cucul::getImportList(void)
{
return cucul_get_import_list();
}

long int Cucul::importMemory(void const *buf, unsigned long int len, char const *fmt)
{
return cucul_import_memory(cv, buf, len, fmt);
}

long int Cucul::importFile(char const *file, char const *fmt)
{
return cucul_import_file(cv, file, fmt);
}

char const *const * Cucul::getExportList(void)
{
return cucul_get_export_list();
}

void *Cucul::exportMemory(char const *fmt, unsigned long int *len)
{
return cucul_export_memory(cv, fmt, len);
}

Dither::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)
{
dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
@@ -384,47 +408,3 @@ Font::~Font()
cucul_free_font(font);
}

Buffer::Buffer()
{
buffer_ = NULL;
}

Buffer::~Buffer()
{
if(buffer_)
cucul_free_buffer(buffer_);
}

char const *const * Buffer::getExportList(void)
{
return cucul_get_export_list();
}

void *Buffer::getData(void)
{
return cucul_get_buffer_data(buffer_);
}

void Buffer::loadMemory(void *buf, unsigned long int size)
{
buffer_ = cucul_load_memory(buf, size);
if(buffer_ == NULL)
throw -1;
}

void Buffer::loadFile(char const *filename)
{
buffer_ = cucul_load_file(filename);
if(buffer_ == NULL)
throw -1;
}

unsigned long int Buffer::getSize()
{
return cucul_get_buffer_size(buffer_);
}

cucul_buffer *Buffer::getBuffer()
{
return buffer_;
}

+ 24
- 47
cxx/cucul++.h Dosyayı Görüntüle

@@ -25,10 +25,8 @@

#include <cucul.h>


class Cucul;


class Charset
{
unsigned long int utf8ToUtf32(char const *, unsigned int *);
@@ -37,10 +35,6 @@ class Charset
unsigned long int cp437ToUtf32(unsigned char);
};





/* Ugly, I know */
class Font
{
@@ -50,21 +44,23 @@ class Font
char const *const * getList(void);
unsigned int getWidth();
unsigned int getHeight();
void renderCanvas(Cucul *, unsigned char *, unsigned int, unsigned int, unsigned int);
void renderCanvas(Cucul *, unsigned char *, unsigned int,
unsigned int, unsigned int);
unsigned long int const *getBlocks();

private:
cucul_font *font;

};

class Dither
{
public:
Dither(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
Dither(unsigned int, unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int, unsigned int);
~Dither();

void setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[]);
void setPalette(unsigned int r[], unsigned int g[],
unsigned int b[], unsigned int a[]);
void setBrightness(float);
void setGamma(float);
void setContrast(float);
@@ -81,40 +77,16 @@ class Dither

private:
cucul_dither *dither;

};

class Buffer
{
friend class Cucul;
public:
Buffer();
~Buffer();
char const *const * getExportList(void);
void *getData(void);
void loadMemory(void *buf, unsigned long int size);
void loadFile(char const *filename);
unsigned long int getSize();

protected:
cucul_buffer *get_buffer();

private:
cucul_buffer *buffer_;
cucul_buffer *getBuffer();
};


class Cucul
{
friend class Caca;
friend class Dither;
friend class Font;
friend class Buffer;
public:
Cucul();
Cucul(int width, int height);
Cucul(Buffer *, char const *);
~Cucul();

void setSize(unsigned int w, unsigned int h);
@@ -124,7 +96,7 @@ class Cucul
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 Printf(int x, int y , char const * format, ...);
void putChar(int x, int y, unsigned long int ch);
unsigned long int getChar(int, int);
void putStr(int x, int y, char *str);
@@ -134,28 +106,34 @@ class Cucul
void Flip();
void Flop();
void Rotate();
void drawLine(int, int, int, int, char const *);
void drawPolyline(int const x[], int const y[], int, char const *);
void drawLine(int, int, int, int, unsigned long int);
void drawPolyline(int const x[], int const y[], int, unsigned long int);
void drawThinLine(int, int, int, int);
void drawThinPolyline(int const x[], int const y[], int);
void drawCircle(int, int, int, char const *);
void drawEllipse(int, int, int, int, char const *);
void drawCircle(int, int, int, unsigned long int);
void drawEllipse(int, int, int, int, unsigned long int);
void drawThinEllipse(int, int, int, int);
void fillEllipse(int, int, int, int, char const *);
void drawBox(int, int, int, int, char const *);
void fillEllipse(int, int, int, int, unsigned long int);
void drawBox(int, int, int, int, unsigned long int);
void drawThinBox(int, int, int, int);
void fillBox(int, int, int, int, char const *);
void drawTriangle(int, int, int, int, int, int, char const *);
void drawCP437Box(int, int, int, int);
void fillBox(int, int, int, int, unsigned long int);
void drawTriangle(int, int, int, int, int, int, unsigned long int);
void drawThinTriangle(int, int, int, int, int, int);
void fillTriangle(int, int, int, int, int, int, char const *);
void fillTriangle(int, int, int, int, int, int, unsigned long int);
int Rand(int, int);
int setBoundaries(cucul_canvas_t *, int, int,
unsigned int, unsigned int);
int setBoundaries(cucul_canvas_t *, int, int, unsigned int, unsigned int);
unsigned int getFrameCount();
int setFrame(unsigned int);
int createFrame(unsigned int);
int freeFrame(unsigned int);

char const * const * getImportList(void);
long int importMemory(void const *, unsigned long int, char const *);
long int importFile(char const *, char const *);
char const * const * getExportList(void);
void *exportMemory(char const *, unsigned long int *);

protected:
cucul_canvas_t *get_cucul_canvas_t();

@@ -163,5 +141,4 @@ class Cucul
cucul_canvas_t *cv;
};


#endif /* _CUCUL_PP_H */

+ 2
- 8
cxx/cxxtest.cpp Dosyayı Görüntüle

@@ -64,15 +64,9 @@ int main(int argc, char *argv[])

try {
// Import buffer into a canvas
Buffer *buf = new Buffer();
buf->loadMemory((void *)pigstring, strlen(pigstring));
pig = new Cucul(buf, "text");
delete buf;
// Change colour to magenta
pig = new Cucul();
pig->setColorANSI(CUCUL_LIGHTMAGENTA, CUCUL_TRANSPARENT);
for(int y = 0; y < pig->getHeight(); y++)
for(int x = 0; x < pig->getWidth(); x++)
pig->putChar(x, y, pig->getChar(x, y));
pig->importMemory(pigstring, strlen(pigstring), "text");
}
catch(int e) {
cerr << "Error while importing image (" << e << ")" << endl;


Yükleniyor…
İptal
Kaydet