Skip to content

Commit

Permalink
Move reticle drawing near other draw methods
Browse files Browse the repository at this point in the history
Trying to actually refactor it turns into an unwieldy (and non-performant) mess, but reorganizing it at least is helpful to keep my thoughts straight.
  • Loading branch information
ItEndsWithTens committed Jun 12, 2024
1 parent 9775fb4 commit 3c6e1f9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
44 changes: 0 additions & 44 deletions src/SHME.ExternalTool/UI/CustomMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,48 +219,6 @@ public override void Restart()
}
}

public static void DrawReticleBitmap(Graphics g, Pen pen, int width, int height, float percent)
{
pen.Color = Color.White;

g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.PixelOffsetMode = PixelOffsetMode.None;
g.SmoothingMode = SmoothingMode.Default;

g.DrawRectangle(pen, 0, 0, width - 1, height - 1);

int size = (int)Math.Round(height * (percent / 100.0f));
int centerW = width / 2;
int centerH = height / 2;

g.DrawLine(pen, 0, centerH, size, centerH);
g.DrawLine(pen, centerW - size / 2, centerH, centerW + size / 2, centerH);
g.DrawLine(pen, width - 1 - size, centerH, width - 1, centerH);

g.DrawLine(pen, centerW, 0, centerW, size);
g.DrawLine(pen, centerW, centerH - size / 2, centerW, centerH + size / 2);
g.DrawLine(pen, centerW, height - 1 - size, centerW, height - 1);
}
public void DrawReticleGui(Color color, int width, int height, float percent)
{
int left = Guts.RenderPort.Left;
int top = Guts.RenderPort.Top;

int size = (int)Math.Round(height * (percent / 100.0f));
int centerW = left + width / 2;
int centerH = top + height / 2;

Gui.DrawRectangle(left, top, width - 1, height - 1);

Gui.DrawLine(left, centerH, left + size, centerH);
Gui.DrawLine(centerW - size / 2, centerH, centerW + size / 2, centerH);
Gui.DrawLine(left + (width - 1 - size), centerH, left + (width - 1), centerH);

Gui.DrawLine(centerW, top, centerW, top + size);
Gui.DrawLine(centerW, centerH - size / 2, centerW, centerH + size / 2);
Gui.DrawLine(centerW, top + (height - 1 - size), centerW, top + (height - 1));
}

public override void UpdateValues(ToolFormUpdateType type)
{
if (Game.IsNullInstance())
Expand Down Expand Up @@ -509,7 +467,6 @@ private void DrawOverlayBitmap()
DrawGameObjects(g, ref matrix, Point.Empty);
DrawReticleBitmap(
g,
Pen,
Guts.RenderPort.Width,
Guts.RenderPort.Height,
(float)NudCrosshairLength.Value);
Expand All @@ -533,7 +490,6 @@ private void DrawOverlayGui()

DrawGameObjects(Gui, ref matrix, Guts.RenderPort.TopLeft);
DrawReticleGui(
Pen.Color,
Guts.RenderPort.Width,
Guts.RenderPort.Height,
(float)NudCrosshairLength.Value);
Expand Down
44 changes: 44 additions & 0 deletions src/SHME.ExternalTool/UI/Draw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SHME.ExternalTool.Graphics;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace BizHawk.Client.EmuHawk;

Expand Down Expand Up @@ -128,4 +129,47 @@ private void DrawFaceWireframe(object api, int argb)
}
}
}

private void DrawReticleBitmap(Graphics g, int width, int height, float percent)
{
int size = (int)Math.Round(height * (percent / 100.0f));
int centerW = width / 2;
int centerH = height / 2;

Pen.Color = Color.White;
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.PixelOffsetMode = PixelOffsetMode.None;
g.SmoothingMode = SmoothingMode.Default;

g.DrawRectangle(Pen, 0, 0, width - 1, height - 1);

g.DrawLine(Pen, 0, centerH, size, centerH);
g.DrawLine(Pen, centerW - size / 2, centerH, centerW + size / 2, centerH);
g.DrawLine(Pen, width - 1 - size, centerH, width - 1, centerH);

g.DrawLine(Pen, centerW, 0, centerW, size);
g.DrawLine(Pen, centerW, centerH - size / 2, centerW, centerH + size / 2);
g.DrawLine(Pen, centerW, height - 1 - size, centerW, height - 1);
}
private void DrawReticleGui(int width, int height, float percent)
{
int left = Guts.RenderPort.Left;
int top = Guts.RenderPort.Top;

int size = (int)Math.Round(height * (percent / 100.0f));
int centerW = left + width / 2;
int centerH = top + height / 2;

var color = Color.White;

Gui.DrawRectangle(left, top, width - 1, height - 1, color);

Gui.DrawLine(left, centerH, left + size, centerH, color);
Gui.DrawLine(centerW - size / 2, centerH, centerW + size / 2, centerH, color);
Gui.DrawLine(left + (width - 1 - size), centerH, left + (width - 1), centerH, color);

Gui.DrawLine(centerW, top, centerW, top + size, color);
Gui.DrawLine(centerW, centerH - size / 2, centerW, centerH + size / 2, color);
Gui.DrawLine(centerW, top + (height - 1 - size), centerW, top + (height - 1), color);
}
}

0 comments on commit 3c6e1f9

Please sign in to comment.