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
use crate::internal::*;
use crate::texture::*;
use crate::*;
use std::marker::PhantomData;
pub struct StaticBatch<'b, 't: 'b> {
raw: *mut BLZ_StaticBatch,
_marker: PhantomData<&'b ()>,
options: StaticBatchOpts<'t>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StaticBatchOpts<'a> {
pub texture: &'a Texture<'a>,
pub max_sprites: u32,
}
impl<'b, 't: 'b> Drop for StaticBatch<'b, 't> {
fn drop(&mut self) {
unsafe {
BLZ_FreeBatchStatic(self.raw);
}
}
}
impl<'b, 't: 'b> StaticBatch<'b, 't> {
pub fn new(options: StaticBatchOpts<'t>) -> Result<StaticBatch<'b, 't>, String> {
unsafe {
let ptr = BLZ_CreateStatic(options.texture.raw, options.max_sprites as i32);
if ptr.is_null() {
return Err(try_get_err());
} else {
return Ok(StaticBatch { raw: ptr, _marker: PhantomData, options: options });
}
}
}
pub fn draw(
&self,
position: Vector2,
srcRectangle: Option<Rectangle>,
rotationInRadians: f32,
origin: Option<Vector2>,
scale: Option<Vector2>,
color: Color,
flip: SpriteFlip,
) -> CallResult {
unsafe {
wrap_result(BLZ_DrawStatic(
self.raw,
position.into(),
srcRectangle.map(|r| r.into()).as_raw(),
rotationInRadians,
origin.map(|v| v.into()).as_raw(),
scale.map(|v| v.into()).as_raw(),
color.into(),
flip as u32,
))
}
}
pub fn lower_draw(&self, quad: &SpriteQuad) -> CallResult {
let q: BLZ_SpriteQuad = quad.into();
unsafe { wrap_result(BLZ_LowerDrawStatic(self.raw, &q)) }
}
pub fn present(&self, transformMatrix: &[f32; 16]) -> CallResult {
unsafe {
let matrix_ptr: *const f32 = transformMatrix as *const f32;
wrap_result(BLZ_PresentStatic(self.raw, matrix_ptr))
}
}
pub fn get_options(&self) -> &StaticBatchOpts {
&self.options
}
}