From 6179567170b51af2cfa2ebd5bfeabe6fd8d23dff Mon Sep 17 00:00:00 2001 From: Alek-ban Date: Mon, 9 Feb 2026 12:51:18 +0300 Subject: [PATCH] fix: OpenCvImage render clipping --- GSS2.UI.Core/OpenCvImage.cs | 39 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/GSS2.UI.Core/OpenCvImage.cs b/GSS2.UI.Core/OpenCvImage.cs index 1403998..b94bc9e 100644 --- a/GSS2.UI.Core/OpenCvImage.cs +++ b/GSS2.UI.Core/OpenCvImage.cs @@ -259,25 +259,32 @@ public class OpenCvImage : Control public override void Render(DrawingContext context) { - context.FillRectangle(new SolidColorBrush(Background), new Rect(0, 0, Bounds.Width, Bounds.Height)); - if (_bitmap is null) + using (context.PushClip(new Rect(Bounds.Size))) { - base.Render(context); - return; + context.FillRectangle(new SolidColorBrush(Background), new Rect(0, 0, Bounds.Width, Bounds.Height)); + if (_bitmap is null) + { + base.Render(context); + return; + } + + var (sx, sy) = ComputeStretchScale(StretchMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height); + sx *= _zoom; + sy *= _zoom; + + var drawWidth = _bitmap.PixelSize.Width * sx; + var drawHeight = _bitmap.PixelSize.Height * sy; + var destRect = new Rect( + (Bounds.Width - drawWidth) / 2 + _panX, + (Bounds.Height - drawHeight) / 2 + _panY, + drawWidth, drawHeight + ); + + var srcRect = ComputeSourceRect(TileMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height); + + context.DrawImage(_bitmap, srcRect, destRect); } - var (sx, sy) = ComputeStretchScale(StretchMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height); - sx *= _zoom; - sy *= _zoom; - - var drawWidth = _bitmap.PixelSize.Width * sx; - var drawHeight = _bitmap.PixelSize.Height * sy; - var destRect = new Rect((Bounds.Width - drawWidth) / 2 + _panX, (Bounds.Height - drawHeight) / 2 + _panY, drawWidth, drawHeight); - - var srcRect = ComputeSourceRect(TileMode, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height); - - context.DrawImage(_bitmap, srcRect, destRect); - base.Render(context); }