選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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