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.
 
 
 
 
 
 

685 lines
25 KiB

  1. /*
  2. * libcaca .NET bindings for libcaca
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * 2007-2009 Sam Hocevar <sam@hocevar.net>
  5. * All Rights Reserved
  6. *
  7. * $Id$
  8. *
  9. * This library is free software. It comes without any warranty, to
  10. * the extent permitted by applicable law. You can redistribute it
  11. * and/or modify it under the terms of the Do What The Fuck You Want
  12. * To Public License, Version 2, as published by Sam Hocevar. See
  13. * http://sam.zoy.org/wtfpl/COPYING for more details.
  14. */
  15. using System;
  16. using System.Runtime.InteropServices;
  17. using System.Security;
  18. using System.Drawing;
  19. namespace Caca
  20. {
  21. public enum AnsiColor
  22. {
  23. BLACK = 0x00,
  24. BLUE = 0x01,
  25. GREEN = 0x02,
  26. CYAN = 0x03,
  27. RED = 0x04,
  28. MAGENTA = 0x05,
  29. BROWN = 0x06,
  30. LIGHTGRAY = 0x07,
  31. DARKGRAY = 0x08,
  32. LIGHTBLUE = 0x09,
  33. LIGHTGREEN = 0x0a,
  34. LIGHTCYAN = 0x0b,
  35. LIGHTRED = 0x0c,
  36. LIGHTMAGENTA = 0x0d,
  37. YELLOW = 0x0e,
  38. WHITE = 0x0f,
  39. DEFAULT = 0x10,
  40. TRANSPARENT = 0x20,
  41. }
  42. public enum AnsiStyle
  43. {
  44. BOLD = 0x01,
  45. ITALICS = 0x02,
  46. UNDERLINE = 0x04,
  47. BLINK = 0x08,
  48. }
  49. public class Canvas : IDisposable
  50. {
  51. public readonly IntPtr _c_cv;
  52. /* libcaca basic functions */
  53. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  54. SuppressUnmanagedCodeSecurity]
  55. private static extern IntPtr caca_create_canvas(int w, int h);
  56. public Canvas()
  57. {
  58. _c_cv = caca_create_canvas(0, 0);
  59. }
  60. public Canvas(Size s)
  61. {
  62. _c_cv = caca_create_canvas(s.Width, s.Height);
  63. }
  64. public Canvas(int w, int h)
  65. {
  66. _c_cv = caca_create_canvas(h, w);
  67. }
  68. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  69. SuppressUnmanagedCodeSecurity]
  70. private static extern int caca_free_canvas(IntPtr cv);
  71. public void Dispose()
  72. {
  73. /* FIXME: don't destroy ourselves if we're attached */
  74. caca_free_canvas(_c_cv);
  75. GC.SuppressFinalize(this);
  76. }
  77. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  78. SuppressUnmanagedCodeSecurity]
  79. private static extern int caca_set_canvas_size(IntPtr cv,
  80. int w, int h);
  81. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  82. SuppressUnmanagedCodeSecurity]
  83. private static extern int caca_get_canvas_width(IntPtr cv);
  84. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  85. SuppressUnmanagedCodeSecurity]
  86. private static extern int caca_get_canvas_height(IntPtr cv);
  87. public Size Size
  88. {
  89. get { return new Size(caca_get_canvas_width(_c_cv),
  90. caca_get_canvas_height(_c_cv)); }
  91. set { caca_set_canvas_size(_c_cv, value.Width, value.Height); }
  92. }
  93. public Rectangle Rectangle
  94. {
  95. get { return new Rectangle(0, 0, caca_get_canvas_width(_c_cv),
  96. caca_get_canvas_height(_c_cv)); }
  97. set { caca_set_canvas_size(_c_cv, value.Width, value.Height); }
  98. }
  99. /* canvas drawing */
  100. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  101. SuppressUnmanagedCodeSecurity]
  102. private static extern int caca_gotoxy(IntPtr cv, int x, int y);
  103. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  104. SuppressUnmanagedCodeSecurity]
  105. private static extern int caca_wherex(IntPtr cv);
  106. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  107. SuppressUnmanagedCodeSecurity]
  108. private static extern int caca_wherey(IntPtr cv);
  109. public Point Cursor
  110. {
  111. get { return new Point(caca_wherex(_c_cv), caca_wherey(_c_cv)); }
  112. set { caca_gotoxy(_c_cv, value.X, value.Y); }
  113. }
  114. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  115. SuppressUnmanagedCodeSecurity]
  116. private static extern int caca_put_char(IntPtr cv,
  117. int x, int y, uint c);
  118. public int putChar(Point p, uint c)
  119. {
  120. return caca_put_char(_c_cv, p.X, p.Y, c);
  121. }
  122. public int putChar(int x, int y, uint c)
  123. {
  124. return caca_put_char(_c_cv, x, y, c);
  125. }
  126. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  127. SuppressUnmanagedCodeSecurity]
  128. private static extern uint caca_get_char(IntPtr cv, int x, int y);
  129. public uint getChar(Point p)
  130. {
  131. return caca_get_char(_c_cv, p.X, p.Y);
  132. }
  133. public uint getChar(int x, int y)
  134. {
  135. return caca_get_char(_c_cv, x, y);
  136. }
  137. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  138. SuppressUnmanagedCodeSecurity]
  139. private static extern int caca_put_str(IntPtr cv,
  140. int x, int y, string c);
  141. public int putStr(Point p, string c)
  142. {
  143. return caca_put_str(_c_cv, p.X, p.Y, c);
  144. }
  145. public int putStr(int x, int y, string c)
  146. {
  147. return caca_put_str(_c_cv, x, y, c);
  148. }
  149. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  150. SuppressUnmanagedCodeSecurity]
  151. private static extern int caca_get_attr(IntPtr cv, int x, int y);
  152. public int getAttr(Point p)
  153. {
  154. return caca_get_attr(_c_cv, p.X, p.Y);
  155. }
  156. public int getAttr(int x, int y)
  157. {
  158. return caca_get_attr(_c_cv, x, y);
  159. }
  160. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  161. SuppressUnmanagedCodeSecurity]
  162. private static extern int caca_set_attr(IntPtr cv, uint a);
  163. public int setAttr(uint a)
  164. {
  165. return caca_set_attr(_c_cv, a);
  166. }
  167. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  168. SuppressUnmanagedCodeSecurity]
  169. private static extern int caca_put_attr(IntPtr cv,
  170. int x, int y, uint a);
  171. public int putAttr(Point p, uint a)
  172. {
  173. return caca_put_attr(_c_cv, p.X, p.Y, a);
  174. }
  175. public int putAttr(int x, int y, uint a)
  176. {
  177. return caca_put_attr(_c_cv, x, y, a);
  178. }
  179. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  180. SuppressUnmanagedCodeSecurity]
  181. private static extern int caca_set_color_ansi(IntPtr cv,
  182. byte fg, byte bg);
  183. public int setColorAnsi(AnsiColor fg, AnsiColor bg)
  184. {
  185. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  186. }
  187. public int setColorAnsi(uint fg, AnsiColor bg)
  188. {
  189. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  190. }
  191. public int setColorAnsi(AnsiColor fg, uint bg)
  192. {
  193. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  194. }
  195. public int setColorAnsi(uint fg, uint bg)
  196. {
  197. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  198. }
  199. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  200. SuppressUnmanagedCodeSecurity]
  201. private static extern int caca_set_color_argb(IntPtr cv,
  202. uint fg, uint bg);
  203. public int setColorArgb(uint fg, uint bg)
  204. {
  205. return caca_set_color_argb(_c_cv, fg, bg);
  206. }
  207. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  208. SuppressUnmanagedCodeSecurity]
  209. private static extern int caca_clear_canvas(IntPtr cv);
  210. public int Clear()
  211. {
  212. return caca_clear_canvas(_c_cv);
  213. }
  214. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  215. SuppressUnmanagedCodeSecurity]
  216. private static extern int caca_set_canvas_handle(IntPtr cv,
  217. int x, int y);
  218. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  219. SuppressUnmanagedCodeSecurity]
  220. private static extern int caca_get_canvas_handle_x(IntPtr cv);
  221. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  222. SuppressUnmanagedCodeSecurity]
  223. private static extern int caca_get_canvas_handle_y(IntPtr cv);
  224. public Point Handle
  225. {
  226. get { return new Point(caca_get_canvas_handle_x(_c_cv),
  227. caca_get_canvas_handle_y(_c_cv)); }
  228. set { caca_set_canvas_handle(_c_cv, value.X, value.Y); }
  229. }
  230. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  231. SuppressUnmanagedCodeSecurity]
  232. private static extern int caca_blit(IntPtr cv, int x, int y,
  233. IntPtr cv1, IntPtr cv2);
  234. public int Blit(Point p, Canvas canvas)
  235. {
  236. return caca_blit(_c_cv, p.X, p.Y, canvas._c_cv, IntPtr.Zero);
  237. }
  238. public int Blit(Point p, Canvas cv, Canvas mask)
  239. {
  240. return caca_blit(_c_cv, p.X, p.Y, cv._c_cv, mask._c_cv);
  241. }
  242. public int Blit(int x, int y, Canvas canvas)
  243. {
  244. return caca_blit(_c_cv, x, y, canvas._c_cv, IntPtr.Zero);
  245. }
  246. public int Blit(int x, int y, Canvas cv, Canvas mask)
  247. {
  248. return caca_blit(_c_cv, x, y, cv._c_cv, mask._c_cv);
  249. }
  250. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  251. SuppressUnmanagedCodeSecurity]
  252. private static extern int caca_set_canvas_boundaries(IntPtr cv,
  253. int x, int y,
  254. int h, int w);
  255. public int setBoundaries(Rectangle r)
  256. {
  257. return caca_set_canvas_boundaries(_c_cv, r.X, r.Y,
  258. r.Width, r.Height);
  259. }
  260. public int setBoundaries(int x, int y, int w, int h)
  261. {
  262. return caca_set_canvas_boundaries(_c_cv, x, y, w, h);
  263. }
  264. /* canvas transformation */
  265. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  266. SuppressUnmanagedCodeSecurity]
  267. private static extern int caca_invert(IntPtr cv);
  268. public int Invert()
  269. {
  270. return caca_invert(_c_cv);
  271. }
  272. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  273. SuppressUnmanagedCodeSecurity]
  274. private static extern int caca_flip(IntPtr cv);
  275. public int Flip()
  276. {
  277. return caca_flip(_c_cv);
  278. }
  279. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  280. SuppressUnmanagedCodeSecurity]
  281. private static extern int caca_flop(IntPtr cv);
  282. public int Flop()
  283. {
  284. return caca_flop(_c_cv);
  285. }
  286. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  287. SuppressUnmanagedCodeSecurity]
  288. private static extern int caca_rotate_180(IntPtr cv);
  289. public int Rotate180()
  290. {
  291. return caca_rotate_180(_c_cv);
  292. }
  293. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  294. SuppressUnmanagedCodeSecurity]
  295. private static extern int caca_rotate_left(IntPtr cv);
  296. public int RotateLeft()
  297. {
  298. return caca_rotate_left(_c_cv);
  299. }
  300. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  301. SuppressUnmanagedCodeSecurity]
  302. private static extern int caca_rotate_right(IntPtr cv);
  303. public int RotateRight()
  304. {
  305. return caca_rotate_right(_c_cv);
  306. }
  307. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  308. SuppressUnmanagedCodeSecurity]
  309. private static extern int caca_stretch_left(IntPtr cv);
  310. public int StretchLeft()
  311. {
  312. return caca_stretch_left(_c_cv);
  313. }
  314. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  315. SuppressUnmanagedCodeSecurity]
  316. private static extern int caca_stretch_right(IntPtr cv);
  317. public int StretchRight()
  318. {
  319. return caca_stretch_right(_c_cv);
  320. }
  321. /* primitives drawing */
  322. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  323. SuppressUnmanagedCodeSecurity]
  324. private static extern int caca_draw_line(IntPtr cv, int x1, int y1,
  325. int x2, int y2, uint c);
  326. public int drawLine(Point p1, Point p2, uint c)
  327. {
  328. return caca_draw_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y, c);
  329. }
  330. public int drawLine(int x1, int y1, int x2, int y2, uint c)
  331. {
  332. return caca_draw_line(_c_cv, x1, y1, x2, y2, c);
  333. }
  334. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  335. SuppressUnmanagedCodeSecurity]
  336. private static extern int caca_draw_polyline(IntPtr cv, int[] x,
  337. int[] y, int n, uint c);
  338. public int drawPolyline(Point[] lp, uint c)
  339. {
  340. int[] lx = new int[lp.Length];
  341. int[] ly = new int[lp.Length];
  342. for(int i = 0; i < lp.Length; i++)
  343. {
  344. lx[i] = lp[i].X;
  345. ly[i] = lp[i].Y;
  346. }
  347. return caca_draw_polyline(_c_cv, lx, ly, lp.Length - 1, c);
  348. }
  349. public int drawPolyline(int[] lx, int[] ly, uint c)
  350. {
  351. if(lx.Length != ly.Length)
  352. return -1;
  353. return caca_draw_polyline(_c_cv, lx, ly, lx.Length - 1, c);
  354. }
  355. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  356. SuppressUnmanagedCodeSecurity]
  357. private static extern int caca_draw_thin_line(IntPtr cv, int x1,
  358. int y1, int x2, int y2);
  359. public int drawThinLine(Point p1, Point p2)
  360. {
  361. return caca_draw_thin_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y);
  362. }
  363. public int drawThinLine(int x1, int y1, int x2, int y2)
  364. {
  365. return caca_draw_thin_line(_c_cv, x1, y1, x2, y2);
  366. }
  367. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  368. SuppressUnmanagedCodeSecurity]
  369. private static extern int caca_draw_thin_polyline(IntPtr cv, int[] x,
  370. int[] y, int n);
  371. public int drawThinPolyline(Point[] lp)
  372. {
  373. int[] lx = new int[lp.Length];
  374. int[] ly = new int[lp.Length];
  375. for(int i = 0; i < lp.Length; i++)
  376. {
  377. lx[i] = lp[i].X;
  378. ly[i] = lp[i].Y;
  379. }
  380. return caca_draw_thin_polyline(_c_cv, lx, ly, lp.Length - 1);
  381. }
  382. public int drawThinPolyline(int[] lx, int[] ly)
  383. {
  384. if(lx.Length != ly.Length)
  385. return -1;
  386. return caca_draw_thin_polyline(_c_cv, lx, ly, lx.Length - 1);
  387. }
  388. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  389. SuppressUnmanagedCodeSecurity]
  390. private static extern int caca_draw_circle(IntPtr cv, int x, int y,
  391. int r, uint c);
  392. public int drawCircle(Point p, int r, uint c)
  393. {
  394. return caca_draw_circle(_c_cv, p.X, p.Y, r, c);
  395. }
  396. public int drawCircle(int x, int y, int r, uint c)
  397. {
  398. return caca_draw_circle(_c_cv, x, y, r, c);
  399. }
  400. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  401. SuppressUnmanagedCodeSecurity]
  402. private static extern int caca_draw_ellipse(IntPtr cv, int x, int y,
  403. int a, int b, uint c);
  404. public int drawEllipse(Point p, int a, int b, uint c)
  405. {
  406. return caca_draw_ellipse(_c_cv, p.X, p.Y, a, b, c);
  407. }
  408. public int drawEllipse(int x, int y, int a, int b, uint c)
  409. {
  410. return caca_draw_ellipse(_c_cv, x, y, a, b, c);
  411. }
  412. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  413. SuppressUnmanagedCodeSecurity]
  414. private static extern int caca_draw_thin_ellipse(IntPtr cv,
  415. int x, int y,
  416. int a, int b);
  417. public int drawThinEllipse(Point p, int a, int b)
  418. {
  419. return caca_draw_thin_ellipse(_c_cv, p.X, p.Y, a, b);
  420. }
  421. public int drawThinEllipse(int x, int y, int a, int b)
  422. {
  423. return caca_draw_thin_ellipse(_c_cv, x, y, a, b);
  424. }
  425. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  426. SuppressUnmanagedCodeSecurity]
  427. private static extern int caca_fill_ellipse(IntPtr cv, int x, int y,
  428. int a, int b, uint c);
  429. public int fillEllipse(Point p, int a, int b, uint c)
  430. {
  431. return caca_fill_ellipse(_c_cv, p.X, p.Y, a, b, c);
  432. }
  433. public int fillEllipse(int x, int y, int a, int b, uint c)
  434. {
  435. return caca_fill_ellipse(_c_cv, x, y, a, b, c);
  436. }
  437. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  438. SuppressUnmanagedCodeSecurity]
  439. private static extern int caca_draw_box(IntPtr cv, int x, int y,
  440. int w, int h, uint c);
  441. public int drawBox(Rectangle r, uint c)
  442. {
  443. return caca_draw_box(_c_cv, r.X, r.Y, r.Width, r.Height, c);
  444. }
  445. public int drawBox(int x, int y, int w, int h, uint c)
  446. {
  447. return caca_draw_box(_c_cv, x, y, w, h, c);
  448. }
  449. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  450. SuppressUnmanagedCodeSecurity]
  451. private static extern int caca_draw_thin_box(IntPtr cv, int x, int y,
  452. int w, int h);
  453. public int drawThinBox(Rectangle r)
  454. {
  455. return caca_draw_thin_box(_c_cv, r.X, r.Y, r.Width, r.Height);
  456. }
  457. public int drawThinBox(int x, int y, int w, int h)
  458. {
  459. return caca_draw_thin_box(_c_cv, x, y, w, h);
  460. }
  461. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  462. SuppressUnmanagedCodeSecurity]
  463. private static extern int caca_draw_cp437_box(IntPtr cv, int x, int y,
  464. int w, int h);
  465. public int drawCp437Box(Rectangle r)
  466. {
  467. return caca_draw_cp437_box(_c_cv, r.X, r.Y, r.Width, r.Height);
  468. }
  469. public int drawCp437Box(int x, int y, int w, int h)
  470. {
  471. return caca_draw_cp437_box(_c_cv, x, y, w, h);
  472. }
  473. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  474. SuppressUnmanagedCodeSecurity]
  475. private static extern int caca_fill_box(IntPtr cv, int x, int y,
  476. int w, int h, uint c);
  477. public int fillBox(Rectangle r, uint c)
  478. {
  479. return caca_fill_box(_c_cv, r.X, r.Y, r.Width, r.Height, c);
  480. }
  481. public int fillBox(int x, int y, int w, int h, uint c)
  482. {
  483. return caca_fill_box(_c_cv, x, y, w, h, c);
  484. }
  485. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  486. SuppressUnmanagedCodeSecurity]
  487. private static extern int caca_draw_triangle(IntPtr cv, int x1,
  488. int y1, int x2, int y2,
  489. int x3, int y3, uint c);
  490. public int drawTriangle(Point p1, Point p2, Point p3, uint c)
  491. {
  492. return caca_draw_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
  493. p3.X, p3.Y, c);
  494. }
  495. public int drawTriangle(int x1, int y1, int x2, int y2,
  496. int x3, int y3, uint c)
  497. {
  498. return caca_draw_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c);
  499. }
  500. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  501. SuppressUnmanagedCodeSecurity]
  502. private static extern int caca_draw_thin_triangle(IntPtr cv,
  503. int x1, int y1,
  504. int x2, int y2,
  505. int x3, int y3);
  506. public int drawThinTriangle(Point p1, Point p2, Point p3)
  507. {
  508. return caca_draw_thin_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
  509. p3.X, p3.Y);
  510. }
  511. public int drawThinTriangle(int x1, int y1, int x2, int y2,
  512. int x3, int y3)
  513. {
  514. return caca_draw_thin_triangle(_c_cv, x1, y1, x2, y2, x3, y3);
  515. }
  516. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  517. SuppressUnmanagedCodeSecurity]
  518. private static extern int caca_fill_triangle(IntPtr cv, int x1,
  519. int y1, int x2, int y2,
  520. int x3, int y3, uint c);
  521. public int fillTriangle(Point p1, Point p2, Point p3, uint c)
  522. {
  523. return caca_fill_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
  524. p3.X, p3.Y, c);
  525. }
  526. public int fillTriangle(int x1, int y1, int x2, int y2,
  527. int x3, int y3, uint c)
  528. {
  529. return caca_fill_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c);
  530. }
  531. /* frame handling */
  532. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  533. SuppressUnmanagedCodeSecurity]
  534. private static extern int caca_get_frame_count(IntPtr cv);
  535. public int getFrameCount()
  536. {
  537. return caca_get_frame_count(_c_cv);
  538. }
  539. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  540. SuppressUnmanagedCodeSecurity]
  541. private static extern int caca_set_frame(IntPtr cv, int f);
  542. public int setFrame(int f)
  543. {
  544. return caca_set_frame(_c_cv, f);
  545. }
  546. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  547. SuppressUnmanagedCodeSecurity]
  548. private static extern string caca_get_frame_name(IntPtr cv);
  549. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  550. SuppressUnmanagedCodeSecurity]
  551. private static extern int caca_set_frame_name(IntPtr cv, string n);
  552. public string FrameName
  553. {
  554. get { return caca_get_frame_name(_c_cv); }
  555. set { caca_set_frame_name(_c_cv, value); }
  556. }
  557. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  558. SuppressUnmanagedCodeSecurity]
  559. private static extern int caca_create_frame(IntPtr cv, int f);
  560. public int createFrame(int f)
  561. {
  562. return caca_create_frame(_c_cv, f);
  563. }
  564. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  565. SuppressUnmanagedCodeSecurity]
  566. private static extern int caca_free_frame(IntPtr cv, int f);
  567. public int freeFrame(int f)
  568. {
  569. return caca_free_frame(_c_cv, f);
  570. }
  571. /* bitmap dithering */
  572. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  573. SuppressUnmanagedCodeSecurity]
  574. private static extern int caca_dither_bitmap(IntPtr c, int x, int y,
  575. int w, int h,
  576. IntPtr d, IntPtr data);
  577. public int ditherBitmap(Rectangle r, Dither d, object data)
  578. {
  579. GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
  580. int ret = caca_dither_bitmap(_c_cv, r.X, r.Y, r.Width, r.Height,
  581. d._dither, gch.AddrOfPinnedObject());
  582. gch.Free();
  583. return ret;
  584. }
  585. public int ditherBitmap(int x, int y, int w, int h,
  586. Dither d, object data)
  587. {
  588. GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
  589. int ret = caca_dither_bitmap(_c_cv, x, y, w, h, d._dither,
  590. gch.AddrOfPinnedObject());
  591. gch.Free();
  592. return ret;
  593. }
  594. }
  595. }