dora_ssr/dora/
clip_node.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 clipnode_type() -> i32;
11	fn clipnode_set_stencil(slf: i64, val: i64);
12	fn clipnode_get_stencil(slf: i64) -> i64;
13	fn clipnode_set_alpha_threshold(slf: i64, val: f32);
14	fn clipnode_get_alpha_threshold(slf: i64) -> f32;
15	fn clipnode_set_inverted(slf: i64, val: i32);
16	fn clipnode_is_inverted(slf: i64) -> i32;
17	fn clipnode_new(stencil: i64) -> i64;
18}
19use crate::dora::IObject;
20use crate::dora::INode;
21impl INode for ClipNode { }
22/// A Node that can clip its children based on the alpha values of its stencil.
23pub struct ClipNode { raw: i64 }
24crate::dora_object!(ClipNode);
25impl ClipNode {
26	pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
27		(unsafe { clipnode_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
28			match raw {
29				0 => None,
30				_ => Some(Box::new(ClipNode { raw: raw }))
31			}
32		})
33	}
34	/// Sets the stencil Node that defines the clipping shape.
35	pub fn set_stencil(&mut self, val: &dyn crate::dora::INode) {
36		unsafe { clipnode_set_stencil(self.raw(), val.raw()) };
37	}
38	/// Gets the stencil Node that defines the clipping shape.
39	pub fn get_stencil(&self) -> crate::dora::Node {
40		return unsafe { crate::dora::Node::from(clipnode_get_stencil(self.raw())).unwrap() };
41	}
42	/// Sets the minimum alpha threshold for a pixel to be visible. Value ranges from 0 to 1.
43	pub fn set_alpha_threshold(&mut self, val: f32) {
44		unsafe { clipnode_set_alpha_threshold(self.raw(), val) };
45	}
46	/// Gets the minimum alpha threshold for a pixel to be visible. Value ranges from 0 to 1.
47	pub fn get_alpha_threshold(&self) -> f32 {
48		return unsafe { clipnode_get_alpha_threshold(self.raw()) };
49	}
50	/// Sets whether to invert the clipping area.
51	pub fn set_inverted(&mut self, val: bool) {
52		unsafe { clipnode_set_inverted(self.raw(), if val { 1 } else { 0 }) };
53	}
54	/// Gets whether to invert the clipping area.
55	pub fn is_inverted(&self) -> bool {
56		return unsafe { clipnode_is_inverted(self.raw()) != 0 };
57	}
58	/// Creates a new ClipNode object.
59	///
60	/// # Arguments
61	///
62	/// * `stencil` - The stencil Node that defines the clipping shape. Defaults to `None`.
63	///
64	/// # Returns
65	///
66	/// * A new `ClipNode` object.
67	pub fn new(stencil: &dyn crate::dora::INode) -> ClipNode {
68		unsafe { return ClipNode { raw: clipnode_new(stencil.raw()) }; }
69	}
70}