Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

308 řádky
9.5 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 Cucul;
  19. namespace Caca
  20. {
  21. public enum CacaEventType
  22. {
  23. NONE = 0x0000,
  24. KEY_PRESS = 0x0001,
  25. KEY_RELEASE = 0x0002,
  26. MOUSE_PRESS = 0x0004,
  27. MOUSE_RELEASE = 0x0008,
  28. MOUSE_MOTION = 0x0010,
  29. RESIZE = 0x0020,
  30. QUIT = 0x0040,
  31. ANY = 0xffff,
  32. }
  33. public enum CacaEventKey
  34. {
  35. UNKNOWN = 0x00,
  36. CTRL_A = 0x01,
  37. CTRL_B = 0x02,
  38. CTRL_C = 0x03,
  39. CTRL_D = 0x04,
  40. CTRL_E = 0x05,
  41. CTRL_F = 0x06,
  42. CTRL_G = 0x07,
  43. BACKSPACE = 0x08,
  44. TAB = 0x09,
  45. CTRL_J = 0x0a,
  46. CTRL_K = 0x0b,
  47. CTRL_L = 0x0c,
  48. RETURN = 0x0d,
  49. CTRL_N = 0x0e,
  50. CTRL_O = 0x0f,
  51. CTRL_P = 0x10,
  52. CTRL_Q = 0x11,
  53. CTRL_R = 0x12,
  54. PAUSE = 0x13,
  55. CTRL_T = 0x14,
  56. CTRL_U = 0x15,
  57. CTRL_V = 0x16,
  58. CTRL_W = 0x17,
  59. CTRL_X = 0x18,
  60. CTRL_Y = 0x19,
  61. CTRL_Z = 0x1a,
  62. ESCAPE = 0x1b,
  63. DELETE = 0x7f,
  64. UP = 0x111,
  65. DOWN = 0x112,
  66. LEFT = 0x113,
  67. RIGHT = 0x114,
  68. INSERT = 0x115,
  69. HOME = 0x116,
  70. END = 0x117,
  71. PAGEUP = 0x118,
  72. PAGEDOWN = 0x119,
  73. F1 = 0x11a,
  74. F2 = 0x11b,
  75. F3 = 0x11c,
  76. F4 = 0x11d,
  77. F5 = 0x11e,
  78. F6 = 0x11f,
  79. F7 = 0x120,
  80. F8 = 0x121,
  81. F9 = 0x122,
  82. F10 = 0x123,
  83. F11 = 0x124,
  84. F12 = 0x125,
  85. F13 = 0x126,
  86. F14 = 0x127,
  87. F15 = 0x128,
  88. }
  89. public class CacaEvent : IDisposable
  90. {
  91. public IntPtr cevent;
  92. private IntPtr utf8;
  93. public CacaEvent()
  94. {
  95. cevent = Marshal.AllocHGlobal(32);
  96. utf8 = Marshal.AllocHGlobal(8);
  97. }
  98. public void Dispose()
  99. {
  100. Marshal.FreeHGlobal(cevent);
  101. Marshal.FreeHGlobal(utf8);
  102. GC.SuppressFinalize(this);
  103. }
  104. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  105. SuppressUnmanagedCodeSecurity]
  106. private static extern int caca_get_event_type(IntPtr ev);
  107. public CacaEventType type
  108. {
  109. get { return (CacaEventType)caca_get_event_type(cevent); }
  110. }
  111. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  112. SuppressUnmanagedCodeSecurity]
  113. private static extern int caca_get_event_key_ch(IntPtr ev);
  114. public int keyCh
  115. {
  116. get { return caca_get_event_key_ch(cevent); }
  117. }
  118. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  119. SuppressUnmanagedCodeSecurity]
  120. private static extern int caca_get_event_key_utf32(IntPtr ev);
  121. public int keyUtf32
  122. {
  123. get { return caca_get_event_key_utf32(cevent); }
  124. }
  125. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  126. SuppressUnmanagedCodeSecurity]
  127. private static extern int caca_get_event_key_utf8(IntPtr ev,
  128. IntPtr utf8);
  129. public string keyUtf8
  130. {
  131. get
  132. {
  133. caca_get_event_key_utf8(cevent, utf8);
  134. return Marshal.PtrToStringUni(utf8);
  135. }
  136. }
  137. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  138. SuppressUnmanagedCodeSecurity]
  139. private static extern int caca_get_event_mouse_button(IntPtr ev);
  140. public int mouseButton
  141. {
  142. get { return caca_get_event_mouse_button(cevent); }
  143. }
  144. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  145. SuppressUnmanagedCodeSecurity]
  146. private static extern int caca_get_event_mouse_x(IntPtr ev);
  147. public int mouseX
  148. {
  149. get { return caca_get_event_mouse_x(cevent); }
  150. }
  151. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  152. SuppressUnmanagedCodeSecurity]
  153. private static extern int caca_get_event_mouse_y(IntPtr ev);
  154. public int mouseY
  155. {
  156. get { return caca_get_event_mouse_y(cevent); }
  157. }
  158. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  159. SuppressUnmanagedCodeSecurity]
  160. private static extern int caca_get_event_resize_width(IntPtr ev);
  161. public int resizeWidth
  162. {
  163. get { return caca_get_event_resize_width(cevent); }
  164. }
  165. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  166. SuppressUnmanagedCodeSecurity]
  167. private static extern int caca_get_event_resize_height(IntPtr ev);
  168. public int resizeHeight
  169. {
  170. get { return caca_get_event_resize_height(cevent); }
  171. }
  172. }
  173. public class CacaDisplay : IDisposable
  174. {
  175. private IntPtr _cv;
  176. private IntPtr _dp;
  177. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  178. SuppressUnmanagedCodeSecurity]
  179. private static extern IntPtr caca_create_display(IntPtr cv);
  180. public CacaDisplay(CuculCanvas cv)
  181. {
  182. _cv = cv._cv;
  183. _dp = caca_create_display(_cv);
  184. }
  185. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  186. SuppressUnmanagedCodeSecurity]
  187. private static extern void caca_free_display(IntPtr dp);
  188. public void Dispose()
  189. {
  190. caca_free_display(_dp);
  191. GC.SuppressFinalize(this);
  192. }
  193. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  194. SuppressUnmanagedCodeSecurity]
  195. private static extern void caca_refresh_display(IntPtr dp);
  196. public void Refresh()
  197. {
  198. caca_refresh_display(_dp);
  199. }
  200. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  201. SuppressUnmanagedCodeSecurity]
  202. private static extern void caca_set_display_time(IntPtr dp, int d);
  203. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  204. SuppressUnmanagedCodeSecurity]
  205. private static extern int caca_get_display_time(IntPtr dp);
  206. public int displayTime
  207. {
  208. get { return caca_get_display_time(_dp); }
  209. set { caca_set_display_time(_dp, value); }
  210. }
  211. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  212. SuppressUnmanagedCodeSecurity]
  213. private static extern int caca_get_event(IntPtr dp, int t,
  214. IntPtr cevent,
  215. int timeout);
  216. public CacaEvent getEvent(CacaEventType t, int timeout)
  217. {
  218. CacaEvent e = new CacaEvent();
  219. caca_get_event(_dp, (int)t, e.cevent, timeout);
  220. return e;
  221. }
  222. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  223. SuppressUnmanagedCodeSecurity]
  224. private static extern int caca_get_display_width(IntPtr dp);
  225. public int width
  226. {
  227. get { return caca_get_display_width(_dp); }
  228. }
  229. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  230. SuppressUnmanagedCodeSecurity]
  231. private static extern int caca_get_display_height(IntPtr dp);
  232. public int height
  233. {
  234. get { return caca_get_display_height(_dp); }
  235. }
  236. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  237. SuppressUnmanagedCodeSecurity]
  238. private static extern int caca_set_display_title(IntPtr dp, string t);
  239. public string title
  240. {
  241. set { caca_set_display_title(_dp, value); }
  242. }
  243. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  244. SuppressUnmanagedCodeSecurity]
  245. private static extern void caca_set_mouse(IntPtr k, bool status);
  246. public bool mouse
  247. {
  248. set { caca_set_mouse(_dp, value); }
  249. }
  250. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  251. SuppressUnmanagedCodeSecurity]
  252. private static extern int caca_get_mouse_x(IntPtr k);
  253. public int mouseX
  254. {
  255. get { return caca_get_mouse_x(_dp); }
  256. }
  257. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  258. SuppressUnmanagedCodeSecurity]
  259. private static extern int caca_get_mouse_y(IntPtr k);
  260. public int mouseY
  261. {
  262. get { return caca_get_mouse_y(_dp); }
  263. }
  264. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  265. SuppressUnmanagedCodeSecurity]
  266. private static extern void caca_set_cursor(IntPtr k, bool status);
  267. public bool cursor
  268. {
  269. set { caca_set_cursor(_dp, value); }
  270. }
  271. }
  272. }