1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Structs for Drawing Shapes
use std::sync::Arc;
use crate::{
builder::Shape,
draw::{color, Color},
};
pub struct Painter {
pub(crate) clear_color: Color,
pub(crate) shapes: Vec<Arc<Shape>>,
}
impl Painter {
pub fn new() -> Self {
Self {
clear_color: color::BLACK,
shapes: Vec::new(),
}
}
/// Change the Clear Color used
pub fn clear_color(&mut self, color: Color) {
self.clear_color = color;
}
pub fn draw(&mut self, shape: Shape) {
self.shapes.push(Arc::new(shape));
}
pub fn draw_ref(&mut self, shape: Arc<Shape>) {
self.shapes.push(shape);
}
/*/// Draw an ellipse
pub fn ellipse(&mut self, pos: (f32, f32), radius: (f32, f32), res: u32, clr: Color) {
if res < 3 {
panic!("Failed to draw ellipse, Resolution can't be less then 3");
}
let clr = [clr.r, clr.g, clr.b];
let mut vertices: Vec<Vertex> = vec![vertex([pos.0, pos.1, 0.0], clr)];
let mut indices: Vec<u16> = Vec::new();
for i in 0..res {
let fi = (i as f32 / res as f32) * (PI * 2.0);
let x = fi.cos() * radius.0 + pos.0;
let y = fi.sin() * radius.1 + pos.1;
vertices.push(vertex([x, y, 0.0], clr));
}
for i in 1..vertices.len() {
indices.push(i as u16);
indices.push(if i + 1 == vertices.len() {
1
} else {
(i + 1) as u16
});
indices.push(0);
}
self.shapes.push(Shape::Mesh { vertices, indices });
}
/// Draw a rectangle
pub fn rect(&mut self, pos0: (f32, f32), pos1: (f32, f32), clr: Color) {
let clr = [clr.r, clr.g, clr.b];
self.shapes.push(Shape::Mesh {
vertices: vec![
vertex([pos0.0, pos0.1, 0.0], clr),
vertex([pos1.0, pos0.1, 0.0], clr),
vertex([pos1.0, pos1.1, 0.0], clr),
vertex([pos0.0, pos1.1, 0.0], clr),
],
indices: vec![0, 1, 2, 2, 3, 0],
});
}
/// Draw text on the screen
///
/// 0. this function currently uses pixel coordinates
/// 1. rendered text is in screen space
pub fn text(&mut self, pos: (f32, f32), scale: f32, text: String, clr: Color) {
self.shapes.push(Shape::Text {
pos,
text: vec![Text {
string: text,
scale,
color: clr,
}],
});
}
/// Draw text on the screen
///
/// 0. this function currently uses pixel coordinates
/// 1. rendered text is in screen space
pub fn text_raw(&mut self, pos: (f32, f32), text: Vec<Text>) {
self.shapes.push(Shape::Text { pos, text });
}
// Draw a mesh from vertices and indices
pub fn raw(&mut self, vertices: Vec<Vertex>, indices: Vec<u16>) {
self.shapes.push(Shape::Mesh { vertices, indices })
}*/
}