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