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

Last change on this file since 1422 was 1422, checked in by Jean-Yves Lamoureux, 16 years ago
  • Updated and/or added most of basic cucul functions. Lacks primitives, frames, dither, and import/export.
  • Property svn:keywords set to Id
File size: 13.5 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 1422 2006-11-18 11:25:50Z jylam $
7 *
8 *  This library is free software; you can redistribute it and/or
9 *  modify it under the terms of the Do What The Fuck You Want To
10 *  Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14
15
16using System;
17using System.Runtime.InteropServices;
18using System.Security;
19
20
21namespace libCucul
22  {
23   
24    public unsafe class Cucul : IDisposable
25    {
26    /* Fixme */
27    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]   
28      public static extern IntPtr cucul_create_canvas(int w, int h);
29    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
30      public static extern Int32  cucul_get_canvas_width(IntPtr qq);
31    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
32      public static extern Int32  cucul_get_canvas_height(IntPtr qq);
33    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
34      public static extern Int32  cucul_set_canvas_size(IntPtr qq, int w, int h);
35    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
36      public static extern Int32  cucul_rand(int min, int max);
37    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
38      public static extern Int32  cucul_free_canvas(IntPtr qq);
39     [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
40      public static extern Int32  cucul_set_color(IntPtr qq, int fg, int bg);
41    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
42      public static extern Int32  cucul_set_truecolor(IntPtr qq, Int32 fg, Int32 bg);
43    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
44      public static extern Int32  cucul_putchar(IntPtr qq, int x, int y, char c);
45        [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
46          public static extern Int32  cucul_putstr(IntPtr qq, int x , int y, String c);
47
48    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
49      public static extern Int32  cucul_clear_canvas(IntPtr qq);
50    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
51      public static extern Int32  cucul_blit(IntPtr qq, Int32 x, Int32 y, IntPtr qq1, IntPtr qq2);
52    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
53      public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c);
54    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
55      public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
56    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
57      public static extern Int32 cucul_draw_thin_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2);
58    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
59      public static extern Int32 cucul_draw_thin_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n);
60
61    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
62      public static extern Int32 cucul_gotoxy(IntPtr qq, Int32 x, Int32 y);
63    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
64      public static extern Int32 cucul_get_cursor_x(IntPtr qq);
65    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
66      public static extern Int32 cucul_get_cursor_y(IntPtr qq);
67    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
68      public static extern Int32 cucul_put_char(IntPtr qq, Int32 x, Int32 y, Int32 c);
69    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
70      public static extern Int32 cucul_get_char(IntPtr qq, Int32 x, Int32 y);
71    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
72      public static extern Int32 cucul_put_str(IntPtr qq, Int32 x, Int32 y, string c);
73    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
74      public static extern Int32 cucul_get_attr(IntPtr qq, Int32 x, Int32 y);
75    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
76      public static extern Int32 cucul_set_attr(IntPtr qq, Int32 a);
77    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
78      public static extern Int32 cucul_put_attr(IntPtr qq, Int32 x, Int32 y, Int32 a);
79    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
80      public static extern Int32 cucul_set_color_ansi(IntPtr qq, Int32 fg, Int32 bg);
81    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
82      public static extern Int32 cucul_set_color_argb(IntPtr qq, Int32 fg, Int32 bg);
83    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
84      public static extern Int32 cucul_set_canvas_handle(IntPtr qq, Int32 x, Int32 y);
85    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
86      public static extern Int32 cucul_get_canvas_handle_x(IntPtr qq);
87    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
88      public static extern Int32 cucul_get_canvas_handle_y(IntPtr qq);
89    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
90      public static extern Int32 cucul_set_canvas_boundaries(IntPtr qq, Int32 x, Int32 y,
91                                 Int32 h,  Int32 w);
92
93    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
94      public static extern Int32 cucul_invert(IntPtr qq);
95    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
96      public static extern Int32 cucul_flip(IntPtr qq);
97    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
98      public static extern Int32 cucul_flop(IntPtr qq);
99    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
100      public static extern Int32 cucul_rotate(IntPtr qq);
101
102    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
103      public static extern Int32 cucul_attr_to_ansi(Int64 a);
104    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
105      public static extern Int32 cucul_attr_to_ansi_fg(Int64 a);
106    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
107      public static extern Int32 cucul_attr_to_ansi_bg(Int64 a);
108
109
110
111    /* Constants */
112
113    public const Int32 CUCUL_BLACK = 0x00; /**< The colour index for black. */
114    public const Int32 CUCUL_BLUE = 0x01; /**< The colour index for blue. */
115    public const Int32 CUCUL_GREEN = 0x02; /**< The colour index for green. */
116    public const Int32 CUCUL_CYAN = 0x03; /**< The colour index for cyan. */
117    public const Int32 CUCUL_RED = 0x04; /**< The colour index for red. */
118    public const Int32 CUCUL_MAGENTA = 0x05; /**< The colour index for magenta. */
119    public const Int32 CUCUL_BROWN = 0x06; /**< The colour index for brown. */
120    public const Int32 CUCUL_LIGHTGRAY = 0x07; /**< The colour index for light gray. */
121    public const Int32 CUCUL_DARKGRAY = 0x08; /**< The colour index for dark gray. */
122    public const Int32 CUCUL_LIGHTBLUE = 0x09; /**< The colour index for blue. */
123    public const Int32 CUCUL_LIGHTGREEN = 0x0a; /**< The colour index for light green. */
124    public const Int32 CUCUL_LIGHTCYAN = 0x0b; /**< The colour index for light cyan. */
125    public const Int32 CUCUL_LIGHTRED = 0x0c; /**< The colour index for light red. */
126    public const Int32 CUCUL_LIGHTMAGENTA = 0x0d; /**< The colour index for light magenta. */
127    public const Int32 CUCUL_YELLOW = 0x0e; /**< The colour index for yellow. */
128    public const Int32 CUCUL_WHITE = 0x0f; /**< The colour index for white. */
129    public const Int32 CUCUL_DEFAULT = 0x10; /**< The output driver's default colour. */
130    public const Int32 CUCUL_TRANSPARENT = 0x20; /**< The transparent colour. */
131
132    public const Int32 CUCUL_BOLD = 0x01; /**< The style mask for bold. */
133    public const Int32 CUCUL_ITALICS = 0x02; /**< The style mask for italics. */
134    public const Int32 CUCUL_UNDERLINE = 0x04; /**< The style mask for underline. */
135    public const Int32 CUCUL_BLINK = 0x08; /**< The style mask for blink. */
136
137
138        IntPtr qq;
139
140        public Cucul()
141            {
142               qq = cucul_create_canvas(0, 0);
143            }
144        public void Dispose()
145            {
146               cucul_free_canvas(qq);
147               GC.SuppressFinalize(this);
148            }
149        public Cucul(Int32 w, Int32 h)
150            {
151              qq = cucul_create_canvas(w, h);
152            }
153        public Int32 getWidth()
154            {
155            return cucul_get_canvas_width(qq);
156            }
157        public Int32 getHeight()
158            {
159            return cucul_get_canvas_height(qq);
160            }
161        public Int32 setSize(Int32 w, Int32 h)
162            {
163            return cucul_set_canvas_size(qq, w, h);
164            }
165        public static Int32 Rand(Int32 min, Int32 max)
166            {
167            return cucul_rand(min, max);
168            }
169        public Int32 setColor(int fg, int bg)
170            {
171            return cucul_set_color(qq, fg, bg);
172            }
173        public Int32  setTruecolor(Int32 fg, Int32 bg)
174            {
175            return cucul_set_truecolor(qq, fg, bg);
176            }
177        public Int32  putChar(int x, int y, char c)
178            {
179            return cucul_putchar(qq, x, y, c);
180            }
181        public Int32 clearCanvas()
182            {
183            return cucul_clear_canvas(qq);
184            }
185        public Int32 Blit(int x, int y, Cucul qq1, Cucul qq2)
186            {
187            return cucul_blit(qq, x, y, qq1.get_cucul_t(), qq2.get_cucul_t());
188            }
189        public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c)
190            {
191            return cucul_draw_line(qq, x1, y1, x2, y2, c);
192            }
193        public Int32 putStr(Int32 x, Int32 y, string c)
194            {
195            return cucul_putstr(qq, x, y, c);
196            }
197        public Int32 gotoXY(Int32 x, Int32 y)
198            {
199            return cucul_gotoxy(qq, x, y);
200            }
201        public Int32 getCursorX()
202            {
203            return cucul_get_cursor_x(qq);
204            }
205        public Int32 getCursorY()
206            {
207            return cucul_get_cursor_y(qq);
208            }
209        public Int32 getChar(Int32 x, Int32 y)
210            {
211            return cucul_get_char(qq, x, y);
212            }
213        public Int32 getAttr(Int32 x, Int32 y)
214            {
215            return cucul_get_attr(qq, x, y);
216            }
217        public Int32 setAttr(Int32 a)
218            {
219            return cucul_set_attr(qq, a);
220            }
221        public Int32 setAttr(Int32 x, Int32 y, Int32 a)
222            {
223            return cucul_put_attr(qq, x, y, a);
224            }
225        public Int32 setColorANSI(Int32 fg, Int32 bg)
226            {
227            return cucul_set_color_ansi(qq, fg, bg);
228            }
229        public Int32 setColorARGB(Int32 fg, Int32 bg)
230            {
231            return cucul_set_color_ansi(qq, fg, bg);
232            }
233        public Int32 setCanvasHandle(Int32 x, Int32 y)
234            {
235            return cucul_set_canvas_handle(qq, x, y);
236            }
237        public Int32 getCanvasHandleX()
238            {
239            return cucul_get_canvas_handle_x(qq);
240            }
241        public Int32 getCanvasHandleY()
242            {
243            return cucul_get_canvas_handle_y(qq);
244            }
245        public Int32 setCanvasHandleY(Int32 x, Int32 y, Int32 h,  Int32 w)
246            {
247            return cucul_set_canvas_boundaries(qq, x, y, h, w);
248            }
249         
250
251        public Int32 Invert()
252            {
253            return cucul_invert(qq);
254            }
255        public Int32 Flip()
256            {
257            return cucul_flip(qq);
258            }
259        public Int32 Flop()
260            {
261            return cucul_flop(qq);
262            }
263        public Int32 Rotate()
264            {
265            return cucul_rotate(qq);
266            }
267
268        public Int32 AttrToANSI(Int64 a)
269            {
270            return cucul_attr_to_ansi(a);
271            }
272        public Int32 AttrToANSIFg(Int64 a)
273            {
274            return cucul_attr_to_ansi_fg(a);
275            }
276        public Int32 AttrToANSIBg(Int64 a)
277            {
278            return cucul_attr_to_ansi_bg(a);
279            }
280
281
282
283
284
285
286
287
288
289
290        /* Privates methods, are not meant to be called by user*/
291       
292        public IntPtr get_cucul_t()
293            {
294            return qq;
295            }
296    }
297  }
298
Note: See TracBrowser for help on using the repository browser.