"Fossies" - the Fresh Open Source Software Archive

Member "libcaca-0.99.beta20/caca-sharp/Canvas.cs" (17 Jan 2015, 25491 Bytes) of package /linux/privat/libcaca-0.99.beta20.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Canvas.cs" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.99.beta19_vs_0.99.beta20.

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