--This line, and those below, will be ignored-- M cxx/cucul++.cpp A cxx/cxxtest.cpp M cxx/cucul++.h M cxx/Makefile.amtags/v0.99.beta14
@@ -16,9 +16,9 @@ libcaca___la_LDFLAGS = -no-undefined -version-info @LT_VERSION@ | |||
libcaca___la_LIBADD = ../caca/libcaca.la | |||
if USE_CXX | |||
noinst_PROGRAMS = cpptest | |||
noinst_PROGRAMS = cxxtest | |||
endif | |||
cpptest_SOURCES = cpptest.cpp | |||
cpptest_LDADD = libcaca++.la libcucul++.la ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ | |||
cxxtest_SOURCES = cxxtest.cpp | |||
cxxtest_LDADD = libcaca++.la libcucul++.la ../caca/libcaca.la ../cucul/libcucul.la @CACA_LIBS@ | |||
@@ -23,6 +23,25 @@ | |||
#include "cucul++.h" | |||
unsigned long int Charset::utf8ToUtf32(char const *s, unsigned int *read) | |||
{ | |||
return cucul_utf8_to_utf32(s, read); | |||
} | |||
unsigned int Charset::utf32ToUtf8(char *buf, unsigned long int ch) | |||
{ | |||
return cucul_utf32_to_utf8(buf, ch); | |||
} | |||
unsigned char Charset::utf32ToCp437(unsigned long int ch) | |||
{ | |||
return cucul_utf32_to_cp437(ch); | |||
} | |||
unsigned long int Charset::cp437ToUtf32(unsigned char ch) | |||
{ | |||
return cucul_cp437_to_utf32(ch); | |||
} | |||
Cucul::Cucul() | |||
{ | |||
cv = cucul_create_canvas(0, 0); | |||
@@ -38,7 +57,7 @@ Cucul::Cucul(int width, int height) | |||
Cucul::Cucul(Buffer *b, char const *format) | |||
{ | |||
cv = cucul_import_canvas(b->get_buffer(), format); | |||
cv = cucul_import_canvas(b->getBuffer(), format); | |||
if(!cv) throw -1; | |||
} | |||
@@ -73,6 +92,11 @@ void Cucul::setColor(unsigned int f, unsigned int b) | |||
cucul_set_color(cv, f, b); | |||
} | |||
int Cucul::setTruecolor(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); | |||
@@ -211,6 +235,34 @@ int Cucul::Rand(int min, int max) | |||
return cucul_rand(min, max); | |||
} | |||
unsigned long int Cucul::getColor(int x, int y) | |||
{ | |||
return cucul_get_color(cv, x, y); | |||
} | |||
int Cucul::setBoundaries(cucul_canvas_t *, int x, int y, | |||
unsigned int w, unsigned int h) | |||
{ | |||
return cucul_set_canvas_boundaries(cv, x, y, h, w); | |||
} | |||
unsigned int Cucul::getFrameCount() | |||
{ | |||
return cucul_get_canvas_frame_count(cv); | |||
} | |||
int Cucul::setFrame(unsigned int f) | |||
{ | |||
return cucul_set_canvas_frame(cv, f); | |||
} | |||
int Cucul::createFrame(unsigned int f) | |||
{ | |||
return cucul_create_canvas_frame(cv, f); | |||
} | |||
int Cucul::freeFrame(unsigned int f) | |||
{ | |||
return cucul_create_canvas_frame(cv, f); | |||
} | |||
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); | |||
@@ -316,15 +368,25 @@ void Font::renderCanvas(Cucul *cv, unsigned char *buf, unsigned int x, unsigned | |||
cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w); | |||
} | |||
unsigned long int const *Font::getBlocks() | |||
{ | |||
return cucul_get_font_blocks(font); | |||
} | |||
Font::~Font() | |||
{ | |||
cucul_free_font(font); | |||
} | |||
Buffer::Buffer(Cucul *cv, char const *buf) | |||
Buffer::Buffer() | |||
{ | |||
buffer_ = NULL; | |||
} | |||
Buffer::~Buffer() | |||
{ | |||
buffer = cucul_export_canvas(cv->get_cucul_canvas_t(), buf); | |||
if(!buffer) throw -1; | |||
if(buffer_) | |||
cucul_free_buffer(buffer_); | |||
} | |||
char const *const * Buffer::getExportList(void) | |||
@@ -332,7 +394,31 @@ char const *const * Buffer::getExportList(void) | |||
return cucul_get_export_list(); | |||
} | |||
cucul_buffer *Buffer::get_buffer(void) | |||
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; | |||
return buffer_; | |||
} |
@@ -28,6 +28,19 @@ | |||
class Cucul; | |||
class Charset | |||
{ | |||
unsigned long int utf8ToUtf32(char const *, unsigned int *); | |||
unsigned int utf32ToUtf8(char *, unsigned long int); | |||
unsigned char utf32ToCp437(unsigned long int); | |||
unsigned long int cp437ToUtf32(unsigned char); | |||
}; | |||
/* Ugly, I know */ | |||
class Font | |||
{ | |||
@@ -38,10 +51,11 @@ class Font | |||
unsigned int getWidth(); | |||
unsigned int getHeight(); | |||
void renderCanvas(Cucul *, unsigned char *, unsigned int, unsigned int, unsigned int); | |||
unsigned long int const *getBlocks(); | |||
private: | |||
cucul_font *font; | |||
}; | |||
class Dither | |||
@@ -74,15 +88,20 @@ class Buffer | |||
{ | |||
friend class Cucul; | |||
public: | |||
Buffer(Cucul *cv, char const *); | |||
Buffer(); | |||
~Buffer(); | |||
char const *const * getExportList(void); | |||
void *Buffer::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 *buffer_; | |||
cucul_buffer *getBuffer(); | |||
}; | |||
@@ -102,9 +121,12 @@ class Cucul | |||
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); | |||
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); | |||
void putStr(int x, int y, char *str); | |||
void Clear(void); | |||
void Blit(int, int, Cucul* c1, Cucul* c2); | |||
@@ -127,6 +149,12 @@ class Cucul | |||
void drawThinTriangle(int, int, int, int, int, int); | |||
void fillTriangle(int, int, int, int, int, int, char const *); | |||
int Rand(int, 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); | |||
protected: | |||
cucul_canvas_t *get_cucul_canvas_t(); | |||
@@ -0,0 +1,103 @@ | |||
/* | |||
* cxxtest libcaca++ rendering test | |||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> | |||
* All Rights Reserved | |||
* | |||
* $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 | |||
* Public License, Version 2, as published by Sam Hocevar. See | |||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||
*/ | |||
#include "config.h" | |||
#include <iostream> | |||
#include <cucul++.h> | |||
#include <caca++.h> | |||
using namespace std; | |||
static char const *pig[]= { | |||
" ", | |||
" _ ", | |||
" _._ _..._ .-', _.._(`)) ", | |||
" '-. ` ' /-._.-' ',/ ", | |||
" ) \\ '. ", | |||
" / _ _ | \\ ", | |||
" | a a / | ", | |||
" \\ .-. ; " , | |||
" '-('' ).-' ,' ; ", | |||
" '-; | .' ", | |||
" \\ \\ / ", | |||
" | 7 .__ _.-\\ \\ ", | |||
" | | | ``/ /` / ", | |||
" jgs /,_| | /,_/ / ", | |||
" /,_/ '`-' ", | |||
" ", | |||
NULL | |||
}; | |||
int main(int argc, char *argv[]) | |||
{ | |||
Cucul *qq; | |||
Caca *kk; | |||
Event ev; | |||
int x = 0, y = 0, ix = 1, iy = 1; | |||
try { | |||
qq = new Cucul(); | |||
} | |||
catch (int e) { | |||
cerr << "Error while initializing cucul (" << e << ")" << endl; | |||
return -1; | |||
} | |||
try { | |||
kk = new Caca(qq); | |||
} | |||
catch(int e) { | |||
cerr << "Error while attaching cucul to caca (" << e << ")" << endl; | |||
return -1; | |||
} | |||
kk->setDisplayTime(20000); | |||
while(!kk->getEvent(ev.CACA_EVENT_KEY_PRESS, &ev, 0)) { | |||
/* Draw pig */ | |||
qq->setColor(CUCUL_COLOR_LIGHTMAGENTA, CUCUL_COLOR_BLACK); | |||
for(int i = 0; pig[i]; i++) | |||
qq->putStr(x, y+i, (char*)pig[i]); | |||
/* printf works */ | |||
qq->setColor(CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLACK); | |||
qq->Printf(30,15, "Powered by libcaca %s", VERSION); | |||
/* Blit */ | |||
kk->Display(); | |||
x+=ix; | |||
y+=iy; | |||
if(x>=(qq->getWidth()-35) || x<0 ) | |||
ix=-ix; | |||
if(y>=(qq->getHeight()-15) || y<0 ) | |||
iy=-iy; | |||
} | |||
delete kk; | |||
delete qq; | |||
return 0; | |||
} |