Merge pull request #124 from ww-rm/dev/wpf

v0.16.7
This commit is contained in:
ww-rm
2025-10-06 14:04:13 +08:00
committed by GitHub
5 changed files with 82 additions and 47 deletions

View File

@@ -1,5 +1,10 @@
# CHANGELOG # CHANGELOG
## v0.16.7
- 修复空帧导致的包围盒计算错误
- 修复重复启动程序无法唤出界面的问题
## v0.16.6 ## v0.16.6
- 修复控件尺寸为0时导致的画面缩放错误 - 修复控件尺寸为0时导致的画面缩放错误

View File

@@ -7,7 +7,7 @@
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<BaseOutputPath>$(SolutionDir)out</BaseOutputPath> <BaseOutputPath>$(SolutionDir)out</BaseOutputPath>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion> <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<Version>0.16.6</Version> <Version>0.16.7</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

View File

@@ -110,20 +110,42 @@ namespace Spine
break; break;
} }
for (int ii = 0; ii + 1 < verticesLength; ii += 2) if (verticesLength > 0)
{ {
float vx = vertices[ii]; for (int ii = 0; ii + 1 < verticesLength; ii += 2)
float vy = vertices[ii + 1]; {
minX = Math.Min(minX, vx); float vx = vertices[ii];
minY = Math.Min(minY, vy); float vy = vertices[ii + 1];
maxX = Math.Max(maxX, vx); minX = Math.Min(minX, vx);
maxY = Math.Max(maxY, vy); minY = Math.Min(minY, vy);
maxX = Math.Max(maxX, vx);
maxY = Math.Max(maxY, vy);
}
}
else
{
var boneX = slot.Bone.WorldX;
var boneY = slot.Bone.WorldY;
minX = Math.Min(minX, boneX);
minY = Math.Min(minY, boneY);
maxX = Math.Max(maxX, boneX);
maxY = Math.Max(maxY, boneY);
} }
} }
x = minX; if (minX >= int.MaxValue || minY >= int.MaxValue || maxX <= int.MinValue || maxY <= int.MinValue)
y = minY; {
w = maxX - minX; x = self.X;
h = maxY - minY; y = self.Y;
w = 0;
h = 0;
}
else
{
x = minX;
y = minY;
w = maxX - minX;
h = maxY - minY;
}
} }
/// <summary> /// <summary>

View File

@@ -69,7 +69,7 @@ namespace SpineViewer
_instanceMutex = new Mutex(true, MutexName, out var createdNew); _instanceMutex = new Mutex(true, MutexName, out var createdNew);
if (!createdNew) if (!createdNew)
{ {
SendCommandLineArgs(); ConnectAndSendArgs();
Environment.Exit(0); // 不再启动新实例 Environment.Exit(0); // 不再启动新实例
return; return;
} }
@@ -99,24 +99,27 @@ namespace SpineViewer
LogManager.Configuration = config; LogManager.Configuration = config;
} }
private static void SendCommandLineArgs() private static void ConnectAndSendArgs()
{ {
var args = Environment.GetCommandLineArgs().Skip(1).ToArray();
if (args.Length <= 0)
return;
_logger.Info("Send command line args to existed instance, \"{0}\"", string.Join(", ", args));
try try
{ {
// 已有实例在运行,把参数通过命名管道发过去 // 已有实例在运行,把参数通过命名管道发过去
using (var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out)) using (var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out))
{ {
client.Connect(10000); // 10 秒超时 // 只要启动了实例就要进行连接, 10 秒超时
using (var writer = new StreamWriter(client)) client.Connect(10000);
// 但是只有有参数的时候才发送参数
var args = Environment.GetCommandLineArgs().Skip(1).ToArray();
if (args.Length > 0)
{ {
foreach (var v in args) _logger.Info("Send command line args to existed instance, \"{0}\"", string.Join(", ", args));
using (var writer = new StreamWriter(client))
{ {
writer.WriteLine(v); foreach (var v in args)
{
writer.WriteLine(v);
}
} }
} }
} }
@@ -132,6 +135,7 @@ namespace SpineViewer
{ {
var t = new Task(() => var t = new Task(() =>
{ {
// 防止实例和窗口还没创建好
while (Current is null) Thread.Sleep(10); while (Current is null) Thread.Sleep(10);
while (true) while (true)
{ {
@@ -144,44 +148,48 @@ namespace SpineViewer
} }
while (true) while (true)
{ {
using (var server = new NamedPipeServerStream(PipeName, PipeDirection.In)) try
{ {
server.WaitForConnection(); using (var server = new NamedPipeServerStream(PipeName, PipeDirection.In))
using (var reader = new StreamReader(server))
{ {
var args = new List<string>(); server.WaitForConnection();
string? line;
while ((line = reader.ReadLine()) != null)
args.Add(line);
if (args.Count > 0) // 只要收到连接就可以显示窗口了
Current.Dispatcher.Invoke(() =>
{ {
try var window = (MainWindow)Current.MainWindow;
window.Show();
if (window.WindowState == WindowState.Minimized)
{
window.WindowState = WindowState.Normal;
}
window.Activate();
});
using (var reader = new StreamReader(server))
{
var args = new List<string>();
string? line;
while ((line = reader.ReadLine()) != null)
args.Add(line);
if (args.Count > 0)
{ {
Current.Dispatcher.Invoke(() => Current.Dispatcher.Invoke(() =>
{ {
// 只要收到参数就可以显示窗口了
var window = (MainWindow)Current.MainWindow;
window.Show();
if (window.WindowState == WindowState.Minimized)
{
window.WindowState = WindowState.Normal;
}
window.Activate();
// 尝试加载参数内容 // 尝试加载参数内容
var window = (MainWindow)Current.MainWindow;
var vm = (MainWindowViewModel)window.DataContext; var vm = (MainWindowViewModel)window.DataContext;
vm.SpineObjectListViewModel.AddSpineObjectFromFileList(args); vm.SpineObjectListViewModel.AddSpineObjectFromFileList(args);
}); });
} }
catch (Exception ex)
{
_logger.Trace(ex.ToString());
_logger.Error("Failed to process arguments, {0}", ex.Message);
}
} }
} }
} }
catch (Exception ex)
{
_logger.Trace(ex.ToString());
_logger.Error("Failed to process arguments, {0}", ex.Message);
}
} }
}, default, TaskCreationOptions.LongRunning); }, default, TaskCreationOptions.LongRunning);
t.Start(); t.Start();

View File

@@ -7,7 +7,7 @@
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<BaseOutputPath>$(SolutionDir)out</BaseOutputPath> <BaseOutputPath>$(SolutionDir)out</BaseOutputPath>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion> <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<Version>0.16.6</Version> <Version>0.16.7</Version>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>