25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

407 satır
8.1 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. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains the main functions used by \e libcucul++ applications
  16. * to initialise a drawing context.
  17. */
  18. #include "config.h"
  19. #include <stdio.h> // BUFSIZ
  20. #include <stdarg.h> // va_*
  21. #include "cucul++.h"
  22. unsigned long int Charset::utf8ToUtf32(char const *s, unsigned int *read)
  23. {
  24. return cucul_utf8_to_utf32(s, read);
  25. }
  26. unsigned int Charset::utf32ToUtf8(char *buf, unsigned long int ch)
  27. {
  28. return cucul_utf32_to_utf8(buf, ch);
  29. }
  30. unsigned char Charset::utf32ToCp437(unsigned long int ch)
  31. {
  32. return cucul_utf32_to_cp437(ch);
  33. }
  34. unsigned long int Charset::cp437ToUtf32(unsigned char ch)
  35. {
  36. return cucul_cp437_to_utf32(ch);
  37. }
  38. Cucul::Cucul()
  39. {
  40. cv = cucul_create_canvas(0, 0);
  41. if(!cv)
  42. throw -1;
  43. }
  44. Cucul::Cucul(int width, int height)
  45. {
  46. cv = cucul_create_canvas(width, height);
  47. if(!cv) throw -1;
  48. }
  49. Cucul::~Cucul()
  50. {
  51. if(cv)
  52. cucul_free_canvas(cv);
  53. }
  54. cucul_canvas_t *Cucul::get_cucul_canvas_t()
  55. {
  56. return cv;
  57. }
  58. void Cucul::setSize(unsigned int width, unsigned int height)
  59. {
  60. cucul_set_canvas_size(cv, width, height);
  61. }
  62. unsigned int Cucul::getWidth(void)
  63. {
  64. return cucul_get_canvas_width(cv);
  65. }
  66. unsigned int Cucul::getHeight(void)
  67. {
  68. return cucul_get_canvas_height(cv);
  69. }
  70. int Cucul::setColorANSI(unsigned char f, unsigned char b)
  71. {
  72. return cucul_set_color_ansi(cv, f, b);
  73. }
  74. int Cucul::setColorARGB(unsigned int f, unsigned int b)
  75. {
  76. return cucul_set_color_argb(cv, f, b);
  77. }
  78. void Cucul::putChar(int x, int y, unsigned long int ch)
  79. {
  80. cucul_put_char(cv, x, y, ch);
  81. }
  82. unsigned long int Cucul::getChar(int x, int y)
  83. {
  84. return cucul_get_char(cv, x, y);
  85. }
  86. void Cucul::putStr(int x, int y, char *str)
  87. {
  88. cucul_put_str(cv, x, y, str);
  89. }
  90. void Cucul::Printf(int x, int y, char const * format, ...)
  91. {
  92. char tmp[BUFSIZ];
  93. char *buf = tmp;
  94. va_list args;
  95. va_start(args, format);
  96. #if defined(HAVE_VSNPRINTF)
  97. vsnprintf(buf, getWidth() - x + 1, format, args);
  98. #else
  99. vsprintf(buf, format, args);
  100. #endif
  101. buf[getWidth() - x] = '\0';
  102. va_end(args);
  103. putStr(x, y, buf);
  104. }
  105. void Cucul::Clear(void)
  106. {
  107. cucul_clear_canvas(cv);
  108. }
  109. void Cucul::Blit(int x, int y, Cucul* c1, Cucul* c2)
  110. {
  111. cucul_blit(cv, x, y, c1->get_cucul_canvas_t(),
  112. c2 ? c2->get_cucul_canvas_t() : NULL);
  113. }
  114. void Cucul::Invert()
  115. {
  116. cucul_invert(cv);
  117. }
  118. void Cucul::Flip()
  119. {
  120. cucul_flip(cv);
  121. }
  122. void Cucul::Flop()
  123. {
  124. cucul_flop(cv);
  125. }
  126. void Cucul::Rotate()
  127. {
  128. cucul_rotate_180(cv);
  129. }
  130. void Cucul::drawLine(int x1, int y1, int x2, int y2, unsigned long int ch)
  131. {
  132. cucul_draw_line(cv, x1, y1, x2, y2, ch);
  133. }
  134. void Cucul::drawPolyline(int const x[], int const y[], int f, unsigned long int ch)
  135. {
  136. cucul_draw_polyline(cv, x, y, f, ch);
  137. }
  138. void Cucul::drawThinLine(int x1, int y1, int x2, int y2)
  139. {
  140. cucul_draw_thin_line(cv, x1, y1, x2, y2);
  141. }
  142. void Cucul::drawThinPolyline(int const x[], int const y[], int f)
  143. {
  144. cucul_draw_thin_polyline(cv, x, y, f);
  145. }
  146. void Cucul::drawCircle(int x, int y, int d, unsigned long int ch)
  147. {
  148. cucul_draw_circle(cv, x, y, d, ch);
  149. }
  150. void Cucul::drawEllipse(int x, int y, int d1, int d2, unsigned long int ch)
  151. {
  152. cucul_draw_ellipse(cv, x, y, d1, d2, ch);
  153. }
  154. void Cucul::drawThinEllipse(int x, int y, int d1, int d2)
  155. {
  156. cucul_draw_thin_ellipse(cv, x, y, d1, d2);
  157. }
  158. void Cucul::fillEllipse(int x, int y, int d1, int d2, unsigned long int ch)
  159. {
  160. cucul_fill_ellipse(cv, x, y, d1, d2, ch);
  161. }
  162. void Cucul::drawBox(int x, int y, int w, int h, unsigned long int ch)
  163. {
  164. cucul_draw_box(cv, x, y, w, h, ch);
  165. }
  166. void Cucul::drawThinBox(int x, int y, int w, int h)
  167. {
  168. cucul_draw_thin_box(cv, x, y, w, h);
  169. }
  170. void Cucul::drawCP437Box(int x, int y, int w, int h)
  171. {
  172. cucul_draw_cp437_box(cv, x, y, w, h);
  173. }
  174. void Cucul::fillBox(int x, int y, int w, int h, unsigned long int 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, unsigned long int 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, unsigned long int 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_frame_count(cv);
  210. }
  211. int Cucul::setFrame(unsigned int f)
  212. {
  213. return cucul_set_frame(cv, f);
  214. }
  215. int Cucul::createFrame(unsigned int f)
  216. {
  217. return cucul_create_frame(cv, f);
  218. }
  219. int Cucul::freeFrame(unsigned int f)
  220. {
  221. return cucul_create_frame(cv, f);
  222. }
  223. char const *const * Cucul::getImportList(void)
  224. {
  225. return cucul_get_import_list();
  226. }
  227. long int Cucul::importMemory(void const *buf, unsigned long int len, char const *fmt)
  228. {
  229. return cucul_import_memory(cv, buf, len, fmt);
  230. }
  231. long int Cucul::importFile(char const *file, char const *fmt)
  232. {
  233. return cucul_import_file(cv, file, fmt);
  234. }
  235. char const *const * Cucul::getExportList(void)
  236. {
  237. return cucul_get_export_list();
  238. }
  239. void *Cucul::exportMemory(char const *fmt, unsigned long int *len)
  240. {
  241. return cucul_export_memory(cv, fmt, len);
  242. }
  243. 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)
  244. {
  245. dither = cucul_create_dither(v1, v2, v3, v4, v5, v6, v7, v8);
  246. }
  247. Dither::~Dither()
  248. {
  249. cucul_free_dither(dither);
  250. }
  251. void Dither::setPalette(unsigned int r[], unsigned int g[], unsigned int b[], unsigned int a[])
  252. {
  253. cucul_set_dither_palette(dither, r, g, b, a);
  254. }
  255. void Dither::setBrightness(float f)
  256. {
  257. cucul_set_dither_brightness(dither, f);
  258. }
  259. void Dither::setGamma(float f)
  260. {
  261. cucul_set_dither_gamma(dither, f);
  262. }
  263. void Dither::setContrast(float f)
  264. {
  265. cucul_set_dither_contrast(dither, f);
  266. }
  267. void Dither::setAntialias(char const *cv)
  268. {
  269. cucul_set_dither_antialias(dither, cv);
  270. }
  271. char const *const * Dither::getAntialiasList()
  272. {
  273. return cucul_get_dither_antialias_list(dither);
  274. }
  275. void Dither::setColor(char const *cv)
  276. {
  277. cucul_set_dither_color(dither, cv);
  278. }
  279. char const *const * Dither::getColorList()
  280. {
  281. return cucul_get_dither_color_list(dither);
  282. }
  283. void Dither::setCharset(char const *cv)
  284. {
  285. cucul_set_dither_charset(dither, cv);
  286. }
  287. char const *const * Dither::getCharsetList()
  288. {
  289. return cucul_get_dither_charset_list(dither);
  290. }
  291. void Dither::setMode(char const *cv)
  292. {
  293. cucul_set_dither_algorithm(dither, cv);
  294. }
  295. char const *const * Dither::getModeList(void)
  296. {
  297. return cucul_get_dither_algorithm_list(dither);
  298. }
  299. void Dither::Bitmap(Cucul *cv, int x, int y, int w, int h, void *v)
  300. {
  301. cucul_dither_bitmap(cv->get_cucul_canvas_t(), x, y, w, h, dither, v);
  302. }
  303. Font::Font(void const *s, unsigned int v)
  304. {
  305. font = cucul_load_font(s, v);
  306. if(!font) throw -1;
  307. }
  308. char const *const * Font::getList(void)
  309. {
  310. return cucul_get_font_list();
  311. }
  312. unsigned int Font::getWidth()
  313. {
  314. return cucul_get_font_width(font);
  315. }
  316. unsigned int Font::getHeight()
  317. {
  318. return cucul_get_font_height(font);
  319. }
  320. void Font::renderCanvas(Cucul *cv, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
  321. {
  322. cucul_render_canvas(cv->get_cucul_canvas_t(), font, buf, x, y, w);
  323. }
  324. unsigned long int const *Font::getBlocks()
  325. {
  326. return cucul_get_font_blocks(font);
  327. }
  328. Font::~Font()
  329. {
  330. cucul_free_font(font);
  331. }