dora_ssr/dora/
grabber.rs

1/* Copyright (c) 2016-2025 Li Jin <dragon-fly@qq.com>
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8
9extern "C" {
10	fn grabber_type() -> i32;
11	fn grabber_set_camera(slf: i64, val: i64);
12	fn grabber_get_camera(slf: i64) -> i64;
13	fn grabber_set_effect(slf: i64, val: i64);
14	fn grabber_get_effect(slf: i64) -> i64;
15	fn grabber_set_blend_func(slf: i64, val: i64);
16	fn grabber_get_blend_func(slf: i64) -> i64;
17	fn grabber_set_clear_color(slf: i64, val: i32);
18	fn grabber_get_clear_color(slf: i64) -> i32;
19	fn grabber_set_pos(slf: i64, x: i32, y: i32, pos: i64, z: f32);
20	fn grabber_get_pos(slf: i64, x: i32, y: i32) -> i64;
21	fn grabber_set_color(slf: i64, x: i32, y: i32, color: i32);
22	fn grabber_get_color(slf: i64, x: i32, y: i32) -> i32;
23	fn grabber_move_uv(slf: i64, x: i32, y: i32, offset: i64);
24}
25use crate::dora::IObject;
26/// A grabber which is used to render a part of the scene to a texture
27/// by a grid of vertices.
28pub struct Grabber { raw: i64 }
29crate::dora_object!(Grabber);
30impl Grabber {
31	pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
32		(unsafe { grabber_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
33			match raw {
34				0 => None,
35				_ => Some(Box::new(Grabber { raw: raw }))
36			}
37		})
38	}
39	/// Sets the camera used to render the texture.
40	pub fn set_camera(&mut self, val: &dyn crate::dora::ICamera) {
41		unsafe { grabber_set_camera(self.raw(), val.raw()) };
42	}
43	/// Gets the camera used to render the texture.
44	pub fn get_camera(&self) -> Option<crate::dora::Camera> {
45		return unsafe { crate::dora::Camera::from(grabber_get_camera(self.raw())) };
46	}
47	/// Sets the sprite effect applied to the texture.
48	pub fn set_effect(&mut self, val: &crate::dora::SpriteEffect) {
49		unsafe { grabber_set_effect(self.raw(), val.raw()) };
50	}
51	/// Gets the sprite effect applied to the texture.
52	pub fn get_effect(&self) -> Option<crate::dora::SpriteEffect> {
53		return unsafe { crate::dora::SpriteEffect::from(grabber_get_effect(self.raw())) };
54	}
55	/// Sets the blend function for the grabber.
56	pub fn set_blend_func(&mut self, val: crate::dora::BlendFunc) {
57		unsafe { grabber_set_blend_func(self.raw(), val.to_value()) };
58	}
59	/// Gets the blend function for the grabber.
60	pub fn get_blend_func(&self) -> crate::dora::BlendFunc {
61		return unsafe { crate::dora::BlendFunc::from(grabber_get_blend_func(self.raw())) };
62	}
63	/// Sets the clear color used to clear the texture.
64	pub fn set_clear_color(&mut self, val: &crate::dora::Color) {
65		unsafe { grabber_set_clear_color(self.raw(), val.to_argb() as i32) };
66	}
67	/// Gets the clear color used to clear the texture.
68	pub fn get_clear_color(&self) -> crate::dora::Color {
69		return unsafe { crate::dora::Color::from(grabber_get_clear_color(self.raw())) };
70	}
71	/// Sets the position of a vertex in the grabber grid.
72	///
73	/// # Arguments
74	///
75	/// * `x` - The x-index of the vertex in the grabber grid.
76	/// * `y` - The y-index of the vertex in the grabber grid.
77	/// * `pos` - The new position of the vertex, represented by a Vec2 object.
78	/// * `z` - An optional argument representing the new z-coordinate of the vertex.
79	pub fn set_pos(&mut self, x: i32, y: i32, pos: &crate::dora::Vec2, z: f32) {
80		unsafe { grabber_set_pos(self.raw(), x, y, pos.into_i64(), z); }
81	}
82	/// Gets the position of a vertex in the grabber grid.
83	///
84	/// # Arguments
85	///
86	/// * `x` - The x-index of the vertex in the grabber grid.
87	/// * `y` - The y-index of the vertex in the grabber grid.
88	///
89	/// # Returns
90	///
91	/// * `Vec2` - The position of the vertex.
92	pub fn get_pos(&self, x: i32, y: i32) -> crate::dora::Vec2 {
93		unsafe { return crate::dora::Vec2::from(grabber_get_pos(self.raw(), x, y)); }
94	}
95	/// Sets the color of a vertex in the grabber grid.
96	///
97	/// # Arguments
98	///
99	/// * `x` - The x-index of the vertex in the grabber grid.
100	/// * `y` - The y-index of the vertex in the grabber grid.
101	/// * `color` - The new color of the vertex, represented by a Color object.
102	pub fn set_color(&mut self, x: i32, y: i32, color: &crate::dora::Color) {
103		unsafe { grabber_set_color(self.raw(), x, y, color.to_argb() as i32); }
104	}
105	/// Gets the color of a vertex in the grabber grid.
106	///
107	/// # Arguments
108	///
109	/// * `x` - The x-index of the vertex in the grabber grid.
110	/// * `y` - The y-index of the vertex in the grabber grid.
111	///
112	/// # Returns
113	///
114	/// * `Color` - The color of the vertex.
115	pub fn get_color(&self, x: i32, y: i32) -> crate::dora::Color {
116		unsafe { return crate::dora::Color::from(grabber_get_color(self.raw(), x, y)); }
117	}
118	/// Sets the UV coordinates of a vertex in the grabber grid.
119	///
120	/// # Arguments
121	///
122	/// * `x` - The x-index of the vertex in the grabber grid.
123	/// * `y` - The y-index of the vertex in the grabber grid.
124	/// * `offset` - The new UV coordinates of the vertex, represented by a Vec2 object.
125	pub fn move_uv(&mut self, x: i32, y: i32, offset: &crate::dora::Vec2) {
126		unsafe { grabber_move_uv(self.raw(), x, y, offset.into_i64()); }
127	}
128}