Web source: container == content — element grid + selection box sized to the cropped frame's canvas extent
- FindContentBounds already trimmed the bitmap; the grid/box still rendered at the uncropped user size, so Fill stretched the tight widget into a bigger frame = dead-between-content-and-border. - ContentCanvasSize maps the crop rect to canvas units (1920/pixW per axis, DPI-correct) and the preview event now carries (bitmap, canvasW, canvasH). - OnWebView2PreviewBitmapChanged sets the element Width/Height to that size; the grid and the SelectionOverlay (both bound to the element's Width/Height) now equal the widget exactly. - IsPreviewDragging (set in MainWindow drag/resize) suppresses auto-fit mid-gesture. - Tests 10/10 (alpha bounds, canvas-size mapping incl. DPI, control size); 0 warnings.
This commit is contained in:
@@ -2290,6 +2290,11 @@ public class MainViewModel : ViewModelBase
|
||||
_ = RedesignateBackgroundAsync($"{MonitorKeyPrefix}{display.Index}");
|
||||
}
|
||||
|
||||
// True while the user is dragging/resizing an element on the preview canvas
|
||||
// (set by MainWindow code-behind). Suppresses the web source's auto-fit so it
|
||||
// doesn't fight the gesture mid-drag.
|
||||
public bool IsPreviewDragging { get; set; }
|
||||
|
||||
public void InitWebView2(Panel hostPanel)
|
||||
{
|
||||
_webView2Manager = new WebView2Manager(hostPanel, System.Windows.Application.Current.Dispatcher);
|
||||
@@ -2297,11 +2302,26 @@ public class MainViewModel : ViewModelBase
|
||||
RegisterLoadedWebSources();
|
||||
}
|
||||
|
||||
private void OnWebView2PreviewBitmapChanged(string sourceId, WriteableBitmap bitmap)
|
||||
private void OnWebView2PreviewBitmapChanged(string sourceId, WriteableBitmap bitmap, double canvasW, double canvasH)
|
||||
{
|
||||
foreach (var scene in Scenes)
|
||||
foreach (var el in scene.Elements.OfType<Source>().Where(s => s.Id == sourceId))
|
||||
{
|
||||
el.VideoImageSource = bitmap;
|
||||
|
||||
// The container must equal the content: size the element grid
|
||||
// (and therefore the selection box) to the cropped frame's canvas
|
||||
// extent. Skipped while the user is dragging/resizing the element
|
||||
// so the gesture isn't fought mid-drag.
|
||||
if (IsPreviewDragging || canvasW < 1 || canvasH < 1) continue;
|
||||
var w = Math.Clamp(Math.Round(canvasW), 1, 1920);
|
||||
var h = Math.Clamp(Math.Round(canvasH), 1, 1080);
|
||||
if (Math.Abs(el.Width - w) > 1 || Math.Abs(el.Height - h) > 1)
|
||||
{
|
||||
el.Width = w;
|
||||
el.Height = h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
|
||||
Reference in New Issue
Block a user