ferroui_base/media/
i_scene_brush.rs1use crate::media::immutable::immutable_tile_brush::immutable_tile_brush_interfaces;
2use crate::media::immutable::ImmutableTileBrush;
3use crate::media::ref_adapter::RefAdapter;
4use crate::media::{Brush, DrawingBrush, IImmutableBrush, ITileBrush, VisualBrush};
5use crate::platform::IDrawingContextImpl;
6use crate::{Matrix, ObjectType, Rect, Upcast};
7use std::rc::Rc;
8
9pub trait ISceneBrush: ITileBrush {
11 fn create_content(&self) -> Option<Rc<dyn ISceneBrushContent>>;
13}
14
15impl<T: ObjectType + Upcast<Brush>> ISceneBrush for RefAdapter<T> {
18 fn create_content(&self) -> Option<Rc<dyn ISceneBrushContent>> {
19 match self.object().downcast_ref::<VisualBrush>() {
20 Some(visual_brush) => visual_brush.create_content(),
21 None => self.class::<DrawingBrush>().create_content(),
22 }
23 }
24}
25
26pub trait ISceneBrushContent: IImmutableBrush {
28 fn brush(&self) -> Rc<dyn ITileBrush>;
30
31 fn rect(&self) -> Rect;
33
34 fn render(&self, context: &mut dyn IDrawingContextImpl, transform: Option<Matrix>);
36
37 fn use_scalable_rasterization(&self) -> bool;
40
41 fn dispose(&self);
43}
44
45#[derive(Clone)]
47pub struct ImmutableSceneBrush {
48 base: ImmutableTileBrush,
49}
50
51immutable_tile_brush_interfaces!(ImmutableSceneBrush);
52
53impl ImmutableSceneBrush {
54 pub fn new(source: &dyn ITileBrush) -> Self {
56 Self { base: ImmutableTileBrush::from_brush(source) }
57 }
58}