Compare commits

...

14 Commits

Author SHA1 Message Date
ww-rm
4b23c779d3 Merge pull request #124 from ww-rm/dev/wpf
v0.16.7
2025-10-06 14:04:13 +08:00
ww-rm
f5684a50dc update to v0.16.7 2025-10-06 14:03:19 +08:00
ww-rm
579ce9f944 update changelog 2025-10-06 14:03:03 +08:00
ww-rm
7aa88089b8 修复空帧导致的包围盒计算错误 2025-10-06 14:02:21 +08:00
ww-rm
be983f8407 修复窗口二次显示错误 2025-10-06 13:32:03 +08:00
ww-rm
249b930602 Merge pull request #122 from ww-rm/dev/wpf
v0.16.6
2025-10-04 20:55:59 +08:00
ww-rm
6472f378b7 update to v0.16.6 2025-10-04 20:53:29 +08:00
ww-rm
8672f0571c udpate changelog 2025-10-04 20:53:06 +08:00
ww-rm
e7a990c1bd 修复可能出现的0缩放错误 2025-10-04 20:50:08 +08:00
ww-rm
6727fa8e8f Merge pull request #120 from ww-rm/dev/wpf
v0.16.5
2025-10-04 16:59:08 +08:00
ww-rm
66d8c489b5 update to v0.16.5 2025-10-04 16:58:32 +08:00
ww-rm
1931c4713a update changelog 2025-10-04 16:58:09 +08:00
ww-rm
f19f172e7c 修复窗口联动显示问题 2025-10-04 16:56:32 +08:00
ww-rm
092fa76124 修复对于某些旧atlas没有size行的读取异常 2025-10-04 16:38:14 +08:00
8 changed files with 172 additions and 74 deletions

View File

@@ -1,5 +1,19 @@
# CHANGELOG
## v0.16.7
- 修复空帧导致的包围盒计算错误
- 修复重复启动程序无法唤出界面的问题
## v0.16.6
- 修复控件尺寸为0时导致的画面缩放错误
## v0.16.5
- 修复对于无 size 行的旧 atlas 格式读取错误
- 修复托盘化之后无法联动显示窗口的问题
## v0.16.4
- 增加 apng 导出格式

View File

@@ -240,8 +240,8 @@ namespace SFMLRenderer
if (RenderWindow is null) return;
float parentW = (float)sizeInfo.NewSize.Width;
float parentH = (float)sizeInfo.NewSize.Height;
float renderW = (float)_hwndHost.ActualWidth;
float renderH = (float)_hwndHost.ActualHeight;
float renderW = _resolution.X;
float renderH = _resolution.Y;
float scale = Math.Min(parentW / renderW, parentH / renderH); // 两方向取较小值, 保证 parent 覆盖 render
renderW *= scale;
renderH *= scale;

View File

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

View File

@@ -112,6 +112,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime34.AtlasPage page, string path)
@@ -147,6 +155,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime35.AtlasPage page, string path)
@@ -182,6 +198,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime36.AtlasPage page, string path)
@@ -217,6 +241,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime37.AtlasPage page, string path)
@@ -252,6 +284,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime38.AtlasPage page, string path)
@@ -288,9 +328,13 @@ namespace Spine.Implementations
page.rendererObject = texture;
// 似乎是不需要设置的, 因为存在某些 png 和 atlas 大小不同的情况, 一般是有一些缩放, 如果设置了反而渲染异常
// page.width = (int)texture.Size.X;
// page.height = (int)texture.Size.Y;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime40.AtlasPage page, string path)
@@ -326,6 +370,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime41.AtlasPage page, string path)
@@ -361,6 +413,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Load(SpineRuntime42.AtlasPage page, string path)
@@ -396,6 +456,14 @@ namespace Spine.Implementations
if (ForceMipmap) texture.GenerateMipmap();
page.rendererObject = texture;
// 有些旧的 atlas 会省略 size 行, 这时需要在读取纹理时赋值
if (page.width <= 0 || page.height <= 0)
{
var texSize = texture.Size;
page.width = (int)texSize.X;
page.height = (int)texSize.Y;
}
}
public virtual void Unload(object texture)

View File

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

View File

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

View File

@@ -69,8 +69,7 @@ namespace SpineViewer
_instanceMutex = new Mutex(true, MutexName, out var createdNew);
if (!createdNew)
{
ShowExistedInstance();
SendCommandLineArgs();
ConnectAndSendArgs();
Environment.Exit(0); // 不再启动新实例
return;
}
@@ -100,55 +99,27 @@ namespace SpineViewer
LogManager.Configuration = config;
}
private static void ShowExistedInstance()
private static void ConnectAndSendArgs()
{
try
{
// 遍历同名进程
var processes = Process.GetProcessesByName(ProcessName);
foreach (var p in processes)
{
// 跳过当前进程
if (p.Id == Process.GetCurrentProcess().Id)
continue;
IntPtr hWnd = p.MainWindowHandle;
if (hWnd != IntPtr.Zero)
{
// 3. 显示并置顶窗口
if (User32.IsIconic(hWnd))
{
User32.ShowWindow(hWnd, User32.SW_RESTORE);
}
User32.SetForegroundWindow(hWnd);
break; // 找到一个就可以退出
}
}
}
catch
{
// 忽略异常,不影响当前进程退出
}
}
private static void SendCommandLineArgs()
{
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
{
// 已有实例在运行,把参数通过命名管道发过去
using (var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out))
{
client.Connect(10000); // 10 秒超时
using (var writer = new StreamWriter(client))
// 只要启动了实例就要进行连接, 10 秒超时
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);
}
}
}
}
@@ -164,6 +135,7 @@ namespace SpineViewer
{
var t = new Task(() =>
{
// 防止实例和窗口还没创建好
while (Current is null) Thread.Sleep(10);
while (true)
{
@@ -176,26 +148,48 @@ namespace SpineViewer
}
while (true)
{
using (var server = new NamedPipeServerStream(PipeName, PipeDirection.In))
try
{
server.WaitForConnection();
using (var reader = new StreamReader(server))
using (var server = new NamedPipeServerStream(PipeName, PipeDirection.In))
{
var args = new List<string>();
string? line;
while ((line = reader.ReadLine()) != null)
args.Add(line);
server.WaitForConnection();
if (args.Count > 0)
// 只要收到连接就可以显示窗口了
Current.Dispatcher.Invoke(() =>
{
Current.Dispatcher.Invoke(() =>
var window = (MainWindow)Current.MainWindow;
window.Show();
if (window.WindowState == WindowState.Minimized)
{
var vm = (MainWindowViewModel)((MainWindow)Current.MainWindow).DataContext;
vm.SpineObjectListViewModel.AddSpineObjectFromFileList(args);
});
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(() =>
{
// 尝试加载参数内容
var window = (MainWindow)Current.MainWindow;
var vm = (MainWindowViewModel)window.DataContext;
vm.SpineObjectListViewModel.AddSpineObjectFromFileList(args);
});
}
}
}
}
catch (Exception ex)
{
_logger.Trace(ex.ToString());
_logger.Error("Failed to process arguments, {0}", ex.Message);
}
}
}, default, TaskCreationOptions.LongRunning);
t.Start();

View File

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