use super::grid_impl::BrailleGrid;
use super::shapes::{self, Shape};
use crate::style::Color;
pub struct BrailleContext<'a> {
grid: &'a mut BrailleGrid,
}
impl<'a> BrailleContext<'a> {
pub fn new(grid: &'a mut BrailleGrid) -> Self {
Self { grid }
}
pub fn width(&self) -> usize {
self.grid.width()
}
pub fn height(&self) -> usize {
self.grid.height()
}
pub fn clear(&mut self) {
self.grid.clear();
}
pub fn set(&mut self, x: usize, y: usize, color: Color) {
self.grid.set(x, y, color);
}
pub fn draw<S: Shape>(&mut self, shape: &S) {
shape.draw(self.grid);
}
pub fn line(&mut self, x0: f64, y0: f64, x1: f64, y1: f64, color: Color) {
self.draw(&shapes::Line::new(x0, y0, x1, y1, color));
}
pub fn circle(&mut self, x: f64, y: f64, radius: f64, color: Color) {
self.draw(&shapes::Circle::new(x, y, radius, color));
}
pub fn filled_circle(&mut self, x: f64, y: f64, radius: f64, color: Color) {
self.draw(&shapes::FilledCircle::new(x, y, radius, color));
}
pub fn rect(&mut self, x: f64, y: f64, width: f64, height: f64, color: Color) {
self.draw(&shapes::Rectangle::new(x, y, width, height, color));
}
pub fn filled_rect(&mut self, x: f64, y: f64, width: f64, height: f64, color: Color) {
self.draw(&shapes::FilledRectangle::new(x, y, width, height, color));
}
pub fn points(&mut self, coords: Vec<(f64, f64)>, color: Color) {
self.draw(&shapes::Points::new(coords, color));
}
pub fn arc(
&mut self,
x: f64,
y: f64,
radius: f64,
start_angle: f64,
end_angle: f64,
color: Color,
) {
self.draw(&shapes::Arc::new(
x,
y,
radius,
start_angle,
end_angle,
color,
));
}
pub fn arc_degrees(
&mut self,
x: f64,
y: f64,
radius: f64,
start_deg: f64,
end_deg: f64,
color: Color,
) {
self.draw(&shapes::Arc::from_degrees(
x, y, radius, start_deg, end_deg, color,
));
}
pub fn polygon(&mut self, vertices: Vec<(f64, f64)>, color: Color) {
self.draw(&shapes::Polygon::new(vertices, color));
}
pub fn regular_polygon(&mut self, x: f64, y: f64, radius: f64, sides: usize, color: Color) {
self.draw(&shapes::Polygon::regular(x, y, radius, sides, color));
}
pub fn filled_polygon(&mut self, vertices: Vec<(f64, f64)>, color: Color) {
self.draw(&shapes::FilledPolygon::new(vertices, color));
}
}