Skip to content

Commit 3df8eba

Browse files
committed
Remove unused dependencies and update overlay logic: Eliminate 'windows-numerics' from Cargo files, adjust frame rate handling in README, and improve overlay test structure for clarity.
1 parent 61139f2 commit 3df8eba

File tree

5 files changed

+11
-26
lines changed

5 files changed

+11
-26
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@ edition = "2021"
55

66
[dependencies]
77
windows = { git = "https://github.com/microsoft/windows-rs", features = [
8-
"Win32_System_Com",
98
"Win32_Graphics_Direct2D_Common",
109
"Win32_Graphics_Direct3D",
1110
"Win32_Graphics_Direct3D11",
1211
"Win32_Graphics_Dxgi_Common",
1312
"Win32_Graphics_Gdi",
14-
"Win32_System_LibraryLoader",
15-
"Win32_System_Performance",
16-
"Win32_System_SystemInformation",
17-
"Win32_UI_Animation",
1813
"Win32_UI_WindowsAndMessaging",
1914
] }
20-
windows-numerics = { git = "https://github.com/microsoft/windows-rs" }
2115

2216
[profile.release]
2317
lto = true

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ let mut window_info = WINDOWINFO::default();
2222
GetWindowInfo(game_window, &mut window_info);
2323

2424
// init ez-overlay with window_info and draw_rect_list
25-
const FRAME_RATE: u64 = 60;
2625
let draw_rect_list_clone = Arc::clone(&draw_rect_list);
2726
std::thread::spawn(move || {
2827
let mut overlay = windows_ez_overlay::Overlay::new(
@@ -31,10 +30,9 @@ std::thread::spawn(move || {
3130
window_info.rcClient.right,
3231
window_info.rcClient.bottom,
3332
draw_rect_list_clone,
34-
FRAME_RATE,
3533
true,
36-
);
37-
let _ = overlay.window_loop();
34+
).unwrap();
35+
overlay.run().unwrap();
3836
});
3937

4038
// ... do your stuff ...

src/overlay.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use windows::{
55
Win32::Graphics::Dxgi::Common::*, Win32::Graphics::Dxgi::*, Win32::Graphics::Gdi::*,
66
Win32::UI::WindowsAndMessaging::*,
77
};
8-
use windows_numerics::*;
98

109
pub struct Window {
1110
handle: HWND,
@@ -88,6 +87,8 @@ impl Window {
8887
debug_assert!(!handle.is_invalid());
8988
debug_assert!(handle == self.handle);
9089

90+
SetLayeredWindowAttributes(handle, COLORREF(0), 0, LWA_COLORKEY)?;
91+
9192
let mut message = MSG::default();
9293
loop {
9394
if self.visible {
@@ -182,7 +183,7 @@ impl Window {
182183
},
183184
brush,
184185
2.0,
185-
None,
186+
&self.style,
186187
);
187188
if self.draw_bottom_line_flag {
188189
let rect_width = rect.right - rect.left;
@@ -275,7 +276,7 @@ fn create_brush(target: &ID2D1DeviceContext) -> Result<ID2D1SolidColorBrush> {
275276

276277
let properties = D2D1_BRUSH_PROPERTIES {
277278
opacity: 0.8,
278-
transform: Matrix3x2::identity(),
279+
..Default::default()
279280
};
280281

281282
unsafe { target.CreateSolidColorBrush(&color, Some(&properties)) }
@@ -389,7 +390,7 @@ fn create_swapchain(device: &ID3D11Device, window: HWND) -> Result<IDXGISwapChai
389390
},
390391
BufferUsage: DXGI_USAGE_RENDER_TARGET_OUTPUT,
391392
BufferCount: 2,
392-
SwapEffect: DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
393+
SwapEffect: DXGI_SWAP_EFFECT_DISCARD,
393394
..Default::default()
394395
};
395396

tests/overlay_test.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
use windows::Win32::System::Com::{CoInitializeEx, COINIT_MULTITHREADED};
2-
31
#[test]
42
fn overlay_test() {
5-
unsafe {
6-
CoInitializeEx(None, COINIT_MULTITHREADED).ok().unwrap();
7-
}
8-
9-
const FRAME_RATE: u64 = 60;
10-
113
let rect_list = std::sync::Arc::new(std::sync::RwLock::new(vec![
124
windows::Win32::Foundation::RECT {
135
left: 0,
@@ -32,8 +24,10 @@ fn overlay_test() {
3224
});
3325
}
3426

27+
const FRAME_RATE: u64 = 60;
28+
const TICK_RATE: std::time::Duration = std::time::Duration::from_millis(1000 / FRAME_RATE);
29+
3530
let mut frame_count = 0;
36-
let tick_rate = std::time::Duration::from_millis(1000 / FRAME_RATE);
3731
let mut last_tick = std::time::Instant::now();
3832
loop {
3933
{
@@ -46,8 +40,7 @@ fn overlay_test() {
4640
});
4741
}
4842

49-
let timeout = tick_rate.saturating_sub(last_tick.elapsed());
50-
std::thread::sleep(timeout);
43+
std::thread::sleep(TICK_RATE.saturating_sub(last_tick.elapsed()));
5144
last_tick = std::time::Instant::now();
5245

5346
frame_count += 1;

0 commit comments

Comments
 (0)