mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix image source apply issue
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ public class Unsafe
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用指针操作简化封送
|
/// 使用指针操作简化封送
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="lPARAM"></param>
|
/// <param name="lPARAM">lParam</param>
|
||||||
/// <param name="minWidth"></param>
|
/// <param name="minWidth">最小宽度</param>
|
||||||
/// <param name="minHeight"></param>
|
/// <param name="minHeight">最小高度</param>
|
||||||
public static unsafe void SetMinTrackSize(nint lPARAM, float minWidth, float minHeight)
|
public static unsafe void SetMinTrackSize(nint lPARAM, float minWidth, float minHeight)
|
||||||
{
|
{
|
||||||
MINMAXINFO* rect2 = (MINMAXINFO*)lPARAM;
|
MINMAXINFO* rect2 = (MINMAXINFO*)lPARAM;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingsUI", "SettingsUI\Se
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.SourceGeneration", "Snap.Hutao.SourceGeneration\Snap.Hutao.SourceGeneration.csproj", "{8B96721E-5604-47D2-9B72-06FEBAD0CE00}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.SourceGeneration", "Snap.Hutao.SourceGeneration\Snap.Hutao.SourceGeneration.csproj", "{8B96721E-5604-47D2-9B72-06FEBAD0CE00}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snap.Hutao.Win32", "Snap.Hutao.Win32\Snap.Hutao.Win32.csproj", "{29209B14-A6E1-442E-9287-2C65B03C96CD}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.Win32", "Snap.Hutao.Win32\Snap.Hutao.Win32.csproj", "{29209B14-A6E1-442E-9287-2C65B03C96CD}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -96,8 +96,8 @@ Global
|
|||||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|arm64.ActiveCfg = Release|Any CPU
|
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|arm64.ActiveCfg = Release|Any CPU
|
||||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|arm64.Build.0 = Release|Any CPU
|
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|arm64.Build.0 = Release|Any CPU
|
||||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x64.ActiveCfg = Release|Any CPU
|
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x64.ActiveCfg = Release|x64
|
||||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x64.Build.0 = Release|Any CPU
|
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x64.Build.0 = Release|x64
|
||||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x86.ActiveCfg = Release|Any CPU
|
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x86.Build.0 = Release|Any CPU
|
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
@@ -17,11 +17,17 @@ public class ContentDialogBehavior : BehaviorBase<FrameworkElement>
|
|||||||
protected override void OnAssociatedObjectLoaded()
|
protected override void OnAssociatedObjectLoaded()
|
||||||
{
|
{
|
||||||
DependencyObject parent = VisualTreeHelper.GetParent(AssociatedObject);
|
DependencyObject parent = VisualTreeHelper.GetParent(AssociatedObject);
|
||||||
DependencyObject child = VisualTreeHelper.GetChild(parent, 2);
|
|
||||||
Rectangle smokeLayerBackground = (Rectangle)child;
|
|
||||||
|
|
||||||
smokeLayerBackground.Margin = new Thickness(0);
|
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||||
smokeLayerBackground.RegisterPropertyChangedCallback(FrameworkElement.MarginProperty, OnMarginChanged);
|
{
|
||||||
|
DependencyObject current = VisualTreeHelper.GetChild(parent, i);
|
||||||
|
if (current is Rectangle { Name: "SmokeLayerBackground" } background)
|
||||||
|
{
|
||||||
|
background.ClearValue(FrameworkElement.MarginProperty);
|
||||||
|
background.RegisterPropertyChangedCallback(FrameworkElement.MarginProperty, OnMarginChanged);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnMarginChanged(DependencyObject sender, DependencyProperty property)
|
private static void OnMarginChanged(DependencyObject sender, DependencyProperty property)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Snap.Hutao.Core.Exception;
|
|||||||
using Snap.Hutao.Core.Threading;
|
using Snap.Hutao.Core.Threading;
|
||||||
using Snap.Hutao.Extension;
|
using Snap.Hutao.Extension;
|
||||||
using Snap.Hutao.Service.Abstraction;
|
using Snap.Hutao.Service.Abstraction;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Windows.Storage;
|
using Windows.Storage;
|
||||||
using Windows.Storage.Streams;
|
using Windows.Storage.Streams;
|
||||||
@@ -81,50 +82,52 @@ public abstract class CompositionImage : Microsoft.UI.Xaml.Controls.Control
|
|||||||
spriteVisual.Size = ActualSize;
|
spriteVisual.Size = ActualSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnApplyImageFailed(Exception exception)
|
private static void OnApplyImageFailed(Uri? uri, Exception exception)
|
||||||
{
|
{
|
||||||
Ioc.Default
|
IInfoBarService infoBarService = Ioc.Default.GetRequiredService<IInfoBarService>();
|
||||||
.GetRequiredService<IInfoBarService>()
|
|
||||||
.Error(exception, "应用合成图像时发生异常");
|
if (exception is HttpRequestException httpRequestException)
|
||||||
|
{
|
||||||
|
infoBarService.Warning($"GET {uri}\n{httpRequestException}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
infoBarService.Error(exception, $"应用 {nameof(CompositionImage)} 的源时发生异常");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
|
private static void OnSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs arg)
|
||||||
{
|
{
|
||||||
CompositionImage image = (CompositionImage)sender;
|
CompositionImage image = (CompositionImage)sender;
|
||||||
|
CancellationToken token = LoadingTokenSource.Register(image);
|
||||||
_ = TryGetImageUri(arg, out Uri? uri);
|
|
||||||
ILogger<CompositionImage> logger = Ioc.Default.GetRequiredService<ILogger<CompositionImage>>();
|
ILogger<CompositionImage> logger = Ioc.Default.GetRequiredService<ILogger<CompositionImage>>();
|
||||||
image.ApplyImageInternalAsync(uri, LoadingTokenSource.Register(image)).SafeForget(logger, OnApplyImageFailed);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TryGetImageUri(DependencyPropertyChangedEventArgs arg, [NotNullWhen(true)] out Uri? result)
|
// source is valid
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
if (arg.NewValue is Uri inner && !string.IsNullOrEmpty(inner.Host))
|
if (arg.NewValue is Uri inner && !string.IsNullOrEmpty(inner.Host))
|
||||||
{
|
{
|
||||||
// value is different from old one and not
|
// value is different from old one
|
||||||
if (inner != (arg.OldValue as Uri))
|
if (inner != (arg.OldValue as Uri))
|
||||||
{
|
{
|
||||||
result = inner;
|
image.ApplyImageInternalAsync(inner, token).SafeForget(logger, ex => OnApplyImageFailed(inner, ex));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return false;
|
{
|
||||||
|
// should hide
|
||||||
|
image.HideAsync(token).SafeForget(logger);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ApplyImageInternalAsync(Uri? uri, CancellationToken token)
|
private async Task ApplyImageInternalAsync(Uri? uri, CancellationToken token)
|
||||||
{
|
{
|
||||||
await AnimationBuilder.Create().Opacity(0d).StartAsync(this, token);
|
await HideAsync(token);
|
||||||
|
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
StorageFile storageFile = await imageCache.GetFileFromCacheAsync(uri);
|
StorageFile storageFile = await imageCache.GetFileFromCacheAsync(uri);
|
||||||
|
|
||||||
Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
|
Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
|
||||||
|
|
||||||
LoadedImageSurface? imageSurface = null;
|
LoadedImageSurface? imageSurface = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
imageSurface = await LoadImageSurfaceAsync(storageFile, token);
|
imageSurface = await LoadImageSurfaceAsync(storageFile, token);
|
||||||
@@ -141,12 +144,21 @@ public abstract class CompositionImage : Microsoft.UI.Xaml.Controls.Control
|
|||||||
OnUpdateVisual(spriteVisual);
|
OnUpdateVisual(spriteVisual);
|
||||||
|
|
||||||
ElementCompositionPreview.SetElementChildVisual(this, spriteVisual);
|
ElementCompositionPreview.SetElementChildVisual(this, spriteVisual);
|
||||||
|
await ShowAsync(token);
|
||||||
await AnimationBuilder.Create().Opacity(1d).StartAsync(this, token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task ShowAsync(CancellationToken token)
|
||||||
|
{
|
||||||
|
return AnimationBuilder.Create().Opacity(1d).StartAsync(this, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task HideAsync(CancellationToken token)
|
||||||
|
{
|
||||||
|
return AnimationBuilder.Create().Opacity(0d).StartAsync(this, token);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
|
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.NewSize != e.PreviousSize && spriteVisual != null)
|
if (e.NewSize != e.PreviousSize && spriteVisual != null)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ internal class ConcurrentCancellationTokenSource<TItem>
|
|||||||
private readonly ConcurrentDictionary<TItem, CancellationTokenSource> waitingItems = new();
|
private readonly ConcurrentDictionary<TItem, CancellationTokenSource> waitingItems = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 未某个项注册取消令牌
|
/// 为某个项注册取消令牌
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">项</param>
|
/// <param name="item">项</param>
|
||||||
/// <returns>取消令牌</returns>
|
/// <returns>取消令牌</returns>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) DGP Studio. All rights reserved.
|
// Copyright (c) DGP Studio. All rights reserved.
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
|
using Microsoft.UI;
|
||||||
|
using Microsoft.UI.Windowing;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Snap.Hutao.Control.HostBackdrop;
|
using Snap.Hutao.Control.HostBackdrop;
|
||||||
using Snap.Hutao.Core.Logging;
|
using Snap.Hutao.Core.Logging;
|
||||||
@@ -23,6 +25,9 @@ internal class WindowManager
|
|||||||
private const int MinWidth = 848;
|
private const int MinWidth = 848;
|
||||||
private const int MinHeight = 524;
|
private const int MinHeight = 524;
|
||||||
private const int SubclassId = 101;
|
private const int SubclassId = 101;
|
||||||
|
|
||||||
|
private static readonly Windows.UI.Color SystemBaseLowColor = Windows.UI.Color.FromArgb(0x33, 0xFF, 0xFF, 0xFF);
|
||||||
|
private static readonly Windows.UI.Color SystemBaseMediumLowColor = Windows.UI.Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF);
|
||||||
private readonly HWND handle;
|
private readonly HWND handle;
|
||||||
private readonly Window window;
|
private readonly Window window;
|
||||||
private readonly UIElement titleBar;
|
private readonly UIElement titleBar;
|
||||||
@@ -42,7 +47,9 @@ internal class WindowManager
|
|||||||
this.window = window;
|
this.window = window;
|
||||||
this.titleBar = titleBar;
|
this.titleBar = titleBar;
|
||||||
logger = Ioc.Default.GetRequiredService<ILogger<WindowManager>>();
|
logger = Ioc.Default.GetRequiredService<ILogger<WindowManager>>();
|
||||||
|
|
||||||
handle = (HWND)WindowNative.GetWindowHandle(window);
|
handle = (HWND)WindowNative.GetWindowHandle(window);
|
||||||
|
|
||||||
InitializeWindow();
|
InitializeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,11 +77,29 @@ internal class WindowManager
|
|||||||
|
|
||||||
private void InitializeWindow()
|
private void InitializeWindow()
|
||||||
{
|
{
|
||||||
window.ExtendsContentIntoTitleBar = true;
|
if (false && AppWindowTitleBar.IsCustomizationSupported())
|
||||||
window.SetTitleBar(titleBar);
|
{
|
||||||
window.Closed += OnWindowClosed;
|
AppWindow appWindow = GetAppWindow();
|
||||||
|
AppWindowTitleBar titleBar = appWindow.TitleBar;
|
||||||
|
titleBar.ExtendsContentIntoTitleBar = true;
|
||||||
|
|
||||||
SetWindowText(handle, "胡桃");
|
titleBar.ButtonBackgroundColor = Colors.Transparent;
|
||||||
|
titleBar.ButtonHoverBackgroundColor = SystemBaseLowColor;
|
||||||
|
titleBar.ButtonPressedBackgroundColor = SystemBaseMediumLowColor;
|
||||||
|
titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
|
||||||
|
|
||||||
|
// appWindow.TitleBar.SetDragRectangles();
|
||||||
|
appWindow.Title = "胡桃";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window.ExtendsContentIntoTitleBar = true;
|
||||||
|
window.SetTitleBar(titleBar);
|
||||||
|
|
||||||
|
SetWindowText(handle, "胡桃");
|
||||||
|
}
|
||||||
|
|
||||||
|
window.Closed += OnWindowClosed;
|
||||||
RECT rect = RetriveWindowRect();
|
RECT rect = RetriveWindowRect();
|
||||||
if (rect.Size > 0)
|
if (rect.Size > 0)
|
||||||
{
|
{
|
||||||
@@ -112,4 +137,10 @@ internal class WindowManager
|
|||||||
|
|
||||||
return DefSubclassProc(hwnd, uMsg, wParam, lParam);
|
return DefSubclassProc(hwnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AppWindow GetAppWindow()
|
||||||
|
{
|
||||||
|
WindowId windowId = Win32Interop.GetWindowIdFromWindow(handle);
|
||||||
|
return AppWindow.GetFromWindowId(windowId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<Identity
|
<Identity
|
||||||
Name="7f0db578-026f-4e0b-a75b-d5d06bb0a74d"
|
Name="7f0db578-026f-4e0b-a75b-d5d06bb0a74d"
|
||||||
Publisher="CN=DGP Studio"
|
Publisher="CN=DGP Studio"
|
||||||
Version="1.0.20.0" />
|
Version="1.0.22.0" />
|
||||||
|
|
||||||
<Properties>
|
<Properties>
|
||||||
<DisplayName>胡桃</DisplayName>
|
<DisplayName>胡桃</DisplayName>
|
||||||
|
|||||||
Reference in New Issue
Block a user