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 899 2006-04-26 12:11:55Z 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 | Cucul::Cucul() |
---|
27 | { |
---|
28 | cv = cucul_create_canvas(0, 0); |
---|
29 | if(!cv) |
---|
30 | throw -1; |
---|
31 | } |
---|
32 | |
---|
33 | Cucul::Cucul(int width, int height) |
---|
34 | { |
---|
35 | cv = cucul_create_canvas(width, height); |
---|
36 | if(!cv) throw -1; |
---|
37 | } |
---|
38 | |
---|
39 | Cucul::Cucul(Buffer *b, char const *format) |
---|
40 | { |
---|
41 | cv = cucul_import_canvas(b->get_buffer(), format); |
---|
42 | if(!cv) throw -1; |
---|
43 | } |
---|
44 | |
---|
45 | Cucul::~Cucul() |
---|
46 | { |
---|
47 | if(cv) |
---|
48 | cucul_free_canvas(cv); |
---|
49 | } |
---|
50 | |
---|
51 | cucul_canvas_t *Cucul::get_cucul_canvas_t() |
---|
52 | { |
---|
53 | return cv; |
---|
54 | } |
---|
55 | |
---|
56 | void Cucul::setSize(unsigned int width, unsigned int height) |
---|
57 | { |
---|
58 | cucul_set_canvas_size(cv, width, height); |
---|
59 | } |
---|
60 | |
---|
61 | unsigned int Cucul::getWidth(void) |
---|
62 | { |
---|
63 | return cucul_get_canvas_width(cv); |
---|
64 | } |
---|
65 | |
---|
66 | unsigned int Cucul::getHeight(void) |
---|
67 | { |
---|
68 | return cucul_get_canvas_height(cv); |
---|
69 | } |
---|
70 | |
---|
71 | void Cucul::setColor(unsigned int f, unsigned int b) |
---|
72 | { |
---|
73 | cucul_set_color(cv, f, b); |
---|
74 | } |
---|
75 | |
---|
76 | char const * Cucul::getColorName(unsigned int color) |
---|
77 | { |
---|
78 | return cucul_get_color_name(color); |
---|
79 | } |
---|
80 | |
---|
81 | void Cucul::putChar(int x, int y, char ch) |
---|
82 | { |
---|
83 | cucul_putchar(cv, x, y, ch); |
---|
84 | } |
---|
85 | |
---|
86 | void Cucul::putStr(int x, int y, char *str) |
---|
87 | { |
---|
88 | cucul_putstr(cv, x, y, str); |
---|
89 | } |
---|
90 | |
---|
91 | void Cucul::Printf(int x, int y, char const * format,...) |
---|
92 | { |
---|
93 | char tmp[BUFSIZ]; |
---|
94 | char *buf = tmp; |
---|
95 | va_list args; |
---|
96 | |
---|
97 | va_start(args, format); |
---|
98 | #if defined(HAVE_VSNPRINTF) |
---|
99 | vsnprintf(buf, getWidth() - x + 1, format, args); |
---|
100 | #else |
---|
101 | vsprintf(buf, format, args); |
---|
102 | #endif |
---|
103 | buf[getWidth() - x] = '\0'; |
---|
104 | va_end(args); |
---|
105 | |
---|
106 | putStr(x, y, buf); |
---|
107 | } |
---|
108 | |
---|
109 | void Cucul::Clear(void) |
---|
110 | { |
---|
111 | cucul_clear_canvas(cv); |
---|
112 | } |
---|
113 | |
---|
114 | void Cucul::Blit(int x, int y, Cucul* c1, Cucul* c2) |
---|
115 | { |
---|
116 | cucul_blit(cv, x, y, c1->get_cucul_canvas_t(), c2->get_cucul_canvas_t()); |
---|
117 | } |
---|
118 | |
---|
119 | void Cucul::Invert() |
---|
120 | { |
---|
121 | cucul_invert(cv); |
---|
122 | } |
---|
123 | |
---|
124 | void Cucul::Flip() |
---|
125 | { |
---|
126 | cucul_flip(cv); |
---|
127 | } |
---|
128 | |
---|
129 | void Cucul::Flop() |
---|
130 | { |
---|
131 | cucul_flop(cv); |
---|
132 | } |
---|
133 | |
---|
134 | void Cucul::Rotate() |
---|
135 | { |
---|
136 | cucul_rotate(cv); |
---|
137 | } |
---|
138 | |
---|
139 | void Cucul::drawLine(int x1, int y1, int x2, int y2, char const *ch) |
---|
140 | { |
---|
141 | cucul_draw_line(cv, x1, y1, x2, y2, ch); |
---|
142 | } |
---|
143 | |
---|
144 | void Cucul::drawPolyline(int const x[], int const y[], int f, char const *ch) |
---|
145 | { |
---|
146 | cucul_draw_polyline(cv, x, y, f, ch); |
---|
147 | } |
---|
148 | |
---|
149 | void Cucul::drawThinLine(int x1, int y1, int x2, int y2) |
---|
150 | { |
---|
151 | cucul_draw_thin_line(cv, x1, y1, x2, y2); |
---|
152 | } |
---|
153 | |
---|
154 | void Cucul::drawThinPolyline(int const x[], int const y[], int f) |
---|
155 | { |
---|
156 | cucul_draw_thin_polyline(cv, x, y, f); |
---|
157 | } |
---|
158 | |
---|
159 | void Cucul::drawCircle(int x, int y, int d, char const *ch) |
---|
160 | { |
---|
161 | cucul_draw_circle(cv, x, y, d, ch); |
---|
162 | } |
---|
163 | |
---|
164 | void Cucul::drawEllipse(int x, int y, int d1, int d2, char const *ch) |
---|
165 | { |
---|
166 | cucul_draw_ellipse(cv, x, y, d1, d2, ch); |
---|
167 | } |
---|
168 | |
---|
169 | void Cucul::drawThinEllipse(int x, int y, int d1, int d2) |
---|
170 | { |
---|
171 | cucul_draw_thin_ellipse(cv, x, y, d1, d2); |
---|
172 | } |
---|
173 | |
---|
174 | void Cucul::fillEllipse(int x, int y, int d1, int d2, char const *ch) |
---|
175 | { |
---|
176 | cucul_fill_ellipse(cv, x, y, d1, d2, ch); |
---|
177 | } |
---|
178 | |
---|
179 | void Cucul::drawBox(int x, int y, int w, int h, char const *ch) |
---|
180 | { |
---|
181 | cucul_draw_box(cv, x, y, w, h, ch); |
---|
182 | } |
---|
183 | |
---|
184 | void Cucul::drawThinBox(int x, int y, int w, int h) |
---|
185 | { |
---|
186 | cucul_draw_thin_box(cv, x, y, w, h); |
---|
187 | } |
---|
188 | |
---|
189 | void Cucul::fillBox(int x, int y, int w, int h, char const *ch) |
---|
190 | { |
---|
191 | cucul_fill_box(cv, x, y, w, h, ch); |
---|
192 | } |
---|
193 | |
---|
194 | void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, char const *ch) |
---|
195 | { |
---|
196 | cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch); |
---|
197 | } |
---|
198 | |
---|
199 | void Cucul::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3) |
---|
200 | { |
---|
201 | cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3); |
---|
202 | } |
---|
203 | |
---|
204 | void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, const char *ch) |
---|
205 | { |
---|
206 | cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch); |
---|
207 | } |
---|
208 | |
---|
209 | int Cucul::Rand(int min, int max) |
---|
210 | { |
---|
211 | return cucul_rand(min, max); |
---|
212 | } |
---|
213 | |
---|
214 | Dither::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) |
---|
215 | { |
---|
216 | dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8); |
---|
217 | } |
---|
218 | Dither::~Dither() |
---|
219 | { |
---|
220 | cucul_free_dither(dither); |
---|
221 | } |
---|
222 | |
---|
223 | void Dither::setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[]) |
---|
224 | { |
---|
225 | cucul_set_dither_palette(dither, r, g, b, a); |
---|
226 | } |
---|
227 | |
---|
228 | void Dither::setBrightness(float f) |
---|
229 | { |
---|
230 | cucul_set_dither_brightness(dither, f); |
---|
231 | } |
---|
232 | |
---|
233 | void Dither::setGamma(float f) |
---|
234 | { |
---|
235 | cucul_set_dither_gamma(dither, f); |
---|
236 | } |
---|
237 | |
---|
238 | void Dither::setContrast(float f) |
---|
239 | { |
---|
240 | cucul_set_dither_contrast(dither, f); |
---|
241 | } |
---|
242 | |
---|
243 | void Dither::setInvert(int i) |
---|
244 | { |
---|
245 | cucul_set_dither_invert(dither, i); |
---|
246 | } |
---|
247 | |
---|
248 | void Dither::setAntialias(char const *cv) |
---|
249 | { |
---|
250 | cucul_set_dither_antialias(dither, cv); |
---|
251 | } |
---|
252 | |
---|
253 | char const *const * Dither::getAntialiasList() |
---|
254 | { |
---|
255 | return cucul_get_dither_antialias_list(dither); |
---|
256 | } |
---|
257 | |
---|
258 | void Dither::setColor(char const *cv) |
---|
259 | { |
---|
260 | cucul_set_dither_color(dither, cv); |
---|
261 | } |
---|
262 | |
---|
263 | char const *const * Dither::getColorList() |
---|
264 | { |
---|
265 | return cucul_get_dither_color_list(dither); |
---|
266 | } |
---|
267 | |
---|
268 | void Dither::setCharset(char const *cv) |
---|
269 | { |
---|
270 | cucul_set_dither_charset(dither, cv); |
---|
271 | } |
---|
272 | |
---|
273 | char const *const * Dither::getCharsetList() |
---|
274 | { |
---|
275 | return cucul_get_dither_charset_list(dither); |
---|
276 | } |
---|
277 | |
---|
278 | void Dither::setMode(char const *cv) |
---|
279 | { |
---|
280 | cucul_set_dither_mode(dither, cv); |
---|
281 | } |
---|
282 | |
---|
283 | char const *const * Dither::getModeList(void) |
---|
284 | { |
---|
285 | return cucul_get_dither_mode_list(dither); |
---|
286 | } |
---|
287 | |
---|
288 | void Dither::Bitmap(Cucul *cv, int x, int y, int w, int h, void *v) |
---|
289 | { |
---|
290 | cucul_dither_bitmap(cv->get_cucul_canvas_t(), x, y, w, h, dither, v); |
---|
291 | } |
---|
292 | |
---|
293 | Font::Font(void const *s, unsigned int v) |
---|
294 | { |
---|
295 | font = cucul_load_font(s, v); |
---|
296 | if(!font) throw -1; |
---|
297 | } |
---|
298 | |
---|
299 | char const *const * Font::getList(void) |
---|
300 | { |
---|
301 | return cucul_get_font_list(); |
---|
302 | } |
---|
303 | |
---|
304 | unsigned int Font::getWidth() |
---|
305 | { |
---|
306 | return cucul_get_font_width(font); |
---|
307 | } |
---|
308 | |
---|
309 | unsigned int Font::getHeight() |
---|
310 | { |
---|
311 | return cucul_get_font_height(font); |
---|
312 | } |
---|
313 | |
---|
314 | void Font::renderCanvas(Cucul *cv, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w) |
---|
315 | { |
---|
316 | cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w); |
---|
317 | } |
---|
318 | |
---|
319 | Font::~Font() |
---|
320 | { |
---|
321 | cucul_free_font(font); |
---|
322 | } |
---|
323 | |
---|
324 | Buffer::Buffer(Cucul *cv, char const *buf) |
---|
325 | { |
---|
326 | buffer = cucul_export_canvas(cv->get_cucul_canvas_t(), buf); |
---|
327 | if(!buffer) throw -1; |
---|
328 | } |
---|
329 | |
---|
330 | char const *const * Buffer::getExportList(void) |
---|
331 | { |
---|
332 | return cucul_get_export_list(); |
---|
333 | } |
---|
334 | |
---|
335 | cucul_buffer *Buffer::get_buffer(void) |
---|
336 | { |
---|
337 | return buffer; |
---|
338 | } |
---|