rive_rs/shapes/
cubic_detached_vertex.rs
1use crate::core::{Core, ObjectRef, OnAdded, Property};
6use crate::math;
7use crate::shapes::{CubicVertex, PathVertex};
8
9#[derive(Debug, Default)]
10pub struct CubicDetachedVertex {
11 cubic_vertex: CubicVertex,
12 in_rotation: Property<f32>,
13 in_distance: Property<f32>,
14 out_rotation: Property<f32>,
15 out_distance: Property<f32>,
16}
17
18impl ObjectRef<'_, CubicDetachedVertex> {
19 pub fn in_rotation(&self) -> f32 {
20 self.in_rotation.get()
21 }
22
23 pub fn set_in_rotation(&self, in_rotation: f32) {
24 if self.in_rotation() == in_rotation {
25 return;
26 }
27
28 self.in_rotation.set(in_rotation);
29
30 self.cast::<CubicVertex>().invalidate_in();
31 self.cast::<PathVertex>().mark_path_dirty();
32 }
33
34 pub fn in_distance(&self) -> f32 {
35 self.in_distance.get()
36 }
37
38 pub fn set_in_distance(&self, in_distance: f32) {
39 if self.in_distance() == in_distance {
40 return;
41 }
42
43 self.in_distance.set(in_distance);
44
45 self.cast::<CubicVertex>().invalidate_in();
46 self.cast::<PathVertex>().mark_path_dirty();
47 }
48
49 pub fn out_rotation(&self) -> f32 {
50 self.out_rotation.get()
51 }
52
53 pub fn set_out_rotation(&self, out_rotation: f32) {
54 if self.out_rotation() == out_rotation {
55 return;
56 }
57
58 self.out_rotation.set(out_rotation);
59
60 self.cast::<CubicVertex>().invalidate_out();
61 self.cast::<PathVertex>().mark_path_dirty();
62 }
63
64 pub fn out_distance(&self) -> f32 {
65 self.out_distance.get()
66 }
67
68 pub fn set_out_distance(&self, out_distance: f32) {
69 if self.out_distance() == out_distance {
70 return;
71 }
72
73 self.out_distance.set(out_distance);
74
75 self.cast::<CubicVertex>().invalidate_out();
76 self.cast::<PathVertex>().mark_path_dirty();
77 }
78}
79
80impl ObjectRef<'_, CubicDetachedVertex> {
81 pub fn compute_in(&self) {
82 let pos = math::Vec::new(self.cast::<PathVertex>().x(), self.cast::<PathVertex>().y());
83 let diff = math::Vec::new(
84 self.in_rotation().cos() * self.in_distance(),
85 self.in_rotation().sin() * self.in_distance(),
86 );
87
88 self.cast::<CubicVertex>().set_in_point(pos + diff);
89 }
90
91 pub fn compute_out(&self) {
92 let pos = math::Vec::new(self.cast::<PathVertex>().x(), self.cast::<PathVertex>().y());
93 let diff = math::Vec::new(
94 self.out_rotation().cos() * self.out_distance(),
95 self.out_rotation().sin() * self.out_distance(),
96 );
97
98 self.cast::<CubicVertex>().set_out_point(pos + diff);
99 }
100}
101
102impl Core for CubicDetachedVertex {
103 parent_types![(cubic_vertex, CubicVertex)];
104
105 properties![
106 (84, in_rotation, set_in_rotation),
107 (85, in_distance, set_in_distance),
108 (86, out_rotation, set_out_rotation),
109 (87, out_distance, set_out_distance),
110 cubic_vertex,
111 ];
112}
113
114impl OnAdded for ObjectRef<'_, CubicDetachedVertex> {
115 on_added!(CubicVertex);
116}