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

Last change on this file since 1156 was 1156, checked in by Jean-Yves Lamoureux, 15 years ago
  • Updated C++ bindings to support every single cucul/caca functionnality. Renamed cpptest to cxxtext for consistency.


--This line, and those below, will be ignored--

M cxx/cucul++.cpp
A cxx/cxxtest.cpp
M cxx/cucul++.h
M cxx/Makefile.am

  • Property svn:keywords set to Id
File size: 8.1 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 1156 2006-09-30 18:56:23Z jylam $
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
26
27unsigned long int Charset::utf8ToUtf32(char const *s, unsigned int *read)
28{
29    return cucul_utf8_to_utf32(s, read);
30}
31unsigned int Charset::utf32ToUtf8(char *buf, unsigned long int ch)
32{
33    return cucul_utf32_to_utf8(buf, ch);
34}
35unsigned char Charset::utf32ToCp437(unsigned long int ch)
36{
37    return cucul_utf32_to_cp437(ch);
38}
39unsigned long int Charset::cp437ToUtf32(unsigned char ch)
40{
41    return cucul_cp437_to_utf32(ch);
42}
43
44
45Cucul::Cucul()
46{
47    cv = cucul_create_canvas(0, 0);
48    if(!cv)
49        throw -1;
50}
51
52Cucul::Cucul(int width, int height)
53{
54    cv = cucul_create_canvas(width, height);
55    if(!cv) throw -1;
56}
57
58Cucul::Cucul(Buffer *b, char const *format)
59{
60    cv = cucul_import_canvas(b->getBuffer(), format);
61    if(!cv) throw -1;
62}
63
64Cucul::~Cucul()
65{
66    if(cv)
67        cucul_free_canvas(cv);
68}
69
70cucul_canvas_t *Cucul::get_cucul_canvas_t()
71{
72    return cv;
73}
74
75void Cucul::setSize(unsigned int width, unsigned int height)
76{
77    cucul_set_canvas_size(cv, width, height);
78}
79
80unsigned int Cucul::getWidth(void)
81{
82    return cucul_get_canvas_width(cv);
83}
84
85unsigned int Cucul::getHeight(void)
86{
87    return cucul_get_canvas_height(cv);
88}
89
90void Cucul::setColor(unsigned int f, unsigned int b)
91{
92    cucul_set_color(cv, f, b);
93}
94
95int  Cucul::setTruecolor(unsigned int f, unsigned int b)
96{
97    return cucul_set_truecolor(cv, f, b);
98}
99
100char const * Cucul::getColorName(unsigned int color)
101{
102    return cucul_get_color_name(color);
103}
104
105void Cucul::putChar(int x, int y, char ch)
106{
107    cucul_putchar(cv, x, y, ch);
108}
109
110void Cucul::putStr(int x, int y, char *str)
111{
112    cucul_putstr(cv, x, y, str);
113}
114
115void Cucul::Printf(int x, int y, char const * format,...)
116{
117    char tmp[BUFSIZ];
118    char *buf = tmp;
119    va_list args;
120
121    va_start(args, format);
122#if defined(HAVE_VSNPRINTF)
123    vsnprintf(buf, getWidth() - x + 1, format, args);
124#else
125    vsprintf(buf, format, args);
126#endif
127    buf[getWidth() - x] = '\0';
128    va_end(args);
129
130    putStr(x, y, buf);
131}
132
133void Cucul::Clear(void)
134{
135    cucul_clear_canvas(cv);
136}
137
138void Cucul::Blit(int x, int y, Cucul* c1, Cucul* c2)
139{
140    cucul_blit(cv, x, y, c1->get_cucul_canvas_t(), c2->get_cucul_canvas_t());
141}
142
143void Cucul::Invert()
144{
145    cucul_invert(cv);
146}
147
148void Cucul::Flip()
149{
150    cucul_flip(cv);
151}
152
153void Cucul::Flop()
154{
155    cucul_flop(cv);
156}
157
158void Cucul::Rotate()
159{
160    cucul_rotate(cv);
161}
162
163void Cucul::drawLine(int x1, int y1, int x2, int y2, char const *ch)
164{
165    cucul_draw_line(cv, x1, y1, x2, y2, ch);
166}
167
168void Cucul::drawPolyline(int const x[], int const y[], int f, char const *ch)
169{
170    cucul_draw_polyline(cv, x, y, f, ch);
171}
172
173void Cucul::drawThinLine(int x1, int y1, int x2, int y2)
174{
175    cucul_draw_thin_line(cv, x1, y1, x2, y2);
176}
177
178void Cucul::drawThinPolyline(int const x[], int const y[], int f)
179{
180    cucul_draw_thin_polyline(cv, x, y, f);
181}
182
183void Cucul::drawCircle(int x, int y, int d, char const *ch)
184{
185    cucul_draw_circle(cv, x, y, d, ch);
186}
187
188void Cucul::drawEllipse(int x, int y, int d1, int d2, char const *ch)
189{
190    cucul_draw_ellipse(cv, x, y, d1, d2, ch);
191}
192
193void Cucul::drawThinEllipse(int x, int y, int d1, int d2)
194{
195    cucul_draw_thin_ellipse(cv, x, y, d1, d2);
196}
197
198void Cucul::fillEllipse(int x, int y, int d1, int d2, char const *ch)
199{
200    cucul_fill_ellipse(cv, x, y, d1, d2, ch);
201}
202
203void Cucul::drawBox(int x, int y, int w, int h, char const *ch)
204{
205    cucul_draw_box(cv, x, y, w, h, ch);
206}
207
208void Cucul::drawThinBox(int x, int y, int w, int h)
209{
210    cucul_draw_thin_box(cv, x, y, w, h);
211}
212
213void Cucul::fillBox(int x, int y, int w, int h, char const *ch)
214{
215    cucul_fill_box(cv, x, y, w, h, ch);
216}
217
218void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, char const *ch)
219{
220    cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
221}
222
223void Cucul::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
224{
225    cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
226}
227
228void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, const char *ch)
229{
230    cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
231}
232
233int Cucul::Rand(int min, int max)
234{
235    return cucul_rand(min, max);
236}
237
238unsigned long int Cucul::getColor(int x, int y)
239{
240    return cucul_get_color(cv, x, y);
241}
242
243int Cucul::setBoundaries(cucul_canvas_t *, int x, int y,
244                         unsigned int w, unsigned int h)
245{
246    return cucul_set_canvas_boundaries(cv, x, y, h, w);
247}
248
249unsigned int Cucul::getFrameCount()
250{
251    return cucul_get_canvas_frame_count(cv);
252}
253int Cucul::setFrame(unsigned int f)
254{
255    return cucul_set_canvas_frame(cv, f);
256}
257int Cucul::createFrame(unsigned int f)
258{
259    return cucul_create_canvas_frame(cv, f);
260}
261int Cucul::freeFrame(unsigned int f)
262{
263    return cucul_create_canvas_frame(cv, f);
264}
265
266Dither::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)
267{
268    dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
269}
270Dither::~Dither()
271{
272    cucul_free_dither(dither);
273}
274
275void Dither::setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
276{
277    cucul_set_dither_palette(dither, r, g, b, a);
278}
279
280void Dither::setBrightness(float f)
281{
282    cucul_set_dither_brightness(dither, f);
283}
284
285void Dither::setGamma(float f)
286{
287    cucul_set_dither_gamma(dither, f);
288}
289
290void Dither::setContrast(float f)
291{
292    cucul_set_dither_contrast(dither, f);
293}
294
295void Dither::setInvert(int i)
296{
297    cucul_set_dither_invert(dither, i);
298}
299
300void Dither::setAntialias(char const *cv)
301{
302    cucul_set_dither_antialias(dither, cv);
303}
304
305char const *const * Dither::getAntialiasList()
306{
307    return cucul_get_dither_antialias_list(dither);
308}
309
310void Dither::setColor(char const *cv)
311{
312    cucul_set_dither_color(dither, cv);
313}
314
315char const *const * Dither::getColorList()
316{
317    return cucul_get_dither_color_list(dither);
318}
319
320void Dither::setCharset(char const *cv)
321{
322    cucul_set_dither_charset(dither, cv);
323}
324
325char const *const * Dither::getCharsetList()
326{
327    return cucul_get_dither_charset_list(dither);
328}
329
330void Dither::setMode(char const *cv)
331{
332    cucul_set_dither_mode(dither, cv);
333}
334
335char const *const * Dither::getModeList(void)
336{
337    return cucul_get_dither_mode_list(dither);
338}
339
340void Dither::Bitmap(Cucul *cv, int x, int y, int w, int h, void *v)
341{
342    cucul_dither_bitmap(cv->get_cucul_canvas_t(), x, y, w, h, dither, v);
343}
344
345Font::Font(void const *s, unsigned int v)
346{
347    font = cucul_load_font(s, v);
348    if(!font) throw -1;
349}
350
351char const *const * Font::getList(void)
352{
353    return cucul_get_font_list();
354}
355
356unsigned int Font::getWidth()
357{
358    return cucul_get_font_width(font);
359}
360
361unsigned int Font::getHeight()
362{
363    return cucul_get_font_height(font);
364}
365
366void Font::renderCanvas(Cucul *cv, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
367{
368    cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w);
369}
370
371unsigned long int const *Font::getBlocks()
372{
373    return cucul_get_font_blocks(font);
374}
375
376Font::~Font()
377{
378    cucul_free_font(font);
379}
380
381Buffer::Buffer()
382{
383    buffer_ = NULL;
384}
385
386Buffer::~Buffer()
387{
388    if(buffer_)
389        cucul_free_buffer(buffer_);
390}
391
392char const *const * Buffer::getExportList(void)
393{
394    return cucul_get_export_list();
395}
396
397void *Buffer::getData(void)
398{
399    return cucul_get_buffer_data(buffer_);
400}
401
402void Buffer::loadMemory(void *buf, unsigned long int size)
403{
404    buffer_ = cucul_load_memory(buf, size);
405    if(buffer_ == NULL)
406        throw -1;
407}
408
409void Buffer::loadFile(char const *filename)
410{
411    buffer_ = cucul_load_file(filename);
412    if(buffer_ == NULL)
413        throw -1;
414}
415
416unsigned long int Buffer::getSize()
417{
418    return cucul_get_buffer_size(buffer_);
419}
420
421cucul_buffer *Buffer::getBuffer()
422{
423    return buffer_;
424}
Note: See TracBrowser for help on using the repository browser.