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.
 
 
 
 
 
 

142 Zeilen
5.1 KiB

  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. * $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 class Display : IDisposable
  22. {
  23. private Canvas _cv;
  24. public Canvas Canvas { get { return _cv; } }
  25. private IntPtr _c_cv;
  26. private IntPtr _c_dp;
  27. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  28. SuppressUnmanagedCodeSecurity]
  29. private static extern IntPtr caca_create_display(IntPtr cv);
  30. public Display(Canvas cv)
  31. {
  32. _cv = cv;
  33. _c_cv = _cv._c_cv;
  34. _c_dp = caca_create_display(_c_cv);
  35. }
  36. public Display()
  37. {
  38. /* XXX: we do not call caca_create_display() with a NULL
  39. * argument because it's then impossible to create a Canvas
  40. * and I don't want to add a weird constructor */
  41. _cv = new Canvas();
  42. _c_cv = _cv._c_cv;
  43. _c_dp = caca_create_display(_c_cv);
  44. }
  45. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  46. SuppressUnmanagedCodeSecurity]
  47. private static extern int caca_free_display(IntPtr dp);
  48. public void Dispose()
  49. {
  50. caca_free_display(_c_dp);
  51. GC.SuppressFinalize(this);
  52. }
  53. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  54. SuppressUnmanagedCodeSecurity]
  55. private static extern int caca_refresh_display(IntPtr dp);
  56. public void Refresh()
  57. {
  58. caca_refresh_display(_c_dp);
  59. }
  60. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  61. SuppressUnmanagedCodeSecurity]
  62. private static extern int caca_set_display_time(IntPtr dp, int d);
  63. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  64. SuppressUnmanagedCodeSecurity]
  65. private static extern int caca_get_display_time(IntPtr dp);
  66. public int DisplayTime
  67. {
  68. get { return caca_get_display_time(_c_dp); }
  69. set { caca_set_display_time(_c_dp, value); }
  70. }
  71. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  72. SuppressUnmanagedCodeSecurity]
  73. private static extern int caca_get_event(IntPtr dp, uint t,
  74. IntPtr cevent,
  75. int timeout);
  76. public Event getEvent(EventType t, int timeout)
  77. {
  78. Event e = new Event();
  79. caca_get_event(_c_dp, (uint)t, e.cevent, timeout);
  80. return e;
  81. }
  82. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  83. SuppressUnmanagedCodeSecurity]
  84. private static extern int caca_get_display_width(IntPtr dp);
  85. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  86. SuppressUnmanagedCodeSecurity]
  87. private static extern int caca_get_display_height(IntPtr dp);
  88. public Size Size
  89. {
  90. get { return new Size(caca_get_display_width(_c_dp),
  91. caca_get_display_height(_c_dp)); }
  92. }
  93. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  94. SuppressUnmanagedCodeSecurity]
  95. private static extern int caca_set_display_title(IntPtr dp, string t);
  96. public string Title
  97. {
  98. set { caca_set_display_title(_c_dp, value); }
  99. }
  100. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  101. SuppressUnmanagedCodeSecurity]
  102. private static extern int caca_set_mouse(IntPtr k, bool status);
  103. public bool Mouse
  104. {
  105. set { caca_set_mouse(_c_dp, value); }
  106. }
  107. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  108. SuppressUnmanagedCodeSecurity]
  109. private static extern int caca_get_mouse_x(IntPtr k);
  110. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  111. SuppressUnmanagedCodeSecurity]
  112. private static extern int caca_get_mouse_y(IntPtr k);
  113. public Point MousePos
  114. {
  115. get { return new Point(caca_get_mouse_x(_c_dp),
  116. caca_get_mouse_y(_c_dp)); }
  117. }
  118. [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
  119. SuppressUnmanagedCodeSecurity]
  120. private static extern int caca_set_cursor(IntPtr k, bool status);
  121. public bool Cursor
  122. {
  123. set { caca_set_cursor(_c_dp, value); }
  124. }
  125. }
  126. }