Changeset 1428 for libcaca


Ignore:
Timestamp:
Nov 23, 2006, 9:22:03 PM (14 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • .Net : Fixed drawLine() and updated example (rasters rule)
Location:
libcaca/trunk/DotNet
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/DotNet/Cucul.cs

    r1424 r1428  
    5151      public static extern Int32  cucul_blit(IntPtr qq, Int32 x, Int32 y, IntPtr qq1, IntPtr qq2);
    5252    [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);
     53      public static extern Int32 cucul_draw_line(IntPtr qq, Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 c);
    5454    [DllImport("libCucul.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
    5555      public static extern Int32 cucul_draw_polyline(IntPtr qq, Int32[] x, Int32[] y, Int32 n, IntPtr c);
     
    191191            return cucul_putchar(qq, x, y, c);
    192192            }
    193         public Int32 clearCanvas()
     193        public Int32 Clear()
    194194            {
    195195            return cucul_clear_canvas(qq);
     
    199199            return cucul_blit(qq, x, y, qq1.get_cucul_t(), qq2.get_cucul_t());
    200200            }
    201         public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, string c)
     201        public Int32 drawLine(Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 c)
    202202            {
    203203            return cucul_draw_line(qq, x1, y1, x2, y2, c);
  • libcaca/trunk/DotNet/test.cs

    r1424 r1428  
    2222
    2323        public static void Main() {
     24        int barCount = 6;
    2425        Console.WriteLine("libcaca .NET test");
    2526                Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");
     
    2829        Cucul qq = new Cucul();
    2930
    30         /* Get size, and change it */
    31         Console.WriteLine("Old size : {0}x{1}", qq.getWidth(), qq.getHeight());
    32         qq.setSize(80,50);
    33         Console.WriteLine("Newsize  : {0}x{1}", qq.getWidth(), qq.getHeight());
    34 
     31 
    3532        /* Random number. This is a static method,
    3633           not to be used with previous instance */
    3734        Console.WriteLine("A random number : {0}", Cucul.Rand(0, 1337));
    3835
    39         /* Draw stuff on our canvas */
    40         qq.putChar(0,0, 'J');
    41         qq.setColor(Cucul.CUCUL_BLUE, Cucul.CUCUL_RED);
    42         qq.drawLine(10, 15, 45, 27, "#");
    43         qq.putStr(10, 10, "Hello from .NET");
    44         Console.WriteLine("Char at 0,0 : {0}", qq.getChar(0,0));
    45         qq.Flip();
    46 
    47 
    48         /* Create a Dither instance */
    49         Dither dither = new Dither(32, 320, 200, 320, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
    50         dither.setBrightness((float)0.7);
    51         string[] aalist = dither.getAntialiasList();
    52         Console.WriteLine("List : '{0}'", aalist[1]);
    5336
    5437
    5538        /* We have a proper canvas, let's display it using Caca */
    5639        Caca kk = new Caca(qq);
    57         kk.setDisplayTime(2000000); // Refresh every 2 seconds
     40        kk.setDisplayTime(20000); // Refresh every 20 ms
    5841
    5942        kk.setDisplayTitle("libcaca .NET Bindings test suite");
    6043
     44        double v;
     45        Int32 y = 0;
    6146        Event e = new Event();
    62         int startTime = kk.getDisplayTime();
     47        Int32 i;
     48       
     49        DateTime startTime = DateTime.Now;
    6350        while(kk.getEvent(Event.type.KEY_RELEASE, e, 10) == 0)
    6451          {
    65           kk.Refresh();
    66           Console.WriteLine("Render time : {0}", kk.getDisplayTime()-startTime);
     52            TimeSpan curTime = DateTime.Now - startTime;
     53            double t = curTime.TotalMilliseconds;
     54            qq.setColor(Cucul.CUCUL_WHITE, Cucul.CUCUL_BLACK);
     55            for(i=0; i<barCount;i++)
     56             {
     57                v = ((Math.Sin((t/500.0)+(i/((double)barCount)))+1)/2)*qq.getHeight();
     58                y = (Int32) v;
     59
     60 
     61
     62                qq.setColor(i+1, Cucul.CUCUL_BLACK);
     63                /* drawLine is already clipped, we don't care about overflows */
     64                qq.drawLine(0, y-2, qq.getWidth(), y-2, '-');
     65                qq.drawLine(0, y-1, qq.getWidth(), y-1, '*');
     66                qq.drawLine(0, y, qq.getWidth(), y, '#');
     67                qq.drawLine(0, y+1, qq.getWidth(), y+1, '*');
     68                qq.drawLine(0, y+2, qq.getWidth(), y+2, '-');
     69             }
     70
     71             qq.setColor(Cucul.CUCUL_WHITE, Cucul.CUCUL_BLUE);   
     72             qq.putStr(qq.getWidth() - 30,qq.getHeight() - 2," -=[ Powered by libcaca ]=- ");
     73             qq.setColor(Cucul.CUCUL_WHITE, Cucul.CUCUL_BLACK);   
     74 
     75
     76            kk.Refresh();
     77            qq.Clear();
     78           
    6779          }
    6880
    69         /* Force deletion of our instance for fun */
     81        /* Force deletion of our instances for fun */
    7082        qq.Dispose();
     83        kk.Dispose();
    7184        }
    7285
Note: See TracChangeset for help on using the changeset viewer.