rive_rs/shapes/paint/
fill.rsuse std::cell::RefCell;
use std::rc::Rc;
use crate::core::{Core, Object, ObjectRef, OnAdded, Property};
use crate::math::Mat;
use crate::renderer::Style;
use crate::shapes::paint::{ShapePaint, ShapePaintMutator};
use crate::shapes::path_space::PathSpace;
use crate::shapes::{CommandPath, FillRule};
use crate::{RenderPaint, Renderer};
#[derive(Debug, Default)]
pub struct Fill {
shape_paint: ShapePaint,
fill_rule: Property<FillRule>,
}
impl ObjectRef<'_, Fill> {
pub fn fill_rule(&self) -> FillRule {
self.fill_rule.get()
}
pub fn set_fill_rule(&self, fill_rule: FillRule) {
self.fill_rule.set(fill_rule);
}
}
impl ObjectRef<'_, Fill> {
pub fn init_render_paint(
&self,
mutator: Object<ShapePaintMutator>,
) -> Option<Rc<RefCell<RenderPaint>>> {
let render_paint = self.cast::<ShapePaint>().init_render_paint(mutator).unwrap();
render_paint.borrow_mut().style = Style::Fill;
Some(render_paint)
}
pub fn path_space(&self) -> PathSpace {
PathSpace::LOCAL
}
pub fn draw(&self, renderer: &mut impl Renderer, path: &CommandPath, transform: Mat) {
if !self.cast::<ShapePaint>().is_visible() {
return;
}
let render_paint = self.cast::<ShapePaint>().render_paint();
render_paint.borrow_mut().fill_rule = self.fill_rule();
renderer.draw(path, transform, &*render_paint.borrow());
}
}
impl Core for Fill {
parent_types![(shape_paint, ShapePaint)];
properties![(40, fill_rule, set_fill_rule), shape_paint];
}
impl OnAdded for ObjectRef<'_, Fill> {
on_added!(ShapePaint);
}