Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

187 lignes
6.4 KiB

  1. /*
  2. * CacaSharp .NET bindings for libcaca
  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. using libCucul;
  18. namespace libCaca
  19. {
  20. enum Keys
  21. {
  22. CACA_KEY_UNKNOWN = 0x00, /**< Unknown key. */
  23. /* The following keys have ASCII equivalents */
  24. CACA_KEY_BACKSPACE = 0x08, /**< The backspace key. */
  25. CACA_KEY_TAB = 0x09, /**< The tabulation key. */
  26. CACA_KEY_RETURN = 0x0d, /**< The return key. */
  27. CACA_KEY_PAUSE = 0x13, /**< The pause key. */
  28. CACA_KEY_ESCAPE = 0x1b, /**< The escape key. */
  29. CACA_KEY_DELETE = 0x7f, /**< The delete key. */
  30. /* The following keys do not have ASCII equivalents but have been
  31. * chosen to match the SDL equivalents */
  32. CACA_KEY_UP = 0x111, /**< The up arrow key. */
  33. CACA_KEY_DOWN = 0x112, /**< The down arrow key. */
  34. CACA_KEY_LEFT = 0x113, /**< The left arrow key. */
  35. CACA_KEY_RIGHT = 0x114, /**< The right arrow key. */
  36. CACA_KEY_INSERT = 0x115, /**< The insert key. */
  37. CACA_KEY_HOME = 0x116, /**< The home key. */
  38. CACA_KEY_END = 0x117, /**< The end key. */
  39. CACA_KEY_PAGEUP = 0x118, /**< The page up key. */
  40. CACA_KEY_PAGEDOWN = 0x119, /**< The page down key. */
  41. CACA_KEY_F1 = 0x11a, /**< The F1 key. */
  42. CACA_KEY_F2 = 0x11b, /**< The F2 key. */
  43. CACA_KEY_F3 = 0x11c, /**< The F3 key. */
  44. CACA_KEY_F4 = 0x11d, /**< The F4 key. */
  45. CACA_KEY_F5 = 0x11e, /**< The F5 key. */
  46. CACA_KEY_F6 = 0x11f, /**< The F6 key. */
  47. CACA_KEY_F7 = 0x120, /**< The F7 key. */
  48. CACA_KEY_F8 = 0x121, /**< The F8 key. */
  49. CACA_KEY_F9 = 0x122, /**< The F9 key. */
  50. CACA_KEY_F10 = 0x123, /**< The F10 key. */
  51. CACA_KEY_F11 = 0x124, /**< The F11 key. */
  52. CACA_KEY_F12 = 0x125, /**< The F12 key. */
  53. CACA_KEY_F13 = 0x126, /**< The F13 key. */
  54. CACA_KEY_F14 = 0x127, /**< The F14 key. */
  55. CACA_KEY_F15 = 0x128 /**< The F15 key. */
  56. }
  57. public unsafe class Event
  58. {
  59. public enum type
  60. {
  61. NONE = 0x0000, /**< No event. */
  62. KEY_PRESS = 0x0001, /**< A key was pressed. */
  63. KEY_RELEASE = 0x0002, /**< A key was released. */
  64. MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
  65. MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
  66. MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
  67. RESIZE = 0x0020, /**< The window was resized. */
  68. QUIT = 0x0040, /**< The user requested to quit. */
  69. ANY = 0xffff /**< Bitmask for any event. */
  70. };
  71. }
  72. public unsafe class Caca : IDisposable
  73. {
  74. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  75. public static extern IntPtr caca_create_display(IntPtr qq);
  76. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  77. public static extern void caca_free_display(IntPtr kk);
  78. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  79. public static extern void caca_refresh_display(IntPtr kk);
  80. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  81. public static extern void caca_set_display_time(IntPtr kk, Int32 d);
  82. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  83. public static extern Int32 caca_get_display_time(IntPtr kk);
  84. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  85. public static extern Int32 caca_get_display_width(IntPtr kk);
  86. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  87. public static extern Int32 caca_get_display_height(IntPtr kk);
  88. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  89. public static extern Int32 caca_set_display_title(IntPtr kk, string t);
  90. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  91. public static extern Int32 caca_get_event(IntPtr k, Event.type t, Event e, Int32 timeout);
  92. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  93. public static extern Int32 caca_get_mouse_x(IntPtr k);
  94. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  95. public static extern Int32 caca_get_mouse_y(IntPtr k);
  96. [DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  97. public static extern void caca_set_mouse(IntPtr k, bool status);
  98. IntPtr qq;
  99. IntPtr kk;
  100. public Caca(Cucul qqt)
  101. {
  102. qq = qqt.get_cucul_t();
  103. kk = caca_create_display(qq);
  104. }
  105. public void Dispose()
  106. {
  107. caca_free_display(kk);
  108. GC.SuppressFinalize(this);
  109. }
  110. public void Refresh()
  111. {
  112. caca_refresh_display(kk);
  113. }
  114. public void setDisplayTime(Int32 d)
  115. {
  116. caca_set_display_time(kk, d);
  117. }
  118. public Int32 getDisplayTime()
  119. {
  120. return caca_get_display_time(kk);
  121. }
  122. public Int32 getDisplayWidth()
  123. {
  124. return caca_get_display_width(kk);
  125. }
  126. public Int32 getDisplayHeight()
  127. {
  128. return caca_get_display_height(kk);
  129. }
  130. public Int32 setDisplayTitle(string t)
  131. {
  132. return caca_set_display_title(kk, t);
  133. }
  134. public Int32 getEvent(Event.type t, Event e, Int32 timeout)
  135. {
  136. return caca_get_event(kk, t, e, timeout);
  137. }
  138. public Int32 getMouseX()
  139. {
  140. return caca_get_mouse_x(kk);
  141. }
  142. public Int32 getMouseY()
  143. {
  144. return caca_get_mouse_y(kk);
  145. }
  146. public void caca_set_mouse(bool status)
  147. {
  148. caca_set_mouse(kk, status);
  149. }
  150. public IntPtr get_caca_t()
  151. {
  152. return kk;
  153. }
  154. }
  155. }