1use crate::b2_math::{B2Transform, B2vec2};
2
3use std::cell::RefCell;
4use std::rc::Rc;
5use bitflags::bitflags;
6
7#[derive(Copy, Clone, Debug)]
9pub struct B2color {
10 pub r: f32,
11 pub g: f32,
12 pub b: f32,
13 pub a: f32,
14}
15impl B2color {
16 pub fn new(r_in: f32, g_in: f32, b_in: f32) -> B2color {
17 return B2color {
18 r: r_in,
19 g: g_in,
20 b: b_in,
21 a: 1.0,
22 };
23 }
24
25 pub fn new_with_alpha(r_in: f32, g_in: f32, b_in: f32, a_in: f32) -> B2color {
26 return B2color {
27 r: r_in,
28 g: g_in,
29 b: b_in,
30 a: a_in,
31 };
32 }
33
34 pub fn set(&mut self, r_in: f32, g_in: f32, b_in: f32) {
35 self.r = r_in;
36 self.g = g_in;
37 self.b = b_in;
38 }
39
40 pub fn set_with_alpha(&mut self, r_in: f32, g_in: f32, b_in: f32, a_in: f32) {
41 self.r = r_in;
42 self.g = g_in;
43 self.b = b_in;
44 self.a = a_in;
45 }
46}
47
48#[derive(Debug, Clone, Copy, Default)]
49pub struct B2draw {
50 m_draw_flags: B2drawShapeFlags,
51}
52
53bitflags! {
54 #[derive(Debug, Clone, Copy, Default)]
55 pub struct B2drawShapeFlags: u16 {
56 const SHAPE_BIT = 0x0001;
58 const JOINT_BIT = 0x0002;
60 const AABB_BIT = 0x0004;
62 const PAIR_BIT = 0x0008;
64 const CENTER_OF_MASS_BIT = 0x0010;
66}
67}
68
69impl B2draw {
70 pub fn set_flags(&mut self, flags: B2drawShapeFlags) {
72 self.m_draw_flags = flags;
73 }
74
75 pub fn get_flags(self) -> B2drawShapeFlags {
77 return self.m_draw_flags;
78 }
79
80 pub fn append_flags(&mut self, flags: B2drawShapeFlags) {
82 self.m_draw_flags.insert(flags);
83 }
84
85 pub fn clear_flags(&mut self, flags: B2drawShapeFlags) {
87 self.m_draw_flags.remove(flags);
88 }
89}
90
91pub type B2drawTraitPtr = Rc<RefCell<dyn B2drawTrait>>;
92
93pub trait B2drawTrait {
94 fn get_base(&self) -> &B2draw;
95 fn get_base_mut(&mut self) -> &mut B2draw;
96 fn draw_polygon(&mut self, vertices: &[B2vec2], color: B2color);
98
99 fn draw_solid_polygon(&mut self, vertices: &[B2vec2], color: B2color);
101
102 fn draw_circle(&mut self, center: B2vec2, radius: f32, color: B2color);
104
105 fn draw_solid_circle(&mut self, center: B2vec2, radius: f32, axis: B2vec2, color: B2color);
107
108 fn draw_segment(&mut self, p1: B2vec2, p2: B2vec2, color: B2color);
110
111 fn draw_transform(&mut self, xf: B2Transform);
114
115 fn draw_point(&mut self, p: B2vec2, size: f32, color: B2color);
117}