ferroui_base/media/
stream_geometry_context.rs1use crate::media::precise_elliptic_arc_helper::PreciseEllipticArcHelper;
2use crate::media::{FillRule, SweepDirection};
3#[allow(deprecated)]
4use crate::platform::IStreamGeometryContextImpl;
5use crate::platform::IGeometryContext;
6use crate::{Point, Size};
7
8pub struct StreamGeometryContext {
14 context: Box<dyn IGeometryContext>,
15 current_point: Point,
16 is_disposed: bool,
17}
18
19impl StreamGeometryContext {
20 #[deprecated(note = "Use StreamGeometry::open instead.")]
22 #[allow(deprecated)]
23 pub fn new(impl_: Box<dyn IStreamGeometryContextImpl>) -> Self {
24 Self::from_context(impl_)
25 }
26
27 pub(crate) fn from_context(context: Box<dyn IGeometryContext>) -> Self {
29 Self { context, current_point: Point::default(), is_disposed: false }
30 }
31
32 pub fn precise_arc_to(
48 &mut self,
49 point: Point,
50 size: Size,
51 rotation_angle: f64,
52 is_large_arc: bool,
53 sweep_direction: SweepDirection,
54 ) {
55 let current_point = self.current_point;
56 PreciseEllipticArcHelper::arc_to(self, current_point, point, size, rotation_angle, is_large_arc, sweep_direction);
57 }
58}
59
60impl IGeometryContext for StreamGeometryContext {
61 fn set_fill_rule(&mut self, fill_rule: FillRule) {
62 self.context.set_fill_rule(fill_rule);
63 }
64
65 fn arc_to(
66 &mut self,
67 point: Point,
68 size: Size,
69 rotation_angle: f64,
70 is_large_arc: bool,
71 sweep_direction: SweepDirection,
72 is_stroked: bool,
73 ) {
74 self.context.arc_to(point, size, rotation_angle, is_large_arc, sweep_direction, is_stroked);
75 self.current_point = point;
76 }
77
78 fn begin_figure(&mut self, start_point: Point, is_filled: bool) {
79 self.context.begin_figure(start_point, is_filled);
80 self.current_point = start_point;
81 }
82
83 fn cubic_bezier_to(&mut self, control_point1: Point, control_point2: Point, end_point: Point, is_stroked: bool) {
84 self.context.cubic_bezier_to(control_point1, control_point2, end_point, is_stroked);
85 self.current_point = end_point;
86 }
87
88 fn quadratic_bezier_to(&mut self, control_point: Point, end_point: Point, is_stroked: bool) {
89 self.context.quadratic_bezier_to(control_point, end_point, is_stroked);
90 self.current_point = end_point;
91 }
92
93 fn line_to(&mut self, point: Point, is_stroked: bool) {
94 self.context.line_to(point, is_stroked);
95 self.current_point = point;
96 }
97
98 fn end_figure(&mut self, is_closed: bool) {
99 self.context.end_figure(is_closed);
100 }
101
102 fn dispose(&mut self) {
104 if !self.is_disposed {
105 self.is_disposed = true;
106 self.context.dispose();
107 }
108 }
109}
110
111impl Drop for StreamGeometryContext {
112 fn drop(&mut self) {
113 self.dispose();
114 }
115}