選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

test.cs 4.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 = "LIBCACA *** 100% PURE WIN *** ";
  30. scroll = new CuculCanvas(new Size(message.Length, 1));
  31. scroll.setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
  32. scroll.putStr(new Point(0, 0), message);
  33. CuculFont f = new CuculFont(CuculFont.getList()[0]);
  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. 0xff0000, 0xff00, 0xff, 0xff000000);
  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. int w = Size.Width;
  47. int h = Size.Height;
  48. int x = (int)(t / 10) % (6 * w);
  49. int y = (int)(h * (2.0 + Math.Sin(t / 200.0)) / 4);
  50. ditherBitmap(new Rectangle(- x, h / 2 - y, w * 6, y * 2), d, image);
  51. ditherBitmap(new Rectangle(6 * w - x, h / 2 - y, w * 6, y * 2), d, image);
  52. setColorAnsi(Libcucul.WHITE, Libcucul.BLACK);
  53. for(int i = 0; i < barCount; i++)
  54. {
  55. double v = ((Math.Sin((t / 500.0)
  56. + (i / ((double)barCount))) + 1) / 2) * Size.Height;
  57. Point p1 = new Point(0, (int)v);
  58. Point p2 = new Point(Size.Width - 1, (int)v);
  59. setColorAnsi(i + 9, Libcucul.BLACK);
  60. /* drawLine is already clipped, we don't care about overflows */
  61. drawLine(p1 + new Size(0, -2), p2 + new Size(0, -2), '-');
  62. drawLine(p1 + new Size(0, -1), p2 + new Size(0, -1), '*');
  63. drawLine(p1, p2, '#');
  64. drawLine(p1 + new Size(0, 1), p2 + new Size(0, 1), '*');
  65. drawLine(p1 + new Size(0, 2), p2 + new Size(0, 2), '-');
  66. }
  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. displayTime = 20000; // Refresh every 20 ms
  78. title = "libcaca .NET Bindings test suite";
  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. }