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

View file

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