source: libcaca/trunk/DotNet/Cucul.cs @ 1462

Last change on this file since 1462 was 1462, checked in by Sam Hocevar, 14 years ago
  • Bwarf, typo in the no warranty clause.
  • Property svn:keywords set to Id
File size: 20.6 KB
Line 
1/*
2 *  CuculSharp      .NET bindings for libcucul
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  $Id: Cucul.cs 1462 2006-12-12 01:53:54Z sam $
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15
16
17using System;
18using System.Runtime.InteropServices;
19using System.Security;
20
21
22namespace libCucul
23  {
24   
25    public unsafe class Cucul : IDisposable
26    {
27    /* Fixme */
28    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]   
29      public static extern IntPtr cucul_create_canvas(int w, int h);
30    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
31      public static extern Int32  cucul_get_canvas_width(IntPtr qq);
32    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
33      public static extern Int32  cucul_get_canvas_height(IntPtr qq);
34    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
35      public static extern Int32  cucul_set_canvas_size(IntPtr qq, int w, int h);
36    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
37      public static extern Int32  cucul_rand(int min, int max);
38    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
39      public static extern Int32  cucul_free_canvas(IntPtr qq);
40     [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
41      public static extern Int32  cucul_set_color(IntPtr qq, int fg, int bg);
42    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
43      public static extern Int32  cucul_set_truecolor(IntPtr qq, Int32 fg, Int32 bg);
44    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
45      public static extern Int32  cucul_putchar(IntPtr qq, int x, int y, char c);
46        [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
47          public static extern Int32  cucul_putstr(IntPtr qq, int x , int y, String c);
48
49    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
50      public static extern Int32  cucul_clear_canvas(IntPtr qq);
51    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
52      public static extern Int32  cucul_blit(IntPtr qq, Int32 x, Int32 y, IntPtr qq1, IntPtr qq2);
53    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
54      public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 c);
55    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
56      public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
57    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
58      public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
59    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
60      public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);
61
62    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
63      public static extern Int32 cucul_gotoxy(IntPtr qq, Int32 x, Int32 y);
64    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
65      public static extern Int32 cucul_get_cursor_x(IntPtr qq);
66    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
67      public static extern Int32 cucul_get_cursor_y(IntPtr qq);
68    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
69      public static extern Int32 cucul_put_char(IntPtr qq, Int32 x, Int32 y, Int32 c);
70    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
71      public static extern Int32 cucul_get_char(IntPtr qq, Int32 x, Int32 y);
72    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
73      public static extern Int32 cucul_put_str(IntPtr qq, Int32 x, Int32 y, string c);
74    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
75      public static extern Int32 cucul_get_attr(IntPtr qq, Int32 x, Int32 y);
76    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
77      public static extern Int32 cucul_set_attr(IntPtr qq, Int32 a);
78    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
79      public static extern Int32 cucul_put_attr(IntPtr qq, Int32 x, Int32 y, Int32 a);
80    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
81      public static extern Int32 cucul_set_color_ansi(IntPtr qq, Int32 fg, Int32 bg);
82    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
83      public static extern Int32 cucul_set_color_argb(IntPtr qq, Int32 fg, Int32 bg);
84    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
85      public static extern Int32 cucul_set_canvas_handle(IntPtr qq, Int32 x, Int32 y);
86    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
87      public static extern Int32 cucul_get_canvas_handle_x(IntPtr qq);
88    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
89      public static extern Int32 cucul_get_canvas_handle_y(IntPtr qq);
90    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
91      public static extern Int32 cucul_set_canvas_boundaries(IntPtr qq, Int32 x, Int32 y,
92                                 Int32 h,  Int32 w);
93
94    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
95      public static extern Int32 cucul_invert(IntPtr qq);
96    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
97      public static extern Int32 cucul_flip(IntPtr qq);
98    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
99      public static extern Int32 cucul_flop(IntPtr qq);
100    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
101      public static extern Int32 cucul_rotate(IntPtr qq);
102
103    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
104      public static extern Int32 cucul_attr_to_ansi(Int64 a);
105    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
106      public static extern Int32 cucul_attr_to_ansi_fg(Int64 a);
107    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
108      public static extern Int32 cucul_attr_to_ansi_bg(Int64 a);
109
110    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
111       public static extern Int32 cucul_get_frame_count(IntPtr qq);
112    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
113       public static extern Int32 cucul_set_frame(IntPtr qq, Int32 f);
114    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
115       public static extern string cucul_get_frame_name(IntPtr qq);
116    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
117       public static extern Int32 cucul_set_frame_name(IntPtr qq, string n);
118    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
119       public static extern Int32 cucul_create_frame(IntPtr qq, Int32 f);
120    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
121       public static extern Int32 cucul_free_frame(IntPtr qq, Int32 f);
122
123
124    /* Constants */
125
126    public const Int32 CUCUL_BLACK = 0x00; /**< The colour index for black. */
127    public const Int32 CUCUL_BLUE = 0x01; /**< The colour index for blue. */
128    public const Int32 CUCUL_GREEN = 0x02; /**< The colour index for green. */
129    public const Int32 CUCUL_CYAN = 0x03; /**< The colour index for cyan. */
130    public const Int32 CUCUL_RED = 0x04; /**< The colour index for red. */
131    public const Int32 CUCUL_MAGENTA = 0x05; /**< The colour index for magenta. */
132    public const Int32 CUCUL_BROWN = 0x06; /**< The colour index for brown. */
133    public const Int32 CUCUL_LIGHTGRAY = 0x07; /**< The colour index for light gray. */
134    public const Int32 CUCUL_DARKGRAY = 0x08; /**< The colour index for dark gray. */
135    public const Int32 CUCUL_LIGHTBLUE = 0x09; /**< The colour index for blue. */
136    public const Int32 CUCUL_LIGHTGREEN = 0x0a; /**< The colour index for light green. */
137    public const Int32 CUCUL_LIGHTCYAN = 0x0b; /**< The colour index for light cyan. */
138    public const Int32 CUCUL_LIGHTRED = 0x0c; /**< The colour index for light red. */
139    public const Int32 CUCUL_LIGHTMAGENTA = 0x0d; /**< The colour index for light magenta. */
140    public const Int32 CUCUL_YELLOW = 0x0e; /**< The colour index for yellow. */
141    public const Int32 CUCUL_WHITE = 0x0f; /**< The colour index for white. */
142    public const Int32 CUCUL_DEFAULT = 0x10; /**< The output driver's default colour. */
143    public const Int32 CUCUL_TRANSPARENT = 0x20; /**< The transparent colour. */
144
145    public const Int32 CUCUL_BOLD = 0x01; /**< The style mask for bold. */
146    public const Int32 CUCUL_ITALICS = 0x02; /**< The style mask for italics. */
147    public const Int32 CUCUL_UNDERLINE = 0x04; /**< The style mask for underline. */
148    public const Int32 CUCUL_BLINK = 0x08; /**< The style mask for blink. */
149
150
151        IntPtr qq;
152
153        public Cucul()
154            {
155               qq = cucul_create_canvas(0, 0);
156            }
157        public void Dispose()
158            {
159               cucul_free_canvas(qq);
160               GC.SuppressFinalize(this);
161            }
162        public Cucul(Int32 w, Int32 h)
163            {
164              qq = cucul_create_canvas(w, h);
165            }
166        public Int32 getWidth()
167            {
168            return cucul_get_canvas_width(qq);
169            }
170        public Int32 getHeight()
171            {
172            return cucul_get_canvas_height(qq);
173            }
174        public Int32 setSize(Int32 w, Int32 h)
175            {
176            return cucul_set_canvas_size(qq, w, h);
177            }
178        public static Int32 Rand(Int32 min, Int32 max)
179            {
180            return cucul_rand(min, max);
181            }
182        public Int32 setColor(int fg, int bg)
183            {
184            return cucul_set_color(qq, fg, bg);
185            }
186        public Int32  setTruecolor(Int32 fg, Int32 bg)
187            {
188            return cucul_set_truecolor(qq, fg, bg);
189            }
190        public Int32  putChar(int x, int y, char c)
191            {
192            return cucul_putchar(qq, x, y, c);
193            }
194        public Int32 Clear()
195            {
196            return cucul_clear_canvas(qq);
197            }
198        public Int32 Blit(int x, int y, Cucul qq1, Cucul qq2)
199            {
200            return cucul_blit(qq, x, y, qq1.get_cucul_t(), qq2.get_cucul_t());
201            }
202        public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 c)
203            {
204            return cucul_draw_line(qq, x1, y1, x2, y2, c);
205            }
206        public Int32 putStr(Int32 x, Int32 y, string c)
207            {
208            return cucul_putstr(qq, x, y, c);
209            }
210        public Int32 gotoXY(Int32 x, Int32 y)
211            {
212            return cucul_gotoxy(qq, x, y);
213            }
214        public Int32 getCursorX()
215            {
216            return cucul_get_cursor_x(qq);
217            }
218        public Int32 getCursorY()
219            {
220            return cucul_get_cursor_y(qq);
221            }
222        public Int32 getChar(Int32 x, Int32 y)
223            {
224            return cucul_get_char(qq, x, y);
225            }
226        public Int32 getAttr(Int32 x, Int32 y)
227            {
228            return cucul_get_attr(qq, x, y);
229            }
230        public Int32 setAttr(Int32 a)
231            {
232            return cucul_set_attr(qq, a);
233            }
234        public Int32 setAttr(Int32 x, Int32 y, Int32 a)
235            {
236            return cucul_put_attr(qq, x, y, a);
237            }
238        public Int32 setColorANSI(Int32 fg, Int32 bg)
239            {
240            return cucul_set_color_ansi(qq, fg, bg);
241            }
242        public Int32 setColorARGB(Int32 fg, Int32 bg)
243            {
244            return cucul_set_color_ansi(qq, fg, bg);
245            }
246        public Int32 setCanvasHandle(Int32 x, Int32 y)
247            {
248            return cucul_set_canvas_handle(qq, x, y);
249            }
250        public Int32 getCanvasHandleX()
251            {
252            return cucul_get_canvas_handle_x(qq);
253            }
254        public Int32 getCanvasHandleY()
255            {
256            return cucul_get_canvas_handle_y(qq);
257            }
258        public Int32 setCanvasHandleY(Int32 x, Int32 y, Int32 h,  Int32 w)
259            {
260            return cucul_set_canvas_boundaries(qq, x, y, h, w);
261            }
262         
263
264        public Int32 Invert()
265            {
266            return cucul_invert(qq);
267            }
268        public Int32 Flip()
269            {
270            return cucul_flip(qq);
271            }
272        public Int32 Flop()
273            {
274            return cucul_flop(qq);
275            }
276        public Int32 Rotate()
277            {
278            return cucul_rotate(qq);
279            }
280
281        public Int32 AttrToANSI(Int64 a)
282            {
283            return cucul_attr_to_ansi(a);
284            }
285        public Int32 AttrToANSIFg(Int64 a)
286            {
287            return cucul_attr_to_ansi_fg(a);
288            }
289        public Int32 AttrToANSIBg(Int64 a)
290            {
291            return cucul_attr_to_ansi_bg(a);
292            }
293
294
295
296
297        public Int32 getFrameCount()
298            {
299            return cucul_get_frame_count(qq);
300            }
301        public Int32 setFrame(Int32 f)
302            {
303            return cucul_set_frame(qq, f);
304            }
305        public string getFrameName()
306            {
307            return cucul_get_frame_name(qq);
308            }
309        public Int32 setFrameName(string n)
310            {
311            return cucul_set_frame_name(qq, n);
312            }
313        public Int32 createFrame(Int32 f)
314            {
315            return cucul_create_frame(qq, f);
316            }
317        public Int32 freeFrame(Int32 f)
318            {
319            return cucul_free_frame(qq, f);
320            }
321
322
323        /* Privates methods, are not meant to be called by user*/
324       
325        public IntPtr get_cucul_t()
326            {
327            return qq;
328            }
329    }
330
331
332
333    public unsafe class Dither : IDisposable
334    {
335    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]   
336      public static extern IntPtr cucul_create_dither(Int32 bpp, Int32 w,
337                                                      Int32 h, Int32 pitch,
338                                                      Int64 rmask,
339                                                      Int64 gmask,
340                                                      Int64 bmask,
341                                                      Int64 amask);
342
343
344    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
345      public static extern Int32 cucul_set_dither_palette(IntPtr d,
346                             Int32[] r, Int32[] g,
347                             Int32[] b, Int32[] a);
348    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
349      public static extern Int32 cucul_set_dither_brightness(IntPtr d, float b);
350    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
351      public static extern Int32 cucul_set_dither_gamma(IntPtr d, float g);
352    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
353      public static extern Int32 cucul_set_dither_contrast(IntPtr d, float c);
354    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
355      public static extern Int32 cucul_set_dither_invert(IntPtr d, int i);
356    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
357      public static extern Int32 cucul_set_dither_antialias(IntPtr d, string s);
358    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
359      public static extern string[] cucul_get_dither_antialias_list(IntPtr d);
360    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
361      public static extern Int32 cucul_set_dither_color(IntPtr d, string s);
362    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
363      public static extern string[] cucul_get_dither_color_list(IntPtr d);
364    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
365      public static extern Int32 cucul_set_dither_charset(IntPtr d, string s);
366    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
367      public static extern string[] cucul_get_dither_charset_list(IntPtr d);
368    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
369      public static extern Int32 cucul_set_dither_mode(IntPtr d, string s);
370    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
371      public static extern string[] cucul_get_dither_mode_list(IntPtr d);
372    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
373      public static extern Int32 cucul_free_dither(IntPtr d);
374
375  /* FIXME  [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] 
376      Int32 cucul_dither_bitmap(Cucul c,Int32  x, Int32 y, Int32 w , Int32 y,
377                         IntPtr d2, void *);*/
378
379
380
381        IntPtr dither;
382
383        public Dither(Int32 bpp, Int32 w,Int32 h, Int32 pitch,
384                      Int64 rmask, Int64 gmask,Int64 bmask, Int64 amask)
385            {
386               dither = cucul_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask);
387            }
388        public void Dispose()
389            {
390               cucul_free_dither(dither);
391               GC.SuppressFinalize(this);
392            }
393        public Int32 setBrightness(float b)
394            {
395            return cucul_set_dither_brightness(dither, b);
396            }
397        public Int32 setGamma(float g)
398            {
399            return cucul_set_dither_gamma(dither, g);
400            }
401        public Int32 setContrast(float c)
402            {
403            return cucul_set_dither_contrast(dither, c);
404            }
405       public Int32 setInvert(Int32 i)
406            {
407            return cucul_set_dither_invert(dither, i);
408            }
409       public Int32 setAntialias(string s)
410            {
411            return cucul_set_dither_antialias(dither, s);
412            }
413       public Int32 setColor(string s)
414            {
415            return cucul_set_dither_color(dither, s);
416            }
417       public Int32 setCharset(string s)
418            {
419            return cucul_set_dither_charset(dither, s);
420            }
421       public Int32 setMode(string s)
422            {
423            return cucul_set_dither_mode(dither, s);
424            }
425       /* <FIXME> */
426       public string[] getAntialiasList()
427            {
428                return cucul_get_dither_antialias_list(dither);
429            }
430       public string[] getColorList()
431            {
432                return cucul_get_dither_color_list(dither);
433            }
434       public string[] getCharsetList()
435            {
436                return cucul_get_dither_charset_list(dither);
437            }
438       public string[] getModeList()
439            {
440                return cucul_get_dither_mode_list(dither);
441            }
442       /* </FIXME> */
443
444    }
445
446
447
448
449
450
451
452
453
454
455
456
457  }
458
Note: See TracBrowser for help on using the repository browser.