Просмотр исходного кода

* Implement all line drawing functions (even variadic ones).

tags/v0.99.beta14
Sam Hocevar sam 17 лет назад
Родитель
Сommit
ad0ad85416
2 измененных файлов: 145 добавлений и 11 удалений
  1. +143
    -5
      csharp/Cucul.cs
  2. +2
    -6
      csharp/test.cs

+ 143
- 5
csharp/Cucul.cs Просмотреть файл

@@ -330,21 +330,159 @@ namespace Cucul
[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_line(IntPtr cv, int x1, int y1,
int x2, int y2, int c);
public int drawLine(Point p1, Point p2, int c)
int x2, int y2, uint c);
public int drawLine(Point p1, Point p2, uint c)
{
return cucul_draw_line(_cv, p1.X, p1.Y, p2.X, p2.Y, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_polyline(IntPtr cv, int[] x, int[] y, int n, IntPtr c);
private static extern int cucul_draw_polyline(IntPtr cv, int[] x,
int[] y, int n, uint c);
public int drawPolyline(Point[] lp, uint c)
{
int[] lx = new int[lp.Length];
int[] ly = new int[lp.Length];
for(int i = 0; i < lp.Length; i++)
{
lx[i] = lp[i].X;
ly[i] = lp[i].Y;
}
return cucul_draw_polyline(_cv, lx, ly, lp.Length - 1, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_thin_line(IntPtr cv, int x1,
int y1, int x2, int y2);
public int drawThinLine(Point p1, Point p2)
{
return cucul_draw_thin_line(_cv, p1.X, p1.Y, p2.X, p2.Y);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_thin_polyline(IntPtr cv, int[] x,
int[] y, int n);
public int drawThinPolyline(Point[] lp)
{
int[] lx = new int[lp.Length];
int[] ly = new int[lp.Length];
for(int i = 0; i < lp.Length; i++)
{
lx[i] = lp[i].X;
ly[i] = lp[i].Y;
}
return cucul_draw_thin_polyline(_cv, lx, ly, lp.Length - 1);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_circle(IntPtr cv, int x, int y,
int r, uint c);
public int drawCircle(Point p1, int r, uint c)
{
return cucul_draw_circle(_cv, p1.X, p1.Y, r, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_ellipse(IntPtr cv, int x, int y,
int a, int b, uint c);
public int drawEllipse(Point p1, int a, int b, uint c)
{
return cucul_draw_ellipse(_cv, p1.X, p1.Y, a, b, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_thin_ellipse(IntPtr cv,
int x, int y,
int a, int b);
public int drawThinEllipse(Point p1, int a, int b)
{
return cucul_draw_thin_ellipse(_cv, p1.X, p1.Y, a, b);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_thin_line(IntPtr cv, int x1, int y1, int x2, int y2);
private static extern int cucul_fill_ellipse(IntPtr cv, int x, int y,
int a, int b, uint c);
public int fillEllipse(Point p1, int a, int b, uint c)
{
return cucul_fill_ellipse(_cv, p1.X, p1.Y, a, b, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_thin_polyline(IntPtr cv, int[] x, int[] y, int n);
private static extern int cucul_draw_box(IntPtr cv, int x, int y,
int w, int h, uint c);
public int drawBox(Rectangle r, uint c)
{
return cucul_draw_box(_cv, r.X, r.Y, r.Width, r.Height, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_thin_box(IntPtr cv, int x, int y,
int w, int h);
public int drawThinBox(Rectangle r)
{
return cucul_draw_thin_box(_cv, r.X, r.Y, r.Width, r.Height);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_cp437_box(IntPtr cv, int x, int y,
int w, int h);
public int drawCp437Box(Rectangle r)
{
return cucul_draw_cp437_box(_cv, r.X, r.Y, r.Width, r.Height);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_fill_box(IntPtr cv, int x, int y,
int w, int h, uint c);
public int fillBox(Rectangle r, uint c)
{
return cucul_fill_box(_cv, r.X, r.Y, r.Width, r.Height, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_triangle(IntPtr cv, int x1,
int y1, int x2, int y2,
int x3, int y3, uint c);
public int drawTriangle(Point p1, Point p2, Point p3, uint c)
{
return cucul_draw_triangle(_cv, p1.X, p1.Y, p2.X, p2.Y,
p3.X, p3.Y, c);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_draw_thin_triangle(IntPtr cv,
int x1, int y1,
int x2, int y2,
int x3, int y3);
public int drawThinTriangle(Point p1, Point p2, Point p3)
{
return cucul_draw_thin_triangle(_cv, p1.X, p1.Y, p2.X, p2.Y,
p3.X, p3.Y);
}

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_fill_triangle(IntPtr cv, int x1,
int y1, int x2, int y2,
int x3, int y3, uint c);
public int fillTriangle(Point p1, Point p2, Point p3, uint c)
{
return cucul_fill_triangle(_cv, p1.X, p1.Y, p2.X, p2.Y,
p3.X, p3.Y, c);
}

/* frame handling */



+ 2
- 6
csharp/test.cs Просмотреть файл

@@ -75,7 +75,7 @@ class DemoCanvas : CuculCanvas
/* drawLine is already clipped, we don't care about overflows */
drawLine(p1 + new Size(0, -2), p2 + new Size(0, -2), '-');
drawLine(p1 + new Size(0, -1), p2 + new Size(0, -1), '*');
drawLine(p1, p2, '#');
drawLine(p1, p2, '#');
drawLine(p1 + new Size(0, 1), p2 + new Size(0, 1), '*');
drawLine(p1 + new Size(0, 2), p2 + new Size(0, 2), '-');
}
@@ -133,10 +133,6 @@ class Test
Console.WriteLine("A random number: {0}", Libcucul.Rand(0, 1337));

dp.EventLoop();

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

}


Загрузка…
Отмена
Сохранить