obs_wrapper/source/
traits.rs

1use obs_sys::{obs_key_event, obs_mouse_event};
2
3use super::context::{CreatableSourceContext, GlobalContext, VideoRenderContext};
4use super::video::VideoDataContext;
5use super::{audio::AudioDataContext, media::MediaState};
6use super::{EnumActiveContext, EnumAllContext, SourceContext, SourceType};
7use crate::data::DataObj;
8use crate::properties::Properties;
9use crate::string::ObsString;
10
11pub trait Sourceable: Sized {
12    fn get_id() -> ObsString;
13    fn get_type() -> SourceType;
14    fn create(create: &mut CreatableSourceContext<Self>, source: SourceContext) -> Self;
15}
16
17macro_rules! simple_trait {
18    ($($f:ident => $t:ident $(-> $ret:ty)?)*) => ($(
19        pub trait $t: Sized {
20            fn $f(&mut self) $(-> $ret)?;
21        }
22    )*)
23}
24
25pub trait GetNameSource {
26    fn get_name() -> ObsString;
27}
28
29simple_trait!(
30    get_width => GetWidthSource -> u32
31    get_height => GetHeightSource -> u32
32    activate => ActivateSource
33    deactivate => DeactivateSource
34);
35
36pub trait UpdateSource: Sized {
37    fn update(&mut self, settings: &mut DataObj, context: &mut GlobalContext);
38}
39
40pub trait MouseWheelSource: Sized {
41    fn mouse_wheel(&mut self, event: obs_mouse_event, xdelta: i32, ydelta: i32);
42}
43
44pub trait MouseClickSource: Sized {
45    fn mouse_click(
46        &mut self,
47        event: obs_mouse_event,
48        button: super::MouseButton,
49        pressed: bool,
50        click_count: u8,
51    );
52}
53
54pub trait MouseMoveSource: Sized {
55    fn mouse_move(&mut self, event: obs_mouse_event, leave: bool);
56}
57
58pub trait KeyClickSource: Sized {
59    fn key_click(&mut self, event: obs_key_event, pressed: bool);
60}
61
62pub trait FocusSource: Sized {
63    fn focus(&mut self, focused: bool);
64}
65
66pub trait VideoRenderSource: Sized {
67    fn video_render(&mut self, context: &mut GlobalContext, render: &mut VideoRenderContext);
68}
69
70pub trait AudioRenderSource: Sized {
71    fn audio_render(&mut self, context: &mut GlobalContext);
72}
73
74pub trait GetPropertiesSource: Sized {
75    fn get_properties(&mut self) -> Properties;
76}
77
78pub trait VideoTickSource: Sized {
79    fn video_tick(&mut self, seconds: f32);
80}
81
82pub trait EnumActiveSource: Sized {
83    fn enum_active_sources(&mut self, context: &EnumActiveContext);
84}
85
86pub trait EnumAllSource: Sized {
87    fn enum_all_sources(&mut self, context: &EnumAllContext);
88}
89
90simple_trait!(
91    transition_start => TransitionStartSource
92    transition_stop => TransitionStopSource
93);
94
95pub trait FilterAudioSource: Sized {
96    fn filter_audio(&mut self, audio: &mut AudioDataContext);
97}
98
99pub trait FilterVideoSource: Sized {
100    fn filter_video(&mut self, audio: &mut VideoDataContext);
101}
102
103pub trait MediaPlayPauseSource: Sized {
104    fn play_pause(&mut self, pause: bool);
105}
106
107pub trait MediaGetStateSource: Sized {
108    fn get_state(&mut self) -> MediaState;
109}
110
111pub trait MediaSetTimeSource: Sized {
112    fn set_time(&mut self, milliseconds: i64);
113}
114
115pub trait GetDefaultsSource {
116    fn get_defaults(settings: &mut DataObj);
117}
118
119simple_trait!(
120    restart => MediaRestartSource
121    stop => MediaStopSource
122    next => MediaNextSource
123    previous => MediaPreviousSource
124    get_duration => MediaGetDurationSource -> i64
125    get_time => MediaGetTimeSource -> i64
126);