animate/legacy/texture_node.rs
1use crate::{Color, InternalColor, PaintNode, PipelineNode, RgbaColor, ScalingFilter};
2use glib::{
3 object::{Cast, IsA},
4 translate::*,
5};
6use std::fmt;
7
8glib_wrapper! {
9 pub struct TextureNode(Object<ffi::ClutterTextureNode, ffi::ClutterTextureNodeClass, TextureNodeClass>) @extends PipelineNode, PaintNode;
10
11 match fn {
12 get_type => || ffi::clutter_texture_node_get_type(),
13 }
14}
15
16impl TextureNode {
17 /// Creates a new `PaintNode` that will paint the passed `texture`.
18 ///
19 /// This function will take a reference on `texture`, so it is safe to
20 /// call `object_unref` on `texture` when it returns.
21 ///
22 /// The `color` must not be pre-multiplied with its `Color.alpha`
23 /// channel value; if `color` is `None`, a fully opaque white color will
24 /// be used for blending.
25 /// ## `texture`
26 /// a `dx::Texture`
27 /// ## `color`
28 /// a `Color` used for blending, or `None`
29 /// ## `min_filter`
30 /// the minification filter for the texture
31 /// ## `mag_filter`
32 /// the magnification filter for the texture
33 ///
34 /// # Returns
35 ///
36 /// the newly created `PaintNode`.
37 /// Use `PaintNodeExt::unref` when done
38 pub fn new<P: IsA<dx::Texture>>(
39 texture: &P,
40 color: Option<Color>,
41 min_filter: ScalingFilter,
42 mag_filter: ScalingFilter,
43 ) -> TextureNode {
44 let color = match color {
45 Some(value) => {
46 let RgbaColor {
47 red,
48 green,
49 blue,
50 alpha,
51 } = value.into();
52 Some(InternalColor::new(red, green, blue, alpha))
53 }
54 None => None,
55 };
56 unsafe {
57 PaintNode::from_glib_full(ffi::clutter_texture_node_new(
58 texture.as_ref().to_glib_none().0,
59 color.to_glib_none().0,
60 min_filter.to_glib(),
61 mag_filter.to_glib(),
62 ))
63 .unsafe_cast()
64 }
65 }
66}
67
68impl fmt::Display for TextureNode {
69 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
70 write!(f, "TextureNode")
71 }
72}