No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

143 líneas
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. public DemoCanvas()
  26. {
  27. startTime = DateTime.Now;
  28. image = new uint[16,16];
  29. d = new CuculDither(32, new Size(16, 16), 16 * 4,
  30. 0xff0000, 0xff00, 0xff, 0x0);
  31. }
  32. public void Draw()
  33. {
  34. int barCount = 6;
  35. double t = (DateTime.Now - startTime).TotalMilliseconds;
  36. Clear();
  37. double cos = Math.Cos(t / 500.0);
  38. double sin = Math.Sin(t / 500.0);
  39. for(int y = 0; y < 16; y++)
  40. for(int x = 0; x < 16; x++)
  41. {
  42. double xt = (double)(x - 8);
  43. double yt = (double)(y - 8);
  44. int x2 = (int)(xt * cos + yt * sin + 8.0);
  45. int y2 = (int)(xt * sin - yt * cos + 8.0);
  46. if(x2 < 0) x2 = 0;
  47. if(y2 < 0) y2 = 0;
  48. image[x,y] = (uint)((x2 + y2) << 16)
  49. | (uint)(x2 << 8)
  50. | (uint)(y2);
  51. }
  52. ditherBitmap(Rectangle, d, image);
  53. setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
  54. for(int i = 0; i < barCount; i++)
  55. {
  56. double v = ((Math.Sin((t / 500.0)
  57. + (i / ((double)barCount))) + 1) / 2) * Size.Height;
  58. Point p1 = new Point(0, (int)v);
  59. Point p2 = new Point(Size.Width - 1, (int)v);
  60. setColorAnsi(i + 9, Libcucul.BLACK);
  61. /* drawLine is already clipped, we don't care about overflows */
  62. drawLine(p1 + new Size(0, -2), p2 + new Size(0, -2), '-');
  63. drawLine(p1 + new Size(0, -1), p2 + new Size(0, -1), '*');
  64. drawLine(p1, p2, '#');
  65. drawLine(p1 + new Size(0, 1), p2 + new Size(0, 1), '*');
  66. drawLine(p1 + new Size(0, 2), p2 + new Size(0, 2), '-');
  67. }
  68. setColorAnsi(Libcucul.WHITE, Libcucul.BLUE);
  69. putStr(new Point(-30, -2) + Size, " -=[ Powered by libcaca ]=- ");
  70. setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
  71. }
  72. }
  73. class DemoDisplay : CacaDisplay
  74. {
  75. private DemoCanvas cv;
  76. public DemoDisplay(DemoCanvas _cv) : base(_cv)
  77. {
  78. displayTime = 20000; // Refresh every 20 ms
  79. title = "libcaca .NET Bindings test suite";
  80. cv = _cv;
  81. }
  82. public void EventLoop()
  83. {
  84. CacaEvent ev;
  85. while((ev = getEvent(CacaEventType.KEY_RELEASE, 10)).type == 0)
  86. {
  87. cv.Draw();
  88. Refresh();
  89. }
  90. if(ev.keyCh > 0x20 && ev.keyCh < 0x7f)
  91. Console.WriteLine("Key pressed: {0}", ev.keyUtf8);
  92. else
  93. Console.WriteLine("Key pressed: 0x{0:x}", ev.keyCh);
  94. }
  95. }
  96. class Test
  97. {
  98. public static void Main()
  99. {
  100. Console.WriteLine("libcaca {0} .NET test", Libcaca.getVersion());
  101. Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");
  102. /* Instanciate a cucul canvas */
  103. DemoCanvas cv = new DemoCanvas();
  104. /* We have a proper canvas, let's display it using Caca */
  105. DemoDisplay dp = new DemoDisplay(cv);
  106. /* Random number. This is a static method,
  107. not to be used with previous instance */
  108. Console.WriteLine("A random number: {0}", Libcucul.Rand(0, 1337));
  109. dp.EventLoop();
  110. /* Force deletion of our instances for fun */
  111. dp.Dispose();
  112. cv.Dispose();
  113. }
  114. }