aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/components/main/compositing/mod.rs5
-rw-r--r--src/components/main/platform/common/glut_windowing.rs26
-rw-r--r--src/components/main/windowing.rs2
3 files changed, 21 insertions, 12 deletions
diff --git a/src/components/main/compositing/mod.rs b/src/components/main/compositing/mod.rs
index 954b13e8014..ad065a9966f 100644
--- a/src/components/main/compositing/mod.rs
+++ b/src/components/main/compositing/mod.rs
@@ -290,12 +290,11 @@ fn run_main_loop(port: Port<Msg>,
// When the user pinch-zooms, scale the layer
- do window.set_zoom_callback |delta| {
- let zoom_const = 0.01;
+ do window.set_zoom_callback |magnification| {
let old_world_zoom = *world_zoom;
// Determine zoom amount
- *world_zoom = (*world_zoom + delta.y * zoom_const).max(&1.0);
+ *world_zoom = (*world_zoom * magnification).max(&1.0);
// Update world offset
let corner_to_center_x = world_offset.x + window_size.width as f32 / 2f32;
diff --git a/src/components/main/platform/common/glut_windowing.rs b/src/components/main/platform/common/glut_windowing.rs
index b50698c5674..27db4d71154 100644
--- a/src/components/main/platform/common/glut_windowing.rs
+++ b/src/components/main/platform/common/glut_windowing.rs
@@ -94,16 +94,18 @@ impl WindowMethods<Application> for Window {
window.handle_mouse(button, state, x, y);
}
}
- do glut::mouse_wheel_func |button, direction, x, y| {
+ do glut::mouse_wheel_func |wheel, direction, x, y| {
let delta = if HAVE_PRECISE_MOUSE_WHEEL {
(direction as f32) / 10000.0
} else {
(direction as f32) * 30.0
};
- println(fmt!("delta is %f", delta as float));
-
- window.handle_scroll(delta);
+ match wheel {
+ 1 => window.handle_scroll(Point2D(delta, 0.0)),
+ 2 => window.handle_zoom(delta),
+ _ => window.handle_scroll(Point2D(0.0, delta)),
+ }
}
machack::perform_scroll_wheel_hack();
@@ -170,12 +172,12 @@ impl Window {
12 => self.load_url(), // Ctrl+L
k if k == ('=' as u8) && (glut::get_modifiers() & ACTIVE_CTRL) != 0 => { // Ctrl++
for self.zoom_callback.each |&callback| {
- callback(Point2D(0.0, 20.0));
+ callback(0.1);
}
}
k if k == 31 && (glut::get_modifiers() & ACTIVE_CTRL) != 0 => { // Ctrl+-
for self.zoom_callback.each |&callback| {
- callback(Point2D(0.0, -20.0));
+ callback(-0.1);
}
}
_ => {}
@@ -217,10 +219,18 @@ impl Window {
}
/// Helper function to handle a scroll.
- fn handle_scroll(&mut self, delta: f32) {
+ fn handle_scroll(&mut self, delta: Point2D<f32>) {
match self.scroll_callback {
None => {}
- Some(callback) => callback(Point2D(0.0, delta)),
+ Some(callback) => callback(delta),
+ }
+ }
+
+ /// Helper function to handle a zoom.
+ fn handle_zoom(&mut self, magnification: f32) {
+ match self.zoom_callback {
+ None => {}
+ Some(callback) => callback(magnification),
}
}
diff --git a/src/components/main/windowing.rs b/src/components/main/windowing.rs
index d3dd7b1bf0b..42cce45c60a 100644
--- a/src/components/main/windowing.rs
+++ b/src/components/main/windowing.rs
@@ -29,7 +29,7 @@ pub type MouseCallback = @fn(WindowMouseEvent);
pub type ScrollCallback = @fn(Point2D<f32>);
///Type of the function that is called when the user zooms.
-pub type ZoomCallback = @fn(Point2D<f32>);
+pub type ZoomCallback = @fn(f32);
/// Methods for an abstract Application.
pub trait ApplicationMethods {