您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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