Changeset 2047
- Timestamp:
- Nov 24, 2007, 8:56:33 PM (13 years ago)
- Location:
- libcaca/trunk/csharp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/csharp/Caca.cs
r2046 r2047 83 83 84 84 85 public unsafe class Display : IDisposable85 public unsafe class CacaDisplay : IDisposable 86 86 { 87 87 [DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] … … 117 117 IntPtr _dp; 118 118 119 public Display(CuculCanvas cv)119 public CacaDisplay(CuculCanvas cv) 120 120 { 121 121 _cv = cv._cv; -
libcaca/trunk/csharp/test.cs
r2046 r2047 19 19 using Caca; 20 20 21 class Test { 21 class DemoCanvas : CuculCanvas 22 { 23 private DateTime startTime; 22 24 25 public DemoCanvas() 26 { 27 startTime = DateTime.Now; 28 } 23 29 30 public void Draw() 31 { 32 int barCount = 6; 33 double t = (DateTime.Now - startTime).TotalMilliseconds; 24 34 25 public static void Main() { 26 int barCount = 6; 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 59 class 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 83 class Test 84 { 85 public static void Main() 86 { 27 87 Console.WriteLine("libcaca .NET test"); 28 88 Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>"); 29 89 30 90 /* Instanciate a cucul canvas */ 31 CuculCanvas cv = new CuculCanvas();91 DemoCanvas cv = new DemoCanvas(); 32 92 93 /* We have a proper canvas, let's display it using Caca */ 94 DemoDisplay dp = new DemoDisplay(cv); 33 95 34 96 /* Random number. This is a static method, … … 36 98 Console.WriteLine("A random number : {0}", Libcucul.Rand(0, 1337)); 37 99 38 39 40 /* We have a proper canvas, let's display it using Caca */ 41 Display dp = new Display(cv); 42 dp.setDisplayTime(20000); // Refresh every 20 ms 43 44 dp.setDisplayTitle("libcaca .NET Bindings test suite"); 45 46 double v; 47 Int32 y = 0; 48 Event e = new Event(); 49 int i; 50 51 DateTime startTime = DateTime.Now; 52 while(dp.getEvent(Event.type.KEY_RELEASE, e, 10) == 0) 53 { 54 TimeSpan curTime = DateTime.Now - startTime; 55 double t = curTime.TotalMilliseconds; 56 cv.setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); 57 for(i=0; i<barCount;i++) 58 { 59 v = ((Math.Sin((t/500.0)+(i/((double)barCount)))+1)/2)*cv.height; 60 y = (Int32) v; 61 62 63 64 cv.setColorAnsi(i+9, Libcucul.BLACK); 65 /* drawLine is already clipped, we don't care about overflows */ 66 cv.drawLine(0, y-2, cv.width, y-2, '-'); 67 cv.drawLine(0, y-1, cv.width, y-1, '*'); 68 cv.drawLine(0, y, cv.width, y, '#'); 69 cv.drawLine(0, y+1, cv.width, y+1, '*'); 70 cv.drawLine(0, y+2, cv.width, y+2, '-'); 71 } 72 73 cv.setColorAnsi(Libcucul.WHITE, Libcucul.BLUE); 74 cv.putStr(cv.width - 30,cv.height - 2," -=[ Powered by libcaca ]=- "); 75 cv.setColorAnsi(Libcucul.WHITE, Libcucul.BLACK); 76 77 78 dp.Refresh(); 79 cv.Clear(); 80 81 } 100 dp.EventLoop(); 82 101 83 102 /* Force deletion of our instances for fun */ 84 103 dp.Dispose(); 85 104 cv.Dispose(); 86 105 } 87 106 88 107 }
Note: See TracChangeset
for help on using the changeset viewer.