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

* Add a C# wrapper for cucul_render_canvas().

* Use CuculFont.Render() in the C# test for a nice oldschool effect.
tags/v0.99.beta14
Sam Hocevar sam 17 лет назад
Родитель
Сommit
752a2f7783
2 измененных файлов: 36 добавлений и 24 удалений
  1. +16
    -0
      csharp/Cucul.cs
  2. +20
    -24
      csharp/test.cs

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

@@ -804,6 +804,22 @@ namespace Cucul


return ret; return ret;
} }

[DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl),
SuppressUnmanagedCodeSecurity]
private static extern int cucul_render_canvas(IntPtr cv, IntPtr f,
IntPtr buf, int w, int h,
int pitch);
public int Render(CuculCanvas cv, uint[,] buf, int pitch)
{
GCHandle gch = GCHandle.Alloc(buf, GCHandleType.Pinned);
int ret = cucul_render_canvas(cv._cv, _font,
gch.AddrOfPinnedObject(),
buf.GetLength(0), buf.GetLength(1),
pitch);
gch.Free();
return ret;
}
} }
} }



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

@@ -27,17 +27,25 @@ class DemoCanvas : CuculCanvas


private DateTime startTime; private DateTime startTime;
private CuculDither d; private CuculDither d;
private CuculFont f; private CuculCanvas scroll;


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


image = new uint[16,16]; string message = "LIBCACA *** 100% PURE WIN *** ";
d = new CuculDither(32, new Size(16, 16), 16 * 4, scroll = new CuculCanvas(new Size(message.Length, 1));
0xff0000, 0xff00, 0xff, 0x0); scroll.setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
f = new CuculFont(CuculFont.getList()[0]); scroll.putStr(new Point(0, 0), message);
f.getBlocks(); CuculFont f = new CuculFont(CuculFont.getList()[0]);
int w = f.Size.Width * message.Length;
int h = f.Size.Height;
image = new uint[w, h];
d = new CuculDither(32, new Size(w, h), w * 4,
0xff0000, 0xff00, 0xff, 0xff000000);
f.Render(scroll, image, image.GetLength(0) * 4);
} }


public void Draw() public void Draw()
@@ -47,24 +55,12 @@ class DemoCanvas : CuculCanvas


Clear(); Clear();


double cos = Math.Cos(t / 500.0); int w = Size.Width;
double sin = Math.Sin(t / 500.0); int h = Size.Height;

int x = (int)(t / 10) % (6 * w);
for(int y = 0; y < 16; y++) int y = (int)(h * (2.0 + Math.Sin(t / 200.0)) / 4);
for(int x = 0; x < 16; x++) ditherBitmap(new Rectangle(- x, h / 2 - y, w * 6, y * 2), d, image);
{ ditherBitmap(new Rectangle(6 * w - x, h / 2 - y, w * 6, y * 2), d, image);
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;

image[x,y] = (uint)((x2 + y2) << 16)
| (uint)(x2 << 8)
| (uint)(y2);
}
ditherBitmap(Rectangle, d, image);


setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
for(int i = 0; i < barCount; i++) for(int i = 0; i < barCount; i++)


||||||
x
 
000:0
Загрузка…
Отмена
Сохранить