sfml_xt/graphics/
vertex_vec_ext.rs1use sfml::{
2 graphics::{Color, FloatRect, IntRect, Vertex},
3 system::Vector2,
4};
5
6pub trait VertexVecExt {
8 fn push_quad(&mut self, dst_rect: FloatRect, texture_rect: IntRect, color: Color);
10}
11
12impl VertexVecExt for Vec<Vertex> {
13 fn push_quad(&mut self, dst_rect: FloatRect, texture_rect: IntRect, color: Color) {
14 self.extend_from_slice(&[
15 Vertex {
16 position: Vector2::new(dst_rect.left, dst_rect.top),
17 color,
18 tex_coords: Vector2::new(texture_rect.left as f32, texture_rect.top as f32),
19 },
20 Vertex {
21 position: Vector2::new(dst_rect.left + dst_rect.width, dst_rect.top),
22 color,
23 tex_coords: Vector2::new(
24 (texture_rect.left + texture_rect.width) as f32,
25 texture_rect.top as f32,
26 ),
27 },
28 Vertex {
29 position: Vector2::new(
30 dst_rect.left + dst_rect.width,
31 dst_rect.top + dst_rect.height,
32 ),
33 color,
34 tex_coords: Vector2::new(
35 (texture_rect.left + texture_rect.width) as f32,
36 (texture_rect.top + texture_rect.height) as f32,
37 ),
38 },
39 Vertex {
40 position: Vector2::new(dst_rect.left, dst_rect.top + dst_rect.height),
41 color,
42 tex_coords: Vector2::new(
43 texture_rect.left as f32,
44 (texture_rect.top + texture_rect.height) as f32,
45 ),
46 },
47 ]);
48 }
49}