Skip to main content

obws/requests/
scene_items.rs

1//! Requests related to scene items.
2
3use serde::Serialize;
4use serde_with::skip_serializing_none;
5
6use super::{ids::DestinationSceneId, scenes::SceneId, sources::SourceId};
7use crate::common::{Alignment, BlendMode, BoundsType};
8
9#[derive(Serialize)]
10#[serde(tag = "requestType", content = "requestData")]
11pub(crate) enum Request<'a> {
12    #[serde(rename = "GetSceneItemList")]
13    List {
14        /// Identifier of the scene to get the items of.
15        #[serde(flatten)]
16        scene: SceneId<'a>,
17    },
18    #[serde(rename = "GetGroupSceneItemList")]
19    ListGroup {
20        /// Identifier of the group to get the items of.
21        #[serde(flatten)]
22        scene: SceneId<'a>,
23    },
24    #[serde(rename = "GetSceneItemId")]
25    Id(Id<'a>),
26    #[serde(rename = "GetSceneItemSource")]
27    Source(Source<'a>),
28    #[serde(rename = "CreateSceneItem")]
29    Create(CreateSceneItem<'a>),
30    #[serde(rename = "RemoveSceneItem")]
31    Remove {
32        /// Identifier of the scene the item is in.
33        #[serde(flatten)]
34        scene: SceneId<'a>,
35        /// Numeric ID of the scene item.
36        #[serde(rename = "sceneItemId")]
37        item_id: i64,
38    },
39    #[serde(rename = "DuplicateSceneItem")]
40    Duplicate(Duplicate<'a>),
41    #[serde(rename = "GetSceneItemTransform")]
42    Transform {
43        /// Identifier of the scene the item is in.
44        #[serde(flatten)]
45        scene: SceneId<'a>,
46        /// Numeric ID of the scene item.
47        #[serde(rename = "sceneItemId")]
48        item_id: i64,
49    },
50    #[serde(rename = "SetSceneItemTransform")]
51    SetTransform(SetTransform<'a>),
52    #[serde(rename = "GetSceneItemEnabled")]
53    Enabled {
54        /// Identifier of the scene the item is in.
55        #[serde(flatten)]
56        scene: SceneId<'a>,
57        /// Numeric ID of the scene item.
58        #[serde(rename = "sceneItemId")]
59        item_id: i64,
60    },
61    #[serde(rename = "SetSceneItemEnabled")]
62    SetEnabled(SetEnabled<'a>),
63    #[serde(rename = "GetSceneItemLocked")]
64    Locked {
65        /// Identifier of the scene the item is in.
66        #[serde(flatten)]
67        scene: SceneId<'a>,
68        /// Numeric ID of the scene item.
69        #[serde(rename = "sceneItemId")]
70        item_id: i64,
71    },
72    #[serde(rename = "SetSceneItemLocked")]
73    SetLocked(SetLocked<'a>),
74    #[serde(rename = "GetSceneItemIndex")]
75    Index {
76        /// Identifier of the scene the item is in.
77        #[serde(flatten)]
78        scene: SceneId<'a>,
79        /// Numeric ID of the scene item.
80        #[serde(rename = "sceneItemId")]
81        item_id: i64,
82    },
83    #[serde(rename = "SetSceneItemIndex")]
84    SetIndex(SetIndex<'a>),
85    #[serde(rename = "GetSceneItemBlendMode")]
86    BlendMode {
87        /// Identifier of the scene the item is in.
88        #[serde(flatten)]
89        scene: SceneId<'a>,
90        ///  Numeric ID of the scene item.
91        #[serde(rename = "sceneItemId")]
92        item_id: i64,
93    },
94    #[serde(rename = "SetSceneItemBlendMode")]
95    SetBlendMode(SetBlendMode<'a>),
96    #[serde(rename = "GetSceneItemPrivateSettings")]
97    PrivateSettings {
98        /// Identifier of the scene the item is in.
99        #[serde(flatten)]
100        scene: SceneId<'a>,
101        /// Numeric ID of the scene item.
102        #[serde(rename = "sceneItemId")]
103        item_id: i64,
104    },
105    #[serde(rename = "SetSceneItemPrivateSettings")]
106    SetPrivateSettings(SetPrivateSettingsInternal<'a>),
107}
108
109impl<'a> From<Request<'a>> for super::RequestType<'a> {
110    fn from(value: Request<'a>) -> Self {
111        super::RequestType::SceneItems(value)
112    }
113}
114
115/// Request information for [`crate::client::SceneItems::id`].
116#[skip_serializing_none]
117#[derive(Default, Serialize)]
118#[cfg_attr(feature = "builder", derive(bon::Builder))]
119pub struct Id<'a> {
120    /// Identifier of the scene or group to search in.
121    #[serde(flatten)]
122    pub scene: SceneId<'a>,
123    /// Name of the source to find.
124    #[serde(rename = "sourceName")]
125    pub source: &'a str,
126    /// Number of matches to skip during search.
127    ///
128    /// `>= 0` means first forward. `-1` means last (top) item.
129    #[serde(rename = "searchOffset")]
130    pub search_offset: Option<i32>,
131}
132
133/// Request information for [`crate::client::SceneItems::source`].
134#[skip_serializing_none]
135#[derive(Default, Serialize)]
136#[cfg_attr(feature = "builder", derive(bon::Builder))]
137pub struct Source<'a> {
138    /// Identifier of the scene the item is in.
139    #[serde(flatten)]
140    pub scene: SceneId<'a>,
141    /// Numeric ID of the scene item.
142    #[serde(rename = "sceneItemId")]
143    pub item_id: i64,
144}
145
146/// Request information for [`crate::client::SceneItems::create`].
147#[skip_serializing_none]
148#[derive(Default, Serialize)]
149#[cfg_attr(feature = "builder", derive(bon::Builder))]
150pub struct CreateSceneItem<'a> {
151    /// Identifier of the scene to create the new item in.
152    #[serde(flatten)]
153    pub scene: SceneId<'a>,
154    /// Identifier of the source to add to the scene.
155    #[serde(flatten)]
156    pub source: SourceId<'a>,
157    /// Enable state to apply to the scene item on creation.
158    #[serde(rename = "sceneItemEnabled")]
159    pub enabled: Option<bool>,
160}
161
162/// Request information for [`crate::client::SceneItems::duplicate`].
163#[skip_serializing_none]
164#[derive(Default, Serialize)]
165#[cfg_attr(feature = "builder", derive(bon::Builder))]
166pub struct Duplicate<'a> {
167    /// Identifier of the scene the item is in.
168    #[serde(flatten)]
169    pub scene: SceneId<'a>,
170    /// Numeric ID of the scene item.
171    #[serde(rename = "sceneItemId")]
172    pub item_id: i64,
173    /// Identifier of the scene to create the duplicated item in.
174    #[serde(flatten)]
175    pub destination: Option<DestinationSceneId<'a>>,
176}
177
178/// Request information for [`crate::client::SceneItems::set_transform`].
179#[derive(Default, Serialize)]
180#[cfg_attr(feature = "builder", derive(bon::Builder))]
181pub struct SetTransform<'a> {
182    /// Identifier of the scene the item is in.
183    #[serde(flatten)]
184    pub scene: SceneId<'a>,
185    /// Numeric ID of the scene item.
186    #[serde(rename = "sceneItemId")]
187    pub item_id: i64,
188    /// Object containing scene item transform info to update.
189    #[serde(rename = "sceneItemTransform")]
190    pub transform: SceneItemTransform,
191}
192
193/// Request information for [`crate::client::SceneItems::set_transform`] as part of
194/// [`SetTransform`].
195#[skip_serializing_none]
196#[derive(Default, Serialize)]
197#[cfg_attr(feature = "builder", derive(bon::Builder))]
198pub struct SceneItemTransform {
199    /// Position (or offset) on the screen.
200    #[serde(rename = "position", flatten)]
201    pub position: Option<Position>,
202    /// The clockwise rotation of the scene item in degrees around the point of alignment.
203    #[serde(rename = "rotation")]
204    pub rotation: Option<f32>,
205    /// Scaling of the item.
206    #[serde(rename = "scale", flatten)]
207    pub scale: Option<Scale>,
208    /// The point on the source that the item is manipulated from.
209    #[serde(rename = "alignment")]
210    pub alignment: Option<Alignment>,
211    /// Bound restrictions on the item.
212    #[serde(rename = "bounds", flatten)]
213    pub bounds: Option<Bounds>,
214    /// Cropping values on up to 4 sides.
215    #[serde(rename = "crop", flatten)]
216    pub crop: Option<Crop>,
217}
218
219impl From<crate::responses::scene_items::SceneItemTransform> for SceneItemTransform {
220    fn from(t: crate::responses::scene_items::SceneItemTransform) -> Self {
221        Self {
222            position: Some(Position {
223                x: Some(t.position_x),
224                y: Some(t.position_y),
225            }),
226            rotation: Some(t.rotation),
227            scale: Some(Scale {
228                x: Some(t.scale_x),
229                y: Some(t.scale_y),
230            }),
231            alignment: Some(t.alignment),
232            bounds: Some(Bounds {
233                r#type: Some(t.bounds_type),
234                alignment: Some(t.bounds_alignment),
235                width: Some(t.bounds_width),
236                height: Some(t.bounds_height),
237            }),
238            crop: Some(Crop {
239                left: Some(t.crop_left),
240                right: Some(t.crop_right),
241                top: Some(t.crop_top),
242                bottom: Some(t.crop_bottom),
243            }),
244        }
245    }
246}
247
248/// Request information for [`crate::client::SceneItems::set_transform`] as part of
249/// [`SceneItemTransform`].
250#[skip_serializing_none]
251#[derive(Default, Serialize)]
252#[cfg_attr(feature = "builder", derive(bon::Builder))]
253pub struct Position {
254    /// The x position of the source from the left.
255    #[serde(rename = "positionX")]
256    pub x: Option<f32>,
257    /// The y position of the source from the top.
258    #[serde(rename = "positionY")]
259    pub y: Option<f32>,
260}
261
262/// Request information for [`crate::client::SceneItems::set_transform`] as part of
263/// [`SceneItemTransform`].
264#[skip_serializing_none]
265#[derive(Default, Serialize)]
266#[cfg_attr(feature = "builder", derive(bon::Builder))]
267pub struct Scale {
268    /// The x-scale factor of the source.
269    #[serde(rename = "scaleX")]
270    pub x: Option<f32>,
271    /// The y-scale factor of the source.
272    #[serde(rename = "scaleY")]
273    pub y: Option<f32>,
274}
275
276/// Request information for [`crate::client::SceneItems::set_transform`] as part of
277/// [`SceneItemTransform`].
278#[skip_serializing_none]
279#[derive(Default, Serialize)]
280#[cfg_attr(feature = "builder", derive(bon::Builder))]
281pub struct Bounds {
282    /// Type of bounding box.
283    #[serde(rename = "boundsType")]
284    pub r#type: Option<BoundsType>,
285    /// Alignment of the bounding box.
286    #[serde(rename = "boundsAlignment")]
287    pub alignment: Option<Alignment>,
288    /// Width of the bounding box.
289    #[serde(rename = "boundsWidth")]
290    pub width: Option<f32>,
291    /// Height of the bounding box.
292    #[serde(rename = "boundsHeight")]
293    pub height: Option<f32>,
294}
295
296/// Request information for [`crate::client::SceneItems::set_transform`] as part of
297/// [`SceneItemTransform`].
298#[skip_serializing_none]
299#[derive(Default, Serialize)]
300#[cfg_attr(feature = "builder", derive(bon::Builder))]
301pub struct Crop {
302    /// The number of pixels cropped off the left of the source before scaling.
303    #[serde(rename = "cropLeft")]
304    pub left: Option<u32>,
305    /// The number of pixels cropped off the right of the source before scaling.
306    #[serde(rename = "cropRight")]
307    pub right: Option<u32>,
308    /// The number of pixels cropped off the top of the source before scaling.
309    #[serde(rename = "cropTop")]
310    pub top: Option<u32>,
311    /// The number of pixels cropped off the bottom of the source before scaling.
312    #[serde(rename = "cropBottom")]
313    pub bottom: Option<u32>,
314}
315
316/// Request information for [`crate::client::SceneItems::set_enabled`].
317#[derive(Default, Serialize)]
318#[cfg_attr(feature = "builder", derive(bon::Builder))]
319pub struct SetEnabled<'a> {
320    /// Identifier of the scene the item is in.
321    #[serde(flatten)]
322    pub scene: SceneId<'a>,
323    /// Numeric ID of the scene item.
324    #[serde(rename = "sceneItemId")]
325    pub item_id: i64,
326    /// New enable state of the scene item.
327    #[serde(rename = "sceneItemEnabled")]
328    pub enabled: bool,
329}
330
331/// Request information for [`crate::client::SceneItems::set_locked`].
332#[derive(Default, Serialize)]
333#[cfg_attr(feature = "builder", derive(bon::Builder))]
334pub struct SetLocked<'a> {
335    /// Identifier of the scene the item is in.
336    #[serde(flatten)]
337    pub scene: SceneId<'a>,
338    /// Numeric ID of the scene item.
339    #[serde(rename = "sceneItemId")]
340    pub item_id: i64,
341    /// New lock state of the scene item.
342    #[serde(rename = "sceneItemLocked")]
343    pub locked: bool,
344}
345
346/// Request information for [`crate::client::SceneItems::set_index`].
347#[derive(Default, Serialize)]
348#[cfg_attr(feature = "builder", derive(bon::Builder))]
349pub struct SetIndex<'a> {
350    /// Identifier of the scene the item is in.
351    #[serde(flatten)]
352    pub scene: SceneId<'a>,
353    /// Numeric ID of the scene item.
354    #[serde(rename = "sceneItemId")]
355    pub item_id: i64,
356    /// New index position of the scene item.
357    #[serde(rename = "sceneItemIndex")]
358    pub index: u32,
359}
360
361/// Request information for [`crate::client::SceneItems::set_blend_mode`].
362#[derive(Serialize)]
363#[cfg_attr(feature = "builder", derive(bon::Builder))]
364pub struct SetBlendMode<'a> {
365    /// Identifier of the scene the item is in.
366    #[serde(flatten)]
367    pub scene: SceneId<'a>,
368    /// Numeric ID of the scene item.
369    #[serde(rename = "sceneItemId")]
370    pub item_id: i64,
371    /// New blend mode.
372    #[serde(rename = "sceneItemBlendMode")]
373    pub mode: BlendMode,
374}
375
376/// Request information for [`crate::client::SceneItems::set_private_settings`].
377#[cfg_attr(feature = "builder", derive(bon::Builder))]
378pub struct SetPrivateSettings<'a, T> {
379    /// Identifier of the scene the item is in.
380    pub scene: SceneId<'a>,
381    /// Numeric ID of the scene item.
382    pub item_id: i64,
383    /// Object of settings to apply.
384    pub settings: &'a T,
385}
386
387/// Request information for [`crate::client::SceneItems::set_private_settings`].
388#[skip_serializing_none]
389#[derive(Default, Serialize)]
390pub(crate) struct SetPrivateSettingsInternal<'a> {
391    /// Identifier of the scene the item is in.
392    #[serde(flatten)]
393    pub scene: SceneId<'a>,
394    /// Numeric ID of the scene item.
395    #[serde(rename = "sceneItemId")]
396    pub item_id: i64,
397    /// Object of settings to apply.
398    #[serde(rename = "sceneItemSettings")]
399    pub settings: serde_json::Value,
400}