You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

153 lines
6.2 KiB

  1. /*
  2. * CuculSharp .NET bindings for libcucul
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * 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. namespace libCucul
  17. {
  18. public unsafe class Cucul : IDisposable
  19. {
  20. /* Fixme */
  21. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  22. public static extern IntPtr cucul_create_canvas(int w, int h);
  23. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  24. public static extern Int32 cucul_get_canvas_width(IntPtr qq);
  25. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  26. public static extern Int32 cucul_get_canvas_height(IntPtr qq);
  27. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  28. public static extern Int32 cucul_set_canvas_size(IntPtr qq, int w, int h);
  29. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  30. public static extern Int32 cucul_rand(int min, int max);
  31. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  32. public static extern Int32 cucul_free_canvas(IntPtr qq);
  33. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  34. public static extern Int32 cucul_set_color(IntPtr qq, int fg, int bg);
  35. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  36. public static extern Int32 cucul_set_truecolor(IntPtr qq, Int32 fg, Int32 bg);
  37. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  38. public static extern Int32 cucul_putchar(IntPtr qq, int x, int y, char c);
  39. /* [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  40. public static extern Int32 cucul_putstr(IntPtr qq, int, int, String);*/
  41. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  42. public static extern Int32 cucul_clear_canvas(IntPtr qq);
  43. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  44. public static extern Int32 cucul_blit(IntPtr qq, Int32 x, Int32 y, IntPtr qq1, IntPtr qq2);
  45. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  46. public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c);
  47. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  48. public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
  49. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  50. public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
  51. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  52. public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);
  53. /*
  54. char const *cucul_get_color_name(unsigned int);
  55. int cucul_putstr(IntPtr *, int, int, char const *);
  56. int cucul_printf(IntPtr *, int, int, char const *, ...);
  57. */
  58. IntPtr qq;
  59. public Cucul()
  60. {
  61. qq = cucul_create_canvas(0, 0);
  62. }
  63. public void Dispose()
  64. {
  65. cucul_free_canvas(qq);
  66. GC.SuppressFinalize(this);
  67. }
  68. public Cucul(Int32 w, Int32 h)
  69. {
  70. qq = cucul_create_canvas(w, h);
  71. }
  72. public Int32 getWidth()
  73. {
  74. return cucul_get_canvas_width(qq);
  75. }
  76. public Int32 getHeight()
  77. {
  78. return cucul_get_canvas_height(qq);
  79. }
  80. public Int32 setSize(Int32 w, Int32 h)
  81. {
  82. return cucul_set_canvas_size(qq, w, h);
  83. }
  84. public static Int32 Rand(Int32 min, Int32 max)
  85. {
  86. return cucul_rand(min, max);
  87. }
  88. public Int32 setColor(int fg, int bg)
  89. {
  90. return cucul_set_color(qq, fg, bg);
  91. }
  92. public Int32 setTruecolor(Int32 fg, Int32 bg)
  93. {
  94. return cucul_set_truecolor(qq, fg, bg);
  95. }
  96. public Int32 putChar(int x, int y, char c)
  97. {
  98. return cucul_putchar(qq, x, y, c);
  99. }
  100. public Int32 clearCanvas()
  101. {
  102. return cucul_clear_canvas(qq);
  103. }
  104. public Int32 Blit(int x, int y, Cucul qq1, Cucul qq2)
  105. {
  106. return cucul_blit(qq, x, y, qq1.get_cucul_t(), qq2.get_cucul_t());
  107. }
  108. public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c)
  109. {
  110. return cucul_draw_line(qq, x1, y1, x2, y2, c);
  111. }
  112. /*
  113. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  114. public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
  115. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  116. public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
  117. [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
  118. public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);
  119. */
  120. /* Privates methods, are not meant to be called by user*/
  121. public IntPtr get_cucul_t()
  122. {
  123. return qq;
  124. }
  125. }
  126. }