Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

188 Zeilen
5.4 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 EventType
  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 EventKey
  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 Event : IDisposable
  90. {
  91. public IntPtr cevent;
  92. private IntPtr _utf8;
  93. public Event()
  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 EventType Type
  108. {
  109. get { return (EventType)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 uint caca_get_event_key_utf32(IntPtr ev);
  121. public uint 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.PtrToStringAnsi(_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. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  148. SuppressUnmanagedCodeSecurity]
  149. private static extern int caca_get_event_mouse_y(IntPtr ev);
  150. public Point MousePos
  151. {
  152. get { return new Point(caca_get_event_mouse_x(cevent),
  153. caca_get_event_mouse_y(cevent)); }
  154. }
  155. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  156. SuppressUnmanagedCodeSecurity]
  157. private static extern int caca_get_event_resize_width(IntPtr ev);
  158. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  159. SuppressUnmanagedCodeSecurity]
  160. private static extern int caca_get_event_resize_height(IntPtr ev);
  161. public Size ResizeSize
  162. {
  163. get { return new Size(caca_get_event_resize_width(cevent),
  164. caca_get_event_resize_height(cevent)); }
  165. }
  166. }
  167. }