Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

459 rader
21 KiB

  1. /*
  2. * CuculSharp .NET 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. using System;
  15. using System.Runtime.InteropServices;
  16. using System.Security;
  17. namespace libCucul
  18. {
  19. public unsafe class Cucul : IDisposable
  20. {
  21. /* Fixme */
  22. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  23. public static extern IntPtr cucul_create_canvas(int w, int h);
  24. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  25. public static extern Int32 cucul_get_canvas_width(IntPtr qq);
  26. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  27. public static extern Int32 cucul_get_canvas_height(IntPtr qq);
  28. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  29. public static extern Int32 cucul_set_canvas_size(IntPtr qq, int w, int h);
  30. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  31. public static extern Int32 cucul_rand(int min, int max);
  32. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  33. public static extern Int32 cucul_free_canvas(IntPtr qq);
  34. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  35. public static extern Int32 cucul_set_color(IntPtr qq, int fg, int bg);
  36. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  37. public static extern Int32 cucul_set_truecolor(IntPtr qq, Int32 fg, Int32 bg);
  38. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  39. public static extern Int32 cucul_putchar(IntPtr qq, int x, int y, char c);
  40. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  41. public static extern Int32 cucul_putstr(IntPtr qq, int x , int y, String c);
  42. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  43. public static extern Int32 cucul_clear_canvas(IntPtr qq);
  44. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  45. public static extern Int32 cucul_blit(IntPtr qq, Int32 x, Int32 y, IntPtr qq1, IntPtr qq2);
  46. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  47. public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 c);
  48. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  49. public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
  50. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  51. public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
  52. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  53. public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);
  54. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  55. public static extern Int32 cucul_gotoxy(IntPtr qq, Int32 x, Int32 y);
  56. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  57. public static extern Int32 cucul_get_cursor_x(IntPtr qq);
  58. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  59. public static extern Int32 cucul_get_cursor_y(IntPtr qq);
  60. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  61. public static extern Int32 cucul_put_char(IntPtr qq, Int32 x, Int32 y, Int32 c);
  62. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  63. public static extern Int32 cucul_get_char(IntPtr qq, Int32 x, Int32 y);
  64. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  65. public static extern Int32 cucul_put_str(IntPtr qq, Int32 x, Int32 y, string c);
  66. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  67. public static extern Int32 cucul_get_attr(IntPtr qq, Int32 x, Int32 y);
  68. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  69. public static extern Int32 cucul_set_attr(IntPtr qq, Int32 a);
  70. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  71. public static extern Int32 cucul_put_attr(IntPtr qq, Int32 x, Int32 y, Int32 a);
  72. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  73. public static extern Int32 cucul_set_color_ansi(IntPtr qq, Int32 fg, Int32 bg);
  74. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  75. public static extern Int32 cucul_set_color_argb(IntPtr qq, Int32 fg, Int32 bg);
  76. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  77. public static extern Int32 cucul_set_canvas_handle(IntPtr qq, Int32 x, Int32 y);
  78. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  79. public static extern Int32 cucul_get_canvas_handle_x(IntPtr qq);
  80. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  81. public static extern Int32 cucul_get_canvas_handle_y(IntPtr qq);
  82. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  83. public static extern Int32 cucul_set_canvas_boundaries(IntPtr qq, Int32 x, Int32 y,
  84. Int32 h, Int32 w);
  85. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  86. public static extern Int32 cucul_invert(IntPtr qq);
  87. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  88. public static extern Int32 cucul_flip(IntPtr qq);
  89. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  90. public static extern Int32 cucul_flop(IntPtr qq);
  91. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  92. public static extern Int32 cucul_rotate(IntPtr qq);
  93. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  94. public static extern Int32 cucul_attr_to_ansi(Int64 a);
  95. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  96. public static extern Int32 cucul_attr_to_ansi_fg(Int64 a);
  97. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  98. public static extern Int32 cucul_attr_to_ansi_bg(Int64 a);
  99. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  100. public static extern Int32 cucul_get_frame_count(IntPtr qq);
  101. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  102. public static extern Int32 cucul_set_frame(IntPtr qq, Int32 f);
  103. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  104. public static extern string cucul_get_frame_name(IntPtr qq);
  105. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  106. public static extern Int32 cucul_set_frame_name(IntPtr qq, string n);
  107. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  108. public static extern Int32 cucul_create_frame(IntPtr qq, Int32 f);
  109. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  110. public static extern Int32 cucul_free_frame(IntPtr qq, Int32 f);
  111. /* Constants */
  112. public const Int32 CUCUL_BLACK = 0x00; /**< The colour index for black. */
  113. public const Int32 CUCUL_BLUE = 0x01; /**< The colour index for blue. */
  114. public const Int32 CUCUL_GREEN = 0x02; /**< The colour index for green. */
  115. public const Int32 CUCUL_CYAN = 0x03; /**< The colour index for cyan. */
  116. public const Int32 CUCUL_RED = 0x04; /**< The colour index for red. */
  117. public const Int32 CUCUL_MAGENTA = 0x05; /**< The colour index for magenta. */
  118. public const Int32 CUCUL_BROWN = 0x06; /**< The colour index for brown. */
  119. public const Int32 CUCUL_LIGHTGRAY = 0x07; /**< The colour index for light gray. */
  120. public const Int32 CUCUL_DARKGRAY = 0x08; /**< The colour index for dark gray. */
  121. public const Int32 CUCUL_LIGHTBLUE = 0x09; /**< The colour index for blue. */
  122. public const Int32 CUCUL_LIGHTGREEN = 0x0a; /**< The colour index for light green. */
  123. public const Int32 CUCUL_LIGHTCYAN = 0x0b; /**< The colour index for light cyan. */
  124. public const Int32 CUCUL_LIGHTRED = 0x0c; /**< The colour index for light red. */
  125. public const Int32 CUCUL_LIGHTMAGENTA = 0x0d; /**< The colour index for light magenta. */
  126. public const Int32 CUCUL_YELLOW = 0x0e; /**< The colour index for yellow. */
  127. public const Int32 CUCUL_WHITE = 0x0f; /**< The colour index for white. */
  128. public const Int32 CUCUL_DEFAULT = 0x10; /**< The output driver's default colour. */
  129. public const Int32 CUCUL_TRANSPARENT = 0x20; /**< The transparent colour. */
  130. public const Int32 CUCUL_BOLD = 0x01; /**< The style mask for bold. */
  131. public const Int32 CUCUL_ITALICS = 0x02; /**< The style mask for italics. */
  132. public const Int32 CUCUL_UNDERLINE = 0x04; /**< The style mask for underline. */
  133. public const Int32 CUCUL_BLINK = 0x08; /**< The style mask for blink. */
  134. IntPtr qq;
  135. public Cucul()
  136. {
  137. qq = cucul_create_canvas(0, 0);
  138. }
  139. public void Dispose()
  140. {
  141. cucul_free_canvas(qq);
  142. GC.SuppressFinalize(this);
  143. }
  144. public Cucul(Int32 w, Int32 h)
  145. {
  146. qq = cucul_create_canvas(w, h);
  147. }
  148. public Int32 getWidth()
  149. {
  150. return cucul_get_canvas_width(qq);
  151. }
  152. public Int32 getHeight()
  153. {
  154. return cucul_get_canvas_height(qq);
  155. }
  156. public Int32 setSize(Int32 w, Int32 h)
  157. {
  158. return cucul_set_canvas_size(qq, w, h);
  159. }
  160. public static Int32 Rand(Int32 min, Int32 max)
  161. {
  162. return cucul_rand(min, max);
  163. }
  164. public Int32 setColor(int fg, int bg)
  165. {
  166. return cucul_set_color(qq, fg, bg);
  167. }
  168. public Int32 setTruecolor(Int32 fg, Int32 bg)
  169. {
  170. return cucul_set_truecolor(qq, fg, bg);
  171. }
  172. public Int32 putChar(int x, int y, char c)
  173. {
  174. return cucul_putchar(qq, x, y, c);
  175. }
  176. public Int32 Clear()
  177. {
  178. return cucul_clear_canvas(qq);
  179. }
  180. public Int32 Blit(int x, int y, Cucul qq1, Cucul qq2)
  181. {
  182. return cucul_blit(qq, x, y, qq1.get_cucul_t(), qq2.get_cucul_t());
  183. }
  184. public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 c)
  185. {
  186. return cucul_draw_line(qq, x1, y1, x2, y2, c);
  187. }
  188. public Int32 putStr(Int32 x, Int32 y, string c)
  189. {
  190. return cucul_putstr(qq, x, y, c);
  191. }
  192. public Int32 gotoXY(Int32 x, Int32 y)
  193. {
  194. return cucul_gotoxy(qq, x, y);
  195. }
  196. public Int32 getCursorX()
  197. {
  198. return cucul_get_cursor_x(qq);
  199. }
  200. public Int32 getCursorY()
  201. {
  202. return cucul_get_cursor_y(qq);
  203. }
  204. public Int32 getChar(Int32 x, Int32 y)
  205. {
  206. return cucul_get_char(qq, x, y);
  207. }
  208. public Int32 getAttr(Int32 x, Int32 y)
  209. {
  210. return cucul_get_attr(qq, x, y);
  211. }
  212. public Int32 setAttr(Int32 a)
  213. {
  214. return cucul_set_attr(qq, a);
  215. }
  216. public Int32 setAttr(Int32 x, Int32 y, Int32 a)
  217. {
  218. return cucul_put_attr(qq, x, y, a);
  219. }
  220. public Int32 setColorANSI(Int32 fg, Int32 bg)
  221. {
  222. return cucul_set_color_ansi(qq, fg, bg);
  223. }
  224. public Int32 setColorARGB(Int32 fg, Int32 bg)
  225. {
  226. return cucul_set_color_ansi(qq, fg, bg);
  227. }
  228. public Int32 setCanvasHandle(Int32 x, Int32 y)
  229. {
  230. return cucul_set_canvas_handle(qq, x, y);
  231. }
  232. public Int32 getCanvasHandleX()
  233. {
  234. return cucul_get_canvas_handle_x(qq);
  235. }
  236. public Int32 getCanvasHandleY()
  237. {
  238. return cucul_get_canvas_handle_y(qq);
  239. }
  240. public Int32 setCanvasHandleY(Int32 x, Int32 y, Int32 h, Int32 w)
  241. {
  242. return cucul_set_canvas_boundaries(qq, x, y, h, w);
  243. }
  244. public Int32 Invert()
  245. {
  246. return cucul_invert(qq);
  247. }
  248. public Int32 Flip()
  249. {
  250. return cucul_flip(qq);
  251. }
  252. public Int32 Flop()
  253. {
  254. return cucul_flop(qq);
  255. }
  256. public Int32 Rotate()
  257. {
  258. return cucul_rotate(qq);
  259. }
  260. public Int32 AttrToANSI(Int64 a)
  261. {
  262. return cucul_attr_to_ansi(a);
  263. }
  264. public Int32 AttrToANSIFg(Int64 a)
  265. {
  266. return cucul_attr_to_ansi_fg(a);
  267. }
  268. public Int32 AttrToANSIBg(Int64 a)
  269. {
  270. return cucul_attr_to_ansi_bg(a);
  271. }
  272. public Int32 getFrameCount()
  273. {
  274. return cucul_get_frame_count(qq);
  275. }
  276. public Int32 setFrame(Int32 f)
  277. {
  278. return cucul_set_frame(qq, f);
  279. }
  280. public string getFrameName()
  281. {
  282. return cucul_get_frame_name(qq);
  283. }
  284. public Int32 setFrameName(string n)
  285. {
  286. return cucul_set_frame_name(qq, n);
  287. }
  288. public Int32 createFrame(Int32 f)
  289. {
  290. return cucul_create_frame(qq, f);
  291. }
  292. public Int32 freeFrame(Int32 f)
  293. {
  294. return cucul_free_frame(qq, f);
  295. }
  296. /* Privates methods, are not meant to be called by user*/
  297. public IntPtr get_cucul_t()
  298. {
  299. return qq;
  300. }
  301. }
  302. public unsafe class Dither : IDisposable
  303. {
  304. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  305. public static extern IntPtr cucul_create_dither(Int32 bpp, Int32 w,
  306. Int32 h, Int32 pitch,
  307. Int64 rmask,
  308. Int64 gmask,
  309. Int64 bmask,
  310. Int64 amask);
  311. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  312. public static extern Int32 cucul_set_dither_palette(IntPtr d,
  313. Int32[] r, Int32[] g,
  314. Int32[] b, Int32[] a);
  315. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  316. public static extern Int32 cucul_set_dither_brightness(IntPtr d, float b);
  317. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  318. public static extern Int32 cucul_set_dither_gamma(IntPtr d, float g);
  319. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  320. public static extern Int32 cucul_set_dither_contrast(IntPtr d, float c);
  321. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  322. public static extern Int32 cucul_set_dither_invert(IntPtr d, int i);
  323. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  324. public static extern Int32 cucul_set_dither_antialias(IntPtr d, string s);
  325. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  326. public static extern string[] cucul_get_dither_antialias_list(IntPtr d);
  327. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  328. public static extern Int32 cucul_set_dither_color(IntPtr d, string s);
  329. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  330. public static extern string[] cucul_get_dither_color_list(IntPtr d);
  331. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  332. public static extern Int32 cucul_set_dither_charset(IntPtr d, string s);
  333. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  334. public static extern string[] cucul_get_dither_charset_list(IntPtr d);
  335. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  336. public static extern Int32 cucul_set_dither_mode(IntPtr d, string s);
  337. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  338. public static extern string[] cucul_get_dither_mode_list(IntPtr d);
  339. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  340. public static extern Int32 cucul_free_dither(IntPtr d);
  341. /* FIXME [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  342. Int32 cucul_dither_bitmap(Cucul c,Int32 x, Int32 y, Int32 w , Int32 y,
  343. IntPtr d2, void *);*/
  344. IntPtr dither;
  345. public Dither(Int32 bpp, Int32 w,Int32 h, Int32 pitch,
  346. Int64 rmask, Int64 gmask,Int64 bmask, Int64 amask)
  347. {
  348. dither = cucul_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask);
  349. }
  350. public void Dispose()
  351. {
  352. cucul_free_dither(dither);
  353. GC.SuppressFinalize(this);
  354. }
  355. public Int32 setBrightness(float b)
  356. {
  357. return cucul_set_dither_brightness(dither, b);
  358. }
  359. public Int32 setGamma(float g)
  360. {
  361. return cucul_set_dither_gamma(dither, g);
  362. }
  363. public Int32 setContrast(float c)
  364. {
  365. return cucul_set_dither_contrast(dither, c);
  366. }
  367. public Int32 setInvert(Int32 i)
  368. {
  369. return cucul_set_dither_invert(dither, i);
  370. }
  371. public Int32 setAntialias(string s)
  372. {
  373. return cucul_set_dither_antialias(dither, s);
  374. }
  375. public Int32 setColor(string s)
  376. {
  377. return cucul_set_dither_color(dither, s);
  378. }
  379. public Int32 setCharset(string s)
  380. {
  381. return cucul_set_dither_charset(dither, s);
  382. }
  383. public Int32 setMode(string s)
  384. {
  385. return cucul_set_dither_mode(dither, s);
  386. }
  387. /* <FIXME> */
  388. public string[] getAntialiasList()
  389. {
  390. return cucul_get_dither_antialias_list(dither);
  391. }
  392. public string[] getColorList()
  393. {
  394. return cucul_get_dither_color_list(dither);
  395. }
  396. public string[] getCharsetList()
  397. {
  398. return cucul_get_dither_charset_list(dither);
  399. }
  400. public string[] getModeList()
  401. {
  402. return cucul_get_dither_mode_list(dither);
  403. }
  404. /* </FIXME> */
  405. }
  406. }