Skip to content

Commit e568305

Browse files
Fix more edge cases with new hw accelerated GuiApi
fixes #4040 fixes #4041
1 parent 2c63ef4 commit e568305

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs

+20-9
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ public void DrawRectangle(Color color, int x, int y, int width, int height)
425425
var right = x + width - 1;
426426
var bottom = y + height - 1;
427427

428+
if (width == 1 || height == 1)
429+
{
430+
// width or height of 1 is just a single line
431+
DrawLine(color, x, y, right, bottom);
432+
return;
433+
}
434+
428435
// top left to top right
429436
DrawLine(color, x, y, right, y);
430437
// top right (and 1 pixel down) to bottom right
@@ -517,29 +524,33 @@ public void DrawLine(Color color, int x1, int y1, int x2, int y2)
517524
var p1 = new Vector2(x1, y1);
518525
var p2 = new Vector2(x2, y2);
519526

527+
// imgui seems to have behavior which necessitate the rightmost and bottommost ends be extended to correctly draw the line (some subpixel jitter?)
528+
520529
if (p1.X > p2.X)
521530
{
522-
p1.X += 0.5f;
531+
// right to left drawing, extend the beginning by 1 pixel rightwards
532+
p1.X++;
523533
}
524534
else
525535
{
526-
p2.X += 0.5f;
536+
// left to right drawing, extend the end by 1 pixel rightwards
537+
p2.X++;
527538
}
528539

529540
if (p1.Y > p2.Y)
530541
{
531-
p1.Y += 0.5f;
542+
// down to up drawing, extend the beginning by 1 pixel downwards
543+
p1.Y++;
532544
}
533545
else
534546
{
535-
p2.Y += 0.5f;
547+
// up to down drawing, extend the end by 1 pixel downwards
548+
p2.Y++;
536549
}
537550

538-
_imGuiDrawList.AddLine(
539-
p1: p1,
540-
p2: p2,
541-
col: (uint)color.ToArgb(),
542-
thickness: RenderThickness);
551+
_imGuiDrawList.PathLineTo(p1);
552+
_imGuiDrawList.PathLineTo(p2);
553+
_imGuiDrawList.PathStroke((uint)color.ToArgb(), 0, RenderThickness);
543554
}
544555

545556
public void DrawPie(Color color, int x, int y, int width, int height, int startAngle, int sweepAngle)

src/BizHawk.Client.Common/Api/Classes/GuiApi.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ public void DrawPolygon(Point[] points, Color? line = null, Color? background =
387387
public void DrawRectangle(int x, int y, int width, int height, Color? line = null, Color? background = null, DisplaySurfaceID? surfaceID = null)
388388
{
389389
var r = Get2DRenderer(surfaceID);
390-
var w = Math.Max(width, 1);
391-
var h = Math.Max(height, 1);
390+
var w = Math.Max(width, 0);
391+
var h = Math.Max(height, 0);
392392
// GDI+ had an off by one here, we increment width and height to preserve backwards compatibility
393393
w++; h++;
394394
r.DrawRectangle(line ?? _defaultForeground, x, y, w, h);

0 commit comments

Comments
 (0)