diff --git a/csharp/Caca.cs b/csharp/Caca.cs index 9e64c9f..6dcdc4c 100644 --- a/csharp/Caca.cs +++ b/csharp/Caca.cs @@ -21,6 +21,18 @@ using Cucul; namespace Caca { + /* Static libcaca stuff that does not fit in any object */ + public static class Libcaca + { + [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern IntPtr caca_get_version(); + public static string getVersion() + { + return Marshal.PtrToStringAnsi(caca_get_version()); + } + } + public enum CacaEventType { NONE = 0x0000, @@ -148,7 +160,7 @@ namespace Caca get { caca_get_event_key_utf8(cevent, utf8); - return Marshal.PtrToStringUni(utf8); + return Marshal.PtrToStringAnsi(utf8); } } diff --git a/csharp/Cucul.cs b/csharp/Cucul.cs index b7dd311..21185cb 100644 --- a/csharp/Cucul.cs +++ b/csharp/Cucul.cs @@ -25,12 +25,19 @@ namespace Cucul [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] private static extern int cucul_rand(int min, int max); - public static int Rand(int min, int max) { return cucul_rand(min, max); } + [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), + SuppressUnmanagedCodeSecurity] + private static extern IntPtr cucul_get_version(); + public static string getVersion() + { + return Marshal.PtrToStringAnsi(cucul_get_version()); + } + public const int BLACK = 0x00, BLUE = 0x01, GREEN = 0x02, diff --git a/csharp/test.cs b/csharp/test.cs index c699b54..85bec9f 100644 --- a/csharp/test.cs +++ b/csharp/test.cs @@ -33,9 +33,6 @@ class DemoCanvas : CuculCanvas table = new uint[16,16]; d = new CuculDither(32, 16, 16, 16 * 4, 0xff0000, 0xff00, 0xff, 0x0); - for(int y = 0; y < 16; y++) - for(int x = 0; x < 16; x++) - table[x,y] = (uint)((x + y) << 16) | (uint)(x << 8) | (uint)(y); } public void Draw() @@ -45,6 +42,23 @@ class DemoCanvas : CuculCanvas Clear(); + double cos = Math.Cos(t / 500.0); + double sin = Math.Sin(t / 500.0); + + for(int y = 0; y < 16; y++) + for(int x = 0; x < 16; x++) + { + double xt = (double)(x - 8); + double yt = (double)(y - 8); + int x2 = (int)(xt * cos + yt * sin + 8.0); + int y2 = (int)(xt * sin - yt * cos + 8.0); + if(x2 < 0) x2 = 0; + if(y2 < 0) y2 = 0; + + table[x,y] = (uint)((x2 + y2) << 16) + | (uint)(x2 << 8) + | (uint)(y2); + } ditherBitmap(0, 0, width, height, d, table); setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); @@ -102,7 +116,7 @@ class Test { public static void Main() { - Console.WriteLine("libcaca .NET test"); + Console.WriteLine("libcaca {0} .NET test", Libcaca.getVersion()); Console.WriteLine("(c) 2006 Jean-Yves Lamoureux "); /* Instanciate a cucul canvas */