More scren scaling fixes

This commit is contained in:
Ebu
2025-12-02 14:11:40 +01:00
parent 52ad48ed41
commit 654f23f14f
2 changed files with 29 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ use crate::{parameters::PluginParams, window::EditorWindow};
use baseview::{
Event, EventStatus, MouseButton, MouseEvent, WindowEvent, WindowHandler, gl::GlContext,
};
use crossbeam::atomic::AtomicCell;
use ebu_dsp::Rect;
use femtovg::{Canvas, Color, FontId, ImageFlags, ImageId, Paint, Path, renderer::OpenGl};
use nih_plug::prelude::*;
@@ -23,7 +24,7 @@ pub struct PluginGui {
params: Arc<PluginParams>,
canvas: Option<Canvas<OpenGl>>,
_gui_context: Arc<dyn GuiContext>,
scaling_factor: f32,
scaling_factor: Arc<AtomicCell<Option<f32>>>,
freshener_screen_bounds: Rect<f32>,
@@ -41,13 +42,13 @@ pub struct PluginGui {
fn create_canvas(
context: &GlContext,
params: &PluginParams,
scaling_factor: f32,
scaling_factor: &AtomicCell<Option<f32>>,
) -> Result<Canvas<OpenGl>, &'static str> {
let renderer = unsafe { OpenGl::new_from_function(|s| context.get_proc_address(s)) }
.map_err(|_| "Failed to create OpenGL renderer")?;
let mut canvas = Canvas::new(renderer).map_err(|_| "Failed to create femtovg canvas")?;
let (width, height) = params.editor_state.size();
canvas.set_size(width, height, scaling_factor);
canvas.set_size(width, height, scaling_factor.load().unwrap_or(1.0));
Ok(canvas)
}
@@ -56,14 +57,14 @@ impl PluginGui {
window: &mut baseview::Window<'_>,
gui_context: Arc<dyn GuiContext>,
params: Arc<PluginParams>,
scaling_factor: f32,
scaling_factor: Arc<AtomicCell<Option<f32>>>,
) -> Self {
let mut this = Self {
font: Err("Not loaded".to_owned()),
params: params.clone(),
canvas: None,
_gui_context: gui_context,
scaling_factor,
scaling_factor: scaling_factor.clone(),
dirty: true,
mouse_position: (0.0, 0.0),
drag_start_mouse_pos: (0.0, 0.0),
@@ -79,7 +80,7 @@ impl PluginGui {
unsafe {
context.make_current();
}
if let Ok(mut canvas) = create_canvas(context, &params, scaling_factor) {
if let Ok(mut canvas) = create_canvas(context, &params, &scaling_factor) {
this.font = canvas
.add_font_mem(DROID_SANS_FONT)
.map_err(|err| format!("{:?}", err));
@@ -122,17 +123,18 @@ impl WindowHandler for PluginGui {
return;
}
let canvas = self.canvas.as_mut().unwrap();
let scaling_factor = self.scaling_factor.load().unwrap_or(1.0);
if !self.dirty {
//return;
}
let font_size = 12.0 * self.scaling_factor;
let font_size = 12.0 * scaling_factor;
self.freshener_screen_bounds = Rect {
x: 120.0 * self.scaling_factor,
y: 20.0 * self.scaling_factor,
width: FRESHENER_FRAME_WIDTH * self.scaling_factor,
height: FRESHENER_FRAME_HEIGHT * self.scaling_factor,
x: 120.0 * scaling_factor,
y: 20.0 * scaling_factor,
width: FRESHENER_FRAME_WIDTH * scaling_factor,
height: FRESHENER_FRAME_HEIGHT * scaling_factor,
};
let context = match window.gl_context() {
@@ -160,10 +162,10 @@ impl WindowHandler for PluginGui {
let mut freshener_path = Path::new();
freshener_path.rect(
self.freshener_screen_bounds.x * self.scaling_factor,
self.freshener_screen_bounds.y * self.scaling_factor,
self.freshener_screen_bounds.width * self.scaling_factor,
self.freshener_screen_bounds.height * self.scaling_factor,
self.freshener_screen_bounds.x,
self.freshener_screen_bounds.y,
self.freshener_screen_bounds.width,
self.freshener_screen_bounds.height,
);
let frame_index = (self.params.freshness.unmodulated_normalized_value()
@@ -236,9 +238,10 @@ impl WindowHandler for PluginGui {
y += font_size;
}
};
let scaling_factor = self.scaling_factor.load();
print("Debug version");
print(&format!("scaling_factor {}", self.scaling_factor));
print(&format!("scaling_factor {:?}", scaling_factor));
print(&format!(
"screen_bounds {:#?}",
self.freshener_screen_bounds
@@ -275,7 +278,11 @@ impl WindowHandler for PluginGui {
Event::Window(WindowEvent::Resized(size)) => {
let phys_size = size.physical_size();
if let Some(canvas) = self.canvas.as_mut() {
canvas.set_size(phys_size.width, phys_size.height, self.scaling_factor);
canvas.set_size(
phys_size.width,
phys_size.height,
self.scaling_factor.load().unwrap_or(1.0),
);
}
self.dirty = true;
}