Add mouseover to the split parking mapper, sadly just by copying a simpler version of the code...

This commit is contained in:
Dustin Carlino 2020-11-23 12:35:01 -08:00
parent ad0d1ae7a4
commit 6568c9e959
2 changed files with 68 additions and 5 deletions

View File

@ -2,7 +2,7 @@
//! state, based around drawing and interacting with a Map.
use abstutil::{CmdArgs, Timer};
use geom::{Duration, Time};
use geom::{Circle, Distance, Duration, Time};
use map_model::{IntersectionID, Map};
use sim::Sim;
use widgetry::{EventCtx, GfxCtx, SharedAppState};
@ -132,6 +132,71 @@ impl SimpleApp {
};
}
}
pub fn mouseover_unzoomed_roads_and_intersections(&self, ctx: &EventCtx) -> Option<ID> {
self.calculate_current_selection(ctx, true, false)
}
pub fn mouseover_unzoomed_buildings(&self, ctx: &EventCtx) -> Option<ID> {
self.calculate_current_selection(ctx, false, true)
}
pub fn mouseover_unzoomed_everything(&self, ctx: &EventCtx) -> Option<ID> {
self.calculate_current_selection(ctx, true, true)
}
fn calculate_current_selection(
&self,
ctx: &EventCtx,
unzoomed_roads_and_intersections: bool,
unzoomed_buildings: bool,
) -> Option<ID> {
// Unzoomed mode. Ignore when debugging areas.
if ctx.canvas.cam_zoom < self.opts.min_zoom_for_detail
&& !(unzoomed_roads_and_intersections || unzoomed_buildings)
{
return None;
}
let pt = ctx.canvas.get_cursor_in_map_space()?;
let mut objects = self.draw_map.get_renderables_back_to_front(
Circle::new(pt, Distance::meters(3.0)).get_bounds(),
&self.map,
);
objects.reverse();
for obj in objects {
match obj.get_id() {
ID::Road(_) => {
if !unzoomed_roads_and_intersections
|| ctx.canvas.cam_zoom >= self.opts.min_zoom_for_detail
{
continue;
}
}
ID::Intersection(_) => {
if ctx.canvas.cam_zoom < self.opts.min_zoom_for_detail
&& !unzoomed_roads_and_intersections
{
continue;
}
}
ID::Building(_) => {
if ctx.canvas.cam_zoom < self.opts.min_zoom_for_detail && !unzoomed_buildings {
continue;
}
}
_ => {
if ctx.canvas.cam_zoom < self.opts.min_zoom_for_detail {
continue;
}
}
}
if obj.contains_pt(pt, &self.map) {
return Some(obj.get_id());
}
}
None
}
}
impl AppLike for SimpleApp {

View File

@ -197,13 +197,11 @@ impl State<SimpleApp> for ParkingMapper {
ctx.canvas_movement();
if ctx.redo_mouseover() {
let mut maybe_r = None;
// TODO
/*match app.mouseover_unzoomed_roads_and_intersections(ctx) {
let mut maybe_r = match app.mouseover_unzoomed_roads_and_intersections(ctx) {
Some(ID::Road(r)) => Some(r),
Some(ID::Lane(l)) => Some(map.get_l(l).parent),
_ => None,
};*/
};
if let Some(r) = maybe_r {
if map.get_r(r).is_light_rail() {
maybe_r = None;