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.
 
 
 
 
 
 

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