Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

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