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