You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 lines
2.7 KiB

  1. /*
  2. * Test .NET bindings test program
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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. using System;
  15. using Cucul;
  16. using Caca;
  17. class DemoCanvas : CuculCanvas
  18. {
  19. private DateTime startTime;
  20. public DemoCanvas()
  21. {
  22. startTime = DateTime.Now;
  23. }
  24. public void Draw()
  25. {
  26. int barCount = 6;
  27. double t = (DateTime.Now - startTime).TotalMilliseconds;
  28. Clear();
  29. setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
  30. for(int i = 0; i < barCount; i++)
  31. {
  32. double v = ((Math.Sin((t / 500.0)
  33. + (i / ((double)barCount))) + 1) / 2) * height;
  34. int y = (int)v;
  35. setColorAnsi(i + 9, Libcucul.BLACK);
  36. /* drawLine is already clipped, we don't care about overflows */
  37. drawLine(0, y - 2, width, y - 2, '-');
  38. drawLine(0, y - 1, width, y - 1, '*');
  39. drawLine(0, y, width, y, '#');
  40. drawLine(0, y + 1, width, y + 1, '*');
  41. drawLine(0, y + 2, width, y + 2, '-');
  42. }
  43. setColorAnsi(Libcucul.WHITE, Libcucul.BLUE);
  44. putStr(width - 30, height - 2, " -=[ Powered by libcaca ]=- ");
  45. setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
  46. }
  47. }
  48. class DemoDisplay : CacaDisplay
  49. {
  50. private Event e;
  51. private DemoCanvas cv;
  52. public DemoDisplay(DemoCanvas _cv) : base(_cv)
  53. {
  54. setDisplayTime(20000); // Refresh every 20 ms
  55. setDisplayTitle("libcaca .NET Bindings test suite");
  56. cv = _cv;
  57. e = new Event();
  58. }
  59. public void EventLoop()
  60. {
  61. while(getEvent(Event.type.KEY_RELEASE, e, 10) == 0)
  62. {
  63. cv.Draw();
  64. Refresh();
  65. }
  66. }
  67. }
  68. class Test
  69. {
  70. public static void Main()
  71. {
  72. Console.WriteLine("libcaca .NET test");
  73. Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");
  74. /* Instanciate a cucul canvas */
  75. DemoCanvas cv = new DemoCanvas();
  76. /* We have a proper canvas, let's display it using Caca */
  77. DemoDisplay dp = new DemoDisplay(cv);
  78. /* Random number. This is a static method,
  79. not to be used with previous instance */
  80. Console.WriteLine("A random number : {0}", Libcucul.Rand(0, 1337));
  81. dp.EventLoop();
  82. /* Force deletion of our instances for fun */
  83. dp.Dispose();
  84. cv.Dispose();
  85. }
  86. }