gdk4/auto/
gl_texture_builder.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v4_16")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
7use crate::ColorState;
8use crate::{ffi, GLContext, MemoryFormat, Texture};
9use glib::translate::*;
10#[cfg(feature = "v4_16")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
12use glib::{
13    prelude::*,
14    signal::{connect_raw, SignalHandlerId},
15};
16#[cfg(feature = "v4_16")]
17#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21    /// [`GLTextureBuilder`][crate::GLTextureBuilder] is a builder used to construct [`Texture`][crate::Texture] objects from
22    /// GL textures.
23    ///
24    /// The operation is quite simple: Create a texture builder, set all the necessary
25    /// properties - keep in mind that the properties [`context`][struct@crate::GLTextureBuilder#context],
26    /// [`id`][struct@crate::GLTextureBuilder#id], [`width`][struct@crate::GLTextureBuilder#width], and
27    /// [`height`][struct@crate::GLTextureBuilder#height] are mandatory - and then call
28    /// [`build()`][Self::build()] to create the new texture.
29    ///
30    /// [`GLTextureBuilder`][crate::GLTextureBuilder] can be used for quick one-shot construction of
31    /// textures as well as kept around and reused to construct multiple textures.
32    ///
33    /// ## Properties
34    ///
35    ///
36    /// #### `color-state`
37    ///  The color state of the texture.
38    ///
39    /// Readable | Writeable
40    ///
41    ///
42    /// #### `context`
43    ///  The context owning the texture.
44    ///
45    /// Readable | Writeable
46    ///
47    ///
48    /// #### `format`
49    ///  The format when downloading the texture.
50    ///
51    /// Readable | Writeable
52    ///
53    ///
54    /// #### `has-mipmap`
55    ///  If the texture has a mipmap.
56    ///
57    /// Readable | Writeable
58    ///
59    ///
60    /// #### `height`
61    ///  The height of the texture.
62    ///
63    /// Readable | Writeable
64    ///
65    ///
66    /// #### `id`
67    ///  The texture ID to use.
68    ///
69    /// Readable | Writeable
70    ///
71    ///
72    /// #### `sync`
73    ///  An optional `GLSync` object.
74    ///
75    /// If this is set, GTK will wait on it before using the texture.
76    ///
77    /// Readable | Writeable
78    ///
79    ///
80    /// #### `update-region`
81    ///  The update region for [`update-texture`][struct@crate::GLTextureBuilder#update-texture].
82    ///
83    /// Readable | Writeable
84    ///
85    ///
86    /// #### `update-texture`
87    ///  The texture [`update-region`][struct@crate::GLTextureBuilder#update-region] is an update for.
88    ///
89    /// Readable | Writeable
90    ///
91    ///
92    /// #### `width`
93    ///  The width of the texture.
94    ///
95    /// Readable | Writeable
96    #[doc(alias = "GdkGLTextureBuilder")]
97    pub struct GLTextureBuilder(Object<ffi::GdkGLTextureBuilder, ffi::GdkGLTextureBuilderClass>);
98
99    match fn {
100        type_ => || ffi::gdk_gl_texture_builder_get_type(),
101    }
102}
103
104impl GLTextureBuilder {
105    /// Creates a new texture builder.
106    ///
107    /// # Returns
108    ///
109    /// the new `GdkTextureBuilder`
110    #[doc(alias = "gdk_gl_texture_builder_new")]
111    pub fn new() -> GLTextureBuilder {
112        assert_initialized_main_thread!();
113        unsafe { from_glib_full(ffi::gdk_gl_texture_builder_new()) }
114    }
115
116    /// Gets the color state previously set via gdk_gl_texture_builder_set_color_state().
117    ///
118    /// # Returns
119    ///
120    /// the color state
121    #[cfg(feature = "v4_16")]
122    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
123    #[doc(alias = "gdk_gl_texture_builder_get_color_state")]
124    #[doc(alias = "get_color_state")]
125    #[doc(alias = "color-state")]
126    pub fn color_state(&self) -> ColorState {
127        unsafe {
128            from_glib_none(ffi::gdk_gl_texture_builder_get_color_state(
129                self.to_glib_none().0,
130            ))
131        }
132    }
133
134    /// Gets the context previously set via gdk_gl_texture_builder_set_context() or
135    /// [`None`] if none was set.
136    ///
137    /// # Returns
138    ///
139    /// The context
140    #[doc(alias = "gdk_gl_texture_builder_get_context")]
141    #[doc(alias = "get_context")]
142    pub fn context(&self) -> Option<GLContext> {
143        unsafe {
144            from_glib_none(ffi::gdk_gl_texture_builder_get_context(
145                self.to_glib_none().0,
146            ))
147        }
148    }
149
150    /// Gets the format previously set via gdk_gl_texture_builder_set_format().
151    ///
152    /// # Returns
153    ///
154    /// The format
155    #[doc(alias = "gdk_gl_texture_builder_get_format")]
156    #[doc(alias = "get_format")]
157    pub fn format(&self) -> MemoryFormat {
158        unsafe {
159            from_glib(ffi::gdk_gl_texture_builder_get_format(
160                self.to_glib_none().0,
161            ))
162        }
163    }
164
165    /// Gets whether the texture has a mipmap.
166    ///
167    /// # Returns
168    ///
169    /// Whether the texture has a mipmap
170    #[doc(alias = "gdk_gl_texture_builder_get_has_mipmap")]
171    #[doc(alias = "get_has_mipmap")]
172    #[doc(alias = "has-mipmap")]
173    pub fn has_mipmap(&self) -> bool {
174        unsafe {
175            from_glib(ffi::gdk_gl_texture_builder_get_has_mipmap(
176                self.to_glib_none().0,
177            ))
178        }
179    }
180
181    /// Gets the height previously set via gdk_gl_texture_builder_set_height() or
182    /// 0 if the height wasn't set.
183    ///
184    /// # Returns
185    ///
186    /// The height
187    #[doc(alias = "gdk_gl_texture_builder_get_height")]
188    #[doc(alias = "get_height")]
189    pub fn height(&self) -> i32 {
190        unsafe { ffi::gdk_gl_texture_builder_get_height(self.to_glib_none().0) }
191    }
192
193    /// Gets the texture id previously set via gdk_gl_texture_builder_set_id() or
194    /// 0 if the id wasn't set.
195    ///
196    /// # Returns
197    ///
198    /// The id
199    #[doc(alias = "gdk_gl_texture_builder_get_id")]
200    #[doc(alias = "get_id")]
201    pub fn id(&self) -> u32 {
202        unsafe { ffi::gdk_gl_texture_builder_get_id(self.to_glib_none().0) }
203    }
204
205    /// Gets the region previously set via gdk_gl_texture_builder_set_update_region() or
206    /// [`None`] if none was set.
207    ///
208    /// # Returns
209    ///
210    /// The region
211    #[doc(alias = "gdk_gl_texture_builder_get_update_region")]
212    #[doc(alias = "get_update_region")]
213    #[doc(alias = "update-region")]
214    pub fn update_region(&self) -> Option<cairo::Region> {
215        unsafe {
216            from_glib_none(ffi::gdk_gl_texture_builder_get_update_region(
217                self.to_glib_none().0,
218            ))
219        }
220    }
221
222    /// Gets the texture previously set via gdk_gl_texture_builder_set_update_texture() or
223    /// [`None`] if none was set.
224    ///
225    /// # Returns
226    ///
227    /// The texture
228    #[doc(alias = "gdk_gl_texture_builder_get_update_texture")]
229    #[doc(alias = "get_update_texture")]
230    #[doc(alias = "update-texture")]
231    pub fn update_texture(&self) -> Option<Texture> {
232        unsafe {
233            from_glib_none(ffi::gdk_gl_texture_builder_get_update_texture(
234                self.to_glib_none().0,
235            ))
236        }
237    }
238
239    /// Gets the width previously set via gdk_gl_texture_builder_set_width() or
240    /// 0 if the width wasn't set.
241    ///
242    /// # Returns
243    ///
244    /// The width
245    #[doc(alias = "gdk_gl_texture_builder_get_width")]
246    #[doc(alias = "get_width")]
247    pub fn width(&self) -> i32 {
248        unsafe { ffi::gdk_gl_texture_builder_get_width(self.to_glib_none().0) }
249    }
250
251    /// Sets the color state for the texture.
252    ///
253    /// By default, the sRGB colorstate is used. If you don't know what
254    /// colorstates are, this is probably the right thing.
255    /// ## `color_state`
256    /// a [`ColorState`][crate::ColorState]
257    #[cfg(feature = "v4_16")]
258    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
259    #[doc(alias = "gdk_gl_texture_builder_set_color_state")]
260    #[doc(alias = "color-state")]
261    pub fn set_color_state(&self, color_state: &ColorState) {
262        unsafe {
263            ffi::gdk_gl_texture_builder_set_color_state(
264                self.to_glib_none().0,
265                color_state.to_glib_none().0,
266            );
267        }
268    }
269
270    #[cfg(feature = "v4_16")]
271    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
272    #[doc(alias = "color-state")]
273    pub fn connect_color_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
274        &self,
275        f: F,
276    ) -> SignalHandlerId {
277        unsafe extern "C" fn notify_color_state_trampoline<
278            F: Fn(&GLTextureBuilder) + Send + Sync + 'static,
279        >(
280            this: *mut ffi::GdkGLTextureBuilder,
281            _param_spec: glib::ffi::gpointer,
282            f: glib::ffi::gpointer,
283        ) {
284            let f: &F = &*(f as *const F);
285            f(&from_glib_borrow(this))
286        }
287        unsafe {
288            let f: Box_<F> = Box_::new(f);
289            connect_raw(
290                self.as_ptr() as *mut _,
291                b"notify::color-state\0".as_ptr() as *const _,
292                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293                    notify_color_state_trampoline::<F> as *const (),
294                )),
295                Box_::into_raw(f),
296            )
297        }
298    }
299}
300
301#[cfg(feature = "v4_12")]
302#[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
303impl Default for GLTextureBuilder {
304    fn default() -> Self {
305        Self::new()
306    }
307}
308
309unsafe impl Send for GLTextureBuilder {}
310unsafe impl Sync for GLTextureBuilder {}