11use bevy:: prelude:: * ;
22use bevy_prototype_lyon:: prelude:: * ;
33
4- use super :: shape:: Shape ;
4+ use super :: { shape:: { Shape , SingleShape } , shapes:: DoubleShape } ;
5+
6+ #[ derive( Clone , Debug ) ]
7+ pub struct FillPath {
8+ pub size : Vec2 ,
9+ pub path : String ,
10+ pub color : Color ,
11+ pub offset : Vec3 ,
12+ pub scale : f32 ,
13+ pub angle : f32 ,
14+ }
15+
16+ impl Shape for FillPath {
17+ fn _create ( & self , commands : & mut Commands , entity : Entity ) {
18+ self . _do_create ( commands, entity) ;
19+ }
20+ }
21+ impl SingleShape < shapes:: SvgPathShape > for FillPath {
22+ fn get_shape ( & self ) -> shapes:: SvgPathShape {
23+ shapes:: SvgPathShape {
24+ svg_doc_size_in_px : self . size ,
25+ svg_path_string : self . path . clone ( ) ,
26+ }
27+ }
28+ fn get_colors ( & self ) -> ShapeColors {
29+ ShapeColors :: new ( self . color )
30+ }
31+ fn get_draw_mode ( & self ) -> DrawMode {
32+ DrawMode :: Fill ( FillOptions :: default ( ) )
33+ }
34+ fn get_transform ( & self ) -> Transform {
35+ Transform {
36+ translation : self . offset ,
37+ rotation : Quat :: from_rotation_z ( self . angle ) ,
38+ scale : Vec3 :: new ( self . scale , self . scale , 1.0 ) ,
39+ }
40+ }
41+ }
542
643#[ derive( Clone , Debug ) ]
744pub struct StrokePath {
@@ -14,7 +51,12 @@ pub struct StrokePath {
1451 pub angle : f32 ,
1552}
1653
17- impl Shape < shapes:: SvgPathShape > for StrokePath {
54+ impl Shape for StrokePath {
55+ fn _create ( & self , commands : & mut Commands , entity : Entity ) {
56+ self . _do_create ( commands, entity) ;
57+ }
58+ }
59+ impl SingleShape < shapes:: SvgPathShape > for StrokePath {
1860 fn get_shape ( & self ) -> shapes:: SvgPathShape {
1961 shapes:: SvgPathShape {
2062 svg_doc_size_in_px : self . size ,
@@ -36,4 +78,71 @@ impl Shape<shapes::SvgPathShape> for StrokePath {
3678 scale : Vec3 :: new ( self . scale , self . scale , 1.0 ) ,
3779 }
3880 }
81+ }
82+
83+ #[ derive( Clone , Debug ) ]
84+ pub struct StrokeCirclePath {
85+ pub radius : f32 ,
86+ pub path : StrokePath ,
87+ }
88+
89+ impl Shape for StrokeCirclePath {
90+ fn _create ( & self , commands : & mut Commands , entity : Entity ) {
91+ self . _do_create ( commands, entity) ;
92+ }
93+ }
94+ impl DoubleShape < shapes:: Circle , shapes:: SvgPathShape > for StrokeCirclePath {
95+ fn get_shape1 ( & self ) -> shapes:: Circle {
96+ shapes:: Circle {
97+ center : Vec2 :: ZERO ,
98+ radius : self . radius ,
99+ }
100+ }
101+ fn get_shape2 ( & self ) -> shapes:: SvgPathShape {
102+ self . path . get_shape ( )
103+ }
104+ fn get_colors ( & self ) -> ShapeColors {
105+ self . path . get_colors ( )
106+ }
107+ fn get_draw_mode ( & self ) -> DrawMode {
108+ self . path . get_draw_mode ( )
109+ }
110+ fn get_transform ( & self ) -> Transform {
111+ self . path . get_transform ( )
112+ }
113+ }
114+
115+ #[ derive( Clone , Debug ) ]
116+ pub struct StrokeRectanglePath {
117+ pub width : f32 ,
118+ pub height : f32 ,
119+ pub origin : shapes:: RectangleOrigin ,
120+ pub path : StrokePath ,
121+ }
122+
123+ impl Shape for StrokeRectanglePath {
124+ fn _create ( & self , commands : & mut Commands , entity : Entity ) {
125+ self . _do_create ( commands, entity) ;
126+ }
127+ }
128+ impl DoubleShape < shapes:: Rectangle , shapes:: SvgPathShape > for StrokeRectanglePath {
129+ fn get_shape1 ( & self ) -> shapes:: Rectangle {
130+ shapes:: Rectangle {
131+ width : self . width ,
132+ height : self . height ,
133+ origin : self . origin ,
134+ }
135+ }
136+ fn get_shape2 ( & self ) -> shapes:: SvgPathShape {
137+ self . path . get_shape ( )
138+ }
139+ fn get_colors ( & self ) -> ShapeColors {
140+ self . path . get_colors ( )
141+ }
142+ fn get_draw_mode ( & self ) -> DrawMode {
143+ self . path . get_draw_mode ( )
144+ }
145+ fn get_transform ( & self ) -> Transform {
146+ self . path . get_transform ( )
147+ }
39148}
0 commit comments