Use the scroll hack

This commit is contained in:
Patrick Walton 2013-06-05 21:39:54 -07:00
parent 7a435fc6ed
commit 5750069e0a
4 changed files with 19 additions and 20 deletions

View file

@ -42,6 +42,7 @@ DEPS_rust-glut += \
DEPS_rust-layers += \
rust-azure \
rust-cocoa \
rust-geom \
rust-glut \
rust-opengles \
@ -130,6 +131,10 @@ DEPS_rust-layers += \
rust-core-text \
$(NULL)
DEPS_rust-glut += \
rust-cocoa \
$(NULL)
endif
ifeq ($(CFG_OSTYPE),unknown-linux-gnu)

View file

@ -16,6 +16,7 @@ use geom::point::Point2D;
use geom::size::Size2D;
use glut::glut::{DOUBLE, WindowHeight, WindowWidth};
use glut::glut;
use glut::machack;
/// A structure responsible for setting up and tearing down the entire windowing system.
pub struct Application;
@ -78,14 +79,16 @@ impl WindowMethods<Application> for Window {
do glut::keyboard_func |key, _, _| {
window.handle_key(key)
}
do glut::mouse_func |_, _, x, y| {
window.handle_click(x, y);
window.start_drag(x, y)
}
do glut::motion_func |x, y| {
window.continue_drag(x, y)
do glut::mouse_func |button, _, x, y| {
if button < 3 {
window.handle_click(x, y);
} else {
window.handle_scroll(if button == 4 { -30.0 } else { 30.0 });
}
}
machack::perform_scroll_wheel_hack();
window
}
@ -152,20 +155,11 @@ impl Window {
}
}
/// Helper function to start a drag.
fn start_drag(&mut self, x: c_int, y: c_int) {
self.drag_origin = Point2D(x, y)
}
/// Helper function to continue a drag.
fn continue_drag(&mut self, x: c_int, y: c_int) {
let new_point = Point2D(x, y);
let delta = new_point - self.drag_origin;
self.drag_origin = new_point;
/// Helper function to handle a scroll.
fn handle_scroll(&mut self, delta: f32) {
match self.scroll_callback {
None => {}
Some(callback) => callback(Point2D(delta.x as f32, delta.y as f32)),
Some(callback) => callback(Point2D(0.0, delta)),
}
}

@ -1 +1 @@
Subproject commit 61c99b4b1aa8653b8ee8511b6c15099de441ac44
Subproject commit ff8e2a63938ded5d2688619680a981c73d25080d

@ -1 +1 @@
Subproject commit eb35e3957834264e99f42274f9c5c442e747ed3b
Subproject commit 969af0260ef38d2c80ef2f51037da7ed1fc5cc85