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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use super::builder::WindowFlags;

/// A format of a [`super::Window`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum WindowFormat {
    /// A normal window.
    Normal,
    /// A full screen window.
    FullScreen,
    /// A full screen window on the current desktop.
    FullScreenWithCurrentDesktop,
    /// A minimized window.
    Minimized,
    /// A maximized window.
    Maximized,
}

impl From<WindowFlags> for WindowFormat {
    fn from(flags: WindowFlags) -> Self {
        if flags.contains(WindowFlags::FULLSCREEN) {
            WindowFormat::FullScreen
        } else if flags.contains(WindowFlags::FULLSCREEN_DESKTOP) {
            WindowFormat::FullScreenWithCurrentDesktop
        } else if flags.contains(WindowFlags::MINIMIZED) {
            WindowFormat::Minimized
        } else if flags.contains(WindowFlags::MAXIMIZED) {
            WindowFormat::Maximized
        } else {
            WindowFormat::Normal
        }
    }
}

/// A kind of a window's context.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum WindowContextKind {
    /// Using software render context.
    Software,
    /// Using OpenGL render context.
    OpenGl,
    /// Using Vulkan render context.
    Vulkan,
    /// Using Metal render context.
    Metal,
}

impl From<WindowFlags> for WindowContextKind {
    fn from(flags: WindowFlags) -> Self {
        if flags.contains(WindowFlags::OPENGL) {
            WindowContextKind::OpenGl
        } else if flags.contains(WindowFlags::VULKAN) {
            WindowContextKind::Vulkan
        } else if flags.contains(WindowFlags::METAL) {
            WindowContextKind::Metal
        } else {
            WindowContextKind::Software
        }
    }
}

/// A state of a [`super::Window`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WindowState {
    /// A format of the window.
    pub format: WindowFormat,
    /// A kind of render context of the window.
    pub context_kind: WindowContextKind,
    /// Whether the window is hidden.
    pub hidden: bool,
    /// Whether the window is borderless.
    pub borderless: bool,
    /// Whether the window is resizable.
    pub resizable: bool,
    /// Whether the window is grabbed the input.
    pub input_grabbed: bool,
    /// Whether the window is on focus.
    pub on_focus: bool,
    /// Whether the window is on the mouse.
    pub on_mouse: bool,
    /// Whether the window comes from the foreign.
    pub foreign: bool,
    /// Whether the window allows high dpi.
    pub allow_high_dpi: bool,
    /// Whether the window captures the mouse.
    pub mouse_capture: bool,
}

impl From<WindowFlags> for WindowState {
    fn from(flags: WindowFlags) -> Self {
        Self {
            format: flags.into(),
            context_kind: flags.into(),
            hidden: flags.contains(WindowFlags::HIDDEN),
            borderless: flags.contains(WindowFlags::BORDERLESS),
            resizable: flags.contains(WindowFlags::RESIZABLE),
            input_grabbed: flags.contains(WindowFlags::INPUT_GRABBED),
            on_focus: flags.contains(WindowFlags::INPUT_FOCUS),
            on_mouse: flags.contains(WindowFlags::MOUSE_FOCUS),
            foreign: flags.contains(WindowFlags::FOREIGN),
            allow_high_dpi: flags.contains(WindowFlags::ALLOW_HIGHDPI),
            mouse_capture: flags.contains(WindowFlags::MOUSE_CAPTURE),
        }
    }
}