windows_capture/
settings.rs

1use windows::Graphics::Capture::GraphicsCaptureItem;
2
3#[derive(Eq, PartialEq, Clone, Copy, Debug)]
4pub enum ColorFormat {
5    Rgba16F = 10,
6    Rgba8 = 28,
7    Bgra8 = 87,
8}
9
10impl Default for ColorFormat {
11    #[must_use]
12    #[inline]
13    fn default() -> Self {
14        Self::Rgba8
15    }
16}
17
18#[derive(Eq, PartialEq, Clone, Copy, Debug)]
19pub enum CursorCaptureSettings {
20    Default,
21    WithCursor,
22    WithoutCursor,
23}
24
25#[derive(Eq, PartialEq, Clone, Copy, Debug)]
26pub enum DrawBorderSettings {
27    Default,
28    WithBorder,
29    WithoutBorder,
30}
31
32#[derive(Eq, PartialEq, Clone, Debug)]
33/// Represents the settings for screen capturing.
34pub struct Settings<Flags, T: TryInto<GraphicsCaptureItem>> {
35    /// The graphics capture item to capture.
36    pub(crate) item: T,
37    /// Specifies whether to capture the cursor.
38    pub(crate) cursor_capture: CursorCaptureSettings,
39    /// Specifies whether to draw a border around the captured region.
40    pub(crate) draw_border: DrawBorderSettings,
41    /// The color format for the captured graphics.
42    pub(crate) color_format: ColorFormat,
43    /// Additional flags for capturing graphics.
44    pub(crate) flags: Flags,
45}
46
47impl<Flags, T: TryInto<GraphicsCaptureItem>> Settings<Flags, T> {
48    /// Create Capture Settings
49    ///
50    /// # Arguments
51    ///
52    /// * `item` - The graphics capture item.
53    /// * `capture_cursor` - Whether to capture the cursor or not.
54    /// * `draw_border` - Whether to draw a border around the captured region or not.
55    /// * `color_format` - The desired color format for the captured frame.
56    /// * `flags` - Additional flags for the capture settings that will be passed to user defined `new` function.
57    #[must_use]
58    #[inline]
59    pub const fn new(
60        item: T,
61        cursor_capture: CursorCaptureSettings,
62        draw_border: DrawBorderSettings,
63        color_format: ColorFormat,
64        flags: Flags,
65    ) -> Self {
66        Self {
67            item,
68            cursor_capture,
69            draw_border,
70            color_format,
71            flags,
72        }
73    }
74
75    /// Get the item
76    ///
77    /// # Returns
78    ///
79    /// The item to be captured
80    #[must_use]
81    #[inline]
82    pub const fn item(&self) -> &T {
83        &self.item
84    }
85
86    /// Get the cursor capture settings
87    ///
88    /// # Returns
89    ///
90    /// The cursor capture settings
91    #[must_use]
92    #[inline]
93    pub const fn cursor_capture(&self) -> CursorCaptureSettings {
94        self.cursor_capture
95    }
96
97    /// Get the draw border settings
98    ///
99    /// # Returns
100    ///
101    /// The draw border settings
102    #[must_use]
103    #[inline]
104    pub const fn draw_border(&self) -> DrawBorderSettings {
105        self.draw_border
106    }
107
108    /// Get the color format
109    ///
110    /// # Returns
111    ///
112    /// The color format
113    #[must_use]
114    #[inline]
115    pub const fn color_format(&self) -> ColorFormat {
116        self.color_format
117    }
118
119    /// Get the flags
120    ///
121    /// # Returns
122    ///
123    /// The flags
124    #[must_use]
125    #[inline]
126    pub const fn flags(&self) -> &Flags {
127        &self.flags
128    }
129}