Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

326 wiersze
6.3 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()
  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::setSize(unsigned int width, unsigned int height)
  42. {
  43. cucul_set_canvas_size(cv, width, height);
  44. }
  45. unsigned int Cucul::getWidth(void)
  46. {
  47. return cucul_get_canvas_width(cv);
  48. }
  49. unsigned int Cucul::getHeight(void)
  50. {
  51. return cucul_get_canvas_height(cv);
  52. }
  53. void Cucul::setColor(unsigned int f, unsigned int b)
  54. {
  55. cucul_set_color(cv, f, b);
  56. }
  57. char const * Cucul::getColorName(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, getWidth() - x + 1, format, args);
  77. #else
  78. vsprintf(buf, format, args);
  79. #endif
  80. buf[getWidth() - 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::drawLine(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::drawPolyline(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::drawThinLine(int x1, int y1, int x2, int y2)
  117. {
  118. cucul_draw_thin_line(cv, x1, y1, x2, y2);
  119. }
  120. void Cucul::drawThinPolyline(int const x[], int const y[], int f)
  121. {
  122. cucul_draw_thin_polyline(cv, x, y, f);
  123. }
  124. void Cucul::drawCircle(int x, int y, int d, char const *ch)
  125. {
  126. cucul_draw_circle(cv, x, y, d, ch);
  127. }
  128. void Cucul::drawEllipse(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::drawThinEllipse(int x, int y, int d1, int d2)
  133. {
  134. cucul_draw_thin_ellipse(cv, x, y, d1, d2);
  135. }
  136. void Cucul::fillEllipse(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::drawBox(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::drawThinBox(int x, int y, int w, int h)
  145. {
  146. cucul_draw_thin_box(cv, x, y, w, h);
  147. }
  148. void Cucul::fillBox(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::drawTriangle(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::drawThinTriangle(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::fillTriangle(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. 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)
  169. {
  170. dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
  171. }
  172. Dither::~Dither()
  173. {
  174. cucul_free_dither(dither);
  175. }
  176. void Dither::setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
  177. {
  178. cucul_set_dither_palette(dither, r, g, b, a);
  179. }
  180. void Dither::setBrightness(float f)
  181. {
  182. cucul_set_dither_brightness(dither, f);
  183. }
  184. void Dither::setGamma(float f)
  185. {
  186. cucul_set_dither_gamma(dither, f);
  187. }
  188. void Dither::setContrast(float f)
  189. {
  190. cucul_set_dither_contrast(dither, f);
  191. }
  192. void Dither::setInvert(int i)
  193. {
  194. cucul_set_dither_invert(dither, i);
  195. }
  196. void Dither::setAntialias(char const *cv)
  197. {
  198. cucul_set_dither_antialias(dither, cv);
  199. }
  200. char const *const * Dither::getAntialiasList()
  201. {
  202. return cucul_get_dither_antialias_list(dither);
  203. }
  204. void Dither::setColor(char const *cv)
  205. {
  206. cucul_set_dither_color(dither, cv);
  207. }
  208. char const *const * Dither::getColorList()
  209. {
  210. return cucul_get_dither_color_list(dither);
  211. }
  212. void Dither::setCharset(char const *cv)
  213. {
  214. cucul_set_dither_charset(dither, cv);
  215. }
  216. char const *const * Dither::getCharsetList()
  217. {
  218. return cucul_get_dither_charset_list(dither);
  219. }
  220. void Dither::setMode(char const *cv)
  221. {
  222. cucul_set_dither_mode(dither, cv);
  223. }
  224. char const *const * Dither::getModeList(void)
  225. {
  226. return cucul_get_dither_mode_list(dither);
  227. }
  228. void Dither::Bitmap(Cucul *cv, int x, int y, int w, int h, void *v)
  229. {
  230. cucul_dither_bitmap(cv->get_cucul_canvas_t(), x, y, w, h, dither, v);
  231. }
  232. Font::Font(void const *s, unsigned int v)
  233. {
  234. font = cucul_load_font(s, v);
  235. }
  236. char const *const * Font::getList(void)
  237. {
  238. return cucul_get_font_list();
  239. }
  240. unsigned int Font::getWidth()
  241. {
  242. return cucul_get_font_width(font);
  243. }
  244. unsigned int Font::getHeight()
  245. {
  246. return cucul_get_font_height(font);
  247. }
  248. void Font::renderCanvas(Cucul *cv, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
  249. {
  250. cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w);
  251. }
  252. Font::~Font()
  253. {
  254. cucul_free_font(font);
  255. }
  256. Buffer::Buffer(Cucul *cv, char const *buf)
  257. {
  258. buffer = cucul_export_canvas(cv->get_cucul_canvas_t(), buf);
  259. }
  260. char const *const * Buffer::getExportList(void)
  261. {
  262. return cucul_get_export_list();
  263. }