use crate::{ffi, AbyssPolicy, Buffer, CachePolicy, Operation, Processor, Rectangle};
use glib::{
object::ObjectType as _,
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "GeglNode")]
pub struct Node(Object<ffi::GeglNode>);
match fn {
type_ => || ffi::gegl_node_get_type(),
}
}
impl Node {
#[doc(alias = "gegl_node_new")]
pub fn new() -> Node {
unsafe { from_glib_full(ffi::gegl_node_new()) }
}
#[doc(alias = "gegl_node_new_from_file")]
#[doc(alias = "new_from_file")]
pub fn from_file(path: &str) -> Node {
unsafe { from_glib_full(ffi::gegl_node_new_from_file(path.to_glib_none().0)) }
}
#[doc(alias = "gegl_node_new_from_serialized")]
#[doc(alias = "new_from_serialized")]
pub fn from_serialized(chaindata: &str, path_root: &str) -> Node {
unsafe {
from_glib_full(ffi::gegl_node_new_from_serialized(
chaindata.to_glib_none().0,
path_root.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_new_from_xml")]
#[doc(alias = "new_from_xml")]
pub fn from_xml(xmldata: &str, path_root: &str) -> Node {
unsafe {
from_glib_full(ffi::gegl_node_new_from_xml(
xmldata.to_glib_none().0,
path_root.to_glib_none().0,
))
}
}
pub fn builder() -> NodeBuilder {
NodeBuilder::new()
}
#[doc(alias = "gegl_node_add_child")]
#[must_use]
pub fn add_child(&self, child: &Node) -> Option<Node> {
unsafe {
from_glib_none(ffi::gegl_node_add_child(
self.to_glib_none().0,
child.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_blit_buffer")]
pub fn blit_buffer(
&self,
buffer: Option<&Buffer>,
roi: Option<&Rectangle>,
level: i32,
abyss_policy: AbyssPolicy,
) {
unsafe {
ffi::gegl_node_blit_buffer(
self.to_glib_none().0,
buffer.to_glib_none().0,
roi.to_glib_none().0,
level,
abyss_policy.into_glib(),
);
}
}
#[doc(alias = "gegl_node_connect")]
pub fn connect(&self, a_pad_name: &str, b: &Node, b_pad_name: &str) -> bool {
unsafe {
from_glib(ffi::gegl_node_connect(
self.to_glib_none().0,
a_pad_name.to_glib_none().0,
b.to_glib_none().0,
b_pad_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_connect_from")]
pub fn connect_from(&self, input_pad_name: &str, source: &Node, output_pad_name: &str) -> bool {
unsafe {
from_glib(ffi::gegl_node_connect_from(
self.to_glib_none().0,
input_pad_name.to_glib_none().0,
source.to_glib_none().0,
output_pad_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_connect_to")]
pub fn connect_to(&self, output_pad_name: &str, sink: &Node, input_pad_name: &str) -> bool {
unsafe {
from_glib(ffi::gegl_node_connect_to(
self.to_glib_none().0,
output_pad_name.to_glib_none().0,
sink.to_glib_none().0,
input_pad_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_create_child")]
#[must_use]
pub fn create_child(&self, operation: &str) -> Option<Node> {
unsafe {
from_glib_none(ffi::gegl_node_create_child(
self.to_glib_none().0,
operation.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_detect")]
#[must_use]
pub fn detect(&self, x: i32, y: i32) -> Option<Node> {
unsafe { from_glib_none(ffi::gegl_node_detect(self.to_glib_none().0, x, y)) }
}
#[doc(alias = "gegl_node_disconnect")]
pub fn disconnect(&self, input_pad: &str) -> bool {
unsafe {
from_glib(ffi::gegl_node_disconnect(
self.to_glib_none().0,
input_pad.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_find_property")]
pub fn find_property(&self, property_name: &str) -> Option<glib::ParamSpec> {
unsafe {
from_glib_none(ffi::gegl_node_find_property(
self.to_glib_none().0,
property_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_get_children")]
#[doc(alias = "get_children")]
pub fn children(&self) -> Vec<Node> {
unsafe {
FromGlibPtrContainer::from_glib_container(ffi::gegl_node_get_children(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_get_consumers")]
#[doc(alias = "get_consumers")]
pub fn consumers(&self, output_pad: &str) -> (i32, Vec<Node>, Vec<glib::GString>) {
unsafe {
let mut nodes = std::ptr::null_mut();
let mut pads = std::ptr::null_mut();
let ret = ffi::gegl_node_get_consumers(
self.to_glib_none().0,
output_pad.to_glib_none().0,
&mut nodes,
&mut pads,
);
(
ret,
FromGlibPtrContainer::from_glib_full(nodes),
FromGlibPtrContainer::from_glib_full(pads),
)
}
}
#[doc(alias = "gegl_node_get_gegl_operation")]
#[doc(alias = "get_gegl_operation")]
#[doc(alias = "gegl-operation")]
pub fn gegl_operation(&self) -> Option<Operation> {
unsafe { from_glib_none(ffi::gegl_node_get_gegl_operation(self.to_glib_none().0)) }
}
#[doc(alias = "gegl_node_get_input_proxy")]
#[doc(alias = "get_input_proxy")]
#[must_use]
pub fn input_proxy(&self, pad_name: &str) -> Option<Node> {
unsafe {
from_glib_none(ffi::gegl_node_get_input_proxy(
self.to_glib_none().0,
pad_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_get_operation")]
#[doc(alias = "get_operation")]
pub fn operation(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::gegl_node_get_operation(self.to_glib_none().0)) }
}
#[doc(alias = "gegl_node_get_output_proxy")]
#[doc(alias = "get_output_proxy")]
#[must_use]
pub fn output_proxy(&self, pad_name: &str) -> Option<Node> {
unsafe {
from_glib_none(ffi::gegl_node_get_output_proxy(
self.to_glib_none().0,
pad_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_get_parent")]
#[doc(alias = "get_parent")]
#[must_use]
pub fn parent(&self) -> Option<Node> {
unsafe { from_glib_none(ffi::gegl_node_get_parent(self.to_glib_none().0)) }
}
#[doc(alias = "gegl_node_get_passthrough")]
#[doc(alias = "get_passthrough")]
#[doc(alias = "passthrough")]
pub fn is_passthrough(&self) -> bool {
unsafe { from_glib(ffi::gegl_node_get_passthrough(self.to_glib_none().0)) }
}
#[doc(alias = "gegl_node_get_property")]
#[doc(alias = "get_property")]
pub fn property(&self, property_name: &str) -> glib::Value {
unsafe {
let mut value = glib::Value::uninitialized();
ffi::gegl_node_get_property(
self.to_glib_none().0,
property_name.to_glib_none().0,
value.to_glib_none_mut().0,
);
value
}
}
#[doc(alias = "gegl_node_has_pad")]
pub fn has_pad(&self, pad_name: &str) -> bool {
unsafe {
from_glib(ffi::gegl_node_has_pad(
self.to_glib_none().0,
pad_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_introspectable_get_bounding_box")]
pub fn introspectable_get_bounding_box(&self) -> Option<Rectangle> {
unsafe {
from_glib_full(ffi::gegl_node_introspectable_get_bounding_box(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_introspectable_get_property")]
pub fn introspectable_get_property(&self, property_name: &str) -> Option<glib::Value> {
unsafe {
from_glib_full(ffi::gegl_node_introspectable_get_property(
self.to_glib_none().0,
property_name.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_is_graph")]
pub fn is_graph(&self) -> bool {
unsafe { from_glib(ffi::gegl_node_is_graph(self.to_glib_none().0)) }
}
#[doc(alias = "gegl_node_link")]
pub fn link(&self, sink: &Node) {
unsafe {
ffi::gegl_node_link(self.to_glib_none().0, sink.to_glib_none().0);
}
}
#[doc(alias = "gegl_node_list_input_pads")]
pub fn list_input_pads(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gegl_node_list_input_pads(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_list_output_pads")]
pub fn list_output_pads(&self) -> Vec<glib::GString> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::gegl_node_list_output_pads(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_new_processor")]
pub fn new_processor(&self, rectangle: &Rectangle) -> Option<Processor> {
unsafe {
from_glib_full(ffi::gegl_node_new_processor(
self.to_glib_none().0,
rectangle.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_process")]
pub fn process(&self) {
unsafe {
ffi::gegl_node_process(self.to_glib_none().0);
}
}
#[doc(alias = "gegl_node_progress")]
pub fn progress(&self, progress: f64, message: &str) {
unsafe {
ffi::gegl_node_progress(self.to_glib_none().0, progress, message.to_glib_none().0);
}
}
#[doc(alias = "gegl_node_remove_child")]
#[must_use]
pub fn remove_child(&self, child: &Node) -> Option<Node> {
unsafe {
from_glib_none(ffi::gegl_node_remove_child(
self.to_glib_none().0,
child.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_set_enum_as_string")]
pub fn set_enum_as_string(&self, key: &str, value: &str) {
unsafe {
ffi::gegl_node_set_enum_as_string(
self.to_glib_none().0,
key.to_glib_none().0,
value.to_glib_none().0,
);
}
}
#[doc(alias = "gegl_node_set_passthrough")]
#[doc(alias = "passthrough")]
pub fn set_passthrough(&self, passthrough: bool) {
unsafe {
ffi::gegl_node_set_passthrough(self.to_glib_none().0, passthrough.into_glib());
}
}
#[doc(alias = "gegl_node_set_property")]
pub fn set_property(&self, property_name: &str, value: &glib::Value) {
unsafe {
ffi::gegl_node_set_property(
self.to_glib_none().0,
property_name.to_glib_none().0,
value.to_glib_none().0,
);
}
}
#[doc(alias = "gegl_node_set_time")]
pub fn set_time(&self, time: f64) {
unsafe {
ffi::gegl_node_set_time(self.to_glib_none().0, time);
}
}
#[doc(alias = "gegl_node_to_xml")]
pub fn to_xml(&self, path_root: &str) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::gegl_node_to_xml(
self.to_glib_none().0,
path_root.to_glib_none().0,
))
}
}
#[doc(alias = "gegl_node_to_xml_full")]
pub fn to_xml_full(&self, tail: Option<&Node>, path_root: &str) -> Option<glib::GString> {
unsafe {
from_glib_full(ffi::gegl_node_to_xml_full(
self.to_glib_none().0,
tail.to_glib_none().0,
path_root.to_glib_none().0,
))
}
}
#[doc(alias = "cache-policy")]
pub fn cache_policy(&self) -> CachePolicy {
ObjectExt::property(self, "cache-policy")
}
#[doc(alias = "cache-policy")]
pub fn set_cache_policy(&self, cache_policy: CachePolicy) {
ObjectExt::set_property(self, "cache-policy", cache_policy)
}
#[doc(alias = "dont-cache")]
pub fn is_dont_cache(&self) -> bool {
ObjectExt::property(self, "dont-cache")
}
#[doc(alias = "dont-cache")]
pub fn set_dont_cache(&self, dont_cache: bool) {
ObjectExt::set_property(self, "dont-cache", dont_cache)
}
#[doc(alias = "gegl-operation")]
pub fn set_gegl_operation(&self, gegl_operation: Option<&Operation>) {
ObjectExt::set_property(self, "gegl-operation", gegl_operation)
}
pub fn name(&self) -> Option<glib::GString> {
ObjectExt::property(self, "name")
}
pub fn set_name(&self, name: Option<&str>) {
ObjectExt::set_property(self, "name", name)
}
pub fn set_operation(&self, operation: Option<&str>) {
ObjectExt::set_property(self, "operation", operation)
}
#[doc(alias = "use-opencl")]
pub fn uses_opencl(&self) -> bool {
ObjectExt::property(self, "use-opencl")
}
#[doc(alias = "use-opencl")]
pub fn set_use_opencl(&self, use_opencl: bool) {
ObjectExt::set_property(self, "use-opencl", use_opencl)
}
#[doc(alias = "computed")]
pub fn connect_computed<F: Fn(&Self, &Rectangle) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn computed_trampoline<F: Fn(&Node, &Rectangle) + 'static>(
this: *mut ffi::GeglNode,
object: *mut ffi::GeglRectangle,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), &from_glib_borrow(object))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"computed".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
computed_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "invalidated")]
pub fn connect_invalidated<F: Fn(&Self, &Rectangle) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn invalidated_trampoline<F: Fn(&Node, &Rectangle) + 'static>(
this: *mut ffi::GeglNode,
object: *mut ffi::GeglRectangle,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), &from_glib_borrow(object))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"invalidated".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
invalidated_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "progress")]
pub fn connect_progress<F: Fn(&Self, f64) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn progress_trampoline<F: Fn(&Node, f64) + 'static>(
this: *mut ffi::GeglNode,
object: std::ffi::c_double,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), object)
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"progress".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
progress_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "cache-policy")]
pub fn connect_cache_policy_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_cache_policy_trampoline<F: Fn(&Node) + 'static>(
this: *mut ffi::GeglNode,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::cache-policy".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_cache_policy_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "dont-cache")]
pub fn connect_dont_cache_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_dont_cache_trampoline<F: Fn(&Node) + 'static>(
this: *mut ffi::GeglNode,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::dont-cache".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_dont_cache_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "gegl-operation")]
pub fn connect_gegl_operation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_gegl_operation_trampoline<F: Fn(&Node) + 'static>(
this: *mut ffi::GeglNode,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::gegl-operation".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_gegl_operation_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "name")]
pub fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_name_trampoline<F: Fn(&Node) + 'static>(
this: *mut ffi::GeglNode,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::name".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_name_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "operation")]
pub fn connect_operation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_operation_trampoline<F: Fn(&Node) + 'static>(
this: *mut ffi::GeglNode,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::operation".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_operation_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "passthrough")]
pub fn connect_passthrough_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_passthrough_trampoline<F: Fn(&Node) + 'static>(
this: *mut ffi::GeglNode,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::passthrough".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_passthrough_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "use-opencl")]
pub fn connect_use_opencl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_use_opencl_trampoline<F: Fn(&Node) + 'static>(
this: *mut ffi::GeglNode,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::use-opencl".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_use_opencl_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for Node {
fn default() -> Self {
Self::new()
}
}
#[must_use = "The builder must be built to be used"]
pub struct NodeBuilder {
builder: glib::object::ObjectBuilder<'static, Node>,
}
impl NodeBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn cache_policy(self, cache_policy: CachePolicy) -> Self {
Self {
builder: self.builder.property("cache-policy", cache_policy),
}
}
pub fn dont_cache(self, dont_cache: bool) -> Self {
Self {
builder: self.builder.property("dont-cache", dont_cache),
}
}
pub fn gegl_operation(self, gegl_operation: &Operation) -> Self {
Self {
builder: self
.builder
.property("gegl-operation", gegl_operation.clone()),
}
}
pub fn name(self, name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("name", name.into()),
}
}
pub fn operation(self, operation: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("operation", operation.into()),
}
}
pub fn passthrough(self, passthrough: bool) -> Self {
Self {
builder: self.builder.property("passthrough", passthrough),
}
}
pub fn use_opencl(self, use_opencl: bool) -> Self {
Self {
builder: self.builder.property("use-opencl", use_opencl),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Node {
self.builder.build()
}
}