SuRGeoNix / Flyleaf

Media Player .NET Library for WinUI 3/ WPF/WinForms (based on FFmpeg/DirectX)
GNU Lesser General Public License v3.0
687 stars 92 forks source link

Overlaps and Refresh in SharedOverlay #446

Closed eliacanavera1111 closed 3 months ago

eliacanavera1111 commented 3 months ago

Hi @SuRGeoNix! I'm using what you suggested and it's working great:

<!--Just a FlyleafSharedOverlay with two canvases-->
<UserControl x:Class="Streaming_Manager.MosaicControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:fl="clr-namespace:FlyleafLib.Controls.WPF;assembly=FlyleafLib">
    <fl:FlyleafSharedOverlay Name="main_host">
        <fl:FlyleafSharedOverlay.DetachedContent>
            <Canvas x:Name="detached_canvas" Background="Black" AllowDrop="True">
                <!--here the flyleafhosts, for background overlappable videos-->
            </Canvas>
        </fl:FlyleafSharedOverlay.DetachedContent>
        <Canvas Name="MosaicCanvas" Background="Transparent" Panel.ZIndex="0">
            <!--here other usercontrols, for text overlays on the videos-->
        </Canvas>
    </fl:FlyleafSharedOverlay>
</UserControl>

Now, since i need to change the z-index visibility of overlapped flyleafhosts inside the "detached_canvas" but there is no z-index property for them so they overlap in the order they're added on the canvas, I'm editing their canvas.Children[index]:

/// This method is to increase the detached_canvas.flyleafhost[index] by 1
private void AddZIndex(object sender, MouseButtonEventArgs e)
{
    if ((sender as UserControl).Parent is Canvas canvas)
    {
        int index = canvas.Children.IndexOf(sender as UserControl);
        if (index < canvas.Children.Count - 1)
        {
            canvas.Children.RemoveAt(index);
            canvas.Children.Insert(index + 1, sender as UserControl);
            // HERE need to refresh the visual of something
        }
    }
}

If in the detached_canvas i AddZIndex() a flyleafhost under another one, it goes up logically so the index changes, but visually they remain in the same order. While if is not a flyleafhost but other usercontrol, no problems doing so with the same logic.

So I tried clearing the detached_canvas and populate it again with the new order and it works:

detached_canvas.Children.Clear();
foreach (...flyleafhosts) { detached_canvas.Children.Add(...in_the_new_order) }

image

But clearing and repopulating the canvas with all the videos at every edit of an index it's very slow, so my question is: Is there something (like an existing method to call on flyleafhost or the sharedoverlay) to refresh the render of the hosts so that they notice their index changed without having to clear and repopulate the canvas? Thanks in advance.

Originally posted by @eliacanavera1111 in https://github.com/SuRGeoNix/Flyleaf/issues/414#issuecomment-1980603041