plugin to debug polygons in depth

This commit is contained in:
Dustin Carlino 2019-01-12 15:19:25 -08:00
parent daa55026ae
commit 73714ec173
4 changed files with 60 additions and 0 deletions

View 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],
);
}
}

View File

@ -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;

View File

@ -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;
}
}
}

View File

@ -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"),
],
),
]
}