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

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