source: libcaca/trunk/cxx/cucul++.cpp @ 2304

Last change on this file since 2304 was 2304, checked in by Sam Hocevar, 15 years ago
  • Get rid of the last long types in the API.
  • Use size_t and ssize_t where appropriate.
  • Property svn:keywords set to Id
File size: 8.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 2304 2008-04-19 19:25:47Z sam $
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 *  This file contains the main functions used by \e libcucul++ applications
17 *  to initialise a drawing context.
18 */
19
20#include "config.h"
21
22#include <stdio.h> // BUFSIZ
23#include <stdarg.h> // va_*
24
25#include "cucul++.h"
26
27
28uint32_t Charset::utf8ToUtf32(char const *s, size_t *read)
29{
30    return cucul_utf8_to_utf32(s, read);
31}
32size_t Charset::utf32ToUtf8(char *buf, uint32_t ch)
33{
34    return cucul_utf32_to_utf8(buf, ch);
35}
36uint8_t Charset::utf32ToCp437(uint32_t ch)
37{
38    return cucul_utf32_to_cp437(ch);
39}
40uint32_t Charset::cp437ToUtf32(uint8_t ch)
41{
42    return cucul_cp437_to_utf32(ch);
43}
44
45
46Cucul::Cucul()
47{
48    cv = cucul_create_canvas(0, 0);
49    if(!cv)
50        throw -1;
51}
52
53Cucul::Cucul(int width, int height)
54{
55    cv = cucul_create_canvas(width, height);
56    if(!cv) throw -1;
57}
58
59Cucul::~Cucul()
60{
61    if(cv)
62        cucul_free_canvas(cv);
63}
64
65cucul_canvas_t *Cucul::get_cucul_canvas_t()
66{
67    return cv;
68}
69
70void Cucul::setSize(unsigned int width, unsigned int height)
71{
72    cucul_set_canvas_size(cv, width, height);
73}
74
75unsigned int Cucul::getWidth(void)
76{
77    return cucul_get_canvas_width(cv);
78}
79
80unsigned int Cucul::getHeight(void)
81{
82    return cucul_get_canvas_height(cv);
83}
84
85int Cucul::setColorANSI(uint8_t f, uint8_t b)
86{
87    return cucul_set_color_ansi(cv, f, b);
88}
89
90int  Cucul::setColorARGB(unsigned int f, unsigned int b)
91{
92    return cucul_set_color_argb(cv, f, b);
93}
94
95void Cucul::putChar(int x, int y, uint32_t ch)
96{
97    cucul_put_char(cv, x, y, ch);
98}
99
100uint32_t Cucul::getChar(int x, int y)
101{
102    return cucul_get_char(cv, x, y);
103}
104
105void Cucul::putStr(int x, int y, char *str)
106{
107    cucul_put_str(cv, x, y, str);
108}
109
110void Cucul::Printf(int x, int y, char const * format, ...)
111{
112    char tmp[BUFSIZ];
113    char *buf = tmp;
114    va_list args;
115
116    va_start(args, format);
117#if defined(HAVE_VSNPRINTF)
118    vsnprintf(buf, getWidth() - x + 1, format, args);
119#else
120    vsprintf(buf, format, args);
121#endif
122    buf[getWidth() - x] = '\0';
123    va_end(args);
124
125    putStr(x, y, buf);
126}
127
128void Cucul::Clear(void)
129{
130    cucul_clear_canvas(cv);
131}
132
133void Cucul::Blit(int x, int y, Cucul* c1, Cucul* c2)
134{
135    cucul_blit(cv, x, y, c1->get_cucul_canvas_t(),
136                         c2 ? c2->get_cucul_canvas_t() : NULL);
137}
138
139void Cucul::Invert()
140{
141    cucul_invert(cv);
142}
143
144void Cucul::Flip()
145{
146    cucul_flip(cv);
147}
148
149void Cucul::Flop()
150{
151    cucul_flop(cv);
152}
153
154void Cucul::Rotate()
155{
156    cucul_rotate_180(cv);
157}
158
159void Cucul::drawLine(int x1, int y1, int x2, int y2, uint32_t ch)
160{
161    cucul_draw_line(cv, x1, y1, x2, y2, ch);
162}
163
164void Cucul::drawPolyline(int const x[], int const y[], int f, uint32_t ch)
165{
166    cucul_draw_polyline(cv, x, y, f, ch);
167}
168
169void Cucul::drawThinLine(int x1, int y1, int x2, int y2)
170{
171    cucul_draw_thin_line(cv, x1, y1, x2, y2);
172}
173
174void Cucul::drawThinPolyline(int const x[], int const y[], int f)
175{
176    cucul_draw_thin_polyline(cv, x, y, f);
177}
178
179void Cucul::drawCircle(int x, int y, int d, uint32_t ch)
180{
181    cucul_draw_circle(cv, x, y, d, ch);
182}
183
184void Cucul::drawEllipse(int x, int y, int d1, int d2, uint32_t ch)
185{
186    cucul_draw_ellipse(cv, x, y, d1, d2, ch);
187}
188
189void Cucul::drawThinEllipse(int x, int y, int d1, int d2)
190{
191    cucul_draw_thin_ellipse(cv, x, y, d1, d2);
192}
193
194void Cucul::fillEllipse(int x, int y, int d1, int d2, uint32_t ch)
195{
196    cucul_fill_ellipse(cv, x, y, d1, d2, ch);
197}
198
199void Cucul::drawBox(int x, int y, int w, int h, uint32_t ch)
200{
201    cucul_draw_box(cv, x, y, w, h, ch);
202}
203
204void Cucul::drawThinBox(int x, int y, int w, int h)
205{
206    cucul_draw_thin_box(cv, x, y, w, h);
207}
208
209void Cucul::drawCP437Box(int x, int y, int w, int h)
210{
211    cucul_draw_cp437_box(cv, x, y, w, h);
212}
213
214void Cucul::fillBox(int x, int y, int w, int h, uint32_t ch)
215{
216    cucul_fill_box(cv, x, y, w, h, ch);
217}
218
219void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch)
220{
221    cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
222}
223
224void Cucul::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
225{
226    cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
227}
228
229void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, uint32_t ch)
230{
231    cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
232}
233
234int Cucul::Rand(int min, int max)
235{
236    return cucul_rand(min, max);
237}
238
239const char * Cucul::getVersion()
240{
241    return cucul_get_version();
242}
243
244int Cucul::setAttr(uint32_t attr)
245{
246    return cucul_set_attr(cv, attr);
247}
248
249uint32_t Cucul::getAttr(int x, int y)
250{
251    return cucul_get_attr(cv, x, y);
252}
253
254int Cucul::setBoundaries(cucul_canvas_t *, int x, int y,
255                         unsigned int w, unsigned int h)
256{
257    return cucul_set_canvas_boundaries(cv, x, y, h, w);
258}
259
260unsigned int Cucul::getFrameCount()
261{
262    return cucul_get_frame_count(cv);
263}
264int Cucul::setFrame(unsigned int f)
265{
266    return cucul_set_frame(cv, f);
267}
268int Cucul::createFrame(unsigned int f)
269{
270    return cucul_create_frame(cv, f);
271}
272int Cucul::freeFrame(unsigned int f)
273{
274    return cucul_create_frame(cv, f);
275}
276
277char const *const * Cucul::getImportList(void)
278{
279    return cucul_get_import_list();
280}
281
282long int Cucul::importMemory(void const *buf, unsigned long int len, char const *fmt)
283{
284    return cucul_import_memory(cv, buf, len, fmt);
285}
286
287long int Cucul::importFile(char const *file, char const *fmt)
288{
289    return cucul_import_file(cv, file, fmt);
290}
291
292char const *const * Cucul::getExportList(void)
293{
294    return cucul_get_export_list();
295}
296
297void *Cucul::exportMemory(char const *fmt, unsigned long int *len)
298{
299    return cucul_export_memory(cv, fmt, len);
300}
301
302Dither::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)
303{
304    dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
305}
306Dither::~Dither()
307{
308    cucul_free_dither(dither);
309}
310
311void Dither::setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
312{
313    cucul_set_dither_palette(dither, r, g, b, a);
314}
315
316void Dither::setBrightness(float f)
317{
318    cucul_set_dither_brightness(dither, f);
319}
320
321void Dither::setGamma(float f)
322{
323    cucul_set_dither_gamma(dither, f);
324}
325
326void Dither::setContrast(float f)
327{
328    cucul_set_dither_contrast(dither, f);
329}
330
331void Dither::setAntialias(char const *cv)
332{
333    cucul_set_dither_antialias(dither, cv);
334}
335
336char const *const * Dither::getAntialiasList()
337{
338    return cucul_get_dither_antialias_list(dither);
339}
340
341void Dither::setColor(char const *cv)
342{
343    cucul_set_dither_color(dither, cv);
344}
345
346char const *const * Dither::getColorList()
347{
348    return cucul_get_dither_color_list(dither);
349}
350
351void Dither::setCharset(char const *cv)
352{
353    cucul_set_dither_charset(dither, cv);
354}
355
356char const *const * Dither::getCharsetList()
357{
358    return cucul_get_dither_charset_list(dither);
359}
360
361void Dither::setMode(char const *cv)
362{
363    cucul_set_dither_algorithm(dither, cv);
364}
365
366char const *const * Dither::getModeList(void)
367{
368    return cucul_get_dither_algorithm_list(dither);
369}
370
371void Dither::Bitmap(Cucul *cv, int x, int y, int w, int h, void *v)
372{
373    cucul_dither_bitmap(cv->get_cucul_canvas_t(), x, y, w, h, dither, v);
374}
375
376Font::Font(void const *s, unsigned int v)
377{
378    font = cucul_load_font(s, v);
379    if(!font) throw -1;
380}
381
382char const *const * Font::getList(void)
383{
384    return cucul_get_font_list();
385}
386
387unsigned int Font::getWidth()
388{
389    return cucul_get_font_width(font);
390}
391
392unsigned int Font::getHeight()
393{
394    return cucul_get_font_height(font);
395}
396
397void Font::renderCanvas(Cucul *cv, uint8_t *buf, unsigned int x, unsigned int y, unsigned int w)
398{
399    cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w);
400}
401
402uint32_t const *Font::getBlocks()
403{
404    return cucul_get_font_blocks(font);
405}
406
407Font::~Font()
408{
409    cucul_free_font(font);
410}
411
Note: See TracBrowser for help on using the repository browser.