1 | /* |
---|
2 | * libcucul .NET bindings for libcucul |
---|
3 | * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
4 | * 2007 Sam Hocevar <sam@zoy.org> |
---|
5 | * All Rights Reserved |
---|
6 | * |
---|
7 | * $Id: Cucul.cs 2091 2007-11-28 07:15:09Z sam $ |
---|
8 | * |
---|
9 | * This library is free software. It comes without any warranty, to |
---|
10 | * the extent permitted by applicable law. You can redistribute it |
---|
11 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
12 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
13 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
14 | */ |
---|
15 | |
---|
16 | using System; |
---|
17 | using System.Runtime.InteropServices; |
---|
18 | using System.Security; |
---|
19 | using System.Drawing; |
---|
20 | |
---|
21 | namespace Cucul |
---|
22 | { |
---|
23 | /* Static libcucul stuff that does not fit in any object */ |
---|
24 | public static class Libcucul |
---|
25 | { |
---|
26 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
27 | SuppressUnmanagedCodeSecurity] |
---|
28 | private static extern int cucul_rand(int min, int max); |
---|
29 | public static int Rand(int min, int max) |
---|
30 | { |
---|
31 | return cucul_rand(min, max); |
---|
32 | } |
---|
33 | |
---|
34 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
35 | SuppressUnmanagedCodeSecurity] |
---|
36 | private static extern IntPtr cucul_get_version(); |
---|
37 | public static string getVersion() |
---|
38 | { |
---|
39 | return Marshal.PtrToStringAnsi(cucul_get_version()); |
---|
40 | } |
---|
41 | |
---|
42 | public const int BLACK = 0x00, |
---|
43 | BLUE = 0x01, |
---|
44 | GREEN = 0x02, |
---|
45 | CYAN = 0x03, |
---|
46 | RED = 0x04, |
---|
47 | MAGENTA = 0x05, |
---|
48 | BROWN = 0x06, |
---|
49 | LIGHTGRAY = 0x07, |
---|
50 | DARKGRAY = 0x08, |
---|
51 | LIGHTBLUE = 0x09, |
---|
52 | LIGHTGREEN = 0x0a, |
---|
53 | LIGHTCYAN = 0x0b, |
---|
54 | LIGHTRED = 0x0c, |
---|
55 | LIGHTMAGENTA = 0x0d, |
---|
56 | YELLOW = 0x0e, |
---|
57 | WHITE = 0x0f, |
---|
58 | DEFAULT = 0x10, |
---|
59 | TRANSPARENT = 0x20; |
---|
60 | |
---|
61 | public const int BOLD = 0x01, |
---|
62 | ITALICS = 0x02, |
---|
63 | UNDERLINE = 0x04, |
---|
64 | BLINK = 0x08; |
---|
65 | } |
---|
66 | |
---|
67 | public class CuculCanvas : IDisposable |
---|
68 | { |
---|
69 | public readonly IntPtr _cv; |
---|
70 | |
---|
71 | /* libcucul basic functions */ |
---|
72 | |
---|
73 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
74 | SuppressUnmanagedCodeSecurity] |
---|
75 | private static extern IntPtr cucul_create_canvas(int w, int h); |
---|
76 | public CuculCanvas() |
---|
77 | { |
---|
78 | _cv = cucul_create_canvas(0, 0); |
---|
79 | } |
---|
80 | |
---|
81 | public CuculCanvas(Size s) |
---|
82 | { |
---|
83 | _cv = cucul_create_canvas(s.Width, s.Height); |
---|
84 | } |
---|
85 | |
---|
86 | public CuculCanvas(int w, int h) |
---|
87 | { |
---|
88 | _cv = cucul_create_canvas(h, w); |
---|
89 | } |
---|
90 | |
---|
91 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
92 | SuppressUnmanagedCodeSecurity] |
---|
93 | private static extern int cucul_free_canvas(IntPtr cv); |
---|
94 | public void Dispose() |
---|
95 | { |
---|
96 | cucul_free_canvas(_cv); |
---|
97 | GC.SuppressFinalize(this); |
---|
98 | } |
---|
99 | |
---|
100 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
101 | SuppressUnmanagedCodeSecurity] |
---|
102 | private static extern int cucul_set_canvas_size(IntPtr cv, |
---|
103 | int w, int h); |
---|
104 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
105 | SuppressUnmanagedCodeSecurity] |
---|
106 | private static extern int cucul_get_canvas_width(IntPtr cv); |
---|
107 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
108 | SuppressUnmanagedCodeSecurity] |
---|
109 | private static extern int cucul_get_canvas_height(IntPtr cv); |
---|
110 | public Size Size |
---|
111 | { |
---|
112 | get { return new Size(cucul_get_canvas_width(_cv), |
---|
113 | cucul_get_canvas_height(_cv)); } |
---|
114 | set { cucul_set_canvas_size(_cv, value.Width, value.Height); } |
---|
115 | } |
---|
116 | |
---|
117 | public Rectangle Rectangle |
---|
118 | { |
---|
119 | get { return new Rectangle(0, 0, cucul_get_canvas_width(_cv), |
---|
120 | cucul_get_canvas_height(_cv)); } |
---|
121 | set { cucul_set_canvas_size(_cv, value.Width, value.Height); } |
---|
122 | } |
---|
123 | |
---|
124 | /* canvas drawing */ |
---|
125 | |
---|
126 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
127 | SuppressUnmanagedCodeSecurity] |
---|
128 | private static extern int cucul_gotoxy(IntPtr cv, int x, int y); |
---|
129 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
130 | SuppressUnmanagedCodeSecurity] |
---|
131 | private static extern int cucul_get_cursor_x(IntPtr cv); |
---|
132 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
133 | SuppressUnmanagedCodeSecurity] |
---|
134 | private static extern int cucul_get_cursor_y(IntPtr cv); |
---|
135 | public Point Cursor |
---|
136 | { |
---|
137 | get { return new Point(cucul_get_cursor_x(_cv), |
---|
138 | cucul_get_cursor_y(_cv)); } |
---|
139 | set { cucul_gotoxy(_cv, value.X, value.Y); } |
---|
140 | } |
---|
141 | |
---|
142 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
143 | SuppressUnmanagedCodeSecurity] |
---|
144 | private static extern int cucul_put_char(IntPtr cv, |
---|
145 | int x, int y, int c); |
---|
146 | public int putChar(Point p, int c) |
---|
147 | { |
---|
148 | return cucul_put_char(_cv, p.X, p.Y, c); |
---|
149 | } |
---|
150 | |
---|
151 | public int putChar(int x, int y, int c) |
---|
152 | { |
---|
153 | return cucul_put_char(_cv, x, y, c); |
---|
154 | } |
---|
155 | |
---|
156 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
157 | SuppressUnmanagedCodeSecurity] |
---|
158 | private static extern int cucul_get_char(IntPtr cv, int x, int y); |
---|
159 | public int getChar(Point p) |
---|
160 | { |
---|
161 | return cucul_get_char(_cv, p.X, p.Y); |
---|
162 | } |
---|
163 | |
---|
164 | public int getChar(int x, int y) |
---|
165 | { |
---|
166 | return cucul_get_char(_cv, x, y); |
---|
167 | } |
---|
168 | |
---|
169 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
170 | SuppressUnmanagedCodeSecurity] |
---|
171 | private static extern int cucul_put_str(IntPtr cv, |
---|
172 | int x, int y, string c); |
---|
173 | public int putStr(Point p, string c) |
---|
174 | { |
---|
175 | return cucul_put_str(_cv, p.X, p.Y, c); |
---|
176 | } |
---|
177 | |
---|
178 | public int putStr(int x, int y, string c) |
---|
179 | { |
---|
180 | return cucul_put_str(_cv, x, y, c); |
---|
181 | } |
---|
182 | |
---|
183 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
184 | SuppressUnmanagedCodeSecurity] |
---|
185 | private static extern int cucul_get_attr(IntPtr cv, int x, int y); |
---|
186 | public int getAttr(Point p) |
---|
187 | { |
---|
188 | return cucul_get_attr(_cv, p.X, p.Y); |
---|
189 | } |
---|
190 | |
---|
191 | public int getAttr(int x, int y) |
---|
192 | { |
---|
193 | return cucul_get_attr(_cv, x, y); |
---|
194 | } |
---|
195 | |
---|
196 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
197 | SuppressUnmanagedCodeSecurity] |
---|
198 | private static extern int cucul_set_attr(IntPtr cv, int a); |
---|
199 | public int setAttr(int a) |
---|
200 | { |
---|
201 | return cucul_set_attr(_cv, a); |
---|
202 | } |
---|
203 | |
---|
204 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
205 | SuppressUnmanagedCodeSecurity] |
---|
206 | private static extern int cucul_put_attr(IntPtr cv, |
---|
207 | int x, int y, int a); |
---|
208 | public int putAttr(Point p, int a) |
---|
209 | { |
---|
210 | return cucul_put_attr(_cv, p.X, p.Y, a); |
---|
211 | } |
---|
212 | |
---|
213 | public int putAttr(int x, int y, int a) |
---|
214 | { |
---|
215 | return cucul_put_attr(_cv, x, y, a); |
---|
216 | } |
---|
217 | |
---|
218 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
219 | SuppressUnmanagedCodeSecurity] |
---|
220 | private static extern int cucul_set_color_ansi(IntPtr cv, |
---|
221 | byte fg, byte bg); |
---|
222 | public int setColorAnsi(int fg, int bg) |
---|
223 | { |
---|
224 | return cucul_set_color_ansi(_cv, (byte)fg, (byte)bg); |
---|
225 | } |
---|
226 | |
---|
227 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
228 | SuppressUnmanagedCodeSecurity] |
---|
229 | private static extern int cucul_set_color_argb(IntPtr cv, |
---|
230 | int fg, int bg); |
---|
231 | public int setColorArgb(int fg, int bg) |
---|
232 | { |
---|
233 | return cucul_set_color_argb(_cv, fg, bg); |
---|
234 | } |
---|
235 | |
---|
236 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
237 | SuppressUnmanagedCodeSecurity] |
---|
238 | private static extern int cucul_clear_canvas(IntPtr cv); |
---|
239 | public int Clear() |
---|
240 | { |
---|
241 | return cucul_clear_canvas(_cv); |
---|
242 | } |
---|
243 | |
---|
244 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
245 | SuppressUnmanagedCodeSecurity] |
---|
246 | private static extern int cucul_set_canvas_handle(IntPtr cv, |
---|
247 | int x, int y); |
---|
248 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
249 | SuppressUnmanagedCodeSecurity] |
---|
250 | private static extern int cucul_get_canvas_handle_x(IntPtr cv); |
---|
251 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
252 | SuppressUnmanagedCodeSecurity] |
---|
253 | private static extern int cucul_get_canvas_handle_y(IntPtr cv); |
---|
254 | public Point Handle |
---|
255 | { |
---|
256 | get { return new Point(cucul_get_canvas_handle_x(_cv), |
---|
257 | cucul_get_canvas_handle_y(_cv)); } |
---|
258 | set { cucul_set_canvas_handle(_cv, value.X, value.Y); } |
---|
259 | } |
---|
260 | |
---|
261 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
262 | SuppressUnmanagedCodeSecurity] |
---|
263 | private static extern int cucul_blit(IntPtr cv, int x, int y, |
---|
264 | IntPtr cv1, IntPtr cv2); |
---|
265 | public int Blit(Point p, CuculCanvas canvas) |
---|
266 | { |
---|
267 | return cucul_blit(_cv, p.X, p.Y, canvas._cv, IntPtr.Zero); |
---|
268 | } |
---|
269 | |
---|
270 | public int Blit(Point p, CuculCanvas cv, CuculCanvas mask) |
---|
271 | { |
---|
272 | return cucul_blit(_cv, p.X, p.Y, cv._cv, mask._cv); |
---|
273 | } |
---|
274 | |
---|
275 | public int Blit(int x, int y, CuculCanvas canvas) |
---|
276 | { |
---|
277 | return cucul_blit(_cv, x, y, canvas._cv, IntPtr.Zero); |
---|
278 | } |
---|
279 | |
---|
280 | public int Blit(int x, int y, CuculCanvas cv, CuculCanvas mask) |
---|
281 | { |
---|
282 | return cucul_blit(_cv, x, y, cv._cv, mask._cv); |
---|
283 | } |
---|
284 | |
---|
285 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
286 | SuppressUnmanagedCodeSecurity] |
---|
287 | private static extern int cucul_set_canvas_boundaries(IntPtr cv, |
---|
288 | int x, int y, |
---|
289 | int h, int w); |
---|
290 | public int setBoundaries(Rectangle r) |
---|
291 | { |
---|
292 | return cucul_set_canvas_boundaries(_cv, r.X, r.Y, |
---|
293 | r.Width, r.Height); |
---|
294 | } |
---|
295 | |
---|
296 | public int setBoundaries(int x, int y, int w, int h) |
---|
297 | { |
---|
298 | return cucul_set_canvas_boundaries(_cv, x, y, w, h); |
---|
299 | } |
---|
300 | |
---|
301 | /* canvas transformation */ |
---|
302 | |
---|
303 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
304 | SuppressUnmanagedCodeSecurity] |
---|
305 | private static extern int cucul_invert(IntPtr cv); |
---|
306 | public int Invert() |
---|
307 | { |
---|
308 | return cucul_invert(_cv); |
---|
309 | } |
---|
310 | |
---|
311 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
312 | SuppressUnmanagedCodeSecurity] |
---|
313 | private static extern int cucul_flip(IntPtr cv); |
---|
314 | public int Flip() |
---|
315 | { |
---|
316 | return cucul_flip(_cv); |
---|
317 | } |
---|
318 | |
---|
319 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
320 | SuppressUnmanagedCodeSecurity] |
---|
321 | private static extern int cucul_flop(IntPtr cv); |
---|
322 | public int Flop() |
---|
323 | { |
---|
324 | return cucul_flop(_cv); |
---|
325 | } |
---|
326 | |
---|
327 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
328 | SuppressUnmanagedCodeSecurity] |
---|
329 | private static extern int cucul_rotate_180(IntPtr cv); |
---|
330 | public int Rotate180() |
---|
331 | { |
---|
332 | return cucul_rotate_180(_cv); |
---|
333 | } |
---|
334 | |
---|
335 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
336 | SuppressUnmanagedCodeSecurity] |
---|
337 | private static extern int cucul_rotate_left(IntPtr cv); |
---|
338 | public int RotateLeft() |
---|
339 | { |
---|
340 | return cucul_rotate_left(_cv); |
---|
341 | } |
---|
342 | |
---|
343 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
344 | SuppressUnmanagedCodeSecurity] |
---|
345 | private static extern int cucul_rotate_right(IntPtr cv); |
---|
346 | public int RotateRight() |
---|
347 | { |
---|
348 | return cucul_rotate_right(_cv); |
---|
349 | } |
---|
350 | |
---|
351 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
352 | SuppressUnmanagedCodeSecurity] |
---|
353 | private static extern int cucul_stretch_left(IntPtr cv); |
---|
354 | public int StretchLeft() |
---|
355 | { |
---|
356 | return cucul_stretch_left(_cv); |
---|
357 | } |
---|
358 | |
---|
359 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
360 | SuppressUnmanagedCodeSecurity] |
---|
361 | private static extern int cucul_stretch_right(IntPtr cv); |
---|
362 | public int StretchRight() |
---|
363 | { |
---|
364 | return cucul_stretch_right(_cv); |
---|
365 | } |
---|
366 | |
---|
367 | /* primitives drawing */ |
---|
368 | |
---|
369 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
370 | SuppressUnmanagedCodeSecurity] |
---|
371 | private static extern int cucul_draw_line(IntPtr cv, int x1, int y1, |
---|
372 | int x2, int y2, uint c); |
---|
373 | public int drawLine(Point p1, Point p2, uint c) |
---|
374 | { |
---|
375 | return cucul_draw_line(_cv, p1.X, p1.Y, p2.X, p2.Y, c); |
---|
376 | } |
---|
377 | |
---|
378 | public int drawLine(int x1, int y1, int x2, int y2, uint c) |
---|
379 | { |
---|
380 | return cucul_draw_line(_cv, x1, y1, x2, y2, c); |
---|
381 | } |
---|
382 | |
---|
383 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
384 | SuppressUnmanagedCodeSecurity] |
---|
385 | private static extern int cucul_draw_polyline(IntPtr cv, int[] x, |
---|
386 | int[] y, int n, uint c); |
---|
387 | public int drawPolyline(Point[] lp, uint c) |
---|
388 | { |
---|
389 | int[] lx = new int[lp.Length]; |
---|
390 | int[] ly = new int[lp.Length]; |
---|
391 | for(int i = 0; i < lp.Length; i++) |
---|
392 | { |
---|
393 | lx[i] = lp[i].X; |
---|
394 | ly[i] = lp[i].Y; |
---|
395 | } |
---|
396 | return cucul_draw_polyline(_cv, lx, ly, lp.Length - 1, c); |
---|
397 | } |
---|
398 | |
---|
399 | public int drawPolyline(int[] lx, int[] ly, uint c) |
---|
400 | { |
---|
401 | if(lx.Length != ly.Length) |
---|
402 | return -1; |
---|
403 | |
---|
404 | return cucul_draw_polyline(_cv, lx, ly, lx.Length - 1, c); |
---|
405 | } |
---|
406 | |
---|
407 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
408 | SuppressUnmanagedCodeSecurity] |
---|
409 | private static extern int cucul_draw_thin_line(IntPtr cv, int x1, |
---|
410 | int y1, int x2, int y2); |
---|
411 | public int drawThinLine(Point p1, Point p2) |
---|
412 | { |
---|
413 | return cucul_draw_thin_line(_cv, p1.X, p1.Y, p2.X, p2.Y); |
---|
414 | } |
---|
415 | |
---|
416 | public int drawThinLine(int x1, int y1, int x2, int y2) |
---|
417 | { |
---|
418 | return cucul_draw_thin_line(_cv, x1, y1, x2, y2); |
---|
419 | } |
---|
420 | |
---|
421 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
422 | SuppressUnmanagedCodeSecurity] |
---|
423 | private static extern int cucul_draw_thin_polyline(IntPtr cv, int[] x, |
---|
424 | int[] y, int n); |
---|
425 | public int drawThinPolyline(Point[] lp) |
---|
426 | { |
---|
427 | int[] lx = new int[lp.Length]; |
---|
428 | int[] ly = new int[lp.Length]; |
---|
429 | for(int i = 0; i < lp.Length; i++) |
---|
430 | { |
---|
431 | lx[i] = lp[i].X; |
---|
432 | ly[i] = lp[i].Y; |
---|
433 | } |
---|
434 | return cucul_draw_thin_polyline(_cv, lx, ly, lp.Length - 1); |
---|
435 | } |
---|
436 | |
---|
437 | public int drawThinPolyline(int[] lx, int[] ly) |
---|
438 | { |
---|
439 | if(lx.Length != ly.Length) |
---|
440 | return -1; |
---|
441 | |
---|
442 | return cucul_draw_thin_polyline(_cv, lx, ly, lx.Length - 1); |
---|
443 | } |
---|
444 | |
---|
445 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
446 | SuppressUnmanagedCodeSecurity] |
---|
447 | private static extern int cucul_draw_circle(IntPtr cv, int x, int y, |
---|
448 | int r, uint c); |
---|
449 | public int drawCircle(Point p, int r, uint c) |
---|
450 | { |
---|
451 | return cucul_draw_circle(_cv, p.X, p.Y, r, c); |
---|
452 | } |
---|
453 | |
---|
454 | public int drawCircle(int x, int y, int r, uint c) |
---|
455 | { |
---|
456 | return cucul_draw_circle(_cv, x, y, r, c); |
---|
457 | } |
---|
458 | |
---|
459 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
460 | SuppressUnmanagedCodeSecurity] |
---|
461 | private static extern int cucul_draw_ellipse(IntPtr cv, int x, int y, |
---|
462 | int a, int b, uint c); |
---|
463 | public int drawEllipse(Point p, int a, int b, uint c) |
---|
464 | { |
---|
465 | return cucul_draw_ellipse(_cv, p.X, p.Y, a, b, c); |
---|
466 | } |
---|
467 | |
---|
468 | public int drawEllipse(int x, int y, int a, int b, uint c) |
---|
469 | { |
---|
470 | return cucul_draw_ellipse(_cv, x, y, a, b, c); |
---|
471 | } |
---|
472 | |
---|
473 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
474 | SuppressUnmanagedCodeSecurity] |
---|
475 | private static extern int cucul_draw_thin_ellipse(IntPtr cv, |
---|
476 | int x, int y, |
---|
477 | int a, int b); |
---|
478 | public int drawThinEllipse(Point p, int a, int b) |
---|
479 | { |
---|
480 | return cucul_draw_thin_ellipse(_cv, p.X, p.Y, a, b); |
---|
481 | } |
---|
482 | |
---|
483 | public int drawThinEllipse(int x, int y, int a, int b) |
---|
484 | { |
---|
485 | return cucul_draw_thin_ellipse(_cv, x, y, a, b); |
---|
486 | } |
---|
487 | |
---|
488 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
489 | SuppressUnmanagedCodeSecurity] |
---|
490 | private static extern int cucul_fill_ellipse(IntPtr cv, int x, int y, |
---|
491 | int a, int b, uint c); |
---|
492 | public int fillEllipse(Point p, int a, int b, uint c) |
---|
493 | { |
---|
494 | return cucul_fill_ellipse(_cv, p.X, p.Y, a, b, c); |
---|
495 | } |
---|
496 | |
---|
497 | public int fillEllipse(int x, int y, int a, int b, uint c) |
---|
498 | { |
---|
499 | return cucul_fill_ellipse(_cv, x, y, a, b, c); |
---|
500 | } |
---|
501 | |
---|
502 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
503 | SuppressUnmanagedCodeSecurity] |
---|
504 | private static extern int cucul_draw_box(IntPtr cv, int x, int y, |
---|
505 | int w, int h, uint c); |
---|
506 | public int drawBox(Rectangle r, uint c) |
---|
507 | { |
---|
508 | return cucul_draw_box(_cv, r.X, r.Y, r.Width, r.Height, c); |
---|
509 | } |
---|
510 | |
---|
511 | public int drawBox(int x, int y, int w, int h, uint c) |
---|
512 | { |
---|
513 | return cucul_draw_box(_cv, x, y, w, h, c); |
---|
514 | } |
---|
515 | |
---|
516 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
517 | SuppressUnmanagedCodeSecurity] |
---|
518 | private static extern int cucul_draw_thin_box(IntPtr cv, int x, int y, |
---|
519 | int w, int h); |
---|
520 | public int drawThinBox(Rectangle r) |
---|
521 | { |
---|
522 | return cucul_draw_thin_box(_cv, r.X, r.Y, r.Width, r.Height); |
---|
523 | } |
---|
524 | |
---|
525 | public int drawThinBox(int x, int y, int w, int h) |
---|
526 | { |
---|
527 | return cucul_draw_thin_box(_cv, x, y, w, h); |
---|
528 | } |
---|
529 | |
---|
530 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
531 | SuppressUnmanagedCodeSecurity] |
---|
532 | private static extern int cucul_draw_cp437_box(IntPtr cv, int x, int y, |
---|
533 | int w, int h); |
---|
534 | public int drawCp437Box(Rectangle r) |
---|
535 | { |
---|
536 | return cucul_draw_cp437_box(_cv, r.X, r.Y, r.Width, r.Height); |
---|
537 | } |
---|
538 | |
---|
539 | public int drawCp437Box(int x, int y, int w, int h) |
---|
540 | { |
---|
541 | return cucul_draw_cp437_box(_cv, x, y, w, h); |
---|
542 | } |
---|
543 | |
---|
544 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
545 | SuppressUnmanagedCodeSecurity] |
---|
546 | private static extern int cucul_fill_box(IntPtr cv, int x, int y, |
---|
547 | int w, int h, uint c); |
---|
548 | public int fillBox(Rectangle r, uint c) |
---|
549 | { |
---|
550 | return cucul_fill_box(_cv, r.X, r.Y, r.Width, r.Height, c); |
---|
551 | } |
---|
552 | |
---|
553 | public int fillBox(int x, int y, int w, int h, uint c) |
---|
554 | { |
---|
555 | return cucul_fill_box(_cv, x, y, w, h, c); |
---|
556 | } |
---|
557 | |
---|
558 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
559 | SuppressUnmanagedCodeSecurity] |
---|
560 | private static extern int cucul_draw_triangle(IntPtr cv, int x1, |
---|
561 | int y1, int x2, int y2, |
---|
562 | int x3, int y3, uint c); |
---|
563 | public int drawTriangle(Point p1, Point p2, Point p3, uint c) |
---|
564 | { |
---|
565 | return cucul_draw_triangle(_cv, p1.X, p1.Y, p2.X, p2.Y, |
---|
566 | p3.X, p3.Y, c); |
---|
567 | } |
---|
568 | |
---|
569 | public int drawTriangle(int x1, int y1, int x2, int y2, |
---|
570 | int x3, int y3, uint c) |
---|
571 | { |
---|
572 | return cucul_draw_triangle(_cv, x1, y1, x2, y2, x3, y3, c); |
---|
573 | } |
---|
574 | |
---|
575 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
576 | SuppressUnmanagedCodeSecurity] |
---|
577 | private static extern int cucul_draw_thin_triangle(IntPtr cv, |
---|
578 | int x1, int y1, |
---|
579 | int x2, int y2, |
---|
580 | int x3, int y3); |
---|
581 | public int drawThinTriangle(Point p1, Point p2, Point p3) |
---|
582 | { |
---|
583 | return cucul_draw_thin_triangle(_cv, p1.X, p1.Y, p2.X, p2.Y, |
---|
584 | p3.X, p3.Y); |
---|
585 | } |
---|
586 | |
---|
587 | public int drawThinTriangle(int x1, int y1, int x2, int y2, |
---|
588 | int x3, int y3) |
---|
589 | { |
---|
590 | return cucul_draw_thin_triangle(_cv, x1, y1, x2, y2, x3, y3); |
---|
591 | } |
---|
592 | |
---|
593 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
594 | SuppressUnmanagedCodeSecurity] |
---|
595 | private static extern int cucul_fill_triangle(IntPtr cv, int x1, |
---|
596 | int y1, int x2, int y2, |
---|
597 | int x3, int y3, uint c); |
---|
598 | public int fillTriangle(Point p1, Point p2, Point p3, uint c) |
---|
599 | { |
---|
600 | return cucul_fill_triangle(_cv, p1.X, p1.Y, p2.X, p2.Y, |
---|
601 | p3.X, p3.Y, c); |
---|
602 | } |
---|
603 | |
---|
604 | public int fillTriangle(int x1, int y1, int x2, int y2, |
---|
605 | int x3, int y3, uint c) |
---|
606 | { |
---|
607 | return cucul_fill_triangle(_cv, x1, y1, x2, y2, x3, y3, c); |
---|
608 | } |
---|
609 | |
---|
610 | /* frame handling */ |
---|
611 | |
---|
612 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
613 | SuppressUnmanagedCodeSecurity] |
---|
614 | private static extern int cucul_get_frame_count(IntPtr cv); |
---|
615 | public int getFrameCount() |
---|
616 | { |
---|
617 | return cucul_get_frame_count(_cv); |
---|
618 | } |
---|
619 | |
---|
620 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
621 | SuppressUnmanagedCodeSecurity] |
---|
622 | private static extern int cucul_set_frame(IntPtr cv, int f); |
---|
623 | public int setFrame(int f) |
---|
624 | { |
---|
625 | return cucul_set_frame(_cv, f); |
---|
626 | } |
---|
627 | |
---|
628 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
629 | SuppressUnmanagedCodeSecurity] |
---|
630 | private static extern string cucul_get_frame_name(IntPtr cv); |
---|
631 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
632 | SuppressUnmanagedCodeSecurity] |
---|
633 | private static extern int cucul_set_frame_name(IntPtr cv, string n); |
---|
634 | public string FrameName |
---|
635 | { |
---|
636 | get { return cucul_get_frame_name(_cv); } |
---|
637 | set { cucul_set_frame_name(_cv, value); } |
---|
638 | } |
---|
639 | |
---|
640 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
641 | SuppressUnmanagedCodeSecurity] |
---|
642 | private static extern int cucul_create_frame(IntPtr cv, int f); |
---|
643 | public int createFrame(int f) |
---|
644 | { |
---|
645 | return cucul_create_frame(_cv, f); |
---|
646 | } |
---|
647 | |
---|
648 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
649 | SuppressUnmanagedCodeSecurity] |
---|
650 | private static extern int cucul_free_frame(IntPtr cv, int f); |
---|
651 | public int freeFrame(int f) |
---|
652 | { |
---|
653 | return cucul_free_frame(_cv, f); |
---|
654 | } |
---|
655 | |
---|
656 | /* bitmap dithering */ |
---|
657 | |
---|
658 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
659 | SuppressUnmanagedCodeSecurity] |
---|
660 | private static extern int cucul_dither_bitmap(IntPtr c, int x, int y, |
---|
661 | int w, int h, |
---|
662 | IntPtr d, IntPtr data); |
---|
663 | public int ditherBitmap(Rectangle r, CuculDither d, object data) |
---|
664 | { |
---|
665 | GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); |
---|
666 | int ret = cucul_dither_bitmap(_cv, r.X, r.Y, r.Width, r.Height, |
---|
667 | d._dither, gch.AddrOfPinnedObject()); |
---|
668 | gch.Free(); |
---|
669 | return ret; |
---|
670 | } |
---|
671 | |
---|
672 | public int ditherBitmap(int x, int y, int w, int h, |
---|
673 | CuculDither d, object data) |
---|
674 | { |
---|
675 | GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); |
---|
676 | int ret = cucul_dither_bitmap(_cv, x, y, w, h, d._dither, |
---|
677 | gch.AddrOfPinnedObject()); |
---|
678 | gch.Free(); |
---|
679 | return ret; |
---|
680 | } |
---|
681 | } |
---|
682 | |
---|
683 | public class CuculAttr |
---|
684 | { |
---|
685 | private int _attr; |
---|
686 | |
---|
687 | public CuculAttr(int attr) |
---|
688 | { |
---|
689 | _attr = attr; |
---|
690 | } |
---|
691 | |
---|
692 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
693 | SuppressUnmanagedCodeSecurity] |
---|
694 | private static extern byte cucul_attr_to_ansi(Int32 a); |
---|
695 | public byte toAnsi() |
---|
696 | { |
---|
697 | return cucul_attr_to_ansi(_attr); |
---|
698 | } |
---|
699 | |
---|
700 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
701 | SuppressUnmanagedCodeSecurity] |
---|
702 | private static extern byte cucul_attr_to_ansi_fg(Int32 a); |
---|
703 | public byte toAnsiFg() |
---|
704 | { |
---|
705 | return cucul_attr_to_ansi_fg(_attr); |
---|
706 | } |
---|
707 | |
---|
708 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
709 | SuppressUnmanagedCodeSecurity] |
---|
710 | private static extern byte cucul_attr_to_ansi_bg(Int32 a); |
---|
711 | public byte toAnsiBg() |
---|
712 | { |
---|
713 | return cucul_attr_to_ansi_bg(_attr); |
---|
714 | } |
---|
715 | } |
---|
716 | |
---|
717 | public class CuculDither : IDisposable |
---|
718 | { |
---|
719 | public readonly IntPtr _dither; |
---|
720 | |
---|
721 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
722 | SuppressUnmanagedCodeSecurity] |
---|
723 | private static extern IntPtr cucul_create_dither(int bpp, int w, |
---|
724 | int h, int pitch, |
---|
725 | ulong rmask, |
---|
726 | ulong gmask, |
---|
727 | ulong bmask, |
---|
728 | ulong amask); |
---|
729 | public CuculDither(int bpp, Size s, int pitch, |
---|
730 | uint rmask, uint gmask, uint bmask, uint amask) |
---|
731 | { |
---|
732 | _dither = cucul_create_dither(bpp, s.Width, s.Height, pitch, |
---|
733 | rmask, gmask, bmask, amask); |
---|
734 | } |
---|
735 | |
---|
736 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
737 | SuppressUnmanagedCodeSecurity] |
---|
738 | private static extern int cucul_free_dither(IntPtr d); |
---|
739 | public void Dispose() |
---|
740 | { |
---|
741 | cucul_free_dither(_dither); |
---|
742 | GC.SuppressFinalize(this); |
---|
743 | } |
---|
744 | |
---|
745 | /* TODO: fix this shit */ |
---|
746 | |
---|
747 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
748 | SuppressUnmanagedCodeSecurity] |
---|
749 | private static extern int cucul_set_dither_palette(IntPtr d, |
---|
750 | int[] r, int[] g, |
---|
751 | int[] b, int[] a); |
---|
752 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
753 | SuppressUnmanagedCodeSecurity] |
---|
754 | private static extern int cucul_set_dither_brightness(IntPtr d, float b); |
---|
755 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
756 | SuppressUnmanagedCodeSecurity] |
---|
757 | private static extern int cucul_set_dither_gamma(IntPtr d, float g); |
---|
758 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
759 | SuppressUnmanagedCodeSecurity] |
---|
760 | private static extern int cucul_set_dither_contrast(IntPtr d, float c); |
---|
761 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
762 | SuppressUnmanagedCodeSecurity] |
---|
763 | private static extern int cucul_set_dither_invert(IntPtr d, int i); |
---|
764 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
765 | SuppressUnmanagedCodeSecurity] |
---|
766 | private static extern int cucul_set_dither_antialias(IntPtr d, string s); |
---|
767 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
768 | SuppressUnmanagedCodeSecurity] |
---|
769 | private static extern string[] cucul_get_dither_antialias_list(IntPtr d); |
---|
770 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
771 | SuppressUnmanagedCodeSecurity] |
---|
772 | private static extern int cucul_set_dither_color(IntPtr d, string s); |
---|
773 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
774 | SuppressUnmanagedCodeSecurity] |
---|
775 | private static extern string[] cucul_get_dither_color_list(IntPtr d); |
---|
776 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
777 | SuppressUnmanagedCodeSecurity] |
---|
778 | private static extern int cucul_set_dither_charset(IntPtr d, string s); |
---|
779 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
780 | SuppressUnmanagedCodeSecurity] |
---|
781 | private static extern string[] cucul_get_dither_charset_list(IntPtr d); |
---|
782 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
783 | SuppressUnmanagedCodeSecurity] |
---|
784 | private static extern int cucul_set_dither_mode(IntPtr d, string s); |
---|
785 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
786 | SuppressUnmanagedCodeSecurity] |
---|
787 | private static extern string[] cucul_get_dither_mode_list(IntPtr d); |
---|
788 | |
---|
789 | |
---|
790 | public int setBrightness(float b) |
---|
791 | { |
---|
792 | return cucul_set_dither_brightness(_dither, b); |
---|
793 | } |
---|
794 | |
---|
795 | public int setGamma(float g) |
---|
796 | { |
---|
797 | return cucul_set_dither_gamma(_dither, g); |
---|
798 | } |
---|
799 | |
---|
800 | public int setContrast(float c) |
---|
801 | { |
---|
802 | return cucul_set_dither_contrast(_dither, c); |
---|
803 | } |
---|
804 | |
---|
805 | public int setInvert(int i) |
---|
806 | { |
---|
807 | return cucul_set_dither_invert(_dither, i); |
---|
808 | } |
---|
809 | |
---|
810 | public int setAntialias(string s) |
---|
811 | { |
---|
812 | return cucul_set_dither_antialias(_dither, s); |
---|
813 | } |
---|
814 | |
---|
815 | public int setColor(string s) |
---|
816 | { |
---|
817 | return cucul_set_dither_color(_dither, s); |
---|
818 | } |
---|
819 | |
---|
820 | public int setCharset(string s) |
---|
821 | { |
---|
822 | return cucul_set_dither_charset(_dither, s); |
---|
823 | } |
---|
824 | |
---|
825 | public int setMode(string s) |
---|
826 | { |
---|
827 | return cucul_set_dither_mode(_dither, s); |
---|
828 | } |
---|
829 | |
---|
830 | /* <FIXME> */ |
---|
831 | public string[] getAntialiasList() |
---|
832 | { |
---|
833 | return cucul_get_dither_antialias_list(_dither); |
---|
834 | } |
---|
835 | |
---|
836 | public string[] getColorList() |
---|
837 | { |
---|
838 | return cucul_get_dither_color_list(_dither); |
---|
839 | } |
---|
840 | |
---|
841 | public string[] getCharsetList() |
---|
842 | { |
---|
843 | return cucul_get_dither_charset_list(_dither); |
---|
844 | } |
---|
845 | |
---|
846 | public string[] getModeList() |
---|
847 | { |
---|
848 | return cucul_get_dither_mode_list(_dither); |
---|
849 | } |
---|
850 | |
---|
851 | /* </FIXME> */ |
---|
852 | } |
---|
853 | |
---|
854 | public class CuculFont : IDisposable |
---|
855 | { |
---|
856 | private IntPtr _font; |
---|
857 | private GCHandle _gch; |
---|
858 | |
---|
859 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
860 | SuppressUnmanagedCodeSecurity] |
---|
861 | private static extern IntPtr cucul_load_font(IntPtr data, int len); |
---|
862 | public CuculFont(string s) |
---|
863 | { |
---|
864 | IntPtr name = Marshal.StringToHGlobalAnsi(s); |
---|
865 | _font = cucul_load_font(name, 0); |
---|
866 | Marshal.FreeHGlobal(name); |
---|
867 | } |
---|
868 | |
---|
869 | public CuculFont(byte[] buf) |
---|
870 | { |
---|
871 | GCHandle _gch = GCHandle.Alloc(buf, GCHandleType.Pinned); |
---|
872 | _font = cucul_load_font(_gch.AddrOfPinnedObject(), buf.Length); |
---|
873 | } |
---|
874 | |
---|
875 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
876 | SuppressUnmanagedCodeSecurity] |
---|
877 | private static extern int cucul_free_font(IntPtr d); |
---|
878 | public void Dispose() |
---|
879 | { |
---|
880 | cucul_free_font(_font); |
---|
881 | _gch.Free(); |
---|
882 | GC.SuppressFinalize(this); |
---|
883 | } |
---|
884 | |
---|
885 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
886 | SuppressUnmanagedCodeSecurity] |
---|
887 | private static extern IntPtr cucul_get_font_list(); |
---|
888 | public static string[] getList() |
---|
889 | { |
---|
890 | IntPtr l = cucul_get_font_list(); |
---|
891 | |
---|
892 | int size; |
---|
893 | for(size = 0; true; size++) |
---|
894 | if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) |
---|
895 | break; |
---|
896 | |
---|
897 | string[] ret = new string[size]; |
---|
898 | for(int i = 0; i < size; i++) |
---|
899 | { |
---|
900 | IntPtr s = Marshal.ReadIntPtr(l, IntPtr.Size * i); |
---|
901 | ret[i] = Marshal.PtrToStringAnsi(s); |
---|
902 | } |
---|
903 | |
---|
904 | return ret; |
---|
905 | } |
---|
906 | |
---|
907 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
908 | SuppressUnmanagedCodeSecurity] |
---|
909 | private static extern int cucul_get_font_width(IntPtr font); |
---|
910 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
911 | SuppressUnmanagedCodeSecurity] |
---|
912 | private static extern int cucul_get_font_height(IntPtr font); |
---|
913 | public Size Size |
---|
914 | { |
---|
915 | get { return new Size(cucul_get_font_width(_font), |
---|
916 | cucul_get_font_height(_font)); } |
---|
917 | } |
---|
918 | |
---|
919 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
920 | SuppressUnmanagedCodeSecurity] |
---|
921 | private static extern IntPtr cucul_get_font_blocks(IntPtr font); |
---|
922 | public int[,] getBlocks() |
---|
923 | { |
---|
924 | IntPtr l = cucul_get_font_blocks(_font); |
---|
925 | |
---|
926 | int size; |
---|
927 | for(size = 1; true; size += 2) |
---|
928 | if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero) |
---|
929 | break; |
---|
930 | |
---|
931 | int[,] ret = new int[size,2]; |
---|
932 | for(int i = 0; i < size; i++) |
---|
933 | { |
---|
934 | ret[i,0] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2); |
---|
935 | ret[i,1] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2 + 1); |
---|
936 | } |
---|
937 | |
---|
938 | return ret; |
---|
939 | } |
---|
940 | |
---|
941 | [DllImport("libcucul.dll", CallingConvention=CallingConvention.Cdecl), |
---|
942 | SuppressUnmanagedCodeSecurity] |
---|
943 | private static extern int cucul_render_canvas(IntPtr cv, IntPtr f, |
---|
944 | IntPtr buf, int w, int h, |
---|
945 | int pitch); |
---|
946 | public int Render(CuculCanvas cv, uint[,] buf, int pitch) |
---|
947 | { |
---|
948 | GCHandle gch = GCHandle.Alloc(buf, GCHandleType.Pinned); |
---|
949 | int ret = cucul_render_canvas(cv._cv, _font, |
---|
950 | gch.AddrOfPinnedObject(), |
---|
951 | buf.GetLength(0), buf.GetLength(1), |
---|
952 | pitch); |
---|
953 | gch.Free(); |
---|
954 | return ret; |
---|
955 | } |
---|
956 | } |
---|
957 | } |
---|
958 | |
---|