Add configuration to invert zoom direction

This commit is contained in:
Hanno Braun 2022-10-11 14:15:46 +02:00
parent da81720a00
commit e4c8fcbb42
4 changed files with 14 additions and 2 deletions

View File

@ -11,6 +11,7 @@ use serde::Deserialize;
pub struct Config {
pub default_path: Option<PathBuf>,
pub default_model: Option<PathBuf>,
pub invert_zoom: Option<bool>,
}
impl Config {

View File

@ -80,11 +80,13 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}
let invert_zoom = config.invert_zoom.unwrap_or(false);
if let Some(model) = model {
let watcher = model.load_and_watch(parameters)?;
run(Some(watcher), shape_processor, status)?;
run(Some(watcher), shape_processor, status, invert_zoom)?;
} else {
run(None, shape_processor, status)?;
run(None, shape_processor, status, invert_zoom)?;
}
Ok(())

View File

@ -32,6 +32,7 @@ pub fn run(
watcher: Option<Watcher>,
shape_processor: ShapeProcessor,
mut status: StatusReport,
invert_zoom: bool,
) -> Result<(), Error> {
let event_loop = EventLoop::new();
let window = Window::new(&event_loop)?;
@ -214,6 +215,7 @@ pub fn run(
&window,
&held_mouse_button,
&mut previous_cursor,
invert_zoom,
);
if let (Some(input_event), Some(fp)) = (input_event, focus_point) {
input_handler.handle_event(input_event, fp, &mut camera);
@ -226,6 +228,7 @@ fn input_event(
window: &Window,
held_mouse_button: &Option<MouseButton>,
previous_cursor: &mut Option<NormalizedPosition>,
invert_zoom: bool,
) -> Option<input::Event> {
match event {
Event::WindowEvent {
@ -274,6 +277,8 @@ fn input_event(
}) => y * ZOOM_FACTOR_PIXEL,
};
let delta = if invert_zoom { -delta } else { delta };
Some(input::Event::Zoom(delta))
}
_ => None,

View File

@ -5,3 +5,7 @@ default_path = "models"
# The default models that is loaded, if none is specified. If this is a relative
# path, it should be relative to `default_path`.
default_model = "test"
# Indicate whether to invert the zoom direction. Can be used to override the
# OS-level setting.
invert_zoom = false