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.

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