瀏覽代碼

* .Net : Fixed drawLine() and updated example (rasters rule)

tags/v0.99.beta14
Jean-Yves Lamoureux jylam 18 年之前
父節點
當前提交
66eebe567c
共有 2 個檔案被更改,包括 40 行新增27 行删除
  1. +3
    -3
      DotNet/Cucul.cs
  2. +37
    -24
      DotNet/test.cs

+ 3
- 3
DotNet/Cucul.cs 查看文件

@@ -50,7 +50,7 @@ namespace libCucul
[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);
public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 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]
@@ -190,7 +190,7 @@ namespace libCucul
{
return cucul_putchar(qq, x, y, c);
}
public Int32 clearCanvas()
public Int32 Clear()
{
return cucul_clear_canvas(qq);
}
@@ -198,7 +198,7 @@ namespace libCucul
{
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)
public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 c)
{
return cucul_draw_line(qq, x1, y1, x2, y2, c);
}


+ 37
- 24
DotNet/test.cs 查看文件

@@ -21,53 +21,66 @@ class Test {


public static void Main() {
int barCount = 6;
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));

/* Draw stuff on our canvas */
qq.putChar(0,0, 'J');
qq.setColor(Cucul.CUCUL_BLUE, Cucul.CUCUL_RED);
qq.drawLine(10, 15, 45, 27, "#");
qq.putStr(10, 10, "Hello from .NET");
Console.WriteLine("Char at 0,0 : {0}", qq.getChar(0,0));
qq.Flip();


/* Create a Dither instance */
Dither dither = new Dither(32, 320, 200, 320, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
dither.setBrightness((float)0.7);
string[] aalist = dither.getAntialiasList();
Console.WriteLine("List : '{0}'", aalist[1]);


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

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

double v;
Int32 y = 0;
Event e = new Event();
int startTime = kk.getDisplayTime();
Int32 i;
DateTime startTime = DateTime.Now;
while(kk.getEvent(Event.type.KEY_RELEASE, e, 10) == 0)
{
kk.Refresh();
Console.WriteLine("Render time : {0}", kk.getDisplayTime()-startTime);
TimeSpan curTime = DateTime.Now - startTime;
double t = curTime.TotalMilliseconds;
qq.setColor(Cucul.CUCUL_WHITE, Cucul.CUCUL_BLACK);
for(i=0; i<barCount;i++)
{
v = ((Math.Sin((t/500.0)+(i/((double)barCount)))+1)/2)*qq.getHeight();
y = (Int32) v;


qq.setColor(i+1, Cucul.CUCUL_BLACK);
/* drawLine is already clipped, we don't care about overflows */
qq.drawLine(0, y-2, qq.getWidth(), y-2, '-');
qq.drawLine(0, y-1, qq.getWidth(), y-1, '*');
qq.drawLine(0, y, qq.getWidth(), y, '#');
qq.drawLine(0, y+1, qq.getWidth(), y+1, '*');
qq.drawLine(0, y+2, qq.getWidth(), y+2, '-');
}

qq.setColor(Cucul.CUCUL_WHITE, Cucul.CUCUL_BLUE);
qq.putStr(qq.getWidth() - 30,qq.getHeight() - 2," -=[ Powered by libcaca ]=- ");
qq.setColor(Cucul.CUCUL_WHITE, Cucul.CUCUL_BLACK);

kk.Refresh();
qq.Clear();
}

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

}

Loading…
取消
儲存