Skip to content

Commit

Permalink
Add fill_polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
lyonbeckers committed Sep 9, 2023
1 parent e717a57 commit 501166f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
log_to_console, pd_func_caller, pd_func_caller_log,
system::System,
},
alloc::{format, rc::Rc},
alloc::{format, rc::Rc, vec::Vec},
anyhow::{anyhow, ensure, Error},
core::{cell::RefCell, ops::RangeInclusive, ptr, slice},
crankstart_sys::{ctypes::c_int, LCDBitmapTable, LCDPattern},
Expand All @@ -14,8 +14,8 @@ use {
};

pub use crankstart_sys::{
LCDBitmapDrawMode, LCDBitmapFlip, LCDLineCapStyle, LCDRect, LCDSolidColor, PDRect,
PDStringEncoding, LCD_COLUMNS, LCD_ROWS, LCD_ROWSIZE,
LCDBitmapDrawMode, LCDBitmapFlip, LCDLineCapStyle, LCDPolygonFillRule, LCDRect, LCDSolidColor,
PDRect, PDStringEncoding, LCD_COLUMNS, LCD_ROWS, LCD_ROWSIZE,
};

pub fn rect_make(x: f32, y: f32, width: f32, height: f32) -> PDRect {
Expand Down Expand Up @@ -639,6 +639,30 @@ impl Graphics {
)
}

pub fn fill_polygon(
&self,
coords: &[ScreenPoint],
color: LCDColor,
fillrule: LCDPolygonFillRule,
) -> Result<(), Error> {
let n_pts = coords.len();
let mut coords_seq = coords
.iter()
.map(|pt| [pt.x, pt.y])
.flatten()
.collect::<alloc::vec::Vec<_>>();

pd_func_caller!(
(*self.0).fillPolygon,
n_pts as i32,
coords_seq.as_mut_ptr() as *mut i32,
color.into(),
fillrule
)?;

Ok(())
}

pub fn fill_triangle(
&self,
p1: ScreenPoint,
Expand Down

0 comments on commit 501166f

Please sign in to comment.