Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert default zoom direction; add config to override that #1204

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/fj-app/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-viewer/src/input/zoom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ impl Zoom {
let distance = (focus_point.0 - camera.position()).magnitude();
let displacement = zoom_delta * distance.into_f64();
camera.translation = camera.translation
* Transform::translation(Vector::from([0.0, 0.0, -displacement]));
* Transform::translation(Vector::from([0.0, 0.0, displacement]));
}
}
23 changes: 17 additions & 6 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -264,12 +267,20 @@ fn input_event(
Event::WindowEvent {
event: WindowEvent::MouseWheel { delta, .. },
..
} => Some(input::Event::Zoom(match delta {
MouseScrollDelta::LineDelta(_, y) => (*y as f64) * ZOOM_FACTOR_LINE,
MouseScrollDelta::PixelDelta(PhysicalPosition { y, .. }) => {
y * ZOOM_FACTOR_PIXEL
}
})),
} => {
let delta = match delta {
MouseScrollDelta::LineDelta(_, y) => {
(*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,
}
}
Expand Down
4 changes: 4 additions & 0 deletions fj.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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