mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 22:13:27 +03:00
change the mouse cursor based on context [rebuild]
This commit is contained in:
parent
93227a138b
commit
199b175319
@ -233,6 +233,10 @@ impl PrerenderInnards {
|
||||
self.display.gl_window().window().request_redraw();
|
||||
}
|
||||
|
||||
pub fn set_cursor_icon(&self, icon: winit::window::CursorIcon) {
|
||||
self.display.gl_window().window().set_cursor_icon(icon);
|
||||
}
|
||||
|
||||
pub fn draw_new_frame<'a>(&self) -> GfxCtxInnards<'a> {
|
||||
GfxCtxInnards {
|
||||
target: self.display.draw(),
|
||||
|
@ -287,6 +287,10 @@ impl PrerenderInnards {
|
||||
self.windowed_context.window().request_redraw();
|
||||
}
|
||||
|
||||
pub fn set_cursor_icon(&self, icon: winit::window::CursorIcon) {
|
||||
self.windowed_context.window().set_cursor_icon(icon);
|
||||
}
|
||||
|
||||
pub fn draw_new_frame(&self) -> GfxCtxInnards {
|
||||
GfxCtxInnards {
|
||||
gl: &self.gl,
|
||||
|
@ -305,6 +305,10 @@ impl PrerenderInnards {
|
||||
self.window.request_redraw();
|
||||
}
|
||||
|
||||
pub fn set_cursor_icon(&self, icon: winit::window::CursorIcon) {
|
||||
self.window.set_cursor_icon(icon);
|
||||
}
|
||||
|
||||
pub fn draw_new_frame(&self) -> GfxCtxInnards {
|
||||
GfxCtxInnards {
|
||||
gl: &self.gl,
|
||||
|
@ -100,6 +100,12 @@ impl<'a> EventCtx<'a> {
|
||||
pub fn monitor_scale_factor(&self) -> f64 {
|
||||
self.prerender.inner.monitor_scale_factor()
|
||||
}
|
||||
|
||||
pub(crate) fn cursor_clickable(&mut self) {
|
||||
self.prerender
|
||||
.inner
|
||||
.set_cursor_icon(winit::window::CursorIcon::Hand);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LoadingScreen<'a> {
|
||||
|
@ -44,6 +44,25 @@ impl<G: GUI> State<G> {
|
||||
}
|
||||
}
|
||||
|
||||
// Always reset the cursor, unless we're handling an update event. If we're hovering on a
|
||||
// button, we'll discover that by plumbing through the event.
|
||||
if let Event::Update(_) = ev {
|
||||
} else {
|
||||
prerender
|
||||
.inner
|
||||
.set_cursor_icon(if self.canvas.drag_canvas_from.is_some() {
|
||||
// We haven't run canvas_movement() yet, so we don't know if the button has been
|
||||
// released. Bit of a hack to check this here, but better behavior.
|
||||
if ev == Event::LeftMouseButtonUp {
|
||||
winit::window::CursorIcon::Default
|
||||
} else {
|
||||
winit::window::CursorIcon::Grabbing
|
||||
}
|
||||
} else {
|
||||
winit::window::CursorIcon::Default
|
||||
});
|
||||
}
|
||||
|
||||
// It's impossible / very unlikey we'll grab the cursor in map space before the very first
|
||||
// start_drawing call.
|
||||
let input = UserInput::new(ev, &self.canvas);
|
||||
|
@ -91,6 +91,10 @@ impl WidgetImpl for Button {
|
||||
}
|
||||
}
|
||||
|
||||
if self.hovering {
|
||||
ctx.cursor_clickable();
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user