dora_ssr/dora/
line.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 line_type() -> i32;
11	fn line_set_depth_write(slf: i64, val: i32);
12	fn line_is_depth_write(slf: i64) -> i32;
13	fn line_set_blend_func(slf: i64, val: i64);
14	fn line_get_blend_func(slf: i64) -> i64;
15	fn line_add(slf: i64, verts: i64, color: i32);
16	fn line_set(slf: i64, verts: i64, color: i32);
17	fn line_clear(slf: i64);
18	fn line_new() -> i64;
19	fn line_with_vec_color(verts: i64, color: i32) -> i64;
20}
21use crate::dora::IObject;
22use crate::dora::INode;
23impl INode for Line { }
24/// A struct provides functionality for drawing lines using vertices.
25pub struct Line { raw: i64 }
26crate::dora_object!(Line);
27impl Line {
28	pub(crate) fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
29		(unsafe { line_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
30			match raw {
31				0 => None,
32				_ => Some(Box::new(Line { raw: raw }))
33			}
34		})
35	}
36	/// Sets whether the depth should be written. (Default is false)
37	pub fn set_depth_write(&mut self, val: bool) {
38		unsafe { line_set_depth_write(self.raw(), if val { 1 } else { 0 }) };
39	}
40	/// Gets whether the depth should be written. (Default is false)
41	pub fn is_depth_write(&self) -> bool {
42		return unsafe { line_is_depth_write(self.raw()) != 0 };
43	}
44	/// Sets the blend function for the line node.
45	pub fn set_blend_func(&mut self, val: crate::dora::BlendFunc) {
46		unsafe { line_set_blend_func(self.raw(), val.to_value()) };
47	}
48	/// Gets the blend function for the line node.
49	pub fn get_blend_func(&self) -> crate::dora::BlendFunc {
50		return unsafe { crate::dora::BlendFunc::from(line_get_blend_func(self.raw())) };
51	}
52	/// Adds vertices to the line.
53	///
54	/// # Arguments
55	///
56	/// * `verts` - A vector of vertices to add to the line.
57	/// * `color` - Optional. The color of the line.
58	pub fn add(&mut self, verts: &Vec<crate::dora::Vec2>, color: &crate::dora::Color) {
59		unsafe { line_add(self.raw(), crate::dora::Vector::from_vec2(verts), color.to_argb() as i32); }
60	}
61	/// Sets vertices of the line.
62	///
63	/// # Arguments
64	///
65	/// * `verts` - A vector of vertices to set.
66	/// * `color` - Optional. The color of the line.
67	pub fn set(&mut self, verts: &Vec<crate::dora::Vec2>, color: &crate::dora::Color) {
68		unsafe { line_set(self.raw(), crate::dora::Vector::from_vec2(verts), color.to_argb() as i32); }
69	}
70	/// Clears all the vertices of line.
71	pub fn clear(&mut self) {
72		unsafe { line_clear(self.raw()); }
73	}
74	/// Creates and returns a new empty Line object.
75	///
76	/// # Returns
77	///
78	/// * A new `Line` object.
79	pub fn new() -> Line {
80		unsafe { return Line { raw: line_new() }; }
81	}
82	/// Creates and returns a new Line object.
83	///
84	/// # Arguments
85	///
86	/// * `verts` - A vector of vertices to add to the line.
87	/// * `color` - The color of the line.
88	///
89	/// # Returns
90	///
91	/// * A new `Line` object.
92	pub fn with_vec_color(verts: &Vec<crate::dora::Vec2>, color: &crate::dora::Color) -> Line {
93		unsafe { return Line { raw: line_with_vec_color(crate::dora::Vector::from_vec2(verts), color.to_argb() as i32) }; }
94	}
95}