Allow the rotation slider to be dragged
This commit is contained in:
parent
22fe63503f
commit
398718a3c8
|
@ -247,6 +247,11 @@ impl DemoApp {
|
|||
self.camera_pitch -= yrel as f32 * MOUSELOOK_ROTATION_SPEED;
|
||||
self.dirty = true;
|
||||
}
|
||||
Event::MouseMotion { x, y, mousestate, .. } if mousestate.left() => {
|
||||
let point = Point2DI32::new(x, y).scale(self.scale_factor as i32);
|
||||
ui_event = UIEvent::MouseDragged(point);
|
||||
self.dirty = true;
|
||||
}
|
||||
Event::KeyDown { keycode: Some(Keycode::W), .. } => {
|
||||
self.camera_velocity.set_z(-CAMERA_VELOCITY);
|
||||
self.dirty = true;
|
||||
|
|
|
@ -178,7 +178,7 @@ impl DemoUI {
|
|||
let (widget_x, widget_y) = (ROTATE_PANEL_X + PADDING, rotate_panel_y + PADDING);
|
||||
let widget_rect = RectI32::new(Point2DI32::new(widget_x, widget_y),
|
||||
Point2DI32::new(SLIDER_WIDTH, SLIDER_KNOB_HEIGHT));
|
||||
if let Some(position) = event.handle_mouse_down_in_rect(widget_rect) {
|
||||
if let Some(position) = event.handle_mouse_down_or_dragged_in_rect(widget_rect) {
|
||||
self.rotation = position.x();
|
||||
}
|
||||
|
||||
|
@ -267,6 +267,7 @@ impl DemoUI {
|
|||
pub enum UIEvent {
|
||||
None,
|
||||
MouseDown(Point2DI32),
|
||||
MouseDragged(Point2DI32),
|
||||
}
|
||||
|
||||
impl UIEvent {
|
||||
|
@ -283,4 +284,15 @@ impl UIEvent {
|
|||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn handle_mouse_down_or_dragged_in_rect(&mut self, rect: RectI32) -> Option<Point2DI32> {
|
||||
match *self {
|
||||
UIEvent::MouseDown(point) |
|
||||
UIEvent::MouseDragged(point) if rect.contains_point(point) => {
|
||||
*self = UIEvent::None;
|
||||
Some(point - rect.origin())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue