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

Last change on this file since 827 was 827, checked in by Sam Hocevar, 14 years ago
  • Fixed ugly coding style of the C++ bindings. Vieux porc immonde.
  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1/*
2 *  libcucul++    C++ bindings for libcucul
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  $Id: cucul++.cpp 827 2006-04-21 19:06:38Z sam $
7 *
8 *  This library is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14/*
15 *  This file contains the main functions used by \e libcucul++ applications
16 *  to initialise a drawing context.
17 */
18
19#include "config.h"
20
21#include <stdio.h> // BUFSIZ
22#include <stdarg.h> // va_*
23
24#include "cucul++.h"
25
26Cucul::Cucul()
27{
28    cv = cucul_create_canvas(0, 0);
29    if(!cv)
30        throw -1;
31}
32
33Cucul::Cucul(int width, int height)
34{
35    cv = cucul_create_canvas(width, height);
36    if(!cv) throw -1;
37}
38
39Cucul::~Cucul()
40{
41    if(cv)
42        cucul_free_canvas(cv);
43}
44
45cucul_canvas_t *Cucul::get_cucul_canvas_t()
46{
47    return cv;
48}
49
50void Cucul::set_size(unsigned int width, unsigned int height)
51{
52    cucul_set_canvas_size(cv, width, height);
53}
54
55unsigned int Cucul::get_width(void)
56{
57    return cucul_get_canvas_width(cv);
58}
59
60unsigned int Cucul::get_height(void)
61{
62    return cucul_get_canvas_height(cv);
63}
64
65void Cucul::set_color(unsigned int f, unsigned int b)
66{
67    cucul_set_color(cv, f, b);
68}
69
70char const * Cucul::get_color_name(unsigned int color)
71{
72    return cucul_get_color_name(color);
73}
74
75void Cucul::putchar(int x, int y, char ch)
76{
77    cucul_putchar(cv, x, y, ch);
78}
79
80void Cucul::putstr(int x, int y, char *str)
81{
82    cucul_putstr(cv, x, y, str);
83}
84
85void Cucul::printf(int x, int y, char const * format,...)
86{
87    char tmp[BUFSIZ];
88    char *buf = tmp;
89    va_list args;
90
91    va_start(args, format);
92#if defined(HAVE_VSNPRINTF)
93    vsnprintf(buf, get_width() - x + 1, format, args);
94#else
95    vsprintf(buf, format, args);
96#endif
97    buf[get_width() - x] = '\0';
98    va_end(args);
99
100    putstr(x, y, buf);
101}
102
103void Cucul::clear(unsigned char bg )
104{
105    cucul_clear_canvas(cv, bg);
106}
107
108void Cucul::blit(int x, int y, Cucul* c1, Cucul* c2)
109{
110    cucul_blit(cv, x, y, c1->get_cucul_canvas_t(), c2->get_cucul_canvas_t());
111}
112
113void Cucul::invert()
114{
115    cucul_invert(cv);
116}
117
118void Cucul::flip()
119{
120    cucul_flip(cv);
121}
122
123void Cucul::flop()
124{
125    cucul_flop(cv);
126}
127
128void Cucul::rotate()
129{
130    cucul_rotate(cv);
131}
132
133void Cucul::draw_line(int x1, int y1, int x2, int y2, char const *ch)
134{
135    cucul_draw_line(cv, x1, y1, x2, y2, ch);
136}
137 
138void Cucul::draw_polyline(int const x[], int const y[], int f, char const *ch)
139{
140    cucul_draw_polyline(cv, x, y, f, ch);
141}
142 
143void Cucul::draw_thin_line(int x1, int y1, int x2, int y2)
144{
145    cucul_draw_thin_line(cv, x1, y1, x2, y2);
146}
147
148void Cucul::draw_thin_polyline(int const x[], int const y[], int f)
149{
150    cucul_draw_thin_polyline(cv, x, y, f);
151}
152 
153void Cucul::draw_circle(int x, int y, int d, char const *ch)
154{
155    cucul_draw_circle(cv, x, y, d, ch);
156}
157
158void Cucul::draw_ellipse(int x, int y, int d1, int d2, char const *ch)
159{
160    cucul_draw_ellipse(cv, x, y, d1, d2, ch);
161}
162
163void Cucul::draw_thin_ellipse(int x, int y, int d1, int d2)
164{
165    cucul_draw_thin_ellipse(cv, x, y, d1, d2);
166}
167
168void Cucul::fill_ellipse(int x, int y, int d1, int d2, char const *ch)
169{
170    cucul_fill_ellipse(cv, x, y, d1, d2, ch);
171}
172
173void Cucul::draw_box(int x, int y, int w, int h, char const *ch)
174{
175    cucul_draw_box(cv, x, y, w, h, ch);
176}
177 
178void Cucul::draw_thin_box(int x, int y, int w, int h)
179{
180    cucul_draw_thin_box(cv, x, y, w, h);
181}
182
183void Cucul::fill_box(int x, int y, int w, int h, char const *ch)
184{
185    cucul_fill_box(cv, x, y, w, h, ch);
186}
187
188void Cucul::draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char const *ch)
189{
190    cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
191}
192
193void Cucul::draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3)
194{
195    cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
196}
197
198void Cucul::fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, const char *ch)
199{
200    cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
201}
202
203int Cucul::rand(int min, int max)
204{
205    return cucul_rand(min, max);
206}
207
208Cucul::Sprite * Cucul::load_sprite(char const *f)
209{
210    Cucul::Sprite *s = new Cucul::Sprite();
211    s->sprite = cucul_load_sprite(f);
212    return s;
213}
214
215int Cucul::get_sprite_frames(Cucul::Sprite const *s)
216{
217    return cucul_get_sprite_frames(s->sprite);
218}
219
220int Cucul::get_sprite_width(Cucul::Sprite const *s, int v)
221{
222    return cucul_get_sprite_width(s->sprite, v);
223}
224
225int Cucul::get_sprite_height(Cucul::Sprite const *s, int v)
226{
227    return cucul_get_sprite_height(s->sprite, v);
228}
229
230int Cucul::get_sprite_dx(Cucul::Sprite const *s, int v)
231{
232    return cucul_get_sprite_dx(s->sprite, v);
233}
234
235int Cucul::get_sprite_dy(Cucul::Sprite const *s, int v)
236{
237    return cucul_get_sprite_dy(s->sprite, v);
238}
239
240void Cucul::draw_sprite(int x, int y, Cucul::Sprite const *s, int v)
241{
242    cucul_draw_sprite(cv, x, y, s->sprite, v);
243}
244
245void Cucul::free_sprite(Cucul::Sprite *s)
246{
247    cucul_free_sprite(s->sprite);
248}
249
250Cucul::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)
251{
252    Cucul::Dither *d = new Dither();
253    d->dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
254    return d;
255}
256
257void Cucul::set_dither_palette(Cucul::Dither *d, unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
258{
259    cucul_set_dither_palette(d->dither, r, g, b, a);
260}
261
262void Cucul::set_dither_brightness(Cucul::Dither *d, float f)
263{
264    cucul_set_dither_brightness(d->dither, f);
265}
266
267void Cucul::set_dither_gamma(Cucul::Dither *d, float f)
268{
269    cucul_set_dither_gamma(d->dither, f);
270}
271
272void Cucul::set_dither_contrast(Cucul::Dither *d, float f)
273{
274    cucul_set_dither_contrast(d->dither, f);
275}
276
277void Cucul::set_dither_invert(Cucul::Dither *d, int i)
278{
279    cucul_set_dither_invert(d->dither, i);
280}
281
282void Cucul::set_dither_antialias(Cucul::Dither *d, char const *cv)
283{
284    cucul_set_dither_antialias(d->dither, cv);
285}
286 
287char const *const * Cucul::get_dither_antialias_list(Cucul::Dither const *d)
288{
289    return cucul_get_dither_antialias_list(d->dither);
290}
291
292void Cucul::set_dither_color(Cucul::Dither *d, char const *cv)
293{
294    cucul_set_dither_color(d->dither, cv);
295}
296
297char const *const * Cucul::get_dither_color_list(Cucul::Dither const *d)
298{
299    return cucul_get_dither_color_list(d->dither);
300}
301 
302void Cucul::set_dither_charset(Cucul::Dither *d, char const *cv)
303{
304    cucul_set_dither_charset(d->dither, cv);
305}
306
307char const *const * Cucul::get_dither_charset_list(Cucul::Dither const *d)
308{
309    return cucul_get_dither_charset_list(d->dither);
310}
311 
312void Cucul::set_dither_mode(Cucul::Dither *d, char const *cv)
313{
314    cucul_set_dither_mode(d->dither, cv);
315}
316
317char const *const * Cucul::get_dither_mode_list(Cucul::Dither const *d)
318{
319    return cucul_get_dither_mode_list(d->dither);
320}
321
322void Cucul::dither_bitmap(int x, int y, int w, int h,  Cucul::Dither const *d, void *v)
323{
324    cucul_dither_bitmap(cv, x, y, w, h, d->dither, v);
325}
326
327void Cucul::free_dither(Cucul::Dither *d)
328{
329    cucul_free_dither(d->dither);
330}
331
332Cucul::Font * Cucul::load_font(void const *s, unsigned int v)
333{
334    Cucul::Font *f = new Cucul::Font();
335    f->font = cucul_load_font(s, v);
336    return f;
337}
338
339char const *const * Cucul::get_font_list(void)
340{
341    return cucul_get_font_list();
342}
343
344unsigned int Cucul::get_font_width(Cucul::Font *f)
345{
346    return cucul_get_font_width(f->font);
347}
348
349unsigned int Cucul::get_font_height(Cucul::Font *f)
350{
351    return cucul_get_font_height(f->font);
352}
353
354void Cucul::render_canvas(Cucul::Font *f, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
355{
356    cucul_render_canvas(cv, f->font, buf, x, y, w);
357}
358
359void Cucul::free_font(Cucul::Font *f)
360{
361    cucul_free_font(f->font);
362}
363
364Cucul::Buffer * Cucul::export_canvas(char const *buf)
365{
366    Cucul::Buffer *b = new Cucul::Buffer();
367    b->buffer = cucul_export_canvas(cv, buf);
368    return b;
369}
370
371char const *const * Cucul::get_export_list(void)
372{
373    return cucul_get_export_list();
374}
Note: See TracBrowser for help on using the repository browser.