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ů.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * libcaca .NET bindings for libcaca
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * 2007 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://sam.zoy.org/wtfpl/COPYING 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 EventType
  20. {
  21. NONE = 0x0000,
  22. KEY_PRESS = 0x0001,
  23. KEY_RELEASE = 0x0002,
  24. MOUSE_PRESS = 0x0004,
  25. MOUSE_RELEASE = 0x0008,
  26. MOUSE_MOTION = 0x0010,
  27. RESIZE = 0x0020,
  28. QUIT = 0x0040,
  29. ANY = 0xffff,
  30. }
  31. public enum EventKey
  32. {
  33. UNKNOWN = 0x00,
  34. CTRL_A = 0x01,
  35. CTRL_B = 0x02,
  36. CTRL_C = 0x03,
  37. CTRL_D = 0x04,
  38. CTRL_E = 0x05,
  39. CTRL_F = 0x06,
  40. CTRL_G = 0x07,
  41. BACKSPACE = 0x08,
  42. TAB = 0x09,
  43. CTRL_J = 0x0a,
  44. CTRL_K = 0x0b,
  45. CTRL_L = 0x0c,
  46. RETURN = 0x0d,
  47. CTRL_N = 0x0e,
  48. CTRL_O = 0x0f,
  49. CTRL_P = 0x10,
  50. CTRL_Q = 0x11,
  51. CTRL_R = 0x12,
  52. PAUSE = 0x13,
  53. CTRL_T = 0x14,
  54. CTRL_U = 0x15,
  55. CTRL_V = 0x16,
  56. CTRL_W = 0x17,
  57. CTRL_X = 0x18,
  58. CTRL_Y = 0x19,
  59. CTRL_Z = 0x1a,
  60. ESCAPE = 0x1b,
  61. DELETE = 0x7f,
  62. UP = 0x111,
  63. DOWN = 0x112,
  64. LEFT = 0x113,
  65. RIGHT = 0x114,
  66. INSERT = 0x115,
  67. HOME = 0x116,
  68. END = 0x117,
  69. PAGEUP = 0x118,
  70. PAGEDOWN = 0x119,
  71. F1 = 0x11a,
  72. F2 = 0x11b,
  73. F3 = 0x11c,
  74. F4 = 0x11d,
  75. F5 = 0x11e,
  76. F6 = 0x11f,
  77. F7 = 0x120,
  78. F8 = 0x121,
  79. F9 = 0x122,
  80. F10 = 0x123,
  81. F11 = 0x124,
  82. F12 = 0x125,
  83. F13 = 0x126,
  84. F14 = 0x127,
  85. F15 = 0x128,
  86. }
  87. public class Event : IDisposable
  88. {
  89. public IntPtr cevent;
  90. private IntPtr _utf8;
  91. public Event()
  92. {
  93. cevent = Marshal.AllocHGlobal(32);
  94. _utf8 = Marshal.AllocHGlobal(8);
  95. }
  96. public void Dispose()
  97. {
  98. Marshal.FreeHGlobal(cevent);
  99. Marshal.FreeHGlobal(_utf8);
  100. GC.SuppressFinalize(this);
  101. }
  102. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  103. SuppressUnmanagedCodeSecurity]
  104. private static extern int caca_get_event_type(IntPtr ev);
  105. public EventType Type
  106. {
  107. get { return (EventType)caca_get_event_type(cevent); }
  108. }
  109. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  110. SuppressUnmanagedCodeSecurity]
  111. private static extern int caca_get_event_key_ch(IntPtr ev);
  112. public int KeyCh
  113. {
  114. get { return caca_get_event_key_ch(cevent); }
  115. }
  116. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  117. SuppressUnmanagedCodeSecurity]
  118. private static extern uint caca_get_event_key_utf32(IntPtr ev);
  119. public uint KeyUtf32
  120. {
  121. get { return caca_get_event_key_utf32(cevent); }
  122. }
  123. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  124. SuppressUnmanagedCodeSecurity]
  125. private static extern int caca_get_event_key_utf8(IntPtr ev,
  126. IntPtr _utf8);
  127. public string KeyUtf8
  128. {
  129. get
  130. {
  131. caca_get_event_key_utf8(cevent, _utf8);
  132. return Marshal.PtrToStringAnsi(_utf8);
  133. }
  134. }
  135. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  136. SuppressUnmanagedCodeSecurity]
  137. private static extern int caca_get_event_mouse_button(IntPtr ev);
  138. public int MouseButton
  139. {
  140. get { return caca_get_event_mouse_button(cevent); }
  141. }
  142. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  143. SuppressUnmanagedCodeSecurity]
  144. private static extern int caca_get_event_mouse_x(IntPtr ev);
  145. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  146. SuppressUnmanagedCodeSecurity]
  147. private static extern int caca_get_event_mouse_y(IntPtr ev);
  148. public Point MousePos
  149. {
  150. get { return new Point(caca_get_event_mouse_x(cevent),
  151. caca_get_event_mouse_y(cevent)); }
  152. }
  153. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  154. SuppressUnmanagedCodeSecurity]
  155. private static extern int caca_get_event_resize_width(IntPtr ev);
  156. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  157. SuppressUnmanagedCodeSecurity]
  158. private static extern int caca_get_event_resize_height(IntPtr ev);
  159. public Size ResizeSize
  160. {
  161. get { return new Size(caca_get_event_resize_width(cevent),
  162. caca_get_event_resize_height(cevent)); }
  163. }
  164. }
  165. }