Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

cucul++.cpp 7.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*
  2. * libcucul++ C++ bindings for libcucul
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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. #include "config.h"
  18. #include <stdio.h> // BUFSIZ
  19. #include <stdarg.h> // va_*
  20. #include "cucul++.h"
  21. Cucul::Cucul()
  22. {
  23. cv = cucul_create_canvas(0, 0);
  24. if(!cv)
  25. throw -1;
  26. }
  27. Cucul::Cucul(int width, int height)
  28. {
  29. cv = cucul_create_canvas(width, height);
  30. if(!cv) throw -1;
  31. }
  32. Cucul::~Cucul()
  33. {
  34. if(cv)
  35. cucul_free_canvas(cv);
  36. }
  37. cucul_canvas_t *Cucul::get_cucul_canvas_t()
  38. {
  39. return cv;
  40. }
  41. void Cucul::set_size(unsigned int width, unsigned int height)
  42. {
  43. cucul_set_canvas_size(cv, width, height);
  44. }
  45. unsigned int Cucul::get_width(void)
  46. {
  47. return cucul_get_canvas_width(cv);
  48. }
  49. unsigned int Cucul::get_height(void)
  50. {
  51. return cucul_get_canvas_height(cv);
  52. }
  53. void Cucul::set_color(unsigned int f, unsigned int b)
  54. {
  55. cucul_set_color(cv, f, b);
  56. }
  57. char const * Cucul::get_color_name(unsigned int color)
  58. {
  59. return cucul_get_color_name(color);
  60. }
  61. void Cucul::putchar(int x, int y, char ch)
  62. {
  63. cucul_putchar(cv, x, y, ch);
  64. }
  65. void Cucul::putstr(int x, int y, char *str)
  66. {
  67. cucul_putstr(cv, x, y, str);
  68. }
  69. void Cucul::printf(int x, int y, char const * format,...)
  70. {
  71. char tmp[BUFSIZ];
  72. char *buf = tmp;
  73. va_list args;
  74. va_start(args, format);
  75. #if defined(HAVE_VSNPRINTF)
  76. vsnprintf(buf, get_width() - x + 1, format, args);
  77. #else
  78. vsprintf(buf, format, args);
  79. #endif
  80. buf[get_width() - x] = '\0';
  81. va_end(args);
  82. putstr(x, y, buf);
  83. }
  84. void Cucul::clear(void)
  85. {
  86. cucul_clear_canvas(cv);
  87. }
  88. void Cucul::blit(int x, int y, Cucul* c1, Cucul* c2)
  89. {
  90. cucul_blit(cv, x, y, c1->get_cucul_canvas_t(), c2->get_cucul_canvas_t());
  91. }
  92. void Cucul::invert()
  93. {
  94. cucul_invert(cv);
  95. }
  96. void Cucul::flip()
  97. {
  98. cucul_flip(cv);
  99. }
  100. void Cucul::flop()
  101. {
  102. cucul_flop(cv);
  103. }
  104. void Cucul::rotate()
  105. {
  106. cucul_rotate(cv);
  107. }
  108. void Cucul::draw_line(int x1, int y1, int x2, int y2, char const *ch)
  109. {
  110. cucul_draw_line(cv, x1, y1, x2, y2, ch);
  111. }
  112. void Cucul::draw_polyline(int const x[], int const y[], int f, char const *ch)
  113. {
  114. cucul_draw_polyline(cv, x, y, f, ch);
  115. }
  116. void Cucul::draw_thin_line(int x1, int y1, int x2, int y2)
  117. {
  118. cucul_draw_thin_line(cv, x1, y1, x2, y2);
  119. }
  120. void Cucul::draw_thin_polyline(int const x[], int const y[], int f)
  121. {
  122. cucul_draw_thin_polyline(cv, x, y, f);
  123. }
  124. void Cucul::draw_circle(int x, int y, int d, char const *ch)
  125. {
  126. cucul_draw_circle(cv, x, y, d, ch);
  127. }
  128. void Cucul::draw_ellipse(int x, int y, int d1, int d2, char const *ch)
  129. {
  130. cucul_draw_ellipse(cv, x, y, d1, d2, ch);
  131. }
  132. void Cucul::draw_thin_ellipse(int x, int y, int d1, int d2)
  133. {
  134. cucul_draw_thin_ellipse(cv, x, y, d1, d2);
  135. }
  136. void Cucul::fill_ellipse(int x, int y, int d1, int d2, char const *ch)
  137. {
  138. cucul_fill_ellipse(cv, x, y, d1, d2, ch);
  139. }
  140. void Cucul::draw_box(int x, int y, int w, int h, char const *ch)
  141. {
  142. cucul_draw_box(cv, x, y, w, h, ch);
  143. }
  144. void Cucul::draw_thin_box(int x, int y, int w, int h)
  145. {
  146. cucul_draw_thin_box(cv, x, y, w, h);
  147. }
  148. void Cucul::fill_box(int x, int y, int w, int h, char const *ch)
  149. {
  150. cucul_fill_box(cv, x, y, w, h, ch);
  151. }
  152. void Cucul::draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char const *ch)
  153. {
  154. cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
  155. }
  156. void Cucul::draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3)
  157. {
  158. cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
  159. }
  160. void Cucul::fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, const char *ch)
  161. {
  162. cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
  163. }
  164. int Cucul::rand(int min, int max)
  165. {
  166. return cucul_rand(min, max);
  167. }
  168. Cucul::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)
  169. {
  170. Cucul::Dither *d = new Dither();
  171. d->dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
  172. return d;
  173. }
  174. void Cucul::set_dither_palette(Cucul::Dither *d, unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
  175. {
  176. cucul_set_dither_palette(d->dither, r, g, b, a);
  177. }
  178. void Cucul::set_dither_brightness(Cucul::Dither *d, float f)
  179. {
  180. cucul_set_dither_brightness(d->dither, f);
  181. }
  182. void Cucul::set_dither_gamma(Cucul::Dither *d, float f)
  183. {
  184. cucul_set_dither_gamma(d->dither, f);
  185. }
  186. void Cucul::set_dither_contrast(Cucul::Dither *d, float f)
  187. {
  188. cucul_set_dither_contrast(d->dither, f);
  189. }
  190. void Cucul::set_dither_invert(Cucul::Dither *d, int i)
  191. {
  192. cucul_set_dither_invert(d->dither, i);
  193. }
  194. void Cucul::set_dither_antialias(Cucul::Dither *d, char const *cv)
  195. {
  196. cucul_set_dither_antialias(d->dither, cv);
  197. }
  198. char const *const * Cucul::get_dither_antialias_list(Cucul::Dither const *d)
  199. {
  200. return cucul_get_dither_antialias_list(d->dither);
  201. }
  202. void Cucul::set_dither_color(Cucul::Dither *d, char const *cv)
  203. {
  204. cucul_set_dither_color(d->dither, cv);
  205. }
  206. char const *const * Cucul::get_dither_color_list(Cucul::Dither const *d)
  207. {
  208. return cucul_get_dither_color_list(d->dither);
  209. }
  210. void Cucul::set_dither_charset(Cucul::Dither *d, char const *cv)
  211. {
  212. cucul_set_dither_charset(d->dither, cv);
  213. }
  214. char const *const * Cucul::get_dither_charset_list(Cucul::Dither const *d)
  215. {
  216. return cucul_get_dither_charset_list(d->dither);
  217. }
  218. void Cucul::set_dither_mode(Cucul::Dither *d, char const *cv)
  219. {
  220. cucul_set_dither_mode(d->dither, cv);
  221. }
  222. char const *const * Cucul::get_dither_mode_list(Cucul::Dither const *d)
  223. {
  224. return cucul_get_dither_mode_list(d->dither);
  225. }
  226. void Cucul::dither_bitmap(int x, int y, int w, int h, Cucul::Dither const *d, void *v)
  227. {
  228. cucul_dither_bitmap(cv, x, y, w, h, d->dither, v);
  229. }
  230. void Cucul::free_dither(Cucul::Dither *d)
  231. {
  232. cucul_free_dither(d->dither);
  233. }
  234. Cucul::Font * Cucul::load_font(void const *s, unsigned int v)
  235. {
  236. Cucul::Font *f = new Cucul::Font();
  237. f->font = cucul_load_font(s, v);
  238. return f;
  239. }
  240. char const *const * Cucul::get_font_list(void)
  241. {
  242. return cucul_get_font_list();
  243. }
  244. unsigned int Cucul::get_font_width(Cucul::Font *f)
  245. {
  246. return cucul_get_font_width(f->font);
  247. }
  248. unsigned int Cucul::get_font_height(Cucul::Font *f)
  249. {
  250. return cucul_get_font_height(f->font);
  251. }
  252. void Cucul::render_canvas(Cucul::Font *f, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
  253. {
  254. cucul_render_canvas(cv, f->font, buf, x, y, w);
  255. }
  256. void Cucul::free_font(Cucul::Font *f)
  257. {
  258. cucul_free_font(f->font);
  259. }
  260. Cucul::Buffer * Cucul::export_canvas(char const *buf)
  261. {
  262. Cucul::Buffer *b = new Cucul::Buffer();
  263. b->buffer = cucul_export_canvas(cv, buf);
  264. return b;
  265. }
  266. char const *const * Cucul::get_export_list(void)
  267. {
  268. return cucul_get_export_list();
  269. }