1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use raw_window_handle::RawWindowHandle;
use windows::Win32::{Foundation::HWND, Graphics::Direct2D::Common::*};

#[derive(Clone, Copy, Debug)]
#[repr(transparent)]
pub(crate) struct Wrapper<T>(pub(crate) T);

pub type Rgba<T> = gecl::Rgba<T>;

impl From<Wrapper<Rgba<f32>>> for D2D1_COLOR_F {
    #[inline]
    fn from(src: Wrapper<Rgba<f32>>) -> Self {
        Self {
            r: src.0.r,
            g: src.0.g,
            b: src.0.b,
            a: src.0.a,
        }
    }
}

pub trait WindowHandle {
    fn handle(&self) -> HWND;
}

impl WindowHandle for HWND {
    #[inline]
    fn handle(&self) -> HWND {
        *self
    }
}

impl WindowHandle for RawWindowHandle {
    #[inline]
    fn handle(&self) -> HWND {
        let RawWindowHandle::Win32(handle) = self else { panic!() };
        HWND(handle.hwnd as _)
    }
}

impl WindowHandle for *const std::ffi::c_void {
    #[inline]
    fn handle(&self) -> HWND {
        HWND(*self as _)
    }
}

impl WindowHandle for *mut std::ffi::c_void {
    #[inline]
    fn handle(&self) -> HWND {
        HWND(*self as _)
    }
}

impl WindowHandle for isize {
    #[inline]
    fn handle(&self) -> HWND {
        HWND(*self)
    }
}