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.

test.cs 3.4 KiB

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