Skip to content

Commit

Permalink
added line
Browse files Browse the repository at this point in the history
  • Loading branch information
baetz-daniel committed Nov 13, 2020
1 parent b20f8fd commit 173f7d0
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 6 deletions.
73 changes: 71 additions & 2 deletions src/Exomia.Framework/Graphics/SpriteBatch.Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#endregion

using System;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using Exomia.Framework.Mathematics;
using SharpDX;

namespace Exomia.Framework.Graphics
Expand All @@ -28,6 +30,7 @@ public sealed partial class SpriteBatch
/// <param name="rotation"> The rotation. </param>
/// <param name="opacity"> The opacity. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawRectangle(in RectangleF destinationRectangle,
in Color color,
float lineWidth,
Expand Down Expand Up @@ -108,6 +111,7 @@ public void DrawRectangle(in RectangleF destinationRectangle,
/// <param name="destinationRectangle"> Destination rectangle. </param>
/// <param name="color"> The color. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color, float layerDepth)
{
DrawSprite(
Expand All @@ -122,6 +126,7 @@ public void DrawFillRectangle(in RectangleF destinationRectangle, in Color color
/// <param name="color"> The color. </param>
/// <param name="opacity"> The opacity. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawFillRectangle(in RectangleF destinationRectangle,
in Color color,
float opacity,
Expand All @@ -141,6 +146,7 @@ public void DrawFillRectangle(in RectangleF destinationRectangle,
/// <param name="origin"> The origin. </param>
/// <param name="opacity"> The opacity. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawFillRectangle(in RectangleF destinationRectangle,
in Color color,
float rotation,
Expand All @@ -162,6 +168,7 @@ public void DrawFillRectangle(in RectangleF destinationRectangle,
/// <param name="lineWidth"> Width of the line. </param>
/// <param name="opacity"> The opacity. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawLine(in Vector2 point1,
in Vector2 point2,
in Color color,
Expand All @@ -172,6 +179,24 @@ public void DrawLine(in Vector2 point1,
DrawLine(point1, point2, color, lineWidth, opacity, 1.0f, layerDepth);
}

/// <summary>
/// Draw line.
/// </summary>
/// <param name="line"> The line. </param>
/// <param name="color"> The color. </param>
/// <param name="lineWidth"> Width of the line. </param>
/// <param name="opacity"> The opacity. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawLine(in Line2 line,
in Color color,
float lineWidth,
float opacity,
float layerDepth)
{
DrawLine(in line, color, lineWidth, opacity, 1.0f, layerDepth);
}

/// <summary>
/// Draw line.
/// </summary>
Expand All @@ -182,6 +207,7 @@ public void DrawLine(in Vector2 point1,
/// <param name="opacity"> The opacity. </param>
/// <param name="lengthFactor"> The length factor. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawLine(in Vector2 point1,
in Vector2 point2,
in Color color,
Expand All @@ -190,10 +216,32 @@ public void DrawLine(in Vector2 point1,
float lengthFactor,
float layerDepth)
{
DrawLine(new Line2(point1, point2), color, lineWidth, opacity, lengthFactor, layerDepth);
}

/// <summary>
/// Draw line.
/// </summary>
/// <param name="line"> The line. </param>
/// <param name="color"> The color. </param>
/// <param name="lineWidth"> Width of the line. </param>
/// <param name="opacity"> The opacity. </param>
/// <param name="lengthFactor"> The length factor. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawLine(in Line2 line,
in Color color,
float lineWidth,
float opacity,
float lengthFactor,
float layerDepth)
{
float dx = line.X2 - line.X1;
float dy = line.Y2 - line.Y1;
DrawSprite(
_whiteTexture, new RectangleF(
point1.X, point1.Y, Vector2.Distance(point1, point2) * lengthFactor, lineWidth), false,
s_nullRectangle, color, (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X),
line.X1, line.Y1, (float)Math.Sqrt((dx * dx) + (dy * dy)) * lengthFactor, lineWidth), false,
s_nullRectangle, color, (float)Math.Atan2(dy, dx),
s_vector2Zero, opacity, SpriteEffects.None, layerDepth);
}

Expand Down Expand Up @@ -228,6 +276,7 @@ public void DrawPolygon(Vector2[] vertex, in Color color, float lineWidth, float
/// <param name="opacity"> The opacity. </param>
/// <param name="segments"> The segments. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawCircle(in Vector2 center,
float radius,
in Color color,
Expand Down Expand Up @@ -286,6 +335,7 @@ public void DrawCircle(in Vector2 center,
/// <param name="texture"> The texture. </param>
/// <param name="position"> The position. </param>
/// <param name="color"> The color. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture, in Vector2 position, in Color color)
{
DrawSprite(
Expand All @@ -299,6 +349,7 @@ public void Draw(Texture texture, in Vector2 position, in Color color)
/// <param name="texture"> The texture. </param>
/// <param name="destinationRectangle"> Destination rectangle. </param>
/// <param name="color"> The color. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture, in RectangleF destinationRectangle, in Color color)
{
DrawSprite(
Expand All @@ -313,6 +364,7 @@ public void Draw(Texture texture, in RectangleF destinationRectangle, in Color c
/// <param name="position"> The position. </param>
/// <param name="sourceRectangle"> Source rectangle. </param>
/// <param name="color"> The color. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture, in Vector2 position, in Rectangle? sourceRectangle, in Color color)
{
DrawSprite(
Expand All @@ -327,6 +379,7 @@ public void Draw(Texture texture, in Vector2 position, in Rectangle? sourceRecta
/// <param name="destinationRectangle"> Destination rectangle. </param>
/// <param name="sourceRectangle"> Source rectangle. </param>
/// <param name="color"> The color. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture,
in RectangleF destinationRectangle,
in Rectangle? sourceRectangle,
Expand All @@ -346,6 +399,7 @@ public void Draw(Texture texture,
/// <param name="rotation"> The rotation. </param>
/// <param name="origin"> The origin. </param>
/// <param name="layerDepth"> (Optional) Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture,
in Vector2 position,
in Color color,
Expand All @@ -367,6 +421,7 @@ public void Draw(Texture texture,
/// <param name="rotation"> The rotation. </param>
/// <param name="origin"> The origin. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture,
in RectangleF destinationRectangle,
in Color color,
Expand All @@ -391,6 +446,7 @@ public void Draw(Texture texture,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture,
in RectangleF destinationRectangle,
in Rectangle? sourceRectangle,
Expand Down Expand Up @@ -419,6 +475,7 @@ public void Draw(Texture texture,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture,
in Vector2 position,
in Rectangle? sourceRectangle,
Expand Down Expand Up @@ -448,6 +505,7 @@ public void Draw(Texture texture,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Draw(Texture texture,
in Vector2 position,
in Rectangle? sourceRectangle,
Expand Down Expand Up @@ -601,6 +659,7 @@ private unsafe void DrawSprite(Texture texture,
/// <param name="position"> The position. </param>
/// <param name="color"> The color. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font, string text, in Vector2 position, in Color color, float layerDepth)
{
font.Draw(
Expand All @@ -617,6 +676,7 @@ public void DrawText(SpriteFont font, string text, in Vector2 position, in Color
/// <param name="color"> The color. </param>
/// <param name="rotation"> The rotation. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
string text,
in Vector2 position,
Expand All @@ -641,6 +701,7 @@ public void DrawText(SpriteFont font,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
string text,
in Vector2 position,
Expand Down Expand Up @@ -670,6 +731,7 @@ public void DrawText(SpriteFont font,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
string text,
int start,
Expand Down Expand Up @@ -702,6 +764,7 @@ public void DrawText(SpriteFont font,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
string text,
int start,
Expand All @@ -728,6 +791,7 @@ public void DrawText(SpriteFont font,
/// <param name="position"> The position. </param>
/// <param name="color"> The color. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, in Color color, float layerDepth)
{
font.Draw(
Expand All @@ -744,6 +808,7 @@ public void DrawText(SpriteFont font, StringBuilder text, in Vector2 position, i
/// <param name="color"> The color. </param>
/// <param name="rotation"> The rotation. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
StringBuilder text,
in Vector2 position,
Expand All @@ -768,6 +833,7 @@ public void DrawText(SpriteFont font,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
StringBuilder text,
in Vector2 position,
Expand Down Expand Up @@ -797,6 +863,7 @@ public void DrawText(SpriteFont font,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
StringBuilder text,
int start,
Expand Down Expand Up @@ -829,6 +896,7 @@ public void DrawText(SpriteFont font,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void DrawText(SpriteFont font,
StringBuilder text,
int start,
Expand Down Expand Up @@ -860,6 +928,7 @@ public void DrawText(SpriteFont font,
/// <param name="opacity"> The opacity. </param>
/// <param name="effects"> The effects. </param>
/// <param name="layerDepth"> Depth of the layer. </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void DrawTextInternal(Texture texture,
in Vector2 position,
in Rectangle? sourceRectangle,
Expand Down
Loading

0 comments on commit 173f7d0

Please sign in to comment.