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

Last change on this file since 861 was 838, checked in by Sam Hocevar, 14 years ago
  • Removed soon-to-be-thrown-away sprite stuff from the C++ bindings.
  • Property svn:keywords set to Id
File size: 7.0 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 838 2006-04-22 19:00:14Z 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(void)
104{
105    cucul_clear_canvas(cv);
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::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)
209{
210    Cucul::Dither *d = new Dither();
211    d->dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
212    return d;
213}
214
215void Cucul::set_dither_palette(Cucul::Dither *d, unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
216{
217    cucul_set_dither_palette(d->dither, r, g, b, a);
218}
219
220void Cucul::set_dither_brightness(Cucul::Dither *d, float f)
221{
222    cucul_set_dither_brightness(d->dither, f);
223}
224
225void Cucul::set_dither_gamma(Cucul::Dither *d, float f)
226{
227    cucul_set_dither_gamma(d->dither, f);
228}
229
230void Cucul::set_dither_contrast(Cucul::Dither *d, float f)
231{
232    cucul_set_dither_contrast(d->dither, f);
233}
234
235void Cucul::set_dither_invert(Cucul::Dither *d, int i)
236{
237    cucul_set_dither_invert(d->dither, i);
238}
239
240void Cucul::set_dither_antialias(Cucul::Dither *d, char const *cv)
241{
242    cucul_set_dither_antialias(d->dither, cv);
243}
244 
245char const *const * Cucul::get_dither_antialias_list(Cucul::Dither const *d)
246{
247    return cucul_get_dither_antialias_list(d->dither);
248}
249
250void Cucul::set_dither_color(Cucul::Dither *d, char const *cv)
251{
252    cucul_set_dither_color(d->dither, cv);
253}
254
255char const *const * Cucul::get_dither_color_list(Cucul::Dither const *d)
256{
257    return cucul_get_dither_color_list(d->dither);
258}
259 
260void Cucul::set_dither_charset(Cucul::Dither *d, char const *cv)
261{
262    cucul_set_dither_charset(d->dither, cv);
263}
264
265char const *const * Cucul::get_dither_charset_list(Cucul::Dither const *d)
266{
267    return cucul_get_dither_charset_list(d->dither);
268}
269 
270void Cucul::set_dither_mode(Cucul::Dither *d, char const *cv)
271{
272    cucul_set_dither_mode(d->dither, cv);
273}
274
275char const *const * Cucul::get_dither_mode_list(Cucul::Dither const *d)
276{
277    return cucul_get_dither_mode_list(d->dither);
278}
279
280void Cucul::dither_bitmap(int x, int y, int w, int h,  Cucul::Dither const *d, void *v)
281{
282    cucul_dither_bitmap(cv, x, y, w, h, d->dither, v);
283}
284
285void Cucul::free_dither(Cucul::Dither *d)
286{
287    cucul_free_dither(d->dither);
288}
289
290Cucul::Font * Cucul::load_font(void const *s, unsigned int v)
291{
292    Cucul::Font *f = new Cucul::Font();
293    f->font = cucul_load_font(s, v);
294    return f;
295}
296
297char const *const * Cucul::get_font_list(void)
298{
299    return cucul_get_font_list();
300}
301
302unsigned int Cucul::get_font_width(Cucul::Font *f)
303{
304    return cucul_get_font_width(f->font);
305}
306
307unsigned int Cucul::get_font_height(Cucul::Font *f)
308{
309    return cucul_get_font_height(f->font);
310}
311
312void Cucul::render_canvas(Cucul::Font *f, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
313{
314    cucul_render_canvas(cv, f->font, buf, x, y, w);
315}
316
317void Cucul::free_font(Cucul::Font *f)
318{
319    cucul_free_font(f->font);
320}
321
322Cucul::Buffer * Cucul::export_canvas(char const *buf)
323{
324    Cucul::Buffer *b = new Cucul::Buffer();
325    b->buffer = cucul_export_canvas(cv, buf);
326    return b;
327}
328
329char const *const * Cucul::get_export_list(void)
330{
331    return cucul_get_export_list();
332}
Note: See TracBrowser for help on using the repository browser.