mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-17 21:56:21 +00:00
Merge pull request #1204 from hannobraun/zoom
Invert default zoom direction; add config to override that
This commit is contained in:
commit
461f95bd09
@ -11,6 +11,7 @@ use serde::Deserialize;
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub default_path: Option<PathBuf>,
|
pub default_path: Option<PathBuf>,
|
||||||
pub default_model: Option<PathBuf>,
|
pub default_model: Option<PathBuf>,
|
||||||
|
pub invert_zoom: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -80,11 +80,13 @@ fn main() -> anyhow::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let invert_zoom = config.invert_zoom.unwrap_or(false);
|
||||||
|
|
||||||
if let Some(model) = model {
|
if let Some(model) = model {
|
||||||
let watcher = model.load_and_watch(parameters)?;
|
let watcher = model.load_and_watch(parameters)?;
|
||||||
run(Some(watcher), shape_processor, status)?;
|
run(Some(watcher), shape_processor, status, invert_zoom)?;
|
||||||
} else {
|
} else {
|
||||||
run(None, shape_processor, status)?;
|
run(None, shape_processor, status, invert_zoom)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -14,6 +14,6 @@ impl Zoom {
|
|||||||
let distance = (focus_point.0 - camera.position()).magnitude();
|
let distance = (focus_point.0 - camera.position()).magnitude();
|
||||||
let displacement = zoom_delta * distance.into_f64();
|
let displacement = zoom_delta * distance.into_f64();
|
||||||
camera.translation = camera.translation
|
camera.translation = camera.translation
|
||||||
* Transform::translation(Vector::from([0.0, 0.0, -displacement]));
|
* Transform::translation(Vector::from([0.0, 0.0, displacement]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ pub fn run(
|
|||||||
watcher: Option<Watcher>,
|
watcher: Option<Watcher>,
|
||||||
shape_processor: ShapeProcessor,
|
shape_processor: ShapeProcessor,
|
||||||
mut status: StatusReport,
|
mut status: StatusReport,
|
||||||
|
invert_zoom: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
let window = Window::new(&event_loop)?;
|
let window = Window::new(&event_loop)?;
|
||||||
@ -214,6 +215,7 @@ pub fn run(
|
|||||||
&window,
|
&window,
|
||||||
&held_mouse_button,
|
&held_mouse_button,
|
||||||
&mut previous_cursor,
|
&mut previous_cursor,
|
||||||
|
invert_zoom,
|
||||||
);
|
);
|
||||||
if let (Some(input_event), Some(fp)) = (input_event, focus_point) {
|
if let (Some(input_event), Some(fp)) = (input_event, focus_point) {
|
||||||
input_handler.handle_event(input_event, fp, &mut camera);
|
input_handler.handle_event(input_event, fp, &mut camera);
|
||||||
@ -226,6 +228,7 @@ fn input_event(
|
|||||||
window: &Window,
|
window: &Window,
|
||||||
held_mouse_button: &Option<MouseButton>,
|
held_mouse_button: &Option<MouseButton>,
|
||||||
previous_cursor: &mut Option<NormalizedPosition>,
|
previous_cursor: &mut Option<NormalizedPosition>,
|
||||||
|
invert_zoom: bool,
|
||||||
) -> Option<input::Event> {
|
) -> Option<input::Event> {
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
@ -264,12 +267,20 @@ fn input_event(
|
|||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::MouseWheel { delta, .. },
|
event: WindowEvent::MouseWheel { delta, .. },
|
||||||
..
|
..
|
||||||
} => Some(input::Event::Zoom(match delta {
|
} => {
|
||||||
MouseScrollDelta::LineDelta(_, y) => (*y as f64) * ZOOM_FACTOR_LINE,
|
let delta = match delta {
|
||||||
MouseScrollDelta::PixelDelta(PhysicalPosition { y, .. }) => {
|
MouseScrollDelta::LineDelta(_, y) => {
|
||||||
y * ZOOM_FACTOR_PIXEL
|
(*y as f64) * ZOOM_FACTOR_LINE
|
||||||
|
}
|
||||||
|
MouseScrollDelta::PixelDelta(PhysicalPosition {
|
||||||
|
y, ..
|
||||||
|
}) => y * ZOOM_FACTOR_PIXEL,
|
||||||
|
};
|
||||||
|
|
||||||
|
let delta = if invert_zoom { -delta } else { delta };
|
||||||
|
|
||||||
|
Some(input::Event::Zoom(delta))
|
||||||
}
|
}
|
||||||
})),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
fj.toml
4
fj.toml
@ -5,3 +5,7 @@ default_path = "models"
|
|||||||
# The default models that is loaded, if none is specified. If this is a relative
|
# The default models that is loaded, if none is specified. If this is a relative
|
||||||
# path, it should be relative to `default_path`.
|
# path, it should be relative to `default_path`.
|
||||||
default_model = "test"
|
default_model = "test"
|
||||||
|
|
||||||
|
# Indicate whether to invert the zoom direction. Can be used to override the
|
||||||
|
# OS-level setting.
|
||||||
|
invert_zoom = false
|
||||||
|
Loading…
Reference in New Issue
Block a user