1 | /* |
---|
2 | * libcaca .NET bindings for libcaca |
---|
3 | * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org> |
---|
4 | * 2007 Sam Hocevar <sam@zoy.org> |
---|
5 | * All Rights Reserved |
---|
6 | * |
---|
7 | * $Id$ |
---|
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 Caca |
---|
22 | { |
---|
23 | public enum AnsiColor |
---|
24 | { |
---|
25 | BLACK = 0x00, |
---|
26 | BLUE = 0x01, |
---|
27 | GREEN = 0x02, |
---|
28 | CYAN = 0x03, |
---|
29 | RED = 0x04, |
---|
30 | MAGENTA = 0x05, |
---|
31 | BROWN = 0x06, |
---|
32 | LIGHTGRAY = 0x07, |
---|
33 | DARKGRAY = 0x08, |
---|
34 | LIGHTBLUE = 0x09, |
---|
35 | LIGHTGREEN = 0x0a, |
---|
36 | LIGHTCYAN = 0x0b, |
---|
37 | LIGHTRED = 0x0c, |
---|
38 | LIGHTMAGENTA = 0x0d, |
---|
39 | YELLOW = 0x0e, |
---|
40 | WHITE = 0x0f, |
---|
41 | DEFAULT = 0x10, |
---|
42 | TRANSPARENT = 0x20, |
---|
43 | } |
---|
44 | |
---|
45 | public enum AnsiStyle |
---|
46 | { |
---|
47 | BOLD = 0x01, |
---|
48 | ITALICS = 0x02, |
---|
49 | UNDERLINE = 0x04, |
---|
50 | BLINK = 0x08, |
---|
51 | } |
---|
52 | |
---|
53 | public class Canvas : IDisposable |
---|
54 | { |
---|
55 | public readonly IntPtr _c_cv; |
---|
56 | |
---|
57 | /* libcaca basic functions */ |
---|
58 | |
---|
59 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
60 | SuppressUnmanagedCodeSecurity] |
---|
61 | private static extern IntPtr caca_create_canvas(int w, int h); |
---|
62 | public Canvas() |
---|
63 | { |
---|
64 | _c_cv = caca_create_canvas(0, 0); |
---|
65 | } |
---|
66 | |
---|
67 | public Canvas(Size s) |
---|
68 | { |
---|
69 | _c_cv = caca_create_canvas(s.Width, s.Height); |
---|
70 | } |
---|
71 | |
---|
72 | public Canvas(int w, int h) |
---|
73 | { |
---|
74 | _c_cv = caca_create_canvas(h, w); |
---|
75 | } |
---|
76 | |
---|
77 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
78 | SuppressUnmanagedCodeSecurity] |
---|
79 | private static extern int caca_free_canvas(IntPtr cv); |
---|
80 | public void Dispose() |
---|
81 | { |
---|
82 | /* FIXME: don't destroy ourselves if we're attached */ |
---|
83 | caca_free_canvas(_c_cv); |
---|
84 | GC.SuppressFinalize(this); |
---|
85 | } |
---|
86 | |
---|
87 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
88 | SuppressUnmanagedCodeSecurity] |
---|
89 | private static extern int caca_set_canvas_size(IntPtr cv, |
---|
90 | int w, int h); |
---|
91 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
92 | SuppressUnmanagedCodeSecurity] |
---|
93 | private static extern int caca_get_canvas_width(IntPtr cv); |
---|
94 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
95 | SuppressUnmanagedCodeSecurity] |
---|
96 | private static extern int caca_get_canvas_height(IntPtr cv); |
---|
97 | public Size Size |
---|
98 | { |
---|
99 | get { return new Size(caca_get_canvas_width(_c_cv), |
---|
100 | caca_get_canvas_height(_c_cv)); } |
---|
101 | set { caca_set_canvas_size(_c_cv, value.Width, value.Height); } |
---|
102 | } |
---|
103 | |
---|
104 | public Rectangle Rectangle |
---|
105 | { |
---|
106 | get { return new Rectangle(0, 0, caca_get_canvas_width(_c_cv), |
---|
107 | caca_get_canvas_height(_c_cv)); } |
---|
108 | set { caca_set_canvas_size(_c_cv, value.Width, value.Height); } |
---|
109 | } |
---|
110 | |
---|
111 | /* canvas drawing */ |
---|
112 | |
---|
113 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
114 | SuppressUnmanagedCodeSecurity] |
---|
115 | private static extern int caca_gotoxy(IntPtr cv, int x, int y); |
---|
116 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
117 | SuppressUnmanagedCodeSecurity] |
---|
118 | private static extern int caca_get_cursor_x(IntPtr cv); |
---|
119 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
120 | SuppressUnmanagedCodeSecurity] |
---|
121 | private static extern int caca_get_cursor_y(IntPtr cv); |
---|
122 | public Point Cursor |
---|
123 | { |
---|
124 | get { return new Point(caca_get_cursor_x(_c_cv), |
---|
125 | caca_get_cursor_y(_c_cv)); } |
---|
126 | set { caca_gotoxy(_c_cv, value.X, value.Y); } |
---|
127 | } |
---|
128 | |
---|
129 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
130 | SuppressUnmanagedCodeSecurity] |
---|
131 | private static extern int caca_put_char(IntPtr cv, |
---|
132 | int x, int y, uint c); |
---|
133 | public int putChar(Point p, uint c) |
---|
134 | { |
---|
135 | return caca_put_char(_c_cv, p.X, p.Y, c); |
---|
136 | } |
---|
137 | |
---|
138 | public int putChar(int x, int y, uint c) |
---|
139 | { |
---|
140 | return caca_put_char(_c_cv, x, y, c); |
---|
141 | } |
---|
142 | |
---|
143 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
144 | SuppressUnmanagedCodeSecurity] |
---|
145 | private static extern uint caca_get_char(IntPtr cv, int x, int y); |
---|
146 | public uint getChar(Point p) |
---|
147 | { |
---|
148 | return caca_get_char(_c_cv, p.X, p.Y); |
---|
149 | } |
---|
150 | |
---|
151 | public uint getChar(int x, int y) |
---|
152 | { |
---|
153 | return caca_get_char(_c_cv, x, y); |
---|
154 | } |
---|
155 | |
---|
156 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
157 | SuppressUnmanagedCodeSecurity] |
---|
158 | private static extern int caca_put_str(IntPtr cv, |
---|
159 | int x, int y, string c); |
---|
160 | public int putStr(Point p, string c) |
---|
161 | { |
---|
162 | return caca_put_str(_c_cv, p.X, p.Y, c); |
---|
163 | } |
---|
164 | |
---|
165 | public int putStr(int x, int y, string c) |
---|
166 | { |
---|
167 | return caca_put_str(_c_cv, x, y, c); |
---|
168 | } |
---|
169 | |
---|
170 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
171 | SuppressUnmanagedCodeSecurity] |
---|
172 | private static extern int caca_get_attr(IntPtr cv, int x, int y); |
---|
173 | public int getAttr(Point p) |
---|
174 | { |
---|
175 | return caca_get_attr(_c_cv, p.X, p.Y); |
---|
176 | } |
---|
177 | |
---|
178 | public int getAttr(int x, int y) |
---|
179 | { |
---|
180 | return caca_get_attr(_c_cv, x, y); |
---|
181 | } |
---|
182 | |
---|
183 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
184 | SuppressUnmanagedCodeSecurity] |
---|
185 | private static extern int caca_set_attr(IntPtr cv, uint a); |
---|
186 | public int setAttr(uint a) |
---|
187 | { |
---|
188 | return caca_set_attr(_c_cv, a); |
---|
189 | } |
---|
190 | |
---|
191 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
192 | SuppressUnmanagedCodeSecurity] |
---|
193 | private static extern int caca_put_attr(IntPtr cv, |
---|
194 | int x, int y, uint a); |
---|
195 | public int putAttr(Point p, uint a) |
---|
196 | { |
---|
197 | return caca_put_attr(_c_cv, p.X, p.Y, a); |
---|
198 | } |
---|
199 | |
---|
200 | public int putAttr(int x, int y, uint a) |
---|
201 | { |
---|
202 | return caca_put_attr(_c_cv, x, y, a); |
---|
203 | } |
---|
204 | |
---|
205 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
206 | SuppressUnmanagedCodeSecurity] |
---|
207 | private static extern int caca_set_color_ansi(IntPtr cv, |
---|
208 | byte fg, byte bg); |
---|
209 | public int setColorAnsi(AnsiColor fg, AnsiColor bg) |
---|
210 | { |
---|
211 | return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg); |
---|
212 | } |
---|
213 | |
---|
214 | public int setColorAnsi(uint fg, AnsiColor bg) |
---|
215 | { |
---|
216 | return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg); |
---|
217 | } |
---|
218 | |
---|
219 | public int setColorAnsi(AnsiColor fg, uint bg) |
---|
220 | { |
---|
221 | return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg); |
---|
222 | } |
---|
223 | |
---|
224 | public int setColorAnsi(uint fg, uint bg) |
---|
225 | { |
---|
226 | return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg); |
---|
227 | } |
---|
228 | |
---|
229 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
230 | SuppressUnmanagedCodeSecurity] |
---|
231 | private static extern int caca_set_color_argb(IntPtr cv, |
---|
232 | uint fg, uint bg); |
---|
233 | public int setColorArgb(uint fg, uint bg) |
---|
234 | { |
---|
235 | return caca_set_color_argb(_c_cv, fg, bg); |
---|
236 | } |
---|
237 | |
---|
238 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
239 | SuppressUnmanagedCodeSecurity] |
---|
240 | private static extern int caca_clear_canvas(IntPtr cv); |
---|
241 | public int Clear() |
---|
242 | { |
---|
243 | return caca_clear_canvas(_c_cv); |
---|
244 | } |
---|
245 | |
---|
246 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
247 | SuppressUnmanagedCodeSecurity] |
---|
248 | private static extern int caca_set_canvas_handle(IntPtr cv, |
---|
249 | int x, int y); |
---|
250 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
251 | SuppressUnmanagedCodeSecurity] |
---|
252 | private static extern int caca_get_canvas_handle_x(IntPtr cv); |
---|
253 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
254 | SuppressUnmanagedCodeSecurity] |
---|
255 | private static extern int caca_get_canvas_handle_y(IntPtr cv); |
---|
256 | public Point Handle |
---|
257 | { |
---|
258 | get { return new Point(caca_get_canvas_handle_x(_c_cv), |
---|
259 | caca_get_canvas_handle_y(_c_cv)); } |
---|
260 | set { caca_set_canvas_handle(_c_cv, value.X, value.Y); } |
---|
261 | } |
---|
262 | |
---|
263 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
264 | SuppressUnmanagedCodeSecurity] |
---|
265 | private static extern int caca_blit(IntPtr cv, int x, int y, |
---|
266 | IntPtr cv1, IntPtr cv2); |
---|
267 | public int Blit(Point p, Canvas canvas) |
---|
268 | { |
---|
269 | return caca_blit(_c_cv, p.X, p.Y, canvas._c_cv, IntPtr.Zero); |
---|
270 | } |
---|
271 | |
---|
272 | public int Blit(Point p, Canvas cv, Canvas mask) |
---|
273 | { |
---|
274 | return caca_blit(_c_cv, p.X, p.Y, cv._c_cv, mask._c_cv); |
---|
275 | } |
---|
276 | |
---|
277 | public int Blit(int x, int y, Canvas canvas) |
---|
278 | { |
---|
279 | return caca_blit(_c_cv, x, y, canvas._c_cv, IntPtr.Zero); |
---|
280 | } |
---|
281 | |
---|
282 | public int Blit(int x, int y, Canvas cv, Canvas mask) |
---|
283 | { |
---|
284 | return caca_blit(_c_cv, x, y, cv._c_cv, mask._c_cv); |
---|
285 | } |
---|
286 | |
---|
287 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
288 | SuppressUnmanagedCodeSecurity] |
---|
289 | private static extern int caca_set_canvas_boundaries(IntPtr cv, |
---|
290 | int x, int y, |
---|
291 | int h, int w); |
---|
292 | public int setBoundaries(Rectangle r) |
---|
293 | { |
---|
294 | return caca_set_canvas_boundaries(_c_cv, r.X, r.Y, |
---|
295 | r.Width, r.Height); |
---|
296 | } |
---|
297 | |
---|
298 | public int setBoundaries(int x, int y, int w, int h) |
---|
299 | { |
---|
300 | return caca_set_canvas_boundaries(_c_cv, x, y, w, h); |
---|
301 | } |
---|
302 | |
---|
303 | /* canvas transformation */ |
---|
304 | |
---|
305 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
306 | SuppressUnmanagedCodeSecurity] |
---|
307 | private static extern int caca_invert(IntPtr cv); |
---|
308 | public int Invert() |
---|
309 | { |
---|
310 | return caca_invert(_c_cv); |
---|
311 | } |
---|
312 | |
---|
313 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
314 | SuppressUnmanagedCodeSecurity] |
---|
315 | private static extern int caca_flip(IntPtr cv); |
---|
316 | public int Flip() |
---|
317 | { |
---|
318 | return caca_flip(_c_cv); |
---|
319 | } |
---|
320 | |
---|
321 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
322 | SuppressUnmanagedCodeSecurity] |
---|
323 | private static extern int caca_flop(IntPtr cv); |
---|
324 | public int Flop() |
---|
325 | { |
---|
326 | return caca_flop(_c_cv); |
---|
327 | } |
---|
328 | |
---|
329 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
330 | SuppressUnmanagedCodeSecurity] |
---|
331 | private static extern int caca_rotate_180(IntPtr cv); |
---|
332 | public int Rotate180() |
---|
333 | { |
---|
334 | return caca_rotate_180(_c_cv); |
---|
335 | } |
---|
336 | |
---|
337 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
338 | SuppressUnmanagedCodeSecurity] |
---|
339 | private static extern int caca_rotate_left(IntPtr cv); |
---|
340 | public int RotateLeft() |
---|
341 | { |
---|
342 | return caca_rotate_left(_c_cv); |
---|
343 | } |
---|
344 | |
---|
345 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
346 | SuppressUnmanagedCodeSecurity] |
---|
347 | private static extern int caca_rotate_right(IntPtr cv); |
---|
348 | public int RotateRight() |
---|
349 | { |
---|
350 | return caca_rotate_right(_c_cv); |
---|
351 | } |
---|
352 | |
---|
353 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
354 | SuppressUnmanagedCodeSecurity] |
---|
355 | private static extern int caca_stretch_left(IntPtr cv); |
---|
356 | public int StretchLeft() |
---|
357 | { |
---|
358 | return caca_stretch_left(_c_cv); |
---|
359 | } |
---|
360 | |
---|
361 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
362 | SuppressUnmanagedCodeSecurity] |
---|
363 | private static extern int caca_stretch_right(IntPtr cv); |
---|
364 | public int StretchRight() |
---|
365 | { |
---|
366 | return caca_stretch_right(_c_cv); |
---|
367 | } |
---|
368 | |
---|
369 | /* primitives drawing */ |
---|
370 | |
---|
371 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
372 | SuppressUnmanagedCodeSecurity] |
---|
373 | private static extern int caca_draw_line(IntPtr cv, int x1, int y1, |
---|
374 | int x2, int y2, uint c); |
---|
375 | public int drawLine(Point p1, Point p2, uint c) |
---|
376 | { |
---|
377 | return caca_draw_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y, c); |
---|
378 | } |
---|
379 | |
---|
380 | public int drawLine(int x1, int y1, int x2, int y2, uint c) |
---|
381 | { |
---|
382 | return caca_draw_line(_c_cv, x1, y1, x2, y2, c); |
---|
383 | } |
---|
384 | |
---|
385 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
386 | SuppressUnmanagedCodeSecurity] |
---|
387 | private static extern int caca_draw_polyline(IntPtr cv, int[] x, |
---|
388 | int[] y, int n, uint c); |
---|
389 | public int drawPolyline(Point[] lp, uint c) |
---|
390 | { |
---|
391 | int[] lx = new int[lp.Length]; |
---|
392 | int[] ly = new int[lp.Length]; |
---|
393 | for(int i = 0; i < lp.Length; i++) |
---|
394 | { |
---|
395 | lx[i] = lp[i].X; |
---|
396 | ly[i] = lp[i].Y; |
---|
397 | } |
---|
398 | return caca_draw_polyline(_c_cv, lx, ly, lp.Length - 1, c); |
---|
399 | } |
---|
400 | |
---|
401 | public int drawPolyline(int[] lx, int[] ly, uint c) |
---|
402 | { |
---|
403 | if(lx.Length != ly.Length) |
---|
404 | return -1; |
---|
405 | |
---|
406 | return caca_draw_polyline(_c_cv, lx, ly, lx.Length - 1, c); |
---|
407 | } |
---|
408 | |
---|
409 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
410 | SuppressUnmanagedCodeSecurity] |
---|
411 | private static extern int caca_draw_thin_line(IntPtr cv, int x1, |
---|
412 | int y1, int x2, int y2); |
---|
413 | public int drawThinLine(Point p1, Point p2) |
---|
414 | { |
---|
415 | return caca_draw_thin_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y); |
---|
416 | } |
---|
417 | |
---|
418 | public int drawThinLine(int x1, int y1, int x2, int y2) |
---|
419 | { |
---|
420 | return caca_draw_thin_line(_c_cv, x1, y1, x2, y2); |
---|
421 | } |
---|
422 | |
---|
423 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
424 | SuppressUnmanagedCodeSecurity] |
---|
425 | private static extern int caca_draw_thin_polyline(IntPtr cv, int[] x, |
---|
426 | int[] y, int n); |
---|
427 | public int drawThinPolyline(Point[] lp) |
---|
428 | { |
---|
429 | int[] lx = new int[lp.Length]; |
---|
430 | int[] ly = new int[lp.Length]; |
---|
431 | for(int i = 0; i < lp.Length; i++) |
---|
432 | { |
---|
433 | lx[i] = lp[i].X; |
---|
434 | ly[i] = lp[i].Y; |
---|
435 | } |
---|
436 | return caca_draw_thin_polyline(_c_cv, lx, ly, lp.Length - 1); |
---|
437 | } |
---|
438 | |
---|
439 | public int drawThinPolyline(int[] lx, int[] ly) |
---|
440 | { |
---|
441 | if(lx.Length != ly.Length) |
---|
442 | return -1; |
---|
443 | |
---|
444 | return caca_draw_thin_polyline(_c_cv, lx, ly, lx.Length - 1); |
---|
445 | } |
---|
446 | |
---|
447 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
448 | SuppressUnmanagedCodeSecurity] |
---|
449 | private static extern int caca_draw_circle(IntPtr cv, int x, int y, |
---|
450 | int r, uint c); |
---|
451 | public int drawCircle(Point p, int r, uint c) |
---|
452 | { |
---|
453 | return caca_draw_circle(_c_cv, p.X, p.Y, r, c); |
---|
454 | } |
---|
455 | |
---|
456 | public int drawCircle(int x, int y, int r, uint c) |
---|
457 | { |
---|
458 | return caca_draw_circle(_c_cv, x, y, r, c); |
---|
459 | } |
---|
460 | |
---|
461 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
462 | SuppressUnmanagedCodeSecurity] |
---|
463 | private static extern int caca_draw_ellipse(IntPtr cv, int x, int y, |
---|
464 | int a, int b, uint c); |
---|
465 | public int drawEllipse(Point p, int a, int b, uint c) |
---|
466 | { |
---|
467 | return caca_draw_ellipse(_c_cv, p.X, p.Y, a, b, c); |
---|
468 | } |
---|
469 | |
---|
470 | public int drawEllipse(int x, int y, int a, int b, uint c) |
---|
471 | { |
---|
472 | return caca_draw_ellipse(_c_cv, x, y, a, b, c); |
---|
473 | } |
---|
474 | |
---|
475 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
476 | SuppressUnmanagedCodeSecurity] |
---|
477 | private static extern int caca_draw_thin_ellipse(IntPtr cv, |
---|
478 | int x, int y, |
---|
479 | int a, int b); |
---|
480 | public int drawThinEllipse(Point p, int a, int b) |
---|
481 | { |
---|
482 | return caca_draw_thin_ellipse(_c_cv, p.X, p.Y, a, b); |
---|
483 | } |
---|
484 | |
---|
485 | public int drawThinEllipse(int x, int y, int a, int b) |
---|
486 | { |
---|
487 | return caca_draw_thin_ellipse(_c_cv, x, y, a, b); |
---|
488 | } |
---|
489 | |
---|
490 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
491 | SuppressUnmanagedCodeSecurity] |
---|
492 | private static extern int caca_fill_ellipse(IntPtr cv, int x, int y, |
---|
493 | int a, int b, uint c); |
---|
494 | public int fillEllipse(Point p, int a, int b, uint c) |
---|
495 | { |
---|
496 | return caca_fill_ellipse(_c_cv, p.X, p.Y, a, b, c); |
---|
497 | } |
---|
498 | |
---|
499 | public int fillEllipse(int x, int y, int a, int b, uint c) |
---|
500 | { |
---|
501 | return caca_fill_ellipse(_c_cv, x, y, a, b, c); |
---|
502 | } |
---|
503 | |
---|
504 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
505 | SuppressUnmanagedCodeSecurity] |
---|
506 | private static extern int caca_draw_box(IntPtr cv, int x, int y, |
---|
507 | int w, int h, uint c); |
---|
508 | public int drawBox(Rectangle r, uint c) |
---|
509 | { |
---|
510 | return caca_draw_box(_c_cv, r.X, r.Y, r.Width, r.Height, c); |
---|
511 | } |
---|
512 | |
---|
513 | public int drawBox(int x, int y, int w, int h, uint c) |
---|
514 | { |
---|
515 | return caca_draw_box(_c_cv, x, y, w, h, c); |
---|
516 | } |
---|
517 | |
---|
518 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
519 | SuppressUnmanagedCodeSecurity] |
---|
520 | private static extern int caca_draw_thin_box(IntPtr cv, int x, int y, |
---|
521 | int w, int h); |
---|
522 | public int drawThinBox(Rectangle r) |
---|
523 | { |
---|
524 | return caca_draw_thin_box(_c_cv, r.X, r.Y, r.Width, r.Height); |
---|
525 | } |
---|
526 | |
---|
527 | public int drawThinBox(int x, int y, int w, int h) |
---|
528 | { |
---|
529 | return caca_draw_thin_box(_c_cv, x, y, w, h); |
---|
530 | } |
---|
531 | |
---|
532 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
533 | SuppressUnmanagedCodeSecurity] |
---|
534 | private static extern int caca_draw_cp437_box(IntPtr cv, int x, int y, |
---|
535 | int w, int h); |
---|
536 | public int drawCp437Box(Rectangle r) |
---|
537 | { |
---|
538 | return caca_draw_cp437_box(_c_cv, r.X, r.Y, r.Width, r.Height); |
---|
539 | } |
---|
540 | |
---|
541 | public int drawCp437Box(int x, int y, int w, int h) |
---|
542 | { |
---|
543 | return caca_draw_cp437_box(_c_cv, x, y, w, h); |
---|
544 | } |
---|
545 | |
---|
546 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
547 | SuppressUnmanagedCodeSecurity] |
---|
548 | private static extern int caca_fill_box(IntPtr cv, int x, int y, |
---|
549 | int w, int h, uint c); |
---|
550 | public int fillBox(Rectangle r, uint c) |
---|
551 | { |
---|
552 | return caca_fill_box(_c_cv, r.X, r.Y, r.Width, r.Height, c); |
---|
553 | } |
---|
554 | |
---|
555 | public int fillBox(int x, int y, int w, int h, uint c) |
---|
556 | { |
---|
557 | return caca_fill_box(_c_cv, x, y, w, h, c); |
---|
558 | } |
---|
559 | |
---|
560 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
561 | SuppressUnmanagedCodeSecurity] |
---|
562 | private static extern int caca_draw_triangle(IntPtr cv, int x1, |
---|
563 | int y1, int x2, int y2, |
---|
564 | int x3, int y3, uint c); |
---|
565 | public int drawTriangle(Point p1, Point p2, Point p3, uint c) |
---|
566 | { |
---|
567 | return caca_draw_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, |
---|
568 | p3.X, p3.Y, c); |
---|
569 | } |
---|
570 | |
---|
571 | public int drawTriangle(int x1, int y1, int x2, int y2, |
---|
572 | int x3, int y3, uint c) |
---|
573 | { |
---|
574 | return caca_draw_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c); |
---|
575 | } |
---|
576 | |
---|
577 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
578 | SuppressUnmanagedCodeSecurity] |
---|
579 | private static extern int caca_draw_thin_triangle(IntPtr cv, |
---|
580 | int x1, int y1, |
---|
581 | int x2, int y2, |
---|
582 | int x3, int y3); |
---|
583 | public int drawThinTriangle(Point p1, Point p2, Point p3) |
---|
584 | { |
---|
585 | return caca_draw_thin_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, |
---|
586 | p3.X, p3.Y); |
---|
587 | } |
---|
588 | |
---|
589 | public int drawThinTriangle(int x1, int y1, int x2, int y2, |
---|
590 | int x3, int y3) |
---|
591 | { |
---|
592 | return caca_draw_thin_triangle(_c_cv, x1, y1, x2, y2, x3, y3); |
---|
593 | } |
---|
594 | |
---|
595 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
596 | SuppressUnmanagedCodeSecurity] |
---|
597 | private static extern int caca_fill_triangle(IntPtr cv, int x1, |
---|
598 | int y1, int x2, int y2, |
---|
599 | int x3, int y3, uint c); |
---|
600 | public int fillTriangle(Point p1, Point p2, Point p3, uint c) |
---|
601 | { |
---|
602 | return caca_fill_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y, |
---|
603 | p3.X, p3.Y, c); |
---|
604 | } |
---|
605 | |
---|
606 | public int fillTriangle(int x1, int y1, int x2, int y2, |
---|
607 | int x3, int y3, uint c) |
---|
608 | { |
---|
609 | return caca_fill_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c); |
---|
610 | } |
---|
611 | |
---|
612 | /* frame handling */ |
---|
613 | |
---|
614 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
615 | SuppressUnmanagedCodeSecurity] |
---|
616 | private static extern int caca_get_frame_count(IntPtr cv); |
---|
617 | public int getFrameCount() |
---|
618 | { |
---|
619 | return caca_get_frame_count(_c_cv); |
---|
620 | } |
---|
621 | |
---|
622 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
623 | SuppressUnmanagedCodeSecurity] |
---|
624 | private static extern int caca_set_frame(IntPtr cv, int f); |
---|
625 | public int setFrame(int f) |
---|
626 | { |
---|
627 | return caca_set_frame(_c_cv, f); |
---|
628 | } |
---|
629 | |
---|
630 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
631 | SuppressUnmanagedCodeSecurity] |
---|
632 | private static extern string caca_get_frame_name(IntPtr cv); |
---|
633 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
634 | SuppressUnmanagedCodeSecurity] |
---|
635 | private static extern int caca_set_frame_name(IntPtr cv, string n); |
---|
636 | public string FrameName |
---|
637 | { |
---|
638 | get { return caca_get_frame_name(_c_cv); } |
---|
639 | set { caca_set_frame_name(_c_cv, value); } |
---|
640 | } |
---|
641 | |
---|
642 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
643 | SuppressUnmanagedCodeSecurity] |
---|
644 | private static extern int caca_create_frame(IntPtr cv, int f); |
---|
645 | public int createFrame(int f) |
---|
646 | { |
---|
647 | return caca_create_frame(_c_cv, f); |
---|
648 | } |
---|
649 | |
---|
650 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
651 | SuppressUnmanagedCodeSecurity] |
---|
652 | private static extern int caca_free_frame(IntPtr cv, int f); |
---|
653 | public int freeFrame(int f) |
---|
654 | { |
---|
655 | return caca_free_frame(_c_cv, f); |
---|
656 | } |
---|
657 | |
---|
658 | /* bitmap dithering */ |
---|
659 | |
---|
660 | [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), |
---|
661 | SuppressUnmanagedCodeSecurity] |
---|
662 | private static extern int caca_dither_bitmap(IntPtr c, int x, int y, |
---|
663 | int w, int h, |
---|
664 | IntPtr d, IntPtr data); |
---|
665 | public int ditherBitmap(Rectangle r, Dither d, object data) |
---|
666 | { |
---|
667 | GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); |
---|
668 | int ret = caca_dither_bitmap(_c_cv, r.X, r.Y, r.Width, r.Height, |
---|
669 | d._dither, gch.AddrOfPinnedObject()); |
---|
670 | gch.Free(); |
---|
671 | return ret; |
---|
672 | } |
---|
673 | |
---|
674 | public int ditherBitmap(int x, int y, int w, int h, |
---|
675 | Dither d, object data) |
---|
676 | { |
---|
677 | GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned); |
---|
678 | int ret = caca_dither_bitmap(_c_cv, x, y, w, h, d._dither, |
---|
679 | gch.AddrOfPinnedObject()); |
---|
680 | gch.Free(); |
---|
681 | return ret; |
---|
682 | } |
---|
683 | } |
---|
684 | } |
---|
685 | |
---|