diff --git a/SpineViewer.sln b/SpineViewer.sln index cb6c58c..9cb9c0c 100644 --- a/SpineViewer.sln +++ b/SpineViewer.sln @@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpineRuntime35", "SpineRunt EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpineRuntime34", "SpineRuntimes\SpineRuntime34\SpineRuntime34.csproj", "{348605F7-3FF4-1DE0-4B91-7AEFE7BC5C55}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Win32Natives", "Win32Natives\Win32Natives.csproj", "{48864874-7307-950E-A667-62BB66357C62}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -105,6 +107,10 @@ Global {348605F7-3FF4-1DE0-4B91-7AEFE7BC5C55}.Debug|x64.Build.0 = Debug|x64 {348605F7-3FF4-1DE0-4B91-7AEFE7BC5C55}.Release|x64.ActiveCfg = Release|x64 {348605F7-3FF4-1DE0-4B91-7AEFE7BC5C55}.Release|x64.Build.0 = Release|x64 + {48864874-7307-950E-A667-62BB66357C62}.Debug|x64.ActiveCfg = Debug|x64 + {48864874-7307-950E-A667-62BB66357C62}.Debug|x64.Build.0 = Debug|x64 + {48864874-7307-950E-A667-62BB66357C62}.Release|x64.ActiveCfg = Release|x64 + {48864874-7307-950E-A667-62BB66357C62}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SpineViewer/App.xaml.cs b/SpineViewer/App.xaml.cs index f121b0c..dd403ee 100644 --- a/SpineViewer/App.xaml.cs +++ b/SpineViewer/App.xaml.cs @@ -1,6 +1,6 @@ using Microsoft.Win32; using NLog; -using SpineViewer.Natives; +using Win32Natives; using SpineViewer.Resources; using SpineViewer.Services; using SpineViewer.ViewModels.MainWindow; @@ -15,6 +15,7 @@ using System.IO.Pipes; using System.Reflection; using System.Windows; using System.Windows.Interop; +using SpineViewer.Extensions; namespace SpineViewer { @@ -365,9 +366,8 @@ namespace SpineViewer { Resources.MergedDictionaries.Add(new() { Source = new(uri, UriKind.Relative) }); Resources.MergedDictionaries.Add(new() { Source = new("Resources/Theme.xaml", UriKind.Relative) }); - var hwnd = new WindowInteropHelper(Current.MainWindow).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + Current.MainWindow.SetWindowTextColor(AppResource.Color_PrimaryText); + Current.MainWindow.SetWindowCaptionColor(AppResource.Color_Region); _skin = value; } catch (Exception ex) diff --git a/SpineViewer/Extensions/WpfExtension.cs b/SpineViewer/Extensions/WpfExtension.cs index 9ce86e0..ddfd3da 100644 --- a/SpineViewer/Extensions/WpfExtension.cs +++ b/SpineViewer/Extensions/WpfExtension.cs @@ -1,6 +1,4 @@ -using SFML.Graphics; -using SFML.System; -using SkiaSharp; +using SkiaSharp; using System; using System.Collections.Generic; using System.IO; @@ -9,29 +7,31 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; +using Win32Natives; namespace SpineViewer.Extensions { public static class WpfExtension { - public static FloatRect ToFloatRect(this Rect self) + public static SFML.Graphics.FloatRect ToFloatRect(this Rect self) { return new((float)self.X, (float)self.Y, (float)self.Width, (float)self.Height); } - public static Vector2f ToVector2f(this Size self) + public static SFML.System.Vector2f ToVector2f(this Size self) { return new((float)self.Width, (float)self.Height); } - public static Vector2u ToVector2u(this Size self) + public static SFML.System.Vector2u ToVector2u(this Size self) { return new((uint)self.Width, (uint)self.Height); } - public static Vector2i ToVector2i(this Size self) + public static SFML.System.Vector2i ToVector2i(this Size self) { return new((int)self.Width, (int)self.Height); } @@ -60,6 +60,18 @@ namespace SpineViewer.Extensions return wb; } + public static void SetWindowTextColor(this Window self, Color color) + { + var hwnd = new WindowInteropHelper(self).Handle; + Dwmapi.SetWindowTextColor(hwnd, color.R, color.G, color.B); + } + + public static void SetWindowCaptionColor(this Window self, Color color) + { + var hwnd = new WindowInteropHelper(self).Handle; + Dwmapi.SetWindowCaptionColor(hwnd, color.R, color.G, color.B); + } + //public static void SaveToFile(this BitmapSource bitmap, string path) //{ // var ext = Path.GetExtension(path)?.ToLowerInvariant(); diff --git a/SpineViewer/SpineViewer.csproj b/SpineViewer/SpineViewer.csproj index 03b940e..b5ff95c 100644 --- a/SpineViewer/SpineViewer.csproj +++ b/SpineViewer/SpineViewer.csproj @@ -41,5 +41,6 @@ + diff --git a/SpineViewer/ViewModels/MainWindow/PreferenceViewModel.cs b/SpineViewer/ViewModels/MainWindow/PreferenceViewModel.cs index 9f2a823..a7efe9c 100644 --- a/SpineViewer/ViewModels/MainWindow/PreferenceViewModel.cs +++ b/SpineViewer/ViewModels/MainWindow/PreferenceViewModel.cs @@ -5,7 +5,6 @@ using NLog; using Spine; using Spine.Implementations; using SpineViewer.Models; -using SpineViewer.Natives; using SpineViewer.Services; using SpineViewer.Utils; using System; diff --git a/SpineViewer/Views/AboutDialog.xaml.cs b/SpineViewer/Views/AboutDialog.xaml.cs index f390768..a98bc35 100644 --- a/SpineViewer/Views/AboutDialog.xaml.cs +++ b/SpineViewer/Views/AboutDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using SpineViewer.Extensions; using SpineViewer.Resources; using System; using System.Collections.Generic; @@ -14,6 +14,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Win32Natives; namespace SpineViewer.Views { @@ -30,9 +31,8 @@ namespace SpineViewer.Views private void AboutDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } } } diff --git a/SpineViewer/Views/DiagnosticsDialog.xaml.cs b/SpineViewer/Views/DiagnosticsDialog.xaml.cs index 72ca5aa..c79e895 100644 --- a/SpineViewer/Views/DiagnosticsDialog.xaml.cs +++ b/SpineViewer/Views/DiagnosticsDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using SpineViewer.Extensions; using SpineViewer.Resources; using System; using System.Collections.Generic; @@ -14,6 +14,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Win32Natives; namespace SpineViewer.Views { @@ -30,9 +31,8 @@ namespace SpineViewer.Views private void DiagnosticsDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } } } diff --git a/SpineViewer/Views/ExporterDialogs/CustomFFmpegExporterDialog.xaml.cs b/SpineViewer/Views/ExporterDialogs/CustomFFmpegExporterDialog.xaml.cs index eda8ae4..efce9e0 100644 --- a/SpineViewer/Views/ExporterDialogs/CustomFFmpegExporterDialog.xaml.cs +++ b/SpineViewer/Views/ExporterDialogs/CustomFFmpegExporterDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using Win32Natives; using SpineViewer.Resources; using SpineViewer.Services; using SpineViewer.ViewModels.Exporters; @@ -16,6 +16,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using SpineViewer.Extensions; namespace SpineViewer.Views.ExporterDialogs { @@ -32,9 +33,8 @@ namespace SpineViewer.Views.ExporterDialogs private void CustomFFmpegExporterDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } private void ButtonOK_Click(object sender, RoutedEventArgs e) diff --git a/SpineViewer/Views/ExporterDialogs/FFmpegVideoExporterDialog.xaml.cs b/SpineViewer/Views/ExporterDialogs/FFmpegVideoExporterDialog.xaml.cs index b4dbaaa..9b92f6a 100644 --- a/SpineViewer/Views/ExporterDialogs/FFmpegVideoExporterDialog.xaml.cs +++ b/SpineViewer/Views/ExporterDialogs/FFmpegVideoExporterDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using SpineViewer.Extensions; using SpineViewer.Resources; using SpineViewer.Services; using SpineViewer.ViewModels.Exporters; @@ -16,6 +16,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Win32Natives; namespace SpineViewer.Views.ExporterDialogs { @@ -32,9 +33,8 @@ namespace SpineViewer.Views.ExporterDialogs private void FFmpegVideoExporterDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } private void ButtonOK_Click(object sender, RoutedEventArgs e) diff --git a/SpineViewer/Views/ExporterDialogs/FrameExporterDialog.xaml.cs b/SpineViewer/Views/ExporterDialogs/FrameExporterDialog.xaml.cs index b34058f..e29e695 100644 --- a/SpineViewer/Views/ExporterDialogs/FrameExporterDialog.xaml.cs +++ b/SpineViewer/Views/ExporterDialogs/FrameExporterDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using SpineViewer.Extensions; using SpineViewer.Resources; using SpineViewer.Services; using SpineViewer.ViewModels.Exporters; @@ -16,6 +16,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Win32Natives; namespace SpineViewer.Views.ExporterDialogs { @@ -32,9 +33,8 @@ namespace SpineViewer.Views.ExporterDialogs private void FrameExporterDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } private void ButtonOK_Click(object sender, RoutedEventArgs e) diff --git a/SpineViewer/Views/ExporterDialogs/FrameSequenceExporterDialog.xaml.cs b/SpineViewer/Views/ExporterDialogs/FrameSequenceExporterDialog.xaml.cs index 1ed0c47..db4c9d4 100644 --- a/SpineViewer/Views/ExporterDialogs/FrameSequenceExporterDialog.xaml.cs +++ b/SpineViewer/Views/ExporterDialogs/FrameSequenceExporterDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using SpineViewer.Extensions; using SpineViewer.Resources; using SpineViewer.Services; using SpineViewer.ViewModels.Exporters; @@ -16,6 +16,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Win32Natives; namespace SpineViewer.Views.ExporterDialogs { @@ -32,9 +33,8 @@ namespace SpineViewer.Views.ExporterDialogs private void FrameSequenceExporterDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } private void ButtonOK_Click(object sender, RoutedEventArgs e) diff --git a/SpineViewer/Views/MainWindow.xaml.cs b/SpineViewer/Views/MainWindow.xaml.cs index 07aa442..cf59900 100644 --- a/SpineViewer/Views/MainWindow.xaml.cs +++ b/SpineViewer/Views/MainWindow.xaml.cs @@ -1,8 +1,8 @@ using NLog; using SFMLRenderer; using Spine; +using SpineViewer.Extensions; using SpineViewer.Models; -using SpineViewer.Natives; using SpineViewer.Resources; using SpineViewer.Services; using SpineViewer.Utils; @@ -24,6 +24,7 @@ using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; +using Win32Natives; namespace SpineViewer.Views; @@ -98,13 +99,13 @@ public partial class MainWindow : Window // Initialize Wallpaper RenderWindow _wallpaperRenderWindow = new(new(1, 1), "SpineViewerWallpaper", SFML.Window.Styles.None); - _wallpaperRenderWindow.SetVisible(false); + _wallpaperRenderWindow.MaxFps = 30; + var handle = _wallpaperRenderWindow.SystemHandle; var style = User32.GetWindowLong(handle, User32.GWL_STYLE) | User32.WS_POPUP; - var exStyle = User32.GetWindowLong(handle, User32.GWL_EXSTYLE) | User32.WS_EX_LAYERED | User32.WS_EX_TOOLWINDOW; + var exStyle = User32.GetWindowLong(handle, User32.GWL_EXSTYLE) | User32.WS_EX_TOOLWINDOW; User32.SetWindowLong(handle, User32.GWL_STYLE, style); User32.SetWindowLong(handle, User32.GWL_EXSTYLE, exStyle); - User32.SetLayeredWindowAttributes(handle, 0, byte.MaxValue, User32.LWA_ALPHA); DataContext = _vm = new(_renderPanel, _wallpaperRenderWindow); @@ -153,9 +154,8 @@ public partial class MainWindow : Window private void MainWindow_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } private void MainWindow_Loaded(object sender, RoutedEventArgs e) diff --git a/SpineViewer/Views/PreferenceDialog.xaml.cs b/SpineViewer/Views/PreferenceDialog.xaml.cs index 849f47b..27f7aff 100644 --- a/SpineViewer/Views/PreferenceDialog.xaml.cs +++ b/SpineViewer/Views/PreferenceDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using SpineViewer.Extensions; using SpineViewer.Resources; using SpineViewer.Services; using SpineViewer.ViewModels.Exporters; @@ -16,6 +16,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Win32Natives; namespace SpineViewer.Views { @@ -32,9 +33,8 @@ namespace SpineViewer.Views private void PreferenceDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } private void ButtonOK_Click(object sender, RoutedEventArgs e) diff --git a/SpineViewer/Views/ProgressDialog.xaml.cs b/SpineViewer/Views/ProgressDialog.xaml.cs index fde5c03..d59f955 100644 --- a/SpineViewer/Views/ProgressDialog.xaml.cs +++ b/SpineViewer/Views/ProgressDialog.xaml.cs @@ -1,4 +1,4 @@ -using SpineViewer.Natives; +using SpineViewer.Extensions; using SpineViewer.Resources; using SpineViewer.ViewModels; using System; @@ -16,6 +16,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using Win32Natives; namespace SpineViewer.Views { @@ -33,9 +34,8 @@ namespace SpineViewer.Views private void ProgressDialog_SourceInitialized(object? sender, EventArgs e) { - var hwnd = new WindowInteropHelper(this).Handle; - Dwmapi.SetWindowTextColor(hwnd, AppResource.Color_PrimaryText); - Dwmapi.SetWindowCaptionColor(hwnd, AppResource.Color_Region); + this.SetWindowTextColor(AppResource.Color_PrimaryText); + this.SetWindowCaptionColor(AppResource.Color_Region); } private void ProgressWindow_Loaded(object sender, RoutedEventArgs e) diff --git a/SpineViewer/Natives/Dwmapi.cs b/Win32Natives/Dwmapi.cs similarity index 81% rename from SpineViewer/Natives/Dwmapi.cs rename to Win32Natives/Dwmapi.cs index 29fe400..2776186 100644 --- a/SpineViewer/Natives/Dwmapi.cs +++ b/Win32Natives/Dwmapi.cs @@ -4,9 +4,8 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; -using System.Windows.Media; -namespace SpineViewer.Natives +namespace Win32Natives { /// /// dwmapi.dll 包装类 @@ -24,15 +23,15 @@ namespace SpineViewer.Natives [DllImport("dwmapi.dll")] private static extern int DwmSetWindowAttribute(IntPtr hwnd, uint dwAttribute, ref uint pvAttribute, int cbAttribute); - public static bool SetWindowCaptionColor(IntPtr hwnd, Color color) + public static bool SetWindowCaptionColor(IntPtr hwnd, byte r, byte g, byte b) { - int c = color.R | (color.G << 8) | (color.B << 16); + int c = r | (g << 8) | (b << 16); return 0 == DwmSetWindowAttribute(hwnd, DWMWA_CAPTION_COLOR, ref c, sizeof(uint)); } - public static bool SetWindowTextColor(IntPtr hwnd, Color color) + public static bool SetWindowTextColor(IntPtr hwnd, byte r, byte g, byte b) { - int c = color.R | (color.G << 8) | (color.B << 16); + int c = r | (g << 8) | (b << 16); return 0 == DwmSetWindowAttribute(hwnd, DWMWA_TEXT_COLOR, ref c, sizeof(uint)); } diff --git a/SpineViewer/Natives/Gdi32.cs b/Win32Natives/Gdi32.cs similarity index 96% rename from SpineViewer/Natives/Gdi32.cs rename to Win32Natives/Gdi32.cs index 5845cf9..fb3e77e 100644 --- a/SpineViewer/Natives/Gdi32.cs +++ b/Win32Natives/Gdi32.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; -namespace SpineViewer.Natives +namespace Win32Natives { /// /// gdi32.dll 包装类 diff --git a/SpineViewer/Natives/Shell32.cs b/Win32Natives/Shell32.cs similarity index 96% rename from SpineViewer/Natives/Shell32.cs rename to Win32Natives/Shell32.cs index 1a08aa6..e6ac8ba 100644 --- a/SpineViewer/Natives/Shell32.cs +++ b/Win32Natives/Shell32.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; -namespace SpineViewer.Natives +namespace Win32Natives { /// /// shell32.dll 包装类 diff --git a/SpineViewer/Natives/User32.cs b/Win32Natives/User32.cs similarity index 99% rename from SpineViewer/Natives/User32.cs rename to Win32Natives/User32.cs index 4702bd6..1dd4a09 100644 --- a/SpineViewer/Natives/User32.cs +++ b/Win32Natives/User32.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; -namespace SpineViewer.Natives +namespace Win32Natives { /// /// user32.dll 包装类 diff --git a/Win32Natives/Win32Natives.csproj b/Win32Natives/Win32Natives.csproj new file mode 100644 index 0000000..d706d22 --- /dev/null +++ b/Win32Natives/Win32Natives.csproj @@ -0,0 +1,14 @@ + + + + enable + enable + x64 + x64 + net8.0-windows + $(SolutionDir)out + false + 0.0.1 + + +