From 2816b9418e7eaefde2c2575fdcdadad4a304a20a Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 12 Nov 2022 01:58:47 +0100 Subject: [PATCH] Account for DPI scaling in granular dragging --- nih_plug_vizia/src/widgets/param_slider.rs | 18 +++++------ plugins/diopser/src/editor/xy_pad.rs | 35 ++++++++++++---------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/nih_plug_vizia/src/widgets/param_slider.rs b/nih_plug_vizia/src/widgets/param_slider.rs index ed9d3c83..b173cc82 100644 --- a/nih_plug_vizia/src/widgets/param_slider.rs +++ b/nih_plug_vizia/src/widgets/param_slider.rs @@ -535,17 +535,17 @@ impl View for ParamSlider { starting_value: self.param_base.unmodulated_normalized_value(), }); + // These positions should be compensated for the DPI scale so it remains + // consistent + let start_x = + util::remap_current_entity_x_t(cx, granular_drag_status.starting_value); + let delta_x = ((*x - granular_drag_status.starting_x_coordinate) + * GRANULAR_DRAG_MULTIPLIER) + * cx.style.dpi_factor as f32; + self.set_normalized_value_drag( cx, - util::remap_current_entity_x_coordinate( - cx, - // This can be optimized a bit - util::remap_current_entity_x_t( - cx, - granular_drag_status.starting_value, - ) + ((*x - granular_drag_status.starting_x_coordinate) - * GRANULAR_DRAG_MULTIPLIER), - ), + util::remap_current_entity_x_coordinate(cx, start_x + delta_x), ); } else { self.granular_drag_status = None; diff --git a/plugins/diopser/src/editor/xy_pad.rs b/plugins/diopser/src/editor/xy_pad.rs index da381bc9..7fdc8f9e 100644 --- a/plugins/diopser/src/editor/xy_pad.rs +++ b/plugins/diopser/src/editor/xy_pad.rs @@ -344,23 +344,28 @@ impl View for XyPad { .unmodulated_normalized_value(), }); + // These positions should be compensated for the DPI scale so it remains + // consistent + let start_x = util::remap_current_entity_x_t( + cx, + granular_drag_status.x_starting_value, + ); + let delta_x = ((*x - granular_drag_status.starting_x_coordinate) + * GRANULAR_DRAG_MULTIPLIER) + * dpi_scale; + let start_y = util::remap_current_entity_y_t( + cx, + // NOTE: Just like above, the corodinates go from top to bottom + // while we want the X-Y pad to go from bottom to top + 1.0 - granular_drag_status.y_starting_value, + ); + let delta_y = ((*y - granular_drag_status.starting_y_coordinate) + * GRANULAR_DRAG_MULTIPLIER) + * dpi_scale; + self.set_normalized_values_for_mouse_pos( cx, - ( - // This can be optimized a bit - util::remap_current_entity_x_t( - cx, - granular_drag_status.x_starting_value, - ) + ((*x - granular_drag_status.starting_x_coordinate) - * GRANULAR_DRAG_MULTIPLIER), - (util::remap_current_entity_y_t( - cx, - // NOTE: Just like above, the corodinates go from top to bottom - // while we want the X-Y pad to go from bottom to top - 1.0 - granular_drag_status.y_starting_value, - ) + ((*y - granular_drag_status.starting_y_coordinate) - * GRANULAR_DRAG_MULTIPLIER)), - ), + (start_x + delta_x, start_y + delta_y), ); } else { self.granular_drag_status = None;