libobs_wrapper\display/
creation_data.rs1use libobs::{gs_init_data, gs_window};
2use num_traits::ToPrimitive;
3
4use crate::unsafe_send::Sendable;
5
6use super::{GsColorFormat, GsZstencilFormat};
7
8
9#[derive(Clone)]
10pub struct ObsDisplayCreationData {
11 #[cfg(target_family = "windows")]
12 pub(super) parent_window: Sendable<windows::Win32::Foundation::HWND>,
13 pub(super) x: u32,
14 pub(super) y: u32,
15 pub(super) width: u32,
16 pub(super) height: u32,
17 pub(super) format: GsColorFormat,
18 pub(super) zsformat: GsZstencilFormat,
19 pub(super) adapter: u32,
20 pub(super) backbuffers: u32,
21 pub(super) background_color: u32,
22}
23
24impl ObsDisplayCreationData {
25 #[cfg(target_family = "windows")]
26 pub fn new(parent_window: isize, x: u32, y: u32, width: u32, height: u32) -> Self {
27 use std::os::raw::c_void;
28 use windows::Win32::Foundation::HWND;
29
30 Self {
31 parent_window: Sendable(HWND(parent_window as *mut c_void)),
32 format: GsColorFormat::BGRA,
33 zsformat: GsZstencilFormat::ZSNone,
34 x,
35 y,
36 width,
37 height,
38 adapter: 0,
39 backbuffers: 0,
40 background_color: 0
41 }
42 }
43
44 pub fn set_format(mut self, format: GsColorFormat) -> Self {
45 self.format = format;
46 self
47 }
48
49 pub fn set_zsformat(mut self, zsformat: GsZstencilFormat) -> Self {
50 self.zsformat = zsformat;
51 self
52 }
53
54 pub fn set_adapter(mut self, adapter: u32) -> Self {
55 self.adapter = adapter;
56 self
57 }
58
59 pub fn set_backbuffers(mut self, backbuffers: u32) -> Self {
60 self.backbuffers = backbuffers;
61 self
62 }
63
64 pub fn set_background_color(mut self, background_color: u32) -> Self {
65 self.background_color = background_color;
66 self
67 }
68
69 pub(super) fn build(self, window: gs_window) -> gs_init_data {
70 let data = gs_init_data {
71 cx: self.width,
72 cy: self.height,
73 format: self.format.to_i32().unwrap(),
74 zsformat: self.zsformat.to_i32().unwrap(),
75 window,
76 adapter: self.adapter,
77 num_backbuffers: self.backbuffers,
78 };
79
80 data
81 }
82}