Lines.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #region File description
  2. // --------------------------------------------------------------------------------------------------------------------
  3. // <copyright file="Lines.cs" company="GAMADU.COM">
  4. // Copyright © 2013 GAMADU.COM. All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without modification, are
  7. // permitted provided that the following conditions are met:
  8. //
  9. // 1. Redistributions of source code must retain the above copyright notice, this list of
  10. // conditions and the following disclaimer.
  11. //
  12. // 2. Redistributions in binary form must reproduce the above copyright notice, this list
  13. // of conditions and the following disclaimer in the documentation and/or other materials
  14. // provided with the distribution.
  15. //
  16. // THIS SOFTWARE IS PROVIDED BY GAMADU.COM 'AS IS' AND ANY EXPRESS OR IMPLIED
  17. // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GAMADU.COM OR
  19. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. //
  26. // The views and conclusions contained in the software and documentation are those of the
  27. // authors and should not be interpreted as representing official policies, either expressed
  28. // or implied, of GAMADU.COM.
  29. // </copyright>
  30. // <summary>
  31. // The lines.
  32. // </summary>
  33. // --------------------------------------------------------------------------------------------------------------------
  34. #endregion File description
  35. namespace StarWarrior.Primitives
  36. {
  37. #region Using statements
  38. using System.Collections.Generic;
  39. using Microsoft.Xna.Framework;
  40. using Microsoft.Xna.Framework.Graphics;
  41. #endregion
  42. /// <summary>The lines.</summary>
  43. public class Lines
  44. {
  45. /// <summary>The batch.</summary>
  46. private readonly PrimitiveBatch batch;
  47. /// <summary>The lines.</summary>
  48. private readonly List<Vector2> lines;
  49. /// <summary>Initializes a new instance of the <see cref="Lines" /> class.</summary>
  50. /// <param name="primitiveBatch">The primitive batch.</param>
  51. public Lines(PrimitiveBatch primitiveBatch)
  52. {
  53. this.Color = Color.White;
  54. this.lines = new List<Vector2>();
  55. this.batch = primitiveBatch;
  56. }
  57. /// <summary>Gets or sets the color.</summary>
  58. /// <value>The color.</value>
  59. private Color Color { get; set; }
  60. /// <summary>The add line.</summary>
  61. /// <param name="x1">The x 1.</param>
  62. /// <param name="y1">The y 1.</param>
  63. /// <param name="x2">The x 2.</param>
  64. /// <param name="y2">The y 2.</param>
  65. public void AddLine(float x1, float y1, float x2, float y2)
  66. {
  67. this.lines.Add(new Vector2(x1, y1));
  68. this.lines.Add(new Vector2(x2, y2));
  69. }
  70. /// <summary>The draw.</summary>
  71. /// <param name="position">The position.</param>
  72. public void Draw(Vector2 position)
  73. {
  74. this.batch.Begin(PrimitiveType.LineList);
  75. foreach (Vector2 item in this.lines)
  76. {
  77. this.batch.AddVertex(item + position, this.Color);
  78. }
  79. this.batch.End();
  80. }
  81. }
  82. }