mirror of https://codeberg.org/topola/topola.git
egui: paint zones (only convex ones work for now)
This commit is contained in:
parent
c141dfc735
commit
2d5998547a
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use topola::{
|
||||
drawing::{graph::MakePrimitive, primitive::MakeShape, Drawing},
|
||||
drawing::{graph::MakePrimitive, primitive::MakeShape, zone::MakePolygon, Drawing},
|
||||
dsn::{design::DsnDesign, rules::DsnRules},
|
||||
geometry::shape::{BendShape, DotShape, SegShape, Shape},
|
||||
math::Circle,
|
||||
|
|
@ -138,16 +138,30 @@ impl eframe::App for App {
|
|||
let transform = egui::emath::RectTransform::from_to(self.from_rect, viewport_rect);
|
||||
let mut painter = Painter::new(ui, transform);
|
||||
|
||||
if let Some(layout) = &self.drawing {
|
||||
for node in layout.layer_primitive_nodes(1) {
|
||||
let shape = node.primitive(layout).shape();
|
||||
if let Some(drawing) = &self.drawing {
|
||||
for node in drawing.layer_primitive_nodes(1) {
|
||||
let shape = node.primitive(drawing).shape();
|
||||
painter.paint_shape(&shape, egui::Color32::from_rgb(52, 52, 200));
|
||||
}
|
||||
|
||||
for node in layout.layer_primitive_nodes(0) {
|
||||
let shape = node.primitive(layout).shape();
|
||||
for zone in drawing.layer_zones(1) {
|
||||
painter.paint_polygon(
|
||||
&zone.polygon(&drawing),
|
||||
egui::Color32::from_rgb(52, 52, 200),
|
||||
)
|
||||
}
|
||||
|
||||
for node in drawing.layer_primitive_nodes(0) {
|
||||
let shape = node.primitive(drawing).shape();
|
||||
painter.paint_shape(&shape, egui::Color32::from_rgb(200, 52, 52));
|
||||
}
|
||||
|
||||
for zone in drawing.layer_zones(0) {
|
||||
painter.paint_polygon(
|
||||
&zone.polygon(&drawing),
|
||||
egui::Color32::from_rgb(200, 52, 52),
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use egui::{emath::RectTransform, epaint, Color32, Pos2, Ui};
|
||||
use geo::Point;
|
||||
use egui::{emath::RectTransform, epaint, Color32, Pos2, Stroke, Ui};
|
||||
use geo::{CoordsIter, Point, Polygon};
|
||||
use topola::geometry::shape::Shape;
|
||||
|
||||
pub struct Painter<'a> {
|
||||
ui: &'a mut egui::Ui,
|
||||
ui: &'a mut Ui,
|
||||
transform: RectTransform,
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ impl<'a> Painter<'a> {
|
|||
self.transform
|
||||
.transform_pos([seg.to.x() as f32, -seg.to.y() as f32].into()),
|
||||
],
|
||||
egui::Stroke::new(seg.width as f32 * self.transform.scale().x, color),
|
||||
Stroke::new(seg.width as f32 * self.transform.scale().x, color),
|
||||
),
|
||||
Shape::Bend(bend) => {
|
||||
let delta_from = bend.from - bend.c.pos;
|
||||
|
|
@ -47,7 +47,7 @@ impl<'a> Painter<'a> {
|
|||
|
||||
epaint::Shape::line(
|
||||
points,
|
||||
egui::Stroke::new(bend.width as f32 * self.transform.scale().x, color),
|
||||
Stroke::new(bend.width as f32 * self.transform.scale().x, color),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
|
@ -55,6 +55,20 @@ impl<'a> Painter<'a> {
|
|||
self.ui.painter().add(epaint_shape);
|
||||
}
|
||||
|
||||
pub fn paint_polygon(&mut self, polygon: &Polygon, color: Color32) {
|
||||
self.ui.painter().add(epaint::Shape::convex_polygon(
|
||||
polygon
|
||||
.exterior_coords_iter()
|
||||
.map(|coords| {
|
||||
self.transform
|
||||
.transform_pos([coords.x as f32, -coords.y as f32].into())
|
||||
})
|
||||
.collect(),
|
||||
color,
|
||||
Stroke::default(),
|
||||
));
|
||||
}
|
||||
|
||||
pub fn paint_edge(&mut self, from: Point, to: Point, color: Color32) {
|
||||
//
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue