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>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -6,9 +6,9 @@ public class Unsafe
|
||||
/// <summary>
|
||||
/// 使用指针操作简化封送
|
||||
/// </summary>
|
||||
/// <param name="lPARAM"></param>
|
||||
/// <param name="minWidth"></param>
|
||||
/// <param name="minHeight"></param>
|
||||
/// <param name="lPARAM">lParam</param>
|
||||
/// <param name="minWidth">最小宽度</param>
|
||||
/// <param name="minHeight">最小高度</param>
|
||||
public static unsafe void SetMinTrackSize(nint lPARAM, float minWidth, float minHeight)
|
||||
{
|
||||
MINMAXINFO* rect2 = (MINMAXINFO*)lPARAM;
|
||||
|
||||
@@ -14,7 +14,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingsUI", "SettingsUI\Se
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snap.Hutao.SourceGeneration", "Snap.Hutao.SourceGeneration\Snap.Hutao.SourceGeneration.csproj", "{8B96721E-5604-47D2-9B72-06FEBAD0CE00}"
|
||||
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
|
||||
Global
|
||||
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|arm64.ActiveCfg = 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.Build.0 = Release|Any CPU
|
||||
{29209B14-A6E1-442E-9287-2C65B03C96CD}.Release|x64.ActiveCfg = Release|x64
|
||||
{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.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
|
||||
@@ -17,11 +17,17 @@ public class ContentDialogBehavior : BehaviorBase<FrameworkElement>
|
||||
protected override void OnAssociatedObjectLoaded()
|
||||
{
|
||||
DependencyObject parent = VisualTreeHelper.GetParent(AssociatedObject);
|
||||
DependencyObject child = VisualTreeHelper.GetChild(parent, 2);
|
||||
Rectangle smokeLayerBackground = (Rectangle)child;
|
||||
|
||||
smokeLayerBackground.Margin = new Thickness(0);
|
||||
smokeLayerBackground.RegisterPropertyChangedCallback(FrameworkElement.MarginProperty, OnMarginChanged);
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -12,6 +12,7 @@ using Snap.Hutao.Core.Exception;
|
||||
using Snap.Hutao.Core.Threading;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Streams;
|
||||
@@ -81,50 +82,52 @@ public abstract class CompositionImage : Microsoft.UI.Xaml.Controls.Control
|
||||
spriteVisual.Size = ActualSize;
|
||||
}
|
||||
|
||||
private static void OnApplyImageFailed(Exception exception)
|
||||
private static void OnApplyImageFailed(Uri? uri, Exception exception)
|
||||
{
|
||||
Ioc.Default
|
||||
.GetRequiredService<IInfoBarService>()
|
||||
.Error(exception, "应用合成图像时发生异常");
|
||||
IInfoBarService infoBarService = Ioc.Default.GetRequiredService<IInfoBarService>();
|
||||
|
||||
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)
|
||||
{
|
||||
CompositionImage image = (CompositionImage)sender;
|
||||
|
||||
_ = TryGetImageUri(arg, out Uri? uri);
|
||||
CancellationToken token = LoadingTokenSource.Register(image);
|
||||
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)
|
||||
{
|
||||
result = null;
|
||||
// source is valid
|
||||
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))
|
||||
{
|
||||
result = inner;
|
||||
return true;
|
||||
image.ApplyImageInternalAsync(inner, token).SafeForget(logger, ex => OnApplyImageFailed(inner, ex));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
else
|
||||
{
|
||||
// should hide
|
||||
image.HideAsync(token).SafeForget(logger);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ApplyImageInternalAsync(Uri? uri, CancellationToken token)
|
||||
{
|
||||
await AnimationBuilder.Create().Opacity(0d).StartAsync(this, token);
|
||||
await HideAsync(token);
|
||||
|
||||
if (uri != null)
|
||||
{
|
||||
StorageFile storageFile = await imageCache.GetFileFromCacheAsync(uri);
|
||||
|
||||
Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
|
||||
|
||||
LoadedImageSurface? imageSurface = null;
|
||||
|
||||
try
|
||||
{
|
||||
imageSurface = await LoadImageSurfaceAsync(storageFile, token);
|
||||
@@ -141,10 +144,19 @@ public abstract class CompositionImage : Microsoft.UI.Xaml.Controls.Control
|
||||
OnUpdateVisual(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)
|
||||
|
||||
@@ -15,7 +15,7 @@ internal class ConcurrentCancellationTokenSource<TItem>
|
||||
private readonly ConcurrentDictionary<TItem, CancellationTokenSource> waitingItems = new();
|
||||
|
||||
/// <summary>
|
||||
/// 未某个项注册取消令牌
|
||||
/// 为某个项注册取消令牌
|
||||
/// </summary>
|
||||
/// <param name="item">项</param>
|
||||
/// <returns>取消令牌</returns>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Control.HostBackdrop;
|
||||
using Snap.Hutao.Core.Logging;
|
||||
@@ -23,6 +25,9 @@ internal class WindowManager
|
||||
private const int MinWidth = 848;
|
||||
private const int MinHeight = 524;
|
||||
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 Window window;
|
||||
private readonly UIElement titleBar;
|
||||
@@ -42,7 +47,9 @@ internal class WindowManager
|
||||
this.window = window;
|
||||
this.titleBar = titleBar;
|
||||
logger = Ioc.Default.GetRequiredService<ILogger<WindowManager>>();
|
||||
|
||||
handle = (HWND)WindowNative.GetWindowHandle(window);
|
||||
|
||||
InitializeWindow();
|
||||
}
|
||||
|
||||
@@ -69,12 +76,30 @@ internal class WindowManager
|
||||
}
|
||||
|
||||
private void InitializeWindow()
|
||||
{
|
||||
if (false && AppWindowTitleBar.IsCustomizationSupported())
|
||||
{
|
||||
AppWindow appWindow = GetAppWindow();
|
||||
AppWindowTitleBar titleBar = appWindow.TitleBar;
|
||||
titleBar.ExtendsContentIntoTitleBar = true;
|
||||
|
||||
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);
|
||||
window.Closed += OnWindowClosed;
|
||||
|
||||
SetWindowText(handle, "胡桃");
|
||||
}
|
||||
|
||||
window.Closed += OnWindowClosed;
|
||||
RECT rect = RetriveWindowRect();
|
||||
if (rect.Size > 0)
|
||||
{
|
||||
@@ -112,4 +137,10 @@ internal class WindowManager
|
||||
|
||||
return DefSubclassProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
private AppWindow GetAppWindow()
|
||||
{
|
||||
WindowId windowId = Win32Interop.GetWindowIdFromWindow(handle);
|
||||
return AppWindow.GetFromWindowId(windowId);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
<Identity
|
||||
Name="7f0db578-026f-4e0b-a75b-d5d06bb0a74d"
|
||||
Publisher="CN=DGP Studio"
|
||||
Version="1.0.20.0" />
|
||||
Version="1.0.22.0" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>胡桃</DisplayName>
|
||||
|
||||
Reference in New Issue
Block a user