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.
 
 
 
 
 
 

135 lines
4.1 KiB

  1. /*
  2. * Test .NET bindings test program
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * 2007 Sam Hocevar <sam@hocevar.net>
  5. * All Rights Reserved
  6. *
  7. * This program 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. using System;
  14. using System.Drawing;
  15. using System.Runtime.InteropServices;
  16. using Caca;
  17. class DemoCanvas : Canvas
  18. {
  19. private uint[,] image;
  20. private DateTime startTime;
  21. private Dither d;
  22. private Canvas scroll;
  23. public DemoCanvas()
  24. {
  25. startTime = DateTime.Now;
  26. string message = " --- POWERED BY LIBCACA --- OLDSCHOOL TEXT EFFECTS ARE 100% PURE WIN";
  27. scroll = new Canvas(new Size(message.Length, 1));
  28. scroll.setColorAnsi(AnsiColor.WHITE, AnsiColor.TRANSPARENT);
  29. scroll.putStr(new Point(0, 0), message);
  30. Caca.Font f = new Caca.Font(Caca.Font.getList()[1]);
  31. int w = f.Size.Width * message.Length;
  32. int h = f.Size.Height;
  33. image = new uint[w, h];
  34. d = new Dither(32, new Size(w, h), w * 4,
  35. 0xff00, 0xff0000, 0xff000000, 0xff);
  36. f.Render(scroll, image, image.GetLength(0) * 4);
  37. }
  38. public void Draw()
  39. {
  40. int barCount = 6;
  41. double t = (DateTime.Now - startTime).TotalMilliseconds;
  42. Clear();
  43. setColorAnsi(AnsiColor.WHITE, AnsiColor.BLACK);
  44. for(int i = 0; i < barCount; i++)
  45. {
  46. double v = ((Math.Sin((t / 500.0)
  47. + (i / ((double)barCount))) + 1) / 2) * Size.Height;
  48. Point p1 = new Point(0, (int)v);
  49. Point p2 = new Point(Size.Width - 1, (int)v);
  50. setColorAnsi((uint)(i + 9), AnsiColor.BLACK);
  51. /* drawLine is already clipped, we don't care about overflows */
  52. drawLine(p1 + new Size(0, -2), p2 + new Size(0, -2), '-');
  53. drawLine(p1 + new Size(0, -1), p2 + new Size(0, -1), '*');
  54. drawLine(p1, p2, '#');
  55. drawLine(p1 + new Size(0, 1), p2 + new Size(0, 1), '*');
  56. drawLine(p1 + new Size(0, 2), p2 + new Size(0, 2), '-');
  57. }
  58. int w = Size.Width;
  59. int h = Size.Height;
  60. int x = (int)(t / 10) % (12 * w);
  61. int y = (int)(h * (2.0 + Math.Sin(t / 200.0)) / 4);
  62. ditherBitmap(new Rectangle(- x, h / 2 - y, w * 12, y * 2), d, image);
  63. ditherBitmap(new Rectangle(12 * w - x, h / 2 - y, w * 12, y * 2), d, image);
  64. setColorAnsi(AnsiColor.WHITE, AnsiColor.BLUE);
  65. putStr(new Point(-30, -2) + Size, " -=[ Powered by libcaca ]=- ");
  66. setColorAnsi(AnsiColor.WHITE, AnsiColor.BLACK);
  67. }
  68. }
  69. class DemoDisplay : Display
  70. {
  71. private DemoCanvas cv;
  72. public DemoDisplay(DemoCanvas _cv) : base(_cv)
  73. {
  74. Title = "libcaca .NET Bindings test suite";
  75. DisplayTime = 20000; // Refresh every 20 ms
  76. cv = _cv;
  77. }
  78. public void EventLoop()
  79. {
  80. Event ev;
  81. while((ev = getEvent(EventType.KEY_RELEASE, 10)).Type == 0)
  82. {
  83. cv.Draw();
  84. Refresh();
  85. }
  86. if(ev.KeyCh > 0x20 && ev.KeyCh < 0x7f)
  87. Console.WriteLine("Key pressed: {0}", ev.KeyUtf8);
  88. else
  89. Console.WriteLine("Key pressed: 0x{0:x}", ev.KeyCh);
  90. }
  91. }
  92. class Test
  93. {
  94. public static void Main()
  95. {
  96. Console.WriteLine("libcaca {0} .NET test", Libcaca.getVersion());
  97. Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");
  98. /* Instanciate a caca canvas */
  99. DemoCanvas cv = new DemoCanvas();
  100. /* We have a proper canvas, let's display it using Caca */
  101. DemoDisplay dp = new DemoDisplay(cv);
  102. /* Random number. This is a static method,
  103. not to be used with previous instance */
  104. Console.WriteLine("A random number: {0}", Libcaca.Rand(0, 1337));
  105. dp.EventLoop();
  106. }
  107. }