Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Display.cs 5.0 KiB

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