source: libcaca/trunk/cpp/cucul++.cpp @ 783

Last change on this file since 783 was 783, checked in by Jean-Yves Lamoureux, 14 years ago
  • Fixed C++ printf(), added it in example
  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1#include "cucul++.h"
2
3Cucul::Cucul()
4{
5    qq = cucul_create(0,0);
6    if(!qq) throw -1;
7}
8Cucul::Cucul(int width, int height)
9{
10    qq = cucul_create(width, height);
11    if(!qq) throw -1;
12}
13Cucul::~Cucul()
14{
15    if(qq) {
16        cucul_free(qq);
17    }
18}
19
20cucul_t *Cucul::get_cucul_t()
21{
22    return qq;
23}
24
25
26
27void Cucul::set_size(unsigned int width, unsigned int height)
28{
29    cucul_set_size (qq, width, height);
30}
31unsigned int Cucul::get_width(void)
32{
33    return cucul_get_width (qq);
34}
35unsigned int Cucul::get_height(void)
36{
37    return cucul_get_height (qq);
38}
39void Cucul::set_color(unsigned int f, unsigned int b)
40{
41    cucul_set_color (qq, f, b);
42}
43char const * Cucul::get_color_name (unsigned int color)
44{
45    return cucul_get_color_name (color);
46}
47void Cucul::putchar (int x, int y, char c)
48{
49    cucul_putchar (qq, x, y, c);
50}
51void Cucul::putstr (int x, int y, char *str)
52{
53    cucul_putstr(qq, x, y, str);
54}
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}
73
74void    Cucul::clear ()
75{
76    cucul_clear(qq);
77}
78
79void    Cucul::blit ( int x, int y, Cucul* c1, Cucul* c2)
80{
81    cucul_blit(qq, x, y, c1->get_cucul_t(), c2->get_cucul_t());
82}
83
84void    Cucul::invert ()
85{
86    cucul_invert(qq);
87}
88
89void    Cucul::flip ()
90{
91    cucul_flip(qq);
92}
93
94void    Cucul::flop ()
95{
96    cucul_flop(qq);
97}
98
99void    Cucul::rotate ()
100{
101    cucul_rotate(qq);
102}
103
104void    Cucul::draw_line (int x1 , int y1, int x2, int y2, char const *c)
105{
106    cucul_draw_line(qq, x1,y1,x2,y2, c);
107}
108 
109void    Cucul::draw_polyline (int const x[], int const y[], int f, char const *c)
110{
111    cucul_draw_polyline(qq, x, y, f, c);
112}
113 
114void    Cucul::draw_thin_line (int x1 , int y1, int x2, int y2)
115{
116    cucul_draw_thin_line(qq, x1, y1, x2, y2);
117}
118
119void    Cucul::draw_thin_polyline ( int const x[], int const y[], int f)
120{
121    cucul_draw_thin_polyline(qq, x, y, f);
122}
123 
124void    Cucul::draw_circle ( int x, int y, int d, char const *c)
125{
126    cucul_draw_circle(qq, x, y, d, c);
127}
128
129void    Cucul::draw_ellipse ( int x, int y, int d1, int d2, char const *c)
130{
131    cucul_draw_ellipse(qq, x, y, d1, d2, c);
132}
133
134void    Cucul::draw_thin_ellipse ( int x, int y, int d1, int d2)
135{
136    cucul_draw_thin_ellipse(qq, x, y, d1, d2);
137}
138
139void    Cucul::fill_ellipse ( int x, int y, int d1, int d2, char const *c)
140{
141    cucul_fill_ellipse(qq, x, y, d1, d2, c);
142}
143
144void    Cucul::draw_box ( int x, int y, int w, int h, char const *c)
145{
146    cucul_draw_box(qq, x, y, w, h, c);
147}
148 
149void    Cucul::draw_thin_box ( int x, int y, int w, int h)
150{
151    cucul_draw_thin_box(qq, x, y, w, h);
152}
153
154void    Cucul::fill_box ( int x, int y, int w, int h, char const *c)
155{
156    cucul_fill_box(qq, x, y, w, h, c);
157}
158
159void    Cucul::draw_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, char const *c)
160{
161    cucul_draw_triangle(qq, x1, y1, x2, y2, x3, y3, c);
162}
163
164void    Cucul::draw_thin_triangle ( int x1, int y1, int x2, int y2, int x3, int y3)
165{
166    cucul_draw_thin_triangle(qq, x1, y1, x2, y2, x3, y3);
167}
168
169void    Cucul::fill_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, const char *c)
170{
171    cucul_fill_triangle(qq, x1, y1, x2, y2, x3, y3, c);
172}
173
174int     Cucul::rand (int min, int max)
175{
176    return cucul_rand(min, max);
177}
178
179unsigned int    Cucul::sqrt (unsigned int v)
180{
181    return cucul_sqrt(v);
182}
183
184Cucul::Sprite * Cucul::load_sprite (char const *f)
185{
186    Cucul::Sprite *s = new Cucul::Sprite();
187    s->sprite = cucul_load_sprite(f);
188    return s;
189}
190
191int     Cucul::get_sprite_frames (Cucul::Sprite const *s)
192{
193    return cucul_get_sprite_frames(s->sprite);
194}
195
196int     Cucul::get_sprite_width (Cucul::Sprite const *s, int v)
197{
198    return cucul_get_sprite_width(s->sprite, v);
199}
200
201int     Cucul::get_sprite_height (Cucul::Sprite const *s, int v)
202{
203    return cucul_get_sprite_height(s->sprite, v);
204}
205
206int     Cucul::get_sprite_dx (Cucul::Sprite const *s, int v)
207{
208    return cucul_get_sprite_dx(s->sprite, v);
209}
210
211int     Cucul::get_sprite_dy (Cucul::Sprite const *s, int v)
212{
213    return cucul_get_sprite_dy(s->sprite, v);
214}
215
216void    Cucul::draw_sprite ( int x, int y, Cucul::Sprite const *s, int v)
217{
218    cucul_draw_sprite(qq, x, y, s->sprite, v);
219}
220
221void    Cucul::free_sprite (Cucul::Sprite *s)
222{
223    cucul_free_sprite(s->sprite);
224}
225
226Cucul::Dither *         Cucul::create_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)
227{
228    Cucul::Dither *d = new Dither();
229    d->dither = cucul_create_dither(v1,v2,v3,v4,v5,v6,v7,v8);
230    return d;
231}
232
233void    Cucul::set_dither_palette (Cucul::Dither *d, unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
234{
235    cucul_set_dither_palette(d->dither, r, g, b, a);
236}
237
238void    Cucul::set_dither_brightness (Cucul::Dither *d, float f)
239{
240    cucul_set_dither_brightness(d->dither, f);
241}
242
243void    Cucul::set_dither_gamma (Cucul::Dither *d, float f)
244{
245    cucul_set_dither_gamma(d->dither, f);
246}
247
248void    Cucul::set_dither_contrast ( Cucul::Dither *d, float f)
249{
250    cucul_set_dither_contrast(d->dither, f);
251}
252
253void    Cucul::set_dither_invert ( Cucul::Dither *d, int i)
254{
255    cucul_set_dither_invert(d->dither, i);
256}
257
258void    Cucul::set_dither_antialias ( Cucul::Dither *d, char const *c)
259{
260    cucul_set_dither_antialias(d->dither, c);
261}
262 
263char const *const *     Cucul::get_dither_antialias_list ( Cucul::Dither const *d)
264{
265    return cucul_get_dither_antialias_list(d->dither);
266}
267
268void    Cucul::set_dither_color ( Cucul::Dither *d, char const *c)
269{
270    cucul_set_dither_color(d->dither, c);
271}
272
273char const *const *     Cucul::get_dither_color_list ( Cucul::Dither const *d)
274{
275    return cucul_get_dither_color_list(d->dither);
276}
277 
278void    Cucul::set_dither_charset ( Cucul::Dither *d, char const *c)
279{
280    cucul_set_dither_charset(d->dither, c);
281}
282
283char const *const *     Cucul::get_dither_charset_list ( Cucul::Dither const *d)
284{
285    return cucul_get_dither_charset_list(d->dither);
286}
287 
288void    Cucul::set_dither_mode ( Cucul::Dither *d, char const *c)
289{
290    cucul_set_dither_mode(d->dither, c);
291}
292
293char const *const *     Cucul::get_dither_mode_list ( Cucul::Dither const *d)
294{
295    return cucul_get_dither_mode_list(d->dither);
296}
297
298void    Cucul::dither_bitmap ( int x, int y, int w, int h,  Cucul::Dither const *d, void *v)
299{
300    cucul_dither_bitmap(qq, x, y, w, h, d->dither, v);
301}
302
303void    Cucul::free_dither ( Cucul::Dither *d)
304{
305    cucul_free_dither(d->dither);
306}
307
308Cucul::Font *   Cucul::load_font (void const *s, unsigned int v)
309{
310    Cucul::Font *f = new Cucul::Font();
311    f->font = cucul_load_font(s, v);
312    return f;
313}
314
315char const *const *     Cucul::get_font_list (void)
316{
317    return cucul_get_font_list();
318}
319
320unsigned int    Cucul::get_font_width ( Cucul::Font *f)
321{
322    return cucul_get_font_width(f->font);
323}
324
325unsigned int    Cucul::get_font_height ( Cucul::Font *f)
326{
327    return cucul_get_font_height(f->font);
328}
329
330void    Cucul::render_canvas (Cucul::Font *f, unsigned char *c, unsigned int x, unsigned int y, unsigned int w)
331{
332    cucul_render_canvas(qq, f->font, c, x,y,w);
333}
334
335void    Cucul::free_font ( Cucul::Font *f)
336{
337    cucul_free_font(f->font);
338}
339
340Cucul::Buffer *         Cucul::create_export (char const *c)
341{
342    Cucul::Buffer *b = new Cucul::Buffer();
343    b->buffer = cucul_create_export(qq, c);
344    return b;
345}
346
347char const *const *     Cucul::get_export_list (void)
348{
349    return cucul_get_export_list();
350}
Note: See TracBrowser for help on using the repository browser.