Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

336 rindas
15 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; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. using System;
  14. using System.Runtime.InteropServices;
  15. using System.Security;
  16. namespace libCucul
  17. {
  18. public unsafe class Cucul : IDisposable
  19. {
  20. /* Fixme */
  21. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  22. public static extern IntPtr cucul_create_canvas(int w, int h);
  23. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  24. public static extern Int32 cucul_get_canvas_width(IntPtr qq);
  25. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  26. public static extern Int32 cucul_get_canvas_height(IntPtr qq);
  27. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  28. public static extern Int32 cucul_set_canvas_size(IntPtr qq, int w, int h);
  29. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  30. public static extern Int32 cucul_rand(int min, int max);
  31. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  32. public static extern Int32 cucul_free_canvas(IntPtr qq);
  33. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  34. public static extern Int32 cucul_set_color(IntPtr qq, int fg, int bg);
  35. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  36. public static extern Int32 cucul_set_truecolor(IntPtr qq, Int32 fg, Int32 bg);
  37. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  38. public static extern Int32 cucul_putchar(IntPtr qq, int x, int y, char c);
  39. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  40. public static extern Int32 cucul_putstr(IntPtr qq, int x , int y, String c);
  41. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  42. public static extern Int32 cucul_clear_canvas(IntPtr qq);
  43. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  44. public static extern Int32 cucul_blit(IntPtr qq, Int32 x, Int32 y, IntPtr qq1, IntPtr qq2);
  45. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  46. public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c);
  47. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  48. public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
  49. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  50. public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
  51. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  52. public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);
  53. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  54. public static extern Int32 cucul_gotoxy(IntPtr qq, Int32 x, Int32 y);
  55. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  56. public static extern Int32 cucul_get_cursor_x(IntPtr qq);
  57. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  58. public static extern Int32 cucul_get_cursor_y(IntPtr qq);
  59. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  60. public static extern Int32 cucul_put_char(IntPtr qq, Int32 x, Int32 y, Int32 c);
  61. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  62. public static extern Int32 cucul_get_char(IntPtr qq, Int32 x, Int32 y);
  63. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  64. public static extern Int32 cucul_put_str(IntPtr qq, Int32 x, Int32 y, string c);
  65. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  66. public static extern Int32 cucul_get_attr(IntPtr qq, Int32 x, Int32 y);
  67. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  68. public static extern Int32 cucul_set_attr(IntPtr qq, Int32 a);
  69. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  70. public static extern Int32 cucul_put_attr(IntPtr qq, Int32 x, Int32 y, Int32 a);
  71. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  72. public static extern Int32 cucul_set_color_ansi(IntPtr qq, Int32 fg, Int32 bg);
  73. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  74. public static extern Int32 cucul_set_color_argb(IntPtr qq, Int32 fg, Int32 bg);
  75. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  76. public static extern Int32 cucul_set_canvas_handle(IntPtr qq, Int32 x, Int32 y);
  77. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  78. public static extern Int32 cucul_get_canvas_handle_x(IntPtr qq);
  79. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  80. public static extern Int32 cucul_get_canvas_handle_y(IntPtr qq);
  81. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  82. public static extern Int32 cucul_set_canvas_boundaries(IntPtr qq, Int32 x, Int32 y,
  83. Int32 h, Int32 w);
  84. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  85. public static extern Int32 cucul_invert(IntPtr qq);
  86. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  87. public static extern Int32 cucul_flip(IntPtr qq);
  88. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  89. public static extern Int32 cucul_flop(IntPtr qq);
  90. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  91. public static extern Int32 cucul_rotate(IntPtr qq);
  92. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  93. public static extern Int32 cucul_attr_to_ansi(Int64 a);
  94. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  95. public static extern Int32 cucul_attr_to_ansi_fg(Int64 a);
  96. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  97. public static extern Int32 cucul_attr_to_ansi_bg(Int64 a);
  98. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  99. public static extern Int32 cucul_get_frame_count(IntPtr qq);
  100. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  101. public static extern Int32 cucul_set_frame(IntPtr qq, Int32 f);
  102. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  103. public static extern string cucul_get_frame_name(IntPtr qq);
  104. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  105. public static extern Int32 cucul_set_frame_name(IntPtr qq, string n);
  106. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  107. public static extern Int32 cucul_create_frame(IntPtr qq, Int32 f);
  108. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  109. public static extern Int32 cucul_free_frame(IntPtr qq, Int32 f);
  110. /* Constants */
  111. public const Int32 CUCUL_BLACK = 0x00; /**< The colour index for black. */
  112. public const Int32 CUCUL_BLUE = 0x01; /**< The colour index for blue. */
  113. public const Int32 CUCUL_GREEN = 0x02; /**< The colour index for green. */
  114. public const Int32 CUCUL_CYAN = 0x03; /**< The colour index for cyan. */
  115. public const Int32 CUCUL_RED = 0x04; /**< The colour index for red. */
  116. public const Int32 CUCUL_MAGENTA = 0x05; /**< The colour index for magenta. */
  117. public const Int32 CUCUL_BROWN = 0x06; /**< The colour index for brown. */
  118. public const Int32 CUCUL_LIGHTGRAY = 0x07; /**< The colour index for light gray. */
  119. public const Int32 CUCUL_DARKGRAY = 0x08; /**< The colour index for dark gray. */
  120. public const Int32 CUCUL_LIGHTBLUE = 0x09; /**< The colour index for blue. */
  121. public const Int32 CUCUL_LIGHTGREEN = 0x0a; /**< The colour index for light green. */
  122. public const Int32 CUCUL_LIGHTCYAN = 0x0b; /**< The colour index for light cyan. */
  123. public const Int32 CUCUL_LIGHTRED = 0x0c; /**< The colour index for light red. */
  124. public const Int32 CUCUL_LIGHTMAGENTA = 0x0d; /**< The colour index for light magenta. */
  125. public const Int32 CUCUL_YELLOW = 0x0e; /**< The colour index for yellow. */
  126. public const Int32 CUCUL_WHITE = 0x0f; /**< The colour index for white. */
  127. public const Int32 CUCUL_DEFAULT = 0x10; /**< The output driver's default colour. */
  128. public const Int32 CUCUL_TRANSPARENT = 0x20; /**< The transparent colour. */
  129. public const Int32 CUCUL_BOLD = 0x01; /**< The style mask for bold. */
  130. public const Int32 CUCUL_ITALICS = 0x02; /**< The style mask for italics. */
  131. public const Int32 CUCUL_UNDERLINE = 0x04; /**< The style mask for underline. */
  132. public const Int32 CUCUL_BLINK = 0x08; /**< The style mask for blink. */
  133. IntPtr qq;
  134. public Cucul()
  135. {
  136. qq = cucul_create_canvas(0, 0);
  137. }
  138. public void Dispose()
  139. {
  140. cucul_free_canvas(qq);
  141. GC.SuppressFinalize(this);
  142. }
  143. public Cucul(Int32 w, Int32 h)
  144. {
  145. qq = cucul_create_canvas(w, h);
  146. }
  147. public Int32 getWidth()
  148. {
  149. return cucul_get_canvas_width(qq);
  150. }
  151. public Int32 getHeight()
  152. {
  153. return cucul_get_canvas_height(qq);
  154. }
  155. public Int32 setSize(Int32 w, Int32 h)
  156. {
  157. return cucul_set_canvas_size(qq, w, h);
  158. }
  159. public static Int32 Rand(Int32 min, Int32 max)
  160. {
  161. return cucul_rand(min, max);
  162. }
  163. public Int32 setColor(int fg, int bg)
  164. {
  165. return cucul_set_color(qq, fg, bg);
  166. }
  167. public Int32 setTruecolor(Int32 fg, Int32 bg)
  168. {
  169. return cucul_set_truecolor(qq, fg, bg);
  170. }
  171. public Int32 putChar(int x, int y, char c)
  172. {
  173. return cucul_putchar(qq, x, y, c);
  174. }
  175. public Int32 clearCanvas()
  176. {
  177. return cucul_clear_canvas(qq);
  178. }
  179. public Int32 Blit(int x, int y, Cucul qq1, Cucul qq2)
  180. {
  181. return cucul_blit(qq, x, y, qq1.get_cucul_t(), qq2.get_cucul_t());
  182. }
  183. public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c)
  184. {
  185. return cucul_draw_line(qq, x1, y1, x2, y2, c);
  186. }
  187. public Int32 putStr(Int32 x, Int32 y, string c)
  188. {
  189. return cucul_putstr(qq, x, y, c);
  190. }
  191. public Int32 gotoXY(Int32 x, Int32 y)
  192. {
  193. return cucul_gotoxy(qq, x, y);
  194. }
  195. public Int32 getCursorX()
  196. {
  197. return cucul_get_cursor_x(qq);
  198. }
  199. public Int32 getCursorY()
  200. {
  201. return cucul_get_cursor_y(qq);
  202. }
  203. public Int32 getChar(Int32 x, Int32 y)
  204. {
  205. return cucul_get_char(qq, x, y);
  206. }
  207. public Int32 getAttr(Int32 x, Int32 y)
  208. {
  209. return cucul_get_attr(qq, x, y);
  210. }
  211. public Int32 setAttr(Int32 a)
  212. {
  213. return cucul_set_attr(qq, a);
  214. }
  215. public Int32 setAttr(Int32 x, Int32 y, Int32 a)
  216. {
  217. return cucul_put_attr(qq, x, y, a);
  218. }
  219. public Int32 setColorANSI(Int32 fg, Int32 bg)
  220. {
  221. return cucul_set_color_ansi(qq, fg, bg);
  222. }
  223. public Int32 setColorARGB(Int32 fg, Int32 bg)
  224. {
  225. return cucul_set_color_ansi(qq, fg, bg);
  226. }
  227. public Int32 setCanvasHandle(Int32 x, Int32 y)
  228. {
  229. return cucul_set_canvas_handle(qq, x, y);
  230. }
  231. public Int32 getCanvasHandleX()
  232. {
  233. return cucul_get_canvas_handle_x(qq);
  234. }
  235. public Int32 getCanvasHandleY()
  236. {
  237. return cucul_get_canvas_handle_y(qq);
  238. }
  239. public Int32 setCanvasHandleY(Int32 x, Int32 y, Int32 h, Int32 w)
  240. {
  241. return cucul_set_canvas_boundaries(qq, x, y, h, w);
  242. }
  243. public Int32 Invert()
  244. {
  245. return cucul_invert(qq);
  246. }
  247. public Int32 Flip()
  248. {
  249. return cucul_flip(qq);
  250. }
  251. public Int32 Flop()
  252. {
  253. return cucul_flop(qq);
  254. }
  255. public Int32 Rotate()
  256. {
  257. return cucul_rotate(qq);
  258. }
  259. public Int32 AttrToANSI(Int64 a)
  260. {
  261. return cucul_attr_to_ansi(a);
  262. }
  263. public Int32 AttrToANSIFg(Int64 a)
  264. {
  265. return cucul_attr_to_ansi_fg(a);
  266. }
  267. public Int32 AttrToANSIBg(Int64 a)
  268. {
  269. return cucul_attr_to_ansi_bg(a);
  270. }
  271. public Int32 getFrameCount()
  272. {
  273. return cucul_get_frame_count(qq);
  274. }
  275. public Int32 setFrame(Int32 f)
  276. {
  277. return cucul_set_frame(qq, f);
  278. }
  279. public string getFrameName()
  280. {
  281. return cucul_get_frame_name(qq);
  282. }
  283. public Int32 setFrameName(string n)
  284. {
  285. return cucul_set_frame_name(qq, n);
  286. }
  287. public Int32 createFrame(Int32 f)
  288. {
  289. return cucul_create_frame(qq, f);
  290. }
  291. public Int32 freeFrame(Int32 f)
  292. {
  293. return cucul_free_frame(qq, f);
  294. }
  295. /* Privates methods, are not meant to be called by user*/
  296. public IntPtr get_cucul_t()
  297. {
  298. return qq;
  299. }
  300. }
  301. }