소스 검색

* Added preliminary .NET bindings. Caca is complete, Cucul needs to be finished

tags/v0.99.beta14
Jean-Yves Lamoureux jylam 18 년 전
부모
커밋
2dd1d02580
7개의 변경된 파일432개의 추가작업 그리고 0개의 파일을 삭제
  1. +20
    -0
      DotNet/AssemblyInfo.cs
  2. +185
    -0
      DotNet/Caca.cs
  3. +152
    -0
      DotNet/Cucul.cs
  4. +5
    -0
      DotNet/Makefile
  5. +3
    -0
      DotNet/libCaca.dll.config
  6. +3
    -0
      DotNet/libCucul.dll.config
  7. +64
    -0
      DotNet/test.cs

+ 20
- 0
DotNet/AssemblyInfo.cs 파일 보기

@@ -0,0 +1,20 @@
/*
* AssemblyInfo .NET bindings for libcaca
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*
* $Id: caca++.cpp 706 2006-04-26 18:53:08Z jylam $
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/


using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("Cucul")]
[assembly: AssemblyDescription("libcucul .NET bindings")]
[assembly: AssemblyCopyright("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org")]

+ 185
- 0
DotNet/Caca.cs 파일 보기

@@ -0,0 +1,185 @@
/*
* CacaSharp .NET bindings for libcaca
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*
* $Id: caca++.cpp 706 2006-04-26 18:53:08Z jylam $
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/



using System;
using System.Runtime.InteropServices;
using System.Security;

using libCucul;


namespace libCaca
{

enum Keys
{
CACA_KEY_UNKNOWN = 0x00, /**< Unknown key. */

/* The following keys have ASCII equivalents */
CACA_KEY_BACKSPACE = 0x08, /**< The backspace key. */
CACA_KEY_TAB = 0x09, /**< The tabulation key. */
CACA_KEY_RETURN = 0x0d, /**< The return key. */
CACA_KEY_PAUSE = 0x13, /**< The pause key. */
CACA_KEY_ESCAPE = 0x1b, /**< The escape key. */
CACA_KEY_DELETE = 0x7f, /**< The delete key. */

/* The following keys do not have ASCII equivalents but have been
* chosen to match the SDL equivalents */
CACA_KEY_UP = 0x111, /**< The up arrow key. */
CACA_KEY_DOWN = 0x112, /**< The down arrow key. */
CACA_KEY_LEFT = 0x113, /**< The left arrow key. */
CACA_KEY_RIGHT = 0x114, /**< The right arrow key. */

CACA_KEY_INSERT = 0x115, /**< The insert key. */
CACA_KEY_HOME = 0x116, /**< The home key. */
CACA_KEY_END = 0x117, /**< The end key. */
CACA_KEY_PAGEUP = 0x118, /**< The page up key. */
CACA_KEY_PAGEDOWN = 0x119, /**< The page down key. */

CACA_KEY_F1 = 0x11a, /**< The F1 key. */
CACA_KEY_F2 = 0x11b, /**< The F2 key. */
CACA_KEY_F3 = 0x11c, /**< The F3 key. */
CACA_KEY_F4 = 0x11d, /**< The F4 key. */
CACA_KEY_F5 = 0x11e, /**< The F5 key. */
CACA_KEY_F6 = 0x11f, /**< The F6 key. */
CACA_KEY_F7 = 0x120, /**< The F7 key. */
CACA_KEY_F8 = 0x121, /**< The F8 key. */
CACA_KEY_F9 = 0x122, /**< The F9 key. */
CACA_KEY_F10 = 0x123, /**< The F10 key. */
CACA_KEY_F11 = 0x124, /**< The F11 key. */
CACA_KEY_F12 = 0x125, /**< The F12 key. */
CACA_KEY_F13 = 0x126, /**< The F13 key. */
CACA_KEY_F14 = 0x127, /**< The F14 key. */
CACA_KEY_F15 = 0x128 /**< The F15 key. */
}
public unsafe class Event
{
public enum type
{
NONE = 0x0000, /**< No event. */
KEY_PRESS = 0x0001, /**< A key was pressed. */
KEY_RELEASE = 0x0002, /**< A key was released. */
MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
RESIZE = 0x0020, /**< The window was resized. */
QUIT = 0x0040, /**< The user requested to quit. */
ANY = 0xffff /**< Bitmask for any event. */
};
}


public unsafe class Caca : IDisposable
{
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr caca_create_display(IntPtr qq);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void caca_free_display(IntPtr kk);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void caca_refresh_display(IntPtr kk);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void caca_set_delay(IntPtr kk, Int32 d);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 caca_get_rendertime(IntPtr kk);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 caca_get_display_width(IntPtr kk);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 caca_get_display_height(IntPtr kk);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 caca_set_display_title(IntPtr kk, string t);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 caca_get_event(IntPtr k, Event.type t, Event e, Int32 timeout);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 caca_get_mouse_x(IntPtr k);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 caca_get_mouse_y(IntPtr k);
[DllImport("libCaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void caca_set_mouse(IntPtr k, bool status);





IntPtr qq;
IntPtr kk;

public Caca(Cucul qqt)
{
qq = qqt.get_cucul_t();
kk = caca_create_display(qq);
}
public void Dispose()
{
caca_free_display(kk);
GC.SuppressFinalize(this);
}
public void Refresh()
{
caca_refresh_display(kk);
}
public void setDelay(Int32 d)
{
caca_set_delay(kk, d);
}
public Int32 getRendertime()
{
return caca_get_rendertime(kk);
}
public Int32 getDisplayWidth()
{
return caca_get_display_width(kk);
}
public Int32 getDisplayHeight()
{
return caca_get_display_height(kk);
}
public Int32 setDisplayTitle(string t)
{
return caca_set_display_title(kk, t);
}
public Int32 getEvent(Event.type t, Event e, Int32 timeout)
{
return caca_get_event(kk, t, e, timeout);
}
public Int32 getMouseX()
{
return caca_get_mouse_x(kk);
}
public Int32 getMouseY()
{
return caca_get_mouse_y(kk);
}
public void caca_set_mouse(bool status)
{
caca_set_mouse(kk, status);
}







public IntPtr get_caca_t()
{
return kk;
}


}
}

+ 152
- 0
DotNet/Cucul.cs 파일 보기

@@ -0,0 +1,152 @@
/*
* CuculSharp .NET bindings for libcucul
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*
* $Id: caca++.cpp 706 2006-04-26 18:53:08Z jylam $
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/



using System;
using System.Runtime.InteropServices;
using System.Security;



namespace libCucul
{
public unsafe class Cucul : IDisposable
{
/* Fixme */
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr cucul_create_canvas(int w, int h);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_get_canvas_width(IntPtr qq);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_get_canvas_height(IntPtr qq);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_set_canvas_size(IntPtr qq, int w, int h);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_rand(int min, int max);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_free_canvas(IntPtr qq);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_set_color(IntPtr qq, int fg, int bg);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_set_truecolor(IntPtr qq, Int32 fg, Int32 bg);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_putchar(IntPtr qq, int x, int y, char c);
/* [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_putstr(IntPtr qq, int, int, String);*/
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_clear_canvas(IntPtr qq);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_blit(IntPtr qq, Int32 x, Int32 y, IntPtr qq1, IntPtr qq2);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);





/*
char const *cucul_get_color_name(unsigned int);
int cucul_putstr(IntPtr *, int, int, char const *);
int cucul_printf(IntPtr *, int, int, char const *, ...);
*/



IntPtr qq;

public Cucul()
{
qq = cucul_create_canvas(0, 0);
}
public void Dispose()
{
cucul_free_canvas(qq);
GC.SuppressFinalize(this);
}
public Cucul(Int32 w, Int32 h)
{
qq = cucul_create_canvas(w, h);
}
public Int32 getWidth()
{
return cucul_get_canvas_width(qq);
}
public Int32 getHeight()
{
return cucul_get_canvas_height(qq);
}
public Int32 setSize(Int32 w, Int32 h)
{
return cucul_set_canvas_size(qq, w, h);
}
public static Int32 Rand(Int32 min, Int32 max)
{
return cucul_rand(min, max);
}
public Int32 setColor(int fg, int bg)
{
return cucul_set_color(qq, fg, bg);
}
public Int32 setTruecolor(Int32 fg, Int32 bg)
{
return cucul_set_truecolor(qq, fg, bg);
}
public Int32 putChar(int x, int y, char c)
{
return cucul_putchar(qq, x, y, c);
}
public Int32 clearCanvas()
{
return cucul_clear_canvas(qq);
}
public Int32 Blit(int x, int y, Cucul qq1, Cucul qq2)
{
return cucul_blit(qq, x, y, qq1.get_cucul_t(), qq2.get_cucul_t());
}
public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c)
{
return cucul_draw_line(qq, x1, y1, x2, y2, c);
}






/*
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
[DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);
*/



/* Privates methods, are not meant to be called by user*/
public IntPtr get_cucul_t()
{
return qq;
}
}
}


+ 5
- 0
DotNet/Makefile 파일 보기

@@ -0,0 +1,5 @@
all:
mcs AssemblyInfo.cs Cucul.cs -out:libCucul.dll -target:library -unsafe
mcs AssemblyInfo.cs Caca.cs -out:libCaca.dll -target:library /r:./libCucul.dll /lib:./ -unsafe

mcs test.cs -out:test.exe /r:./libCucul.dll /r:./libCaca.dll /lib:./ -unsafe

+ 3
- 0
DotNet/libCaca.dll.config 파일 보기

@@ -0,0 +1,3 @@
<configuration>
<dllmap dll="libCaca.dll" target="libcaca.so" />
</configuration>

+ 3
- 0
DotNet/libCucul.dll.config 파일 보기

@@ -0,0 +1,3 @@
<configuration>
<dllmap dll="libCucul.dll" target="libcucul.so" />
</configuration>

+ 64
- 0
DotNet/test.cs 파일 보기

@@ -0,0 +1,64 @@
/*
* Test .NET bindings test program
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
* All Rights Reserved
*
* $Id: caca++.cpp 706 2006-04-26 18:53:08Z jylam $
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Do What The Fuck You Want To
* Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/


using System;
using libCucul;
using libCaca;

class Test {



public static void Main() {
Console.WriteLine("libcaca .NET test");
Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");
/* Instanciate a cucul canvas */
Cucul qq = new Cucul();
/* Get size, and change it */
Console.WriteLine("Old size : {0}x{1}", qq.getWidth(), qq.getHeight());
qq.setSize(80,50);
Console.WriteLine("Newsize : {0}x{1}", qq.getWidth(), qq.getHeight());

/* Random number. This is a static method,
not to be used with previous instance */
Console.WriteLine("A random number : {0}", Cucul.Rand(0, 1337));


qq.putChar(0,0, 'J');

qq.drawLine(10, 15, 45, 27, "#");



/* We have a proper canvas, let's display it using Caca */
Caca kk = new Caca(qq);
kk.setDelay(2000000); // Refresh every 2 seconds

kk.setDisplayTitle("libcaca .NET Bindings test suite");

Event e = new Event();
while(kk.getEvent(Event.type.KEY_RELEASE, e, 10) == 0)
{
kk.Refresh();
Console.WriteLine("Render time : {0}", kk.getRendertime());
}


/* Force deletion of our instance for fun */
qq.Dispose();
}

}

불러오는 중...
취소
저장