Skip to content

Commit

Permalink
[Editor API] - Added animate to marching ants interface to allow for …
Browse files Browse the repository at this point in the history
…multiple calls to the draw without messing up the animation timing.
  • Loading branch information
Tape-Worm committed Mar 19, 2022
1 parent 4f94779 commit 930386b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ protected override void DrawTexture()
{
Renderer.DrawRectangle(_cubeScreenBounds[i], new GorgonColor(GorgonColor.Black, Opacity * 0.88f), 1);
}


_selectionRect.Animate();
_selectionRect.Draw(_cubeScreenBounds[selectedImage]);

var offset = new Vector2(0, "+X".MeasureLine(_axisFont, true).Height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ protected override void DrawSprite()
Renderer.DrawEllipse(new DX.RectangleF(transformedAnchor.X - 4, transformedAnchor.Y - 4, 8, 8), GorgonColor.Black);
Renderer.DrawEllipse(new DX.RectangleF(transformedAnchor.X - 3, transformedAnchor.Y - 3, 6, 6), GorgonColor.White);

_marchAnts.Animate();
_marchAnts.Draw(marchAntsRect);
Renderer.End();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ protected override void DrawSprite()

// Draw in client space.
Renderer.Begin();
_marchAnts.Animate();
_marchAnts.Draw(marchAntsRect);
Renderer.End();
}
Expand Down
19 changes: 11 additions & 8 deletions Tools/Editor/Gorgon.Editor.API/Rendering/MarchingAnts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,27 @@ public void Dispose()
}

/// <summary>
/// Function to draw the marching ants rectangle.
/// Function to animate the marching ants.
/// </summary>
/// <param name="rect">The rectangular region to draw in.</param>
public void Draw(DX.RectangleF rect)
public void Animate()
{
_step += _marchAntsTexture.Value.Width * (GorgonTiming.Delta * 0.4f);

if (_step > _marchAntsTexture.Value.Width)
{
_step -= _marchAntsTexture.Value.Width;
}

_renderer.DrawRectangle(rect, GorgonColor.White,
texture: _marchAntsTexture.Value,
textureRegion: _marchAntsTexture.Value.ToTexel(new DX.Rectangle((int)-_step, 0, (int)rect.Width, (int)rect.Height)),
textureSampler: GorgonSamplerState.PointFilteringWrapping);
}

/// <summary>
/// Function to draw the marching ants rectangle.
/// </summary>
/// <param name="rect">The rectangular region to draw in.</param>
public void Draw(DX.RectangleF rect) => _renderer.DrawRectangle(rect, GorgonColor.White,
texture: _marchAntsTexture.Value,
textureRegion: _marchAntsTexture.Value.ToTexel(new DX.Rectangle((int)-_step, 0, (int)rect.Width, (int)rect.Height)),
textureSampler: GorgonSamplerState.PointFilteringWrapping);

/// <summary>
/// Function to build an instance of the marching ants texture.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace Gorgon.Editor.Rendering
public interface IMarchingAnts
: IDisposable
{
/// <summary>
/// Function to animate the marching ants.
/// </summary>
void Animate();

/// <summary>
/// Function to draw the marching ants rectangle.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ public void Render()

GetActiveHandle();

_marchingAnts.Animate();
_marchingAnts.Draw(_screenRect);

for (int i = 0; i < _handles.Length; ++i)
Expand Down

0 comments on commit 930386b

Please sign in to comment.