mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
plugin to debug polygons in depth
This commit is contained in:
parent
daa55026ae
commit
73714ec173
48
editor/src/plugins/debug/debug_polygon.rs
Normal file
48
editor/src/plugins/debug/debug_polygon.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use crate::objects::{Ctx, ID};
|
||||
use crate::plugins::{Plugin, PluginCtx};
|
||||
use ezgui::{GfxCtx, Key, Text};
|
||||
use geom::Pt2D;
|
||||
|
||||
pub struct DebugPolygon {
|
||||
pts: Vec<Pt2D>,
|
||||
current_pt: usize,
|
||||
}
|
||||
|
||||
impl DebugPolygon {
|
||||
pub fn new(ctx: &mut PluginCtx) -> Option<DebugPolygon> {
|
||||
if let Some(ID::Intersection(id)) = ctx.primary.current_selection {
|
||||
if ctx
|
||||
.input
|
||||
.contextual_action(Key::G, "debug intersection geometry")
|
||||
{
|
||||
return Some(DebugPolygon {
|
||||
pts: ctx.primary.map.get_i(id).polygon.clone(),
|
||||
current_pt: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for DebugPolygon {
|
||||
fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool {
|
||||
ctx.input.set_mode("Polygon Debugger", &ctx.canvas);
|
||||
if ctx.input.modal_action("quit") {
|
||||
return false;
|
||||
} else if self.current_pt != self.pts.len() - 1 && ctx.input.modal_action("next point") {
|
||||
self.current_pt += 1;
|
||||
} else if self.current_pt != 0 && ctx.input.modal_action("prev point") {
|
||||
self.current_pt -= 1;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, ctx: &Ctx) {
|
||||
ctx.canvas.draw_text_at(
|
||||
g,
|
||||
Text::from_line(format!("{}", self.current_pt)),
|
||||
self.pts[self.current_pt],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
pub mod chokepoints;
|
||||
pub mod classification;
|
||||
pub mod debug_objects;
|
||||
pub mod debug_polygon;
|
||||
pub mod floodfill;
|
||||
pub mod geom_validation;
|
||||
pub mod hider;
|
||||
|
@ -228,6 +228,9 @@ impl UIState for DefaultUIState {
|
||||
} else if let Some(p) = debug::geom_validation::Validator::new(&mut ctx) {
|
||||
self.exclusive_blocking_plugin = Some(Box::new(p));
|
||||
return;
|
||||
} else if let Some(p) = debug::debug_polygon::DebugPolygon::new(&mut ctx) {
|
||||
self.exclusive_blocking_plugin = Some(Box::new(p));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,14 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
ModalMenu::new("Object Hider", vec![(Key::K, "unhide everything")]),
|
||||
// TODO F1?
|
||||
ModalMenu::new("Legend", vec![(Key::L, "quit")]),
|
||||
ModalMenu::new(
|
||||
"Polygon Debugger",
|
||||
vec![
|
||||
(Key::Enter, "quit"),
|
||||
(Key::Dot, "next point"),
|
||||
(Key::Comma, "prev point"),
|
||||
],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user