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.
 
 
 
 
 
 

686 lines
25 KiB

  1. /*
  2. * libcaca .NET bindings for libcaca
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * 2007 Sam Hocevar <sam@zoy.org>
  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_get_cursor_x(IntPtr cv);
  106. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  107. SuppressUnmanagedCodeSecurity]
  108. private static extern int caca_get_cursor_y(IntPtr cv);
  109. public Point Cursor
  110. {
  111. get { return new Point(caca_get_cursor_x(_c_cv),
  112. caca_get_cursor_y(_c_cv)); }
  113. set { caca_gotoxy(_c_cv, value.X, value.Y); }
  114. }
  115. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  116. SuppressUnmanagedCodeSecurity]
  117. private static extern int caca_put_char(IntPtr cv,
  118. int x, int y, uint c);
  119. public int putChar(Point p, uint c)
  120. {
  121. return caca_put_char(_c_cv, p.X, p.Y, c);
  122. }
  123. public int putChar(int x, int y, uint c)
  124. {
  125. return caca_put_char(_c_cv, x, y, c);
  126. }
  127. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  128. SuppressUnmanagedCodeSecurity]
  129. private static extern uint caca_get_char(IntPtr cv, int x, int y);
  130. public uint getChar(Point p)
  131. {
  132. return caca_get_char(_c_cv, p.X, p.Y);
  133. }
  134. public uint getChar(int x, int y)
  135. {
  136. return caca_get_char(_c_cv, x, y);
  137. }
  138. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  139. SuppressUnmanagedCodeSecurity]
  140. private static extern int caca_put_str(IntPtr cv,
  141. int x, int y, string c);
  142. public int putStr(Point p, string c)
  143. {
  144. return caca_put_str(_c_cv, p.X, p.Y, c);
  145. }
  146. public int putStr(int x, int y, string c)
  147. {
  148. return caca_put_str(_c_cv, x, y, c);
  149. }
  150. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  151. SuppressUnmanagedCodeSecurity]
  152. private static extern int caca_get_attr(IntPtr cv, int x, int y);
  153. public int getAttr(Point p)
  154. {
  155. return caca_get_attr(_c_cv, p.X, p.Y);
  156. }
  157. public int getAttr(int x, int y)
  158. {
  159. return caca_get_attr(_c_cv, x, y);
  160. }
  161. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  162. SuppressUnmanagedCodeSecurity]
  163. private static extern int caca_set_attr(IntPtr cv, uint a);
  164. public int setAttr(uint a)
  165. {
  166. return caca_set_attr(_c_cv, a);
  167. }
  168. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  169. SuppressUnmanagedCodeSecurity]
  170. private static extern int caca_put_attr(IntPtr cv,
  171. int x, int y, uint a);
  172. public int putAttr(Point p, uint a)
  173. {
  174. return caca_put_attr(_c_cv, p.X, p.Y, a);
  175. }
  176. public int putAttr(int x, int y, uint a)
  177. {
  178. return caca_put_attr(_c_cv, x, y, a);
  179. }
  180. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  181. SuppressUnmanagedCodeSecurity]
  182. private static extern int caca_set_color_ansi(IntPtr cv,
  183. byte fg, byte bg);
  184. public int setColorAnsi(AnsiColor fg, AnsiColor bg)
  185. {
  186. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  187. }
  188. public int setColorAnsi(uint fg, AnsiColor bg)
  189. {
  190. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  191. }
  192. public int setColorAnsi(AnsiColor fg, uint bg)
  193. {
  194. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  195. }
  196. public int setColorAnsi(uint fg, uint bg)
  197. {
  198. return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
  199. }
  200. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  201. SuppressUnmanagedCodeSecurity]
  202. private static extern int caca_set_color_argb(IntPtr cv,
  203. uint fg, uint bg);
  204. public int setColorArgb(uint fg, uint bg)
  205. {
  206. return caca_set_color_argb(_c_cv, fg, bg);
  207. }
  208. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  209. SuppressUnmanagedCodeSecurity]
  210. private static extern int caca_clear_canvas(IntPtr cv);
  211. public int Clear()
  212. {
  213. return caca_clear_canvas(_c_cv);
  214. }
  215. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  216. SuppressUnmanagedCodeSecurity]
  217. private static extern int caca_set_canvas_handle(IntPtr cv,
  218. int x, int y);
  219. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  220. SuppressUnmanagedCodeSecurity]
  221. private static extern int caca_get_canvas_handle_x(IntPtr cv);
  222. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  223. SuppressUnmanagedCodeSecurity]
  224. private static extern int caca_get_canvas_handle_y(IntPtr cv);
  225. public Point Handle
  226. {
  227. get { return new Point(caca_get_canvas_handle_x(_c_cv),
  228. caca_get_canvas_handle_y(_c_cv)); }
  229. set { caca_set_canvas_handle(_c_cv, value.X, value.Y); }
  230. }
  231. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  232. SuppressUnmanagedCodeSecurity]
  233. private static extern int caca_blit(IntPtr cv, int x, int y,
  234. IntPtr cv1, IntPtr cv2);
  235. public int Blit(Point p, Canvas canvas)
  236. {
  237. return caca_blit(_c_cv, p.X, p.Y, canvas._c_cv, IntPtr.Zero);
  238. }
  239. public int Blit(Point p, Canvas cv, Canvas mask)
  240. {
  241. return caca_blit(_c_cv, p.X, p.Y, cv._c_cv, mask._c_cv);
  242. }
  243. public int Blit(int x, int y, Canvas canvas)
  244. {
  245. return caca_blit(_c_cv, x, y, canvas._c_cv, IntPtr.Zero);
  246. }
  247. public int Blit(int x, int y, Canvas cv, Canvas mask)
  248. {
  249. return caca_blit(_c_cv, x, y, cv._c_cv, mask._c_cv);
  250. }
  251. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  252. SuppressUnmanagedCodeSecurity]
  253. private static extern int caca_set_canvas_boundaries(IntPtr cv,
  254. int x, int y,
  255. int h, int w);
  256. public int setBoundaries(Rectangle r)
  257. {
  258. return caca_set_canvas_boundaries(_c_cv, r.X, r.Y,
  259. r.Width, r.Height);
  260. }
  261. public int setBoundaries(int x, int y, int w, int h)
  262. {
  263. return caca_set_canvas_boundaries(_c_cv, x, y, w, h);
  264. }
  265. /* canvas transformation */
  266. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  267. SuppressUnmanagedCodeSecurity]
  268. private static extern int caca_invert(IntPtr cv);
  269. public int Invert()
  270. {
  271. return caca_invert(_c_cv);
  272. }
  273. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  274. SuppressUnmanagedCodeSecurity]
  275. private static extern int caca_flip(IntPtr cv);
  276. public int Flip()
  277. {
  278. return caca_flip(_c_cv);
  279. }
  280. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  281. SuppressUnmanagedCodeSecurity]
  282. private static extern int caca_flop(IntPtr cv);
  283. public int Flop()
  284. {
  285. return caca_flop(_c_cv);
  286. }
  287. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  288. SuppressUnmanagedCodeSecurity]
  289. private static extern int caca_rotate_180(IntPtr cv);
  290. public int Rotate180()
  291. {
  292. return caca_rotate_180(_c_cv);
  293. }
  294. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  295. SuppressUnmanagedCodeSecurity]
  296. private static extern int caca_rotate_left(IntPtr cv);
  297. public int RotateLeft()
  298. {
  299. return caca_rotate_left(_c_cv);
  300. }
  301. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  302. SuppressUnmanagedCodeSecurity]
  303. private static extern int caca_rotate_right(IntPtr cv);
  304. public int RotateRight()
  305. {
  306. return caca_rotate_right(_c_cv);
  307. }
  308. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  309. SuppressUnmanagedCodeSecurity]
  310. private static extern int caca_stretch_left(IntPtr cv);
  311. public int StretchLeft()
  312. {
  313. return caca_stretch_left(_c_cv);
  314. }
  315. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  316. SuppressUnmanagedCodeSecurity]
  317. private static extern int caca_stretch_right(IntPtr cv);
  318. public int StretchRight()
  319. {
  320. return caca_stretch_right(_c_cv);
  321. }
  322. /* primitives drawing */
  323. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  324. SuppressUnmanagedCodeSecurity]
  325. private static extern int caca_draw_line(IntPtr cv, int x1, int y1,
  326. int x2, int y2, uint c);
  327. public int drawLine(Point p1, Point p2, uint c)
  328. {
  329. return caca_draw_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y, c);
  330. }
  331. public int drawLine(int x1, int y1, int x2, int y2, uint c)
  332. {
  333. return caca_draw_line(_c_cv, x1, y1, x2, y2, c);
  334. }
  335. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  336. SuppressUnmanagedCodeSecurity]
  337. private static extern int caca_draw_polyline(IntPtr cv, int[] x,
  338. int[] y, int n, uint c);
  339. public int drawPolyline(Point[] lp, uint c)
  340. {
  341. int[] lx = new int[lp.Length];
  342. int[] ly = new int[lp.Length];
  343. for(int i = 0; i < lp.Length; i++)
  344. {
  345. lx[i] = lp[i].X;
  346. ly[i] = lp[i].Y;
  347. }
  348. return caca_draw_polyline(_c_cv, lx, ly, lp.Length - 1, c);
  349. }
  350. public int drawPolyline(int[] lx, int[] ly, uint c)
  351. {
  352. if(lx.Length != ly.Length)
  353. return -1;
  354. return caca_draw_polyline(_c_cv, lx, ly, lx.Length - 1, c);
  355. }
  356. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  357. SuppressUnmanagedCodeSecurity]
  358. private static extern int caca_draw_thin_line(IntPtr cv, int x1,
  359. int y1, int x2, int y2);
  360. public int drawThinLine(Point p1, Point p2)
  361. {
  362. return caca_draw_thin_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y);
  363. }
  364. public int drawThinLine(int x1, int y1, int x2, int y2)
  365. {
  366. return caca_draw_thin_line(_c_cv, x1, y1, x2, y2);
  367. }
  368. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  369. SuppressUnmanagedCodeSecurity]
  370. private static extern int caca_draw_thin_polyline(IntPtr cv, int[] x,
  371. int[] y, int n);
  372. public int drawThinPolyline(Point[] lp)
  373. {
  374. int[] lx = new int[lp.Length];
  375. int[] ly = new int[lp.Length];
  376. for(int i = 0; i < lp.Length; i++)
  377. {
  378. lx[i] = lp[i].X;
  379. ly[i] = lp[i].Y;
  380. }
  381. return caca_draw_thin_polyline(_c_cv, lx, ly, lp.Length - 1);
  382. }
  383. public int drawThinPolyline(int[] lx, int[] ly)
  384. {
  385. if(lx.Length != ly.Length)
  386. return -1;
  387. return caca_draw_thin_polyline(_c_cv, lx, ly, lx.Length - 1);
  388. }
  389. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  390. SuppressUnmanagedCodeSecurity]
  391. private static extern int caca_draw_circle(IntPtr cv, int x, int y,
  392. int r, uint c);
  393. public int drawCircle(Point p, int r, uint c)
  394. {
  395. return caca_draw_circle(_c_cv, p.X, p.Y, r, c);
  396. }
  397. public int drawCircle(int x, int y, int r, uint c)
  398. {
  399. return caca_draw_circle(_c_cv, x, y, r, c);
  400. }
  401. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  402. SuppressUnmanagedCodeSecurity]
  403. private static extern int caca_draw_ellipse(IntPtr cv, int x, int y,
  404. int a, int b, uint c);
  405. public int drawEllipse(Point p, int a, int b, uint c)
  406. {
  407. return caca_draw_ellipse(_c_cv, p.X, p.Y, a, b, c);
  408. }
  409. public int drawEllipse(int x, int y, int a, int b, uint c)
  410. {
  411. return caca_draw_ellipse(_c_cv, x, y, a, b, c);
  412. }
  413. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  414. SuppressUnmanagedCodeSecurity]
  415. private static extern int caca_draw_thin_ellipse(IntPtr cv,
  416. int x, int y,
  417. int a, int b);
  418. public int drawThinEllipse(Point p, int a, int b)
  419. {
  420. return caca_draw_thin_ellipse(_c_cv, p.X, p.Y, a, b);
  421. }
  422. public int drawThinEllipse(int x, int y, int a, int b)
  423. {
  424. return caca_draw_thin_ellipse(_c_cv, x, y, a, b);
  425. }
  426. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  427. SuppressUnmanagedCodeSecurity]
  428. private static extern int caca_fill_ellipse(IntPtr cv, int x, int y,
  429. int a, int b, uint c);
  430. public int fillEllipse(Point p, int a, int b, uint c)
  431. {
  432. return caca_fill_ellipse(_c_cv, p.X, p.Y, a, b, c);
  433. }
  434. public int fillEllipse(int x, int y, int a, int b, uint c)
  435. {
  436. return caca_fill_ellipse(_c_cv, x, y, a, b, c);
  437. }
  438. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  439. SuppressUnmanagedCodeSecurity]
  440. private static extern int caca_draw_box(IntPtr cv, int x, int y,
  441. int w, int h, uint c);
  442. public int drawBox(Rectangle r, uint c)
  443. {
  444. return caca_draw_box(_c_cv, r.X, r.Y, r.Width, r.Height, c);
  445. }
  446. public int drawBox(int x, int y, int w, int h, uint c)
  447. {
  448. return caca_draw_box(_c_cv, x, y, w, h, c);
  449. }
  450. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  451. SuppressUnmanagedCodeSecurity]
  452. private static extern int caca_draw_thin_box(IntPtr cv, int x, int y,
  453. int w, int h);
  454. public int drawThinBox(Rectangle r)
  455. {
  456. return caca_draw_thin_box(_c_cv, r.X, r.Y, r.Width, r.Height);
  457. }
  458. public int drawThinBox(int x, int y, int w, int h)
  459. {
  460. return caca_draw_thin_box(_c_cv, x, y, w, h);
  461. }
  462. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  463. SuppressUnmanagedCodeSecurity]
  464. private static extern int caca_draw_cp437_box(IntPtr cv, int x, int y,
  465. int w, int h);
  466. public int drawCp437Box(Rectangle r)
  467. {
  468. return caca_draw_cp437_box(_c_cv, r.X, r.Y, r.Width, r.Height);
  469. }
  470. public int drawCp437Box(int x, int y, int w, int h)
  471. {
  472. return caca_draw_cp437_box(_c_cv, x, y, w, h);
  473. }
  474. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  475. SuppressUnmanagedCodeSecurity]
  476. private static extern int caca_fill_box(IntPtr cv, int x, int y,
  477. int w, int h, uint c);
  478. public int fillBox(Rectangle r, uint c)
  479. {
  480. return caca_fill_box(_c_cv, r.X, r.Y, r.Width, r.Height, c);
  481. }
  482. public int fillBox(int x, int y, int w, int h, uint c)
  483. {
  484. return caca_fill_box(_c_cv, x, y, w, h, c);
  485. }
  486. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  487. SuppressUnmanagedCodeSecurity]
  488. private static extern int caca_draw_triangle(IntPtr cv, int x1,
  489. int y1, int x2, int y2,
  490. int x3, int y3, uint c);
  491. public int drawTriangle(Point p1, Point p2, Point p3, uint c)
  492. {
  493. return caca_draw_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
  494. p3.X, p3.Y, c);
  495. }
  496. public int drawTriangle(int x1, int y1, int x2, int y2,
  497. int x3, int y3, uint c)
  498. {
  499. return caca_draw_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c);
  500. }
  501. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  502. SuppressUnmanagedCodeSecurity]
  503. private static extern int caca_draw_thin_triangle(IntPtr cv,
  504. int x1, int y1,
  505. int x2, int y2,
  506. int x3, int y3);
  507. public int drawThinTriangle(Point p1, Point p2, Point p3)
  508. {
  509. return caca_draw_thin_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
  510. p3.X, p3.Y);
  511. }
  512. public int drawThinTriangle(int x1, int y1, int x2, int y2,
  513. int x3, int y3)
  514. {
  515. return caca_draw_thin_triangle(_c_cv, x1, y1, x2, y2, x3, y3);
  516. }
  517. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  518. SuppressUnmanagedCodeSecurity]
  519. private static extern int caca_fill_triangle(IntPtr cv, int x1,
  520. int y1, int x2, int y2,
  521. int x3, int y3, uint c);
  522. public int fillTriangle(Point p1, Point p2, Point p3, uint c)
  523. {
  524. return caca_fill_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
  525. p3.X, p3.Y, c);
  526. }
  527. public int fillTriangle(int x1, int y1, int x2, int y2,
  528. int x3, int y3, uint c)
  529. {
  530. return caca_fill_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c);
  531. }
  532. /* frame handling */
  533. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  534. SuppressUnmanagedCodeSecurity]
  535. private static extern int caca_get_frame_count(IntPtr cv);
  536. public int getFrameCount()
  537. {
  538. return caca_get_frame_count(_c_cv);
  539. }
  540. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  541. SuppressUnmanagedCodeSecurity]
  542. private static extern int caca_set_frame(IntPtr cv, int f);
  543. public int setFrame(int f)
  544. {
  545. return caca_set_frame(_c_cv, f);
  546. }
  547. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  548. SuppressUnmanagedCodeSecurity]
  549. private static extern string caca_get_frame_name(IntPtr cv);
  550. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  551. SuppressUnmanagedCodeSecurity]
  552. private static extern int caca_set_frame_name(IntPtr cv, string n);
  553. public string FrameName
  554. {
  555. get { return caca_get_frame_name(_c_cv); }
  556. set { caca_set_frame_name(_c_cv, value); }
  557. }
  558. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  559. SuppressUnmanagedCodeSecurity]
  560. private static extern int caca_create_frame(IntPtr cv, int f);
  561. public int createFrame(int f)
  562. {
  563. return caca_create_frame(_c_cv, f);
  564. }
  565. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  566. SuppressUnmanagedCodeSecurity]
  567. private static extern int caca_free_frame(IntPtr cv, int f);
  568. public int freeFrame(int f)
  569. {
  570. return caca_free_frame(_c_cv, f);
  571. }
  572. /* bitmap dithering */
  573. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  574. SuppressUnmanagedCodeSecurity]
  575. private static extern int caca_dither_bitmap(IntPtr c, int x, int y,
  576. int w, int h,
  577. IntPtr d, IntPtr data);
  578. public int ditherBitmap(Rectangle r, Dither d, object data)
  579. {
  580. GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
  581. int ret = caca_dither_bitmap(_c_cv, r.X, r.Y, r.Width, r.Height,
  582. d._dither, gch.AddrOfPinnedObject());
  583. gch.Free();
  584. return ret;
  585. }
  586. public int ditherBitmap(int x, int y, int w, int h,
  587. Dither d, object data)
  588. {
  589. GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
  590. int ret = caca_dither_bitmap(_c_cv, x, y, w, h, d._dither,
  591. gch.AddrOfPinnedObject());
  592. gch.Free();
  593. return ret;
  594. }
  595. }
  596. }