cogl/auto/sub_texture.rs
1#![allow(
2 clippy::too_many_arguments,
3 clippy::let_and_return,
4 clippy::from_over_into
5)]
6
7use crate::{Context, Object, Texture};
8
9use glib::object::IsA;
10use glib::translate::*;
11use std::fmt;
12
13glib_wrapper! {
14 pub struct SubTexture(Object<ffi::CoglSubTexture, SubTextureClass>) @extends Object;
15
16 match fn {
17 get_type => || ffi::cogl_sub_texture_get_gtype(),
18 }
19}
20
21impl SubTexture {
22 /// Creates a high-level `SubTexture` representing a sub-region of
23 /// any other `Texture`. The sub-region must strictly lye within the
24 /// bounds of the `parent_texture`. The returned texture implements the
25 /// `MetaTexture` interface because it's not a low level texture
26 /// that hardware can understand natively.
27 ///
28 /// `<note>`Remember: Unless you are using high level drawing APIs such
29 /// as `cogl_rectangle` or other APIs documented to understand the
30 /// `MetaTexture` interface then you need to use the
31 /// `MetaTexture` interface to resolve a `SubTexture` into a
32 /// low-level texture before drawing.`</note>`
33 /// ## `ctx`
34 /// A `Context` pointer
35 /// ## `parent_texture`
36 /// The full texture containing a sub-region you want
37 /// to make a `SubTexture` from.
38 /// ## `sub_x`
39 /// The top-left x coordinate of the parent region to make
40 /// a texture from.
41 /// ## `sub_y`
42 /// The top-left y coordinate of the parent region to make
43 /// a texture from.
44 /// ## `sub_width`
45 /// The width of the parent region to make a texture from.
46 /// ## `sub_height`
47 /// The height of the parent region to make a texture
48 /// from.
49 ///
50 /// # Returns
51 ///
52 /// A newly allocated `SubTexture`
53 /// representing a sub-region of `parent_texture`.
54 pub fn new<P: IsA<Texture>>(
55 ctx: &Context,
56 parent_texture: &P,
57 sub_x: i32,
58 sub_y: i32,
59 sub_width: i32,
60 sub_height: i32,
61 ) -> SubTexture {
62 unsafe {
63 from_glib_full(ffi::cogl_sub_texture_new(
64 ctx.to_glib_none().0,
65 parent_texture.as_ref().to_glib_none().0,
66 sub_x,
67 sub_y,
68 sub_width,
69 sub_height,
70 ))
71 }
72 }
73
74 /// Retrieves the parent texture that `self` derives its content
75 /// from. This is the texture that was passed to
76 /// `SubTexture::new` as the parent_texture argument.
77 ///
78 /// # Returns
79 ///
80 /// The parent texture that `self`
81 /// derives its content from.
82 pub fn get_parent(&self) -> Option<Texture> {
83 unsafe { from_glib_none(ffi::cogl_sub_texture_get_parent(self.to_glib_none().0)) }
84 }
85}
86
87impl fmt::Display for SubTexture {
88 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 write!(f, "SubTexture")
90 }
91}