simplify drawRectangle

This commit is contained in:
CasualPokePlayer 2024-05-25 17:42:27 -07:00
parent efee5f0cb3
commit cb901b3aff
2 changed files with 13 additions and 23 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Numerics;
namespace BizHawk.Bizware.Graphics namespace BizHawk.Bizware.Graphics
{ {

View File

@ -358,31 +358,20 @@ namespace BizHawk.Bizware.Graphics
{ {
// we don't use AddRect as we want to avoid double drawing at the corners // we don't use AddRect as we want to avoid double drawing at the corners
// as that produces artifacts with alpha blending // as that produces artifacts with alpha blending
var col = (uint)color.ToArgb();
// keep in mind width/height include the beginning pixel
// e.g. a 1x1 rect has the same coordinate for all corners, so you don't + 1, you + 1 - 1
var right = x + width - 1;
var bottom = y + height - 1;
// top left to top right // top left to top right
_imGuiDrawList.AddLine( DrawLine(color, x, y, right, y);
p1: new(x, y),
p2: new(x + width, y),
col: col,
thickness: RenderThickness);
// top right (and 1 pixel down) to bottom right // top right (and 1 pixel down) to bottom right
_imGuiDrawList.AddLine( DrawLine(color, right, y + 1, right, bottom);
p1: new(x + width - 0.5f, y + 1),
p2: new(x + width - 0.5f, y + height),
col: col,
thickness: RenderThickness);
// bottom right (and 1 pixel left) to bottom left // bottom right (and 1 pixel left) to bottom left
_imGuiDrawList.AddLine( DrawLine(color, right - 1, bottom, x, bottom);
p1: new(x + width - 1.5f, y + height - 0.5f),
p2: new(x, y + height - 0.5f),
col: col,
thickness: RenderThickness);
// bottom left (and 1 pixel up) to top left (and 1 pixel down) // bottom left (and 1 pixel up) to top left (and 1 pixel down)
_imGuiDrawList.AddLine( DrawLine(color, x, bottom - 1, x, y + 1);
p1: new(x, y + height - 1.5f),
p2: new(x, y + 1),
col: col,
thickness: RenderThickness);
} }
public void FillRectangle(Color color, int x, int y, int width, int height) public void FillRectangle(Color color, int x, int y, int width, int height)
@ -449,7 +438,7 @@ namespace BizHawk.Bizware.Graphics
{ {
p1.X += 0.5f; p1.X += 0.5f;
} }
else if (p2.X > p1.X) else
{ {
p2.X += 0.5f; p2.X += 0.5f;
} }
@ -458,7 +447,7 @@ namespace BizHawk.Bizware.Graphics
{ {
p1.Y += 0.5f; p1.Y += 0.5f;
} }
else if (p2.Y > p1.Y) else
{ {
p2.Y += 0.5f; p2.Y += 0.5f;
} }