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

Implement pinch zoom emulation to the glutin port #8215

Merged
merged 1 commit into from Oct 27, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implement pinch zoom emulation to the glutin port

The GLFW port had pinch zoom emulation that could be triggered by
holding control and using the mouse wheel. This was very useful for
testing pinch zoom behavior on desktop machines. This commit
implements this for the glutin port.
  • Loading branch information
mrobinson committed Oct 27, 2015
commit c36484257bfd5a2a45dc384dfcbc93c9e0d5aee7
@@ -200,11 +200,20 @@ impl Window {
WindowEvent::MouseWindowMoveEventClass(Point2D::typed(x as f32, y as f32)));
}
Event::MouseWheel(delta) => {
match delta {
MouseScrollDelta::LineDelta(dx, dy) => {
self.scroll_window(dx, dy * LINE_HEIGHT);
}
MouseScrollDelta::PixelDelta(dx, dy) => self.scroll_window(dx, dy)
let (dx, dy) = match delta {
MouseScrollDelta::LineDelta(dx, dy) => (dx, dy * LINE_HEIGHT),
MouseScrollDelta::PixelDelta(dx, dy) => (dx, dy),
};

if !self.key_modifiers.get().intersects(LEFT_CONTROL | RIGHT_CONTROL) {
self.scroll_window(dx, dy);
} else {
let factor = if dy > 0. {
1.1
} else {
1.0 / 1.1
};
self.pinch_zoom(factor);
}
},
Event::Refresh => {
@@ -225,6 +234,10 @@ impl Window {
self.key_modifiers.set(modifiers);
}

fn pinch_zoom(&self, factor: f32) {
self.event_queue.borrow_mut().push(WindowEvent::PinchZoom(factor));
}

/// Helper function to send a scroll event.
fn scroll_window(&self, dx: f32, dy: f32) {
let mouse_pos = self.mouse_pos.get();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.