source: libcaca/trunk/csharp/test.cs @ 2047

Last change on this file since 2047 was 2047, checked in by Sam Hocevar, 13 years ago
  • Rewrote the C# test in a more object-oriented way.
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/*
2 *  Test      .NET bindings test program
3 *  Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
4 *                All Rights Reserved
5 *
6 *  $Id: test.cs 2047 2007-11-24 19:56:33Z sam $
7 *
8 *  This program 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
16using System;
17
18using Cucul;
19using Caca;
20
21class DemoCanvas : CuculCanvas
22{
23    private DateTime startTime;
24
25    public DemoCanvas()
26    {
27        startTime = DateTime.Now;
28    }
29
30    public void Draw()
31    {
32        int barCount = 6;
33        double t = (DateTime.Now - startTime).TotalMilliseconds;
34
35        Clear();
36
37        setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
38        for(int i = 0; i < barCount; i++)
39        {
40            double v = ((Math.Sin((t / 500.0)
41                          + (i / ((double)barCount))) + 1) / 2) * height;
42            int y = (int)v;
43
44            setColorAnsi(i + 9, Libcucul.BLACK);
45            /* drawLine is already clipped, we don't care about overflows */
46            drawLine(0, y - 2, width, y - 2, '-');
47            drawLine(0, y - 1, width, y - 1, '*');
48            drawLine(0, y,     width, y,     '#');
49            drawLine(0, y + 1, width, y + 1, '*');
50            drawLine(0, y + 2, width, y + 2, '-');
51        }
52
53        setColorAnsi(Libcucul.WHITE, Libcucul.BLUE);
54        putStr(width - 30, height - 2, " -=[ Powered by libcaca ]=- ");
55        setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
56    }
57}
58
59class DemoDisplay : CacaDisplay
60{
61    private Event e;
62    private DemoCanvas cv;
63
64    public DemoDisplay(DemoCanvas _cv) : base(_cv)
65    {
66        setDisplayTime(20000); // Refresh every 20 ms
67        setDisplayTitle("libcaca .NET Bindings test suite");
68        cv = _cv;
69        e = new Event();
70    }
71
72    public void EventLoop()
73    {
74        while(getEvent(Event.type.KEY_RELEASE, e, 10) == 0)
75        {
76            cv.Draw();
77
78            Refresh();
79        }
80    }
81}
82
83class Test
84{
85    public static void Main()
86    {
87        Console.WriteLine("libcaca .NET test");
88        Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");
89
90        /* Instanciate a cucul canvas */
91        DemoCanvas cv = new DemoCanvas();
92
93        /* We have a proper canvas, let's display it using Caca */
94        DemoDisplay dp = new DemoDisplay(cv);
95
96        /* Random number. This is a static method,
97           not to be used with previous instance */
98        Console.WriteLine("A random number : {0}", Libcucul.Rand(0, 1337));
99
100        dp.EventLoop();
101
102        /* Force deletion of our instances for fun */
103        dp.Dispose();
104        cv.Dispose();
105    }
106
107}
Note: See TracBrowser for help on using the repository browser.