Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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://sam.zoy.org/wtfpl/COPYING 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. }