Skip to content

Commit 5158b97

Browse files
committed
feat: 支持设置中间纹理精度
1 parent 117d182 commit 5158b97

15 files changed

+127
-18
lines changed

‎Magpie/App.config‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<setting name="AutoRestore" serializeAs="String">
3232
<value>False</value>
3333
</setting>
34+
<setting name="BufferPrecision" serializeAs="String">
35+
<value>0</value>
36+
</setting>
3437
</Magpie.Properties.Settings>
3538
</userSettings>
3639
</configuration>

‎Magpie/MagWindow.cs‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal enum MagWindowStatus : int {
2020

2121
// 用于管理全屏窗口,该窗口在一个新线程中启动,通过事件与主线程通信
2222
internal class MagWindow {
23+
private static NLog.Logger Logger { get; } = NLog.LogManager.GetCurrentClassLogger();
24+
2325
public event Action Closed;
2426

2527
public IntPtr SrcWindow { get; private set; } = IntPtr.Zero;
@@ -72,11 +74,13 @@ public MagWindow(Window parent) {
7274
public void Create(
7375
string scaleModel,
7476
int captureMode,
77+
int bufferPrecision,
7578
bool showFPS,
7679
bool hookCursorAtRuntime,
7780
bool noDisturb = false
7881
) {
7982
if (Status != MagWindowStatus.Idle) {
83+
Logger.Info("已存在全屏窗口,取消进入全屏");
8084
return;
8185
}
8286

@@ -85,19 +89,22 @@ public void Create(
8589
|| !NativeMethods.IsWindowVisible(hwndSrc)
8690
|| NativeMethods.GetWindowShowCmd(hwndSrc) != NativeMethods.SW_NORMAL
8791
) {
88-
// 不合法的源窗口
92+
Logger.Info("源窗口不合法");
8993
return;
9094
}
9195

9296
Status = MagWindowStatus.Starting;
9397
// 使用 WinRT Capturer API 需要在 MTA 中
9498
// C# 窗体必须使用 STA,因此将全屏窗口创建在新的线程里
9599
magThread = new Thread(() => {
100+
Logger.Info("正在新线程中创建全屏窗口");
101+
96102
NativeMethods.RunMagWindow(
97103
(int status, IntPtr errorMsg) => StatusEvent(status, Marshal.PtrToStringUni(errorMsg)),
98104
hwndSrc, // 源窗口句柄
99105
scaleModel, // 缩放模式
100106
captureMode, // 抓取模式
107+
bufferPrecision, // 缓冲区精度
101108
showFPS, // 显示 FPS
102109
noDisturb // 用于调试
103110
);
@@ -123,9 +130,11 @@ public void Destory() {
123130
}
124131

125132
private void HookCursorAtRuntime(IntPtr hwndSrc) {
133+
Logger.Info("正在进行运行时注入");
134+
126135
int pid = NativeMethods.GetWindowProcessId(hwndSrc);
127136
if (pid == 0 || pid == Process.GetCurrentProcess().Id) {
128-
// 不能 hook 本进程
137+
Logger.Info("不能注入本进程,已取消");
129138
return;
130139
}
131140

@@ -146,19 +155,21 @@ private void HookCursorAtRuntime(IntPtr hwndSrc) {
146155
// 使用 EasyHook 注入
147156
try {
148157
RemoteHooking.Inject(
149-
pid, // 要注入的进程的 ID
150-
injectionLibrary, // 32 位 DLL
151-
injectionLibrary, // 64 位 DLL
152-
// 下面为传递给注入 DLL 的参数
153-
channelName,
154-
hwndSrc
158+
pid, // 要注入的进程的 ID
159+
injectionLibrary, // 32 位 DLL
160+
injectionLibrary, // 64 位 DLL
161+
// 下面为传递给注入 DLL 的参数
162+
channelName,
163+
hwndSrc
155164
);
165+
Logger.Info($"已注入CursorHook\n\t进程ID:{pid}\n\t源窗口句柄:{hwndSrc}");
156166
} catch (Exception e) {
157-
Console.WriteLine("CursorHook 注入失败:" + e.Message);
167+
Logger.Error(e, "CursorHook注入失败");
158168
}
159169
}
160170

161171
public void HookCursorAtStartUp(string exePath) {
172+
Logger.Info("正在进行启动时注入");
162173

163174
string channelName = null;
164175
#if DEBUG
@@ -185,8 +196,10 @@ public void HookCursorAtStartUp(string exePath) {
185196
// 下面为传递给注入 DLL 的参数
186197
channelName
187198
);
199+
200+
Logger.Info($"已启动进程并注入\n\t可执行文件:{exePath}");
188201
} catch (Exception e) {
189-
Console.WriteLine("CursorHook 注入失败:" + e.Message);
202+
Logger.Error(e, "CursorHook注入失败");
190203
}
191204
}
192205
}

‎Magpie/MainWindow.xaml.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public partial class MainWindow : Window {
4444
// 不为零时表示全屏窗口不是因为Hotkey关闭的
4545
private IntPtr prevSrcWindow = IntPtr.Zero;
4646
private readonly DispatcherTimer timerRestore = new DispatcherTimer {
47-
Interval = new TimeSpan(0, 0, 0, 0, 200)
47+
Interval = new TimeSpan(0, 0, 0, 0, 300)
4848
};
4949

5050
public MainWindow() {
@@ -214,8 +214,10 @@ private void TxtHotkey_TextChanged(object sender, TextChangedEventArgs e) {
214214
Settings.Default.Hotkey = hotkey;
215215

216216
cmiHotkey.Header = hotkey;
217+
218+
Logger.Info($"快捷键已变更为{txtHotkey.Text}");
217219
} catch (ArgumentException ex) {
218-
Logger.Error(ex, "解析快捷键失败");
220+
Logger.Error(ex, $"解析快捷键失败{txtHotkey.Text}");
219221
txtHotkey.Foreground = Brushes.Red;
220222
}
221223
}
@@ -230,22 +232,25 @@ private void ToggleMagWindow() {
230232
}
231233

232234
if (magWindow.Status == MagWindowStatus.Running) {
233-
// 通过热键关闭全屏窗口
235+
Logger.Info("通过热键退出全屏");
234236
magWindow.Destory();
235237
return;
236238
}
237239

238240
if (magWindow.Status == MagWindowStatus.Starting) {
241+
Logger.Info("全屏窗口正在启动中,忽略切换全屏的请求");
239242
return;
240243
}
241244

242245
string effectsJson = scaleModels[Settings.Default.ScaleMode].Model;
243246
bool showFPS = Settings.Default.ShowFPS;
244247
int captureMode = Settings.Default.CaptureMode;
248+
int bufferPrecision = Settings.Default.BufferPrecision;
245249

246250
magWindow.Create(
247251
effectsJson,
248252
captureMode,
253+
bufferPrecision,
249254
showFPS,
250255
cbbInjectMode.SelectedIndex == 1,
251256
false

‎Magpie/NativeMethods.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public static extern void RunMagWindow(
140140
IntPtr hwndSrc,
141141
[MarshalAs(UnmanagedType.LPUTF8Str)] string scaleModel,
142142
int captureMode,
143+
int bufferPrecision,
143144
[MarshalAs(UnmanagedType.U1)] bool showFPS,
144145
[MarshalAs(UnmanagedType.U1)] bool noDisturb
145146
);

‎Magpie/Options/AdvancedOptionsPage.xaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,15 @@
2323
<ComboBox Margin="10,0,0,0" />
2424
</StackPanel>
2525
<CheckBox Content="{x:Static p:Resources.Show_Frame_Rate}" Margin="0,20,0,0" IsChecked="{Binding Source={x:Static props:Settings.Default},Path=ShowFPS,Mode=TwoWay}"/>
26+
<StackPanel Orientation="Horizontal" Margin="0,20,0,0">
27+
<Label Content="{x:Static p:Resources.Buffer_Precision}" Padding="0" VerticalContentAlignment="Center" />
28+
<ComboBox Margin="10,0,0,0" SelectedIndex="{Binding Source={x:Static props:Settings.Default},Path=BufferPrecision,Mode=TwoWay}">
29+
<ComboBoxItem Content="{x:Static p:Resources.Buffer_Precision_Default}" />
30+
<ComboBoxItem Content="8_UNORM" />
31+
<ComboBoxItem Content="16_UNORM" />
32+
<ComboBoxItem Content="16_FLOAT" />
33+
<ComboBoxItem Content="32_FLOAT" />
34+
</ComboBox>
35+
</StackPanel>
2636
</StackPanel>
2737
</Page>
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
33
<Style TargetType="Button">
44
<Setter Property="Padding" Value="10,5" />
55
</Style>
6+
<Style TargetType="ComboBox">
7+
<Setter Property="Padding" Value="6,5,5,5" />
8+
</Style>
69
</ResourceDictionary>

‎Magpie/Properties/Resources.Designer.cs‎

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Magpie/Properties/Resources.resx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
<data name="Application" xml:space="preserve">
136136
<value>Application</value>
137137
</data>
138+
<data name="Buffer_Precision" xml:space="preserve">
139+
<value>Intermediate Texture Precision</value>
140+
</data>
141+
<data name="Buffer_Precision_Default" xml:space="preserve">
142+
<value>Default</value>
143+
</data>
138144
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
139145
<data name="BuiltInScaleModels" type="System.Resources.ResXFileRef, System.Windows.Forms">
140146
<value>..\Assets\BuiltInScaleModels.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>

‎Magpie/Properties/Resources.zh-CN.resx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
<data name="Application" xml:space="preserve">
136136
<value>应用程序</value>
137137
</data>
138+
<data name="Buffer_Precision" xml:space="preserve">
139+
<value>中间纹理精度</value>
140+
</data>
141+
<data name="Buffer_Precision_Default" xml:space="preserve">
142+
<value>默认</value>
143+
</data>
138144
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
139145
<data name="BuiltInScaleModels" type="System.Resources.ResXFileRef, System.Windows.Forms">
140146
<value>..\Assets\BuiltInScaleModels.zh-CN.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>

‎Magpie/Properties/Settings.Designer.cs‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)