maa_framework/buffer/
rect_buffer.rs1use std::fmt::Debug;
2
3use crate::internal;
4
5pub struct MaaRectBuffer {
6 pub(crate) handle: internal::MaaRectHandle,
7 destroy_at_drop: bool,
8}
9
10impl Debug for MaaRectBuffer {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 f.debug_struct("MaaRectBuffer")
13 .field("x", &self.x())
14 .field("y", &self.y())
15 .field("width", &self.width())
16 .field("height", &self.height())
17 .finish()
18 }
19}
20
21impl From<internal::MaaRectHandle> for MaaRectBuffer {
22 fn from(handle: internal::MaaRectHandle) -> Self {
23 MaaRectBuffer {
24 handle,
25 destroy_at_drop: false,
26 }
27 }
28}
29
30unsafe impl Send for MaaRectBuffer {}
31unsafe impl Sync for MaaRectBuffer {}
32
33impl MaaRectBuffer {
34 pub fn new() -> Self {
35 let handle = unsafe { internal::MaaCreateRectBuffer() };
36
37 MaaRectBuffer {
38 handle,
39 destroy_at_drop: true,
40 }
41 }
42
43 pub fn x(&self) -> i32 {
44 unsafe { internal::MaaGetRectX(self.handle) }
45 }
46
47 pub fn y(&self) -> i32 {
48 unsafe { internal::MaaGetRectY(self.handle) }
49 }
50
51 pub fn width(&self) -> i32 {
52 unsafe { internal::MaaGetRectW(self.handle) }
53 }
54
55 pub fn height(&self) -> i32 {
56 unsafe { internal::MaaGetRectH(self.handle) }
57 }
58
59 pub fn set_x(self, x: i32) -> Self {
60 unsafe {
61 internal::MaaSetRectX(self.handle, x);
62 };
63
64 self
65 }
66
67 pub fn set_y(self, y: i32) -> Self {
68 unsafe {
69 internal::MaaSetRectY(self.handle, y);
70 };
71
72 self
73 }
74
75 pub fn set_width(self, width: i32) -> Self {
76 unsafe {
77 internal::MaaSetRectW(self.handle, width);
78 }
79
80 self
81 }
82
83 pub fn set_height(self, height: i32) -> Self {
84 unsafe {
85 internal::MaaSetRectH(self.handle, height);
86 }
87
88 self
89 }
90}
91
92impl Default for MaaRectBuffer {
93 fn default() -> Self {
94 MaaRectBuffer::new()
95 }
96}
97
98impl Drop for MaaRectBuffer {
99 fn drop(&mut self) {
100 if self.destroy_at_drop {
101 unsafe {
102 internal::MaaDestroyRectBuffer(self.handle);
103 }
104 }
105 }
106}