diff --git a/Cargo.lock b/Cargo.lock index a4970ff..4b88111 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -385,7 +385,7 @@ checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" [[package]] name = "obs-shaderfilter-plus" -version = "0.1.1" +version = "0.3.1" dependencies = [ "anyhow", "apodize", diff --git a/Cargo.toml b/Cargo.toml index a407a77..dc41c2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "obs-shaderfilter-plus" -version = "0.3.0" +version = "0.3.1" authors = ["Jakub Hlusička "] edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index 256fd94..3ffad46 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -413,13 +413,14 @@ struct Data { property_message_display: bool, settings_update_requested: Arc, + shown: bool, enabled: Arc, } impl Data { pub fn new(source: SourceContext) -> Self { let settings_update_requested = Arc::new(AtomicBool::new(true)); - let enabled = Arc::new(AtomicBool::new(true)); + let enabled = Arc::new(AtomicBool::new(false)); let enabled_clone = enabled.clone(); Self { @@ -482,6 +483,7 @@ impl Data { }, property_message_display: false, settings_update_requested, + shown: false, enabled, } } @@ -556,10 +558,18 @@ impl VideoTickSource for ShaderFilterPlus { let elapsed_time_previous = data.elapsed_time_previous.replace(elapsed_time) .unwrap_or(elapsed_time); let now = Instant::now(); - let elapsed_time_since_shown = if let Some(shown_at) = data.shown_at.as_ref() { - shown_at.elapsed().as_secs_f32() + let elapsed_time_since_shown = if data.shown { + if let Some(shown_at) = data.shown_at.as_ref() { + shown_at.elapsed().as_secs_f32() + } else { + data.shown_at = Some(now); + 0.0 + } } else { - data.shown_at = Some(now); + if data.shown_at.is_some() { + data.shown_at = None; + } + 0.0 }; let elapsed_time_since_enabled = if data.enabled.load(Ordering::SeqCst) { @@ -574,7 +584,7 @@ impl VideoTickSource for ShaderFilterPlus { data.enabled_at = None; } - std::f32::NAN + 0.0 }; let elapsed_time_since_shown_previous = data.elapsed_time_since_shown_previous .replace(elapsed_time_since_shown) @@ -799,7 +809,15 @@ impl UpdateSource for ShaderFilterPlus { impl HideSource for ShaderFilterPlus { fn hide(mut context: PluginContext) { if let Some(data) = context.data_mut().as_mut() { - data.shown_at = None; + data.shown = false; + } + } +} + +impl ShowSource for ShaderFilterPlus { + fn show(mut context: PluginContext) { + if let Some(data) = context.data_mut().as_mut() { + data.shown = true; } } } @@ -823,6 +841,7 @@ impl Module for ShaderFilterPlus { .enable_video_render() .enable_video_tick() .enable_hide() + .enable_show() .build(); load_context.register_source(source);