Skip to content

Commit 0126c97

Browse files
committed
Fix AllocateBackBuffer to only add padding for sub-pixel offsets
Expand the back buffer by +1 pixel only when a fractional screen offset would cause content to overflow, rather than always adding padding. This preserves correct border rendering at integer positions. Made-with: Cursor
1 parent 3b82878 commit 0126c97

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

Gui/GUIWidget.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,15 @@ public virtual void OnContainsFocusChanged(FocusChangedArgs e)
814814
}
815815

816816
private void AllocateBackBuffer()
817+
{
818+
AllocateBackBuffer(0, 0);
819+
}
820+
821+
private void AllocateBackBuffer(int extraWidth, int extraHeight)
817822
{
818823
RectangleDouble localBounds = LocalBounds;
819-
// +1 accounts for sub-pixel offsets when compositing at fractional screen positions
820-
int intWidth = Max((int)(Ceiling(localBounds.Right) - Floor(localBounds.Left)) + 1, 1);
821-
int intHeight = Max((int)(Ceiling(localBounds.Top) - Floor(localBounds.Bottom)) + 1, 1);
824+
int intWidth = Max((int)(Ceiling(localBounds.Right) - Floor(localBounds.Left)) + extraWidth, 1);
825+
int intHeight = Max((int)(Ceiling(localBounds.Top) - Floor(localBounds.Bottom)) + extraHeight, 1);
822826
if (backBuffer == null || backBuffer.Width != intWidth || backBuffer.Height != intHeight)
823827
{
824828
backBuffer = new ImageBuffer(intWidth, intHeight, 32, new BlenderPreMultBGRA());
@@ -2130,6 +2134,13 @@ public virtual void OnDraw(Graphics2D graphics2D)
21302134
int yOffset = (int)Floor(child.LocalBounds.Bottom);
21312135
if (child.isCurrentlyInvalid)
21322136
{
2137+
int extraW = xFraction > 0 ? 1 : 0;
2138+
int extraH = yFraction > 0 ? 1 : 0;
2139+
if (extraW > 0 || extraH > 0)
2140+
{
2141+
child.AllocateBackBuffer(extraW, extraH);
2142+
}
2143+
21332144
Graphics2D childBackBufferGraphics2D = child.backBuffer.NewGraphics2D();
21342145
childBackBufferGraphics2D.Clear(new Color(0, 0, 0, 0));
21352146
var transformToBuffer = Affine.NewTranslation(-xOffset + xFraction, -yOffset + yFraction);

0 commit comments

Comments
 (0)