Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. unsigned long int Charset::utf8ToUtf32(char const *s, unsigned int *read)
  22. {
  23. return cucul_utf8_to_utf32(s, read);
  24. }
  25. unsigned int Charset::utf32ToUtf8(char *buf, unsigned long int ch)
  26. {
  27. return cucul_utf32_to_utf8(buf, ch);
  28. }
  29. unsigned char Charset::utf32ToCp437(unsigned long int ch)
  30. {
  31. return cucul_utf32_to_cp437(ch);
  32. }
  33. unsigned long int Charset::cp437ToUtf32(unsigned char ch)
  34. {
  35. return cucul_cp437_to_utf32(ch);
  36. }
  37. Cucul::Cucul()
  38. {
  39. cv = cucul_create_canvas(0, 0);
  40. if(!cv)
  41. throw -1;
  42. }
  43. Cucul::Cucul(int width, int height)
  44. {
  45. cv = cucul_create_canvas(width, height);
  46. if(!cv) throw -1;
  47. }
  48. Cucul::~Cucul()
  49. {
  50. if(cv)
  51. cucul_free_canvas(cv);
  52. }
  53. cucul_canvas_t *Cucul::get_cucul_canvas_t()
  54. {
  55. return cv;
  56. }
  57. void Cucul::setSize(unsigned int width, unsigned int height)
  58. {
  59. cucul_set_canvas_size(cv, width, height);
  60. }
  61. unsigned int Cucul::getWidth(void)
  62. {
  63. return cucul_get_canvas_width(cv);
  64. }
  65. unsigned int Cucul::getHeight(void)
  66. {
  67. return cucul_get_canvas_height(cv);
  68. }
  69. int Cucul::setColorANSI(unsigned char f, unsigned char b)
  70. {
  71. return cucul_set_color_ansi(cv, f, b);
  72. }
  73. int Cucul::setColorARGB(unsigned int f, unsigned int b)
  74. {
  75. return cucul_set_color_argb(cv, f, b);
  76. }
  77. void Cucul::putChar(int x, int y, unsigned long int ch)
  78. {
  79. cucul_put_char(cv, x, y, ch);
  80. }
  81. unsigned long int Cucul::getChar(int x, int y)
  82. {
  83. return cucul_get_char(cv, x, y);
  84. }
  85. void Cucul::putStr(int x, int y, char *str)
  86. {
  87. cucul_put_str(cv, x, y, str);
  88. }
  89. void Cucul::Printf(int x, int y, char const * format, ...)
  90. {
  91. char tmp[BUFSIZ];
  92. char *buf = tmp;
  93. va_list args;
  94. va_start(args, format);
  95. #if defined(HAVE_VSNPRINTF)
  96. vsnprintf(buf, getWidth() - x + 1, format, args);
  97. #else
  98. vsprintf(buf, format, args);
  99. #endif
  100. buf[getWidth() - x] = '\0';
  101. va_end(args);
  102. putStr(x, y, buf);
  103. }
  104. void Cucul::Clear(void)
  105. {
  106. cucul_clear_canvas(cv);
  107. }
  108. void Cucul::Blit(int x, int y, Cucul* c1, Cucul* c2)
  109. {
  110. cucul_blit(cv, x, y, c1->get_cucul_canvas_t(),
  111. c2 ? c2->get_cucul_canvas_t() : NULL);
  112. }
  113. void Cucul::Invert()
  114. {
  115. cucul_invert(cv);
  116. }
  117. void Cucul::Flip()
  118. {
  119. cucul_flip(cv);
  120. }
  121. void Cucul::Flop()
  122. {
  123. cucul_flop(cv);
  124. }
  125. void Cucul::Rotate()
  126. {
  127. cucul_rotate(cv);
  128. }
  129. void Cucul::drawLine(int x1, int y1, int x2, int y2, unsigned long int ch)
  130. {
  131. cucul_draw_line(cv, x1, y1, x2, y2, ch);
  132. }
  133. void Cucul::drawPolyline(int const x[], int const y[], int f, unsigned long int ch)
  134. {
  135. cucul_draw_polyline(cv, x, y, f, ch);
  136. }
  137. void Cucul::drawThinLine(int x1, int y1, int x2, int y2)
  138. {
  139. cucul_draw_thin_line(cv, x1, y1, x2, y2);
  140. }
  141. void Cucul::drawThinPolyline(int const x[], int const y[], int f)
  142. {
  143. cucul_draw_thin_polyline(cv, x, y, f);
  144. }
  145. void Cucul::drawCircle(int x, int y, int d, unsigned long int ch)
  146. {
  147. cucul_draw_circle(cv, x, y, d, ch);
  148. }
  149. void Cucul::drawEllipse(int x, int y, int d1, int d2, unsigned long int ch)
  150. {
  151. cucul_draw_ellipse(cv, x, y, d1, d2, ch);
  152. }
  153. void Cucul::drawThinEllipse(int x, int y, int d1, int d2)
  154. {
  155. cucul_draw_thin_ellipse(cv, x, y, d1, d2);
  156. }
  157. void Cucul::fillEllipse(int x, int y, int d1, int d2, unsigned long int ch)
  158. {
  159. cucul_fill_ellipse(cv, x, y, d1, d2, ch);
  160. }
  161. void Cucul::drawBox(int x, int y, int w, int h, unsigned long int ch)
  162. {
  163. cucul_draw_box(cv, x, y, w, h, ch);
  164. }
  165. void Cucul::drawThinBox(int x, int y, int w, int h)
  166. {
  167. cucul_draw_thin_box(cv, x, y, w, h);
  168. }
  169. void Cucul::drawCP437Box(int x, int y, int w, int h)
  170. {
  171. cucul_draw_cp437_box(cv, x, y, w, h);
  172. }
  173. void Cucul::fillBox(int x, int y, int w, int h, unsigned long int ch)
  174. {
  175. cucul_fill_box(cv, x, y, w, h, ch);
  176. }
  177. void Cucul::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned long int ch)
  178. {
  179. cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
  180. }
  181. void Cucul::drawThinTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
  182. {
  183. cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
  184. }
  185. void Cucul::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, unsigned long int ch)
  186. {
  187. cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
  188. }
  189. int Cucul::Rand(int min, int max)
  190. {
  191. return cucul_rand(min, max);
  192. }
  193. int Cucul::setAttr(unsigned long int attr)
  194. {
  195. return cucul_set_attr(cv, attr);
  196. }
  197. unsigned long int Cucul::getAttr(int x, int y)
  198. {
  199. return cucul_get_attr(cv, x, y);
  200. }
  201. int Cucul::setBoundaries(cucul_canvas_t *, int x, int y,
  202. unsigned int w, unsigned int h)
  203. {
  204. return cucul_set_canvas_boundaries(cv, x, y, h, w);
  205. }
  206. unsigned int Cucul::getFrameCount()
  207. {
  208. return cucul_get_frame_count(cv);
  209. }
  210. int Cucul::setFrame(unsigned int f)
  211. {
  212. return cucul_set_frame(cv, f);
  213. }
  214. int Cucul::createFrame(unsigned int f)
  215. {
  216. return cucul_create_frame(cv, f);
  217. }
  218. int Cucul::freeFrame(unsigned int f)
  219. {
  220. return cucul_create_frame(cv, f);
  221. }
  222. char const *const * Cucul::getImportList(void)
  223. {
  224. return cucul_get_import_list();
  225. }
  226. long int Cucul::importMemory(void const *buf, unsigned long int len, char const *fmt)
  227. {
  228. return cucul_import_memory(cv, buf, len, fmt);
  229. }
  230. long int Cucul::importFile(char const *file, char const *fmt)
  231. {
  232. return cucul_import_file(cv, file, fmt);
  233. }
  234. char const *const * Cucul::getExportList(void)
  235. {
  236. return cucul_get_export_list();
  237. }
  238. void *Cucul::exportMemory(char const *fmt, unsigned long int *len)
  239. {
  240. return cucul_export_memory(cv, fmt, len);
  241. }
  242. 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)
  243. {
  244. dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
  245. }
  246. Dither::~Dither()
  247. {
  248. cucul_free_dither(dither);
  249. }
  250. void Dither::setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
  251. {
  252. cucul_set_dither_palette(dither, r, g, b, a);
  253. }
  254. void Dither::setBrightness(float f)
  255. {
  256. cucul_set_dither_brightness(dither, f);
  257. }
  258. void Dither::setGamma(float f)
  259. {
  260. cucul_set_dither_gamma(dither, f);
  261. }
  262. void Dither::setContrast(float f)
  263. {
  264. cucul_set_dither_contrast(dither, f);
  265. }
  266. void Dither::setInvert(int i)
  267. {
  268. cucul_set_dither_invert(dither, i);
  269. }
  270. void Dither::setAntialias(char const *cv)
  271. {
  272. cucul_set_dither_antialias(dither, cv);
  273. }
  274. char const *const * Dither::getAntialiasList()
  275. {
  276. return cucul_get_dither_antialias_list(dither);
  277. }
  278. void Dither::setColor(char const *cv)
  279. {
  280. cucul_set_dither_color(dither, cv);
  281. }
  282. char const *const * Dither::getColorList()
  283. {
  284. return cucul_get_dither_color_list(dither);
  285. }
  286. void Dither::setCharset(char const *cv)
  287. {
  288. cucul_set_dither_charset(dither, cv);
  289. }
  290. char const *const * Dither::getCharsetList()
  291. {
  292. return cucul_get_dither_charset_list(dither);
  293. }
  294. void Dither::setMode(char const *cv)
  295. {
  296. cucul_set_dither_mode(dither, cv);
  297. }
  298. char const *const * Dither::getModeList(void)
  299. {
  300. return cucul_get_dither_mode_list(dither);
  301. }
  302. void Dither::Bitmap(Cucul *cv, int x, int y, int w, int h, void *v)
  303. {
  304. cucul_dither_bitmap(cv->get_cucul_canvas_t(), x, y, w, h, dither, v);
  305. }
  306. Font::Font(void const *s, unsigned int v)
  307. {
  308. font = cucul_load_font(s, v);
  309. if(!font) throw -1;
  310. }
  311. char const *const * Font::getList(void)
  312. {
  313. return cucul_get_font_list();
  314. }
  315. unsigned int Font::getWidth()
  316. {
  317. return cucul_get_font_width(font);
  318. }
  319. unsigned int Font::getHeight()
  320. {
  321. return cucul_get_font_height(font);
  322. }
  323. void Font::renderCanvas(Cucul *cv, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
  324. {
  325. cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w);
  326. }
  327. unsigned long int const *Font::getBlocks()
  328. {
  329. return cucul_get_font_blocks(font);
  330. }
  331. Font::~Font()
  332. {
  333. cucul_free_font(font);
  334. }