Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

339 linhas
6.5 KiB

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