您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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