Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cucul++.cpp 8.3 KiB

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