Skip to main content

wgpu_shapes/shape/
shapes.rs

1use wgpu::Color;
2
3use crate::render::instance::Instance;
4
5pub struct BasicShapeData {
6    pub scale: (f32, f32),
7    pub pos: (f32, f32),
8    pub rotation: f32,
9    pub color: (f32, f32, f32),
10    pub layer: u16,
11}
12
13impl From<&BasicShapeData> for Instance {
14    fn from(data: &BasicShapeData) -> Self {
15        Instance {
16            position: [data.pos.0, data.pos.1],
17            scale: [data.scale.0, data.scale.1],
18            rotation: data.rotation,
19            color: [data.color.0, data.color.1, data.color.2],
20            layer: data.layer as u32,
21        }
22    }
23}
24
25impl Default for BasicShapeData {
26    fn default() -> Self {
27        BasicShapeData {
28            scale: (20.0, 20.0),
29            pos: (0.0, 0.0),
30            rotation: 0.0,
31            color: (0.0, 0.0, 1.0),
32            layer: 0,
33        }
34    }
35}
36
37pub trait BasicShape {
38    /// size of the shape
39    fn scale(&mut self, width: f32, height: f32) -> &mut Self;
40
41    /// location of the shape in the frame
42    fn pos(&mut self, x: f32, y: f32) -> &mut Self;
43
44    /// rotation of the shape in radians
45    fn rotation(&mut self, rotation: f32) -> &mut Self;
46
47    /// fill color of the shape
48    fn color(&mut self, red: f32, green: f32, blue: f32) -> &mut Self;
49
50    /// fill color of the shape
51    fn color_from_color(&mut self, color: Color) -> &mut Self;
52
53    /// render layer of the shape
54    ///
55    /// higher layer -> foreground
56    fn layer(&mut self, layer: u16) -> &mut Self;
57
58    fn to_instance(&self) -> Instance;
59}