You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

333 rivejä
7.0 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::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. }