Skip to content

Commit 4b8cd59

Browse files
committed
fix aspect ratio positioning #2557
1 parent 952abf7 commit 4b8cd59

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

Intersect.Client.Core/Interface/Game/EventWindow.cs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ private EventWindow(Canvas gameCanvas, Dialog dialog) : base(gameCanvas, nameof(
8989
MaintainAspectRatio = true,
9090
Margin = new Margin(8, 8, 0, 8),
9191
MaximumSize = new Point(128, 128),
92+
RestrictToParent = true,
9293
};
9394

9495
_promptScroller = new ScrollControl(_promptPanel, nameof(_promptScroller))

Intersect.Client.Framework/Gwen/Control/ImagePanel.cs

+25-12
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ protected override void OnMouseClicked(MouseButton mouseButton, Point mousePosit
160160
);
161161
}
162162

163+
protected override void OnPositionChanged(Point oldPosition, Point newPosition)
164+
{
165+
base.OnPositionChanged(oldPosition, newPosition);
166+
}
167+
163168
/// <summary>
164169
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
165170
/// </summary>
@@ -404,34 +409,42 @@ public override bool SizeToChildren(bool resizeX = true, bool resizeY = true, bo
404409

405410
public override bool SetBounds(int x, int y, int width, int height)
406411
{
412+
var updatedX = x;
413+
var updatedY = y;
414+
var updatedWidth = width;
415+
var updatedHeight = height;
407416
if (MaintainAspectRatio)
408417
{
409418
var bounds = Bounds;
410419
var aspectRatio = _textureAspectRatio;
411-
if (width == bounds.Width)
420+
if (updatedWidth == bounds.Width)
412421
{
413-
if (height != bounds.Height)
422+
if (updatedHeight != bounds.Height)
414423
{
415-
var aspectRatioWidth = (int)(height * aspectRatio);
416-
if (aspectRatioWidth > width)
424+
var aspectRatioWidth = (int)(updatedHeight * aspectRatio);
425+
if (aspectRatioWidth > updatedWidth)
417426
{
418-
var deltaWidth = width - aspectRatioWidth;
419-
x += deltaWidth / 2;
420-
width = aspectRatioWidth;
427+
var deltaWidth = updatedWidth - aspectRatioWidth;
428+
updatedX += deltaWidth / 2;
429+
updatedWidth = aspectRatioWidth;
430+
if (RestrictToParent)
431+
{
432+
updatedX = Math.Max(0, updatedX);
433+
}
421434
}
422435
}
423436
}
424-
else if (height == bounds.Height)
437+
else if (updatedHeight == bounds.Height)
425438
{
426-
var aspectRatioHeight = (int)(width / aspectRatio);
427-
if (aspectRatioHeight > height)
439+
var aspectRatioHeight = (int)(updatedWidth / aspectRatio);
440+
if (aspectRatioHeight > updatedHeight)
428441
{
429-
height = aspectRatioHeight;
442+
updatedHeight = aspectRatioHeight;
430443
}
431444
}
432445
}
433446

434-
return base.SetBounds(x, y, width, height);
447+
return base.SetBounds(updatedX, updatedY, updatedWidth, updatedHeight);
435448
}
436449

437450
public override Point GetChildrenSize()

0 commit comments

Comments
 (0)