Initial Air Freshener plugin implementation
This commit is contained in:
76
src/window.rs
Normal file
76
src/window.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
use std::sync::{Arc, atomic::Ordering};
|
||||
use baseview::{Window, WindowOpenOptions, WindowScalePolicy, gl::GlConfig};
|
||||
use crossbeam::atomic::AtomicCell;
|
||||
use nih_plug::{editor::Editor, plugin::Plugin};
|
||||
use crate::{AirFreshener, editor::EditorHandle, parameters::PluginParams, gui::PluginGui};
|
||||
|
||||
pub struct EditorWindow {
|
||||
params: Arc<PluginParams>,
|
||||
scaling_factor: AtomicCell<Option<f32>>,
|
||||
}
|
||||
|
||||
impl EditorWindow {
|
||||
pub const WINDOW_SIZE: (u32, u32) = (230, 320);
|
||||
pub fn new(params: Arc<PluginParams>) -> Self {
|
||||
Self {
|
||||
params,
|
||||
#[cfg(target_os = "macos")]
|
||||
scaling_factor: AtomicCell::new(None),
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
scaling_factor: AtomicCell::new(Some(1.0)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Editor for EditorWindow {
|
||||
fn spawn(
|
||||
&self,
|
||||
parent: nih_plug::prelude::ParentWindowHandle,
|
||||
context: Arc<dyn nih_plug::prelude::GuiContext>,
|
||||
) -> Box<dyn std::any::Any + Send> {
|
||||
let (unscaled_width, unscaled_height) = self.params.editor_state.size();
|
||||
let scaling_factor = self.scaling_factor.load();
|
||||
let gui_context = context.clone();
|
||||
let params = self.params.clone();
|
||||
let window = Window::open_parented(&parent, WindowOpenOptions {
|
||||
title: AirFreshener::NAME.to_owned(),
|
||||
size: baseview::Size { width: unscaled_width as f64, height: unscaled_height as f64 },
|
||||
scale: scaling_factor.map(|factor| WindowScalePolicy::ScaleFactor(factor as f64)).unwrap_or(WindowScalePolicy::SystemScaleFactor),
|
||||
gl_config: Some(GlConfig {
|
||||
version: (3, 2),
|
||||
red_bits: 8,
|
||||
green_bits: 8,
|
||||
blue_bits: 8,
|
||||
alpha_bits: 8,
|
||||
samples: None,
|
||||
srgb: true,
|
||||
double_buffer: true,
|
||||
vsync: false,
|
||||
..Default::default()
|
||||
})
|
||||
}, move |window: &mut baseview::Window<'_>| -> PluginGui {
|
||||
PluginGui::new(window, gui_context, params, scaling_factor.unwrap_or(1.0))
|
||||
});
|
||||
self.params.editor_state.open.store(true, Ordering::Release);
|
||||
Box::new(EditorHandle {
|
||||
state: self.params.editor_state.clone(),
|
||||
window
|
||||
})
|
||||
}
|
||||
|
||||
fn size(&self) -> (u32, u32) {
|
||||
self.params.editor_state.size()
|
||||
}
|
||||
|
||||
fn set_scale_factor(&self, factor: f32) -> bool {
|
||||
if self.params.editor_state.is_open() {
|
||||
return false;
|
||||
}
|
||||
self.scaling_factor.store(Some(factor));
|
||||
true
|
||||
}
|
||||
|
||||
fn param_value_changed(&self, _id: &str, _normalized_value: f32) {}
|
||||
fn param_modulation_changed(&self, _id: &str, _modulation_offset: f32) {}
|
||||
fn param_values_changed(&self) {}
|
||||
}
|
||||
Reference in New Issue
Block a user