ソースを参照

* Rewrote the C# test in a more object-oriented way.

tags/v0.99.beta14
Sam Hocevar sam 18年前
コミット
2f7ac4ca2d
2個のファイルの変更71行の追加52行の削除
  1. +2
    -2
      csharp/Caca.cs
  2. +69
    -50
      csharp/test.cs

+ 2
- 2
csharp/Caca.cs ファイルの表示

@@ -82,7 +82,7 @@ namespace Caca
} }




public unsafe class Display : IDisposable
public unsafe class CacaDisplay : IDisposable
{ {
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern IntPtr caca_create_display(IntPtr cv); public static extern IntPtr caca_create_display(IntPtr cv);
@@ -116,7 +116,7 @@ namespace Caca
IntPtr _cv; IntPtr _cv;
IntPtr _dp; IntPtr _dp;


public Display(CuculCanvas cv)
public CacaDisplay(CuculCanvas cv)
{ {
_cv = cv._cv; _cv = cv._cv;
_dp = caca_create_display(_cv); _dp = caca_create_display(_cv);


+ 69
- 50
csharp/test.cs ファイルの表示

@@ -18,71 +18,90 @@ using System;
using Cucul; using Cucul;
using Caca; using Caca;


class Test {
class DemoCanvas : CuculCanvas
{
private DateTime startTime;


public DemoCanvas()
{
startTime = DateTime.Now;
}



public static void Main() {
public void Draw()
{
int barCount = 6; int barCount = 6;
double t = (DateTime.Now - startTime).TotalMilliseconds;

Clear();

setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
for(int i = 0; i < barCount; i++)
{
double v = ((Math.Sin((t / 500.0)
+ (i / ((double)barCount))) + 1) / 2) * height;
int y = (int)v;

setColorAnsi(i + 9, Libcucul.BLACK);
/* drawLine is already clipped, we don't care about overflows */
drawLine(0, y - 2, width, y - 2, '-');
drawLine(0, y - 1, width, y - 1, '*');
drawLine(0, y, width, y, '#');
drawLine(0, y + 1, width, y + 1, '*');
drawLine(0, y + 2, width, y + 2, '-');
}

setColorAnsi(Libcucul.WHITE, Libcucul.BLUE);
putStr(width - 30, height - 2, " -=[ Powered by libcaca ]=- ");
setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
}
}

class DemoDisplay : CacaDisplay
{
private Event e;
private DemoCanvas cv;

public DemoDisplay(DemoCanvas _cv) : base(_cv)
{
setDisplayTime(20000); // Refresh every 20 ms
setDisplayTitle("libcaca .NET Bindings test suite");
cv = _cv;
e = new Event();
}

public void EventLoop()
{
while(getEvent(Event.type.KEY_RELEASE, e, 10) == 0)
{
cv.Draw();

Refresh();
}
}
}

class Test
{
public static void Main()
{
Console.WriteLine("libcaca .NET test"); Console.WriteLine("libcaca .NET test");
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 */
CuculCanvas cv = new CuculCanvas();
DemoCanvas cv = new DemoCanvas();


/* We have a proper canvas, let's display it using Caca */
DemoDisplay dp = new DemoDisplay(cv);


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




/* We have a proper canvas, let's display it using Caca */
Display dp = new Display(cv);
dp.setDisplayTime(20000); // Refresh every 20 ms

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

double v;
Int32 y = 0;
Event e = new Event();
int i;

DateTime startTime = DateTime.Now;
while(dp.getEvent(Event.type.KEY_RELEASE, e, 10) == 0)
{
TimeSpan curTime = DateTime.Now - startTime;
double t = curTime.TotalMilliseconds;
cv.setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
for(i=0; i<barCount;i++)
{
v = ((Math.Sin((t/500.0)+(i/((double)barCount)))+1)/2)*cv.height;
y = (Int32) v;



cv.setColorAnsi(i+9, Libcucul.BLACK);
/* drawLine is already clipped, we don't care about overflows */
cv.drawLine(0, y-2, cv.width, y-2, '-');
cv.drawLine(0, y-1, cv.width, y-1, '*');
cv.drawLine(0, y, cv.width, y, '#');
cv.drawLine(0, y+1, cv.width, y+1, '*');
cv.drawLine(0, y+2, cv.width, y+2, '-');
}

cv.setColorAnsi(Libcucul.WHITE, Libcucul.BLUE);
cv.putStr(cv.width - 30,cv.height - 2," -=[ Powered by libcaca ]=- ");
cv.setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);


dp.Refresh();
cv.Clear();

}
dp.EventLoop();


/* Force deletion of our instances for fun */ /* Force deletion of our instances for fun */
dp.Dispose(); dp.Dispose();
cv.Dispose(); cv.Dispose();
}
}


} }

読み込み中…
キャンセル
保存