Browse Source

* Implemented getVersion() in the C# bindings.

* Slightly improved the C# test program.
tags/v0.99.beta14
Sam Hocevar sam 17 years ago
parent
commit
1c3f8fee16
3 changed files with 39 additions and 6 deletions
  1. +13
    -1
      csharp/Caca.cs
  2. +8
    -1
      csharp/Cucul.cs
  3. +18
    -4
      csharp/test.cs

+ 13
- 1
csharp/Caca.cs View File

@@ -21,6 +21,18 @@ using Cucul;


namespace Caca 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 public enum CacaEventType
{ {
NONE = 0x0000, NONE = 0x0000,
@@ -148,7 +160,7 @@ namespace Caca
get get
{ {
caca_get_event_key_utf8(cevent, utf8); caca_get_event_key_utf8(cevent, utf8);
return Marshal.PtrToStringUni(utf8);
return Marshal.PtrToStringAnsi(utf8);
} }
} }




+ 8
- 1
csharp/Cucul.cs View File

@@ -25,12 +25,19 @@ namespace Cucul
[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity] SuppressUnmanagedCodeSecurity]
private static extern int cucul_rand(int min, int max); private static extern int cucul_rand(int min, int max);

public static int Rand(int min, int max) public static int Rand(int min, int max)
{ {
return cucul_rand(min, 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, public const int BLACK = 0x00,
BLUE = 0x01, BLUE = 0x01,
GREEN = 0x02, GREEN = 0x02,


+ 18
- 4
csharp/test.cs View File

@@ -33,9 +33,6 @@ class DemoCanvas : CuculCanvas


table = new uint[16,16]; table = new uint[16,16];
d = new CuculDither(32, 16, 16, 16 * 4, 0xff0000, 0xff00, 0xff, 0x0); 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() public void Draw()
@@ -45,6 +42,23 @@ class DemoCanvas : CuculCanvas


Clear(); 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); ditherBitmap(0, 0, width, height, d, table);


setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
@@ -102,7 +116,7 @@ class Test
{ {
public static void Main() public static void Main()
{ {
Console.WriteLine("libcaca .NET test");
Console.WriteLine("libcaca {0} .NET test", Libcaca.getVersion());
Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>"); Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");


/* Instanciate a cucul canvas */ /* Instanciate a cucul canvas */


Loading…
Cancel
Save