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