gdk4/auto/
memory_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
5use crate::{ffi, ColorState, MemoryFormat, Texture};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`MemoryTextureBuilder`][crate::MemoryTextureBuilder] is a builder used to construct [`Texture`][crate::Texture] objects
15    /// from system memory provided via [`glib::Bytes`][crate::glib::Bytes].
16    ///
17    /// The operation is quite simple: Create a texture builder, set all the necessary
18    /// properties - keep in mind that the properties [`bytes`][struct@crate::MemoryTextureBuilder#bytes],
19    /// [`stride`][struct@crate::MemoryTextureBuilder#stride], [`width`][struct@crate::MemoryTextureBuilder#width],
20    /// and [`height`][struct@crate::MemoryTextureBuilder#height] are mandatory - and then call
21    /// [`build()`][Self::build()] to create the new texture.
22    ///
23    /// [`MemoryTextureBuilder`][crate::MemoryTextureBuilder] can be used for quick one-shot construction of
24    /// textures as well as kept around and reused to construct multiple textures.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `bytes`
30    ///  The bytes holding the data.
31    ///
32    /// Readable | Writeable
33    ///
34    ///
35    /// #### `color-state`
36    ///  The colorstate describing the data.
37    ///
38    /// Readable | Writeable
39    ///
40    ///
41    /// #### `format`
42    ///  The format of the data.
43    ///
44    /// Readable | Writeable
45    ///
46    ///
47    /// #### `height`
48    ///  The height of the texture.
49    ///
50    /// Readable | Writeable
51    ///
52    ///
53    /// #### `stride`
54    ///  The rowstride of the texture.
55    ///
56    /// The rowstride is the number of bytes between the first pixel
57    /// in a row of image data, and the first pixel in the next row.
58    ///
59    /// Readable | Writeable
60    ///
61    ///
62    /// #### `update-region`
63    ///  The update region for [`update-texture`][struct@crate::MemoryTextureBuilder#update-texture].
64    ///
65    /// Readable | Writeable
66    ///
67    ///
68    /// #### `update-texture`
69    ///  The texture [`update-region`][struct@crate::MemoryTextureBuilder#update-region] is an update for.
70    ///
71    /// Readable | Writeable
72    ///
73    ///
74    /// #### `width`
75    ///  The width of the texture.
76    ///
77    /// Readable | Writeable
78    #[doc(alias = "GdkMemoryTextureBuilder")]
79    pub struct MemoryTextureBuilder(Object<ffi::GdkMemoryTextureBuilder, ffi::GdkMemoryTextureBuilderClass>);
80
81    match fn {
82        type_ => || ffi::gdk_memory_texture_builder_get_type(),
83    }
84}
85
86impl MemoryTextureBuilder {
87    /// Creates a new texture builder.
88    ///
89    /// # Returns
90    ///
91    /// the new `GdkTextureBuilder`
92    #[doc(alias = "gdk_memory_texture_builder_new")]
93    pub fn new() -> MemoryTextureBuilder {
94        assert_initialized_main_thread!();
95        unsafe { from_glib_full(ffi::gdk_memory_texture_builder_new()) }
96    }
97
98    /// Builds a new [`Texture`][crate::Texture] with the values set up in the builder.
99    ///
100    /// Note that it is a programming error to call this function if any mandatory
101    /// property has not been set.
102    ///
103    /// It is possible to call this function multiple times to create multiple textures,
104    /// possibly with changing properties in between.
105    ///
106    /// # Returns
107    ///
108    /// a newly built [`Texture`][crate::Texture]
109    #[doc(alias = "gdk_memory_texture_builder_build")]
110    pub fn build(&self) -> Texture {
111        unsafe { from_glib_full(ffi::gdk_memory_texture_builder_build(self.to_glib_none().0)) }
112    }
113
114    /// Gets the bytes previously set via gdk_memory_texture_builder_set_bytes()
115    /// or [`None`] if none was set.
116    ///
117    /// # Returns
118    ///
119    /// The bytes
120    #[doc(alias = "gdk_memory_texture_builder_get_bytes")]
121    #[doc(alias = "get_bytes")]
122    pub fn bytes(&self) -> Option<glib::Bytes> {
123        unsafe {
124            from_glib_none(ffi::gdk_memory_texture_builder_get_bytes(
125                self.to_glib_none().0,
126            ))
127        }
128    }
129
130    /// Gets the colorstate previously set via gdk_memory_texture_builder_set_color_state().
131    ///
132    /// # Returns
133    ///
134    /// The colorstate
135    #[doc(alias = "gdk_memory_texture_builder_get_color_state")]
136    #[doc(alias = "get_color_state")]
137    #[doc(alias = "color-state")]
138    pub fn color_state(&self) -> ColorState {
139        unsafe {
140            from_glib_none(ffi::gdk_memory_texture_builder_get_color_state(
141                self.to_glib_none().0,
142            ))
143        }
144    }
145
146    /// Gets the format previously set via gdk_memory_texture_builder_set_format().
147    ///
148    /// # Returns
149    ///
150    /// The format
151    #[doc(alias = "gdk_memory_texture_builder_get_format")]
152    #[doc(alias = "get_format")]
153    pub fn format(&self) -> MemoryFormat {
154        unsafe {
155            from_glib(ffi::gdk_memory_texture_builder_get_format(
156                self.to_glib_none().0,
157            ))
158        }
159    }
160
161    /// Gets the height previously set via gdk_memory_texture_builder_set_height()
162    /// or 0 if the height wasn't set.
163    ///
164    /// # Returns
165    ///
166    /// The height
167    #[doc(alias = "gdk_memory_texture_builder_get_height")]
168    #[doc(alias = "get_height")]
169    pub fn height(&self) -> i32 {
170        unsafe { ffi::gdk_memory_texture_builder_get_height(self.to_glib_none().0) }
171    }
172
173    /// Gets the stride previously set via gdk_memory_texture_builder_set_stride().
174    ///
175    /// # Returns
176    ///
177    /// the stride
178    #[doc(alias = "gdk_memory_texture_builder_get_stride")]
179    #[doc(alias = "get_stride")]
180    pub fn stride(&self) -> usize {
181        unsafe { ffi::gdk_memory_texture_builder_get_stride(self.to_glib_none().0) }
182    }
183
184    /// Gets the region previously set via gdk_memory_texture_builder_set_update_region()
185    /// or [`None`] if none was set.
186    ///
187    /// # Returns
188    ///
189    /// The update region
190    #[doc(alias = "gdk_memory_texture_builder_get_update_region")]
191    #[doc(alias = "get_update_region")]
192    #[doc(alias = "update-region")]
193    pub fn update_region(&self) -> Option<cairo::Region> {
194        unsafe {
195            from_glib_none(ffi::gdk_memory_texture_builder_get_update_region(
196                self.to_glib_none().0,
197            ))
198        }
199    }
200
201    /// Gets the texture previously set via gdk_memory_texture_builder_set_update_texture()
202    /// or [`None`] if none was set.
203    ///
204    /// # Returns
205    ///
206    /// The update texture
207    #[doc(alias = "gdk_memory_texture_builder_get_update_texture")]
208    #[doc(alias = "get_update_texture")]
209    #[doc(alias = "update-texture")]
210    pub fn update_texture(&self) -> Option<Texture> {
211        unsafe {
212            from_glib_none(ffi::gdk_memory_texture_builder_get_update_texture(
213                self.to_glib_none().0,
214            ))
215        }
216    }
217
218    /// Gets the width previously set via gdk_memory_texture_builder_set_width()
219    /// or 0 if the width wasn't set.
220    ///
221    /// # Returns
222    ///
223    /// The width
224    #[doc(alias = "gdk_memory_texture_builder_get_width")]
225    #[doc(alias = "get_width")]
226    pub fn width(&self) -> i32 {
227        unsafe { ffi::gdk_memory_texture_builder_get_width(self.to_glib_none().0) }
228    }
229
230    /// Sets the data to be shown but the texture.
231    ///
232    /// The bytes must be set before calling [`build()`][Self::build()].
233    /// ## `bytes`
234    /// The bytes the texture shows or [`None`] to unset
235    #[doc(alias = "gdk_memory_texture_builder_set_bytes")]
236    #[doc(alias = "bytes")]
237    pub fn set_bytes(&self, bytes: Option<&glib::Bytes>) {
238        unsafe {
239            ffi::gdk_memory_texture_builder_set_bytes(
240                self.to_glib_none().0,
241                bytes.to_glib_none().0,
242            );
243        }
244    }
245
246    /// Sets the colorstate describing the data.
247    ///
248    /// By default, the sRGB colorstate is used. If you don't know
249    /// what colorstates are, this is probably the right thing.
250    /// ## `color_state`
251    /// The colorstate describing the data
252    #[doc(alias = "gdk_memory_texture_builder_set_color_state")]
253    #[doc(alias = "color-state")]
254    pub fn set_color_state(&self, color_state: Option<&ColorState>) {
255        unsafe {
256            ffi::gdk_memory_texture_builder_set_color_state(
257                self.to_glib_none().0,
258                color_state.to_glib_none().0,
259            );
260        }
261    }
262
263    /// Sets the format of the bytes.
264    ///
265    /// The default is `GDK_MEMORY_R8G8B8A8_PREMULTIPLIED`.
266    /// ## `format`
267    /// The texture's format
268    #[doc(alias = "gdk_memory_texture_builder_set_format")]
269    #[doc(alias = "format")]
270    pub fn set_format(&self, format: MemoryFormat) {
271        unsafe {
272            ffi::gdk_memory_texture_builder_set_format(self.to_glib_none().0, format.into_glib());
273        }
274    }
275
276    /// Sets the height of the texture.
277    ///
278    /// The height must be set before calling [`build()`][Self::build()].
279    /// ## `height`
280    /// The texture's height or 0 to unset
281    #[doc(alias = "gdk_memory_texture_builder_set_height")]
282    #[doc(alias = "height")]
283    pub fn set_height(&self, height: i32) {
284        unsafe {
285            ffi::gdk_memory_texture_builder_set_height(self.to_glib_none().0, height);
286        }
287    }
288
289    /// Sets the rowstride of the bytes used.
290    ///
291    /// The rowstride must be set before calling [`build()`][Self::build()].
292    /// ## `stride`
293    /// the stride or 0 to unset
294    #[doc(alias = "gdk_memory_texture_builder_set_stride")]
295    #[doc(alias = "stride")]
296    pub fn set_stride(&self, stride: usize) {
297        unsafe {
298            ffi::gdk_memory_texture_builder_set_stride(self.to_glib_none().0, stride);
299        }
300    }
301
302    /// Sets the region to be updated by this texture.
303    ///
304    /// Together with [`update-texture`][struct@crate::MemoryTextureBuilder#update-texture],
305    /// this describes an update of a previous texture.
306    ///
307    /// When rendering animations of large textures, it is possible that
308    /// consecutive textures are only updating contents in parts of the texture.
309    /// It is then possible to describe this update via these two properties,
310    /// so that GTK can avoid rerendering parts that did not change.
311    ///
312    /// An example would be a screen recording where only the mouse pointer moves.
313    /// ## `region`
314    /// the region to update
315    #[doc(alias = "gdk_memory_texture_builder_set_update_region")]
316    #[doc(alias = "update-region")]
317    pub fn set_update_region(&self, region: Option<&cairo::Region>) {
318        unsafe {
319            ffi::gdk_memory_texture_builder_set_update_region(
320                self.to_glib_none().0,
321                mut_override(region.to_glib_none().0),
322            );
323        }
324    }
325
326    /// Sets the texture to be updated by this texture.
327    ///
328    /// See [`set_update_region()`][Self::set_update_region()] for an explanation.
329    /// ## `texture`
330    /// the texture to update
331    #[doc(alias = "gdk_memory_texture_builder_set_update_texture")]
332    #[doc(alias = "update-texture")]
333    pub fn set_update_texture(&self, texture: Option<&impl IsA<Texture>>) {
334        unsafe {
335            ffi::gdk_memory_texture_builder_set_update_texture(
336                self.to_glib_none().0,
337                texture.map(|p| p.as_ref()).to_glib_none().0,
338            );
339        }
340    }
341
342    /// Sets the width of the texture.
343    ///
344    /// The width must be set before calling [`build()`][Self::build()].
345    /// ## `width`
346    /// The texture's width or 0 to unset
347    #[doc(alias = "gdk_memory_texture_builder_set_width")]
348    #[doc(alias = "width")]
349    pub fn set_width(&self, width: i32) {
350        unsafe {
351            ffi::gdk_memory_texture_builder_set_width(self.to_glib_none().0, width);
352        }
353    }
354
355    #[cfg(feature = "v4_16")]
356    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
357    #[doc(alias = "bytes")]
358    pub fn connect_bytes_notify<F: Fn(&Self) + Send + Sync + 'static>(
359        &self,
360        f: F,
361    ) -> SignalHandlerId {
362        unsafe extern "C" fn notify_bytes_trampoline<
363            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
364        >(
365            this: *mut ffi::GdkMemoryTextureBuilder,
366            _param_spec: glib::ffi::gpointer,
367            f: glib::ffi::gpointer,
368        ) {
369            let f: &F = &*(f as *const F);
370            f(&from_glib_borrow(this))
371        }
372        unsafe {
373            let f: Box_<F> = Box_::new(f);
374            connect_raw(
375                self.as_ptr() as *mut _,
376                b"notify::bytes\0".as_ptr() as *const _,
377                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
378                    notify_bytes_trampoline::<F> as *const (),
379                )),
380                Box_::into_raw(f),
381            )
382        }
383    }
384
385    #[cfg(feature = "v4_16")]
386    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
387    #[doc(alias = "color-state")]
388    pub fn connect_color_state_notify<F: Fn(&Self) + Send + Sync + 'static>(
389        &self,
390        f: F,
391    ) -> SignalHandlerId {
392        unsafe extern "C" fn notify_color_state_trampoline<
393            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
394        >(
395            this: *mut ffi::GdkMemoryTextureBuilder,
396            _param_spec: glib::ffi::gpointer,
397            f: glib::ffi::gpointer,
398        ) {
399            let f: &F = &*(f as *const F);
400            f(&from_glib_borrow(this))
401        }
402        unsafe {
403            let f: Box_<F> = Box_::new(f);
404            connect_raw(
405                self.as_ptr() as *mut _,
406                b"notify::color-state\0".as_ptr() as *const _,
407                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
408                    notify_color_state_trampoline::<F> as *const (),
409                )),
410                Box_::into_raw(f),
411            )
412        }
413    }
414
415    #[cfg(feature = "v4_16")]
416    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
417    #[doc(alias = "format")]
418    pub fn connect_format_notify<F: Fn(&Self) + Send + Sync + 'static>(
419        &self,
420        f: F,
421    ) -> SignalHandlerId {
422        unsafe extern "C" fn notify_format_trampoline<
423            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
424        >(
425            this: *mut ffi::GdkMemoryTextureBuilder,
426            _param_spec: glib::ffi::gpointer,
427            f: glib::ffi::gpointer,
428        ) {
429            let f: &F = &*(f as *const F);
430            f(&from_glib_borrow(this))
431        }
432        unsafe {
433            let f: Box_<F> = Box_::new(f);
434            connect_raw(
435                self.as_ptr() as *mut _,
436                b"notify::format\0".as_ptr() as *const _,
437                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
438                    notify_format_trampoline::<F> as *const (),
439                )),
440                Box_::into_raw(f),
441            )
442        }
443    }
444
445    #[cfg(feature = "v4_16")]
446    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
447    #[doc(alias = "height")]
448    pub fn connect_height_notify<F: Fn(&Self) + Send + Sync + 'static>(
449        &self,
450        f: F,
451    ) -> SignalHandlerId {
452        unsafe extern "C" fn notify_height_trampoline<
453            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
454        >(
455            this: *mut ffi::GdkMemoryTextureBuilder,
456            _param_spec: glib::ffi::gpointer,
457            f: glib::ffi::gpointer,
458        ) {
459            let f: &F = &*(f as *const F);
460            f(&from_glib_borrow(this))
461        }
462        unsafe {
463            let f: Box_<F> = Box_::new(f);
464            connect_raw(
465                self.as_ptr() as *mut _,
466                b"notify::height\0".as_ptr() as *const _,
467                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
468                    notify_height_trampoline::<F> as *const (),
469                )),
470                Box_::into_raw(f),
471            )
472        }
473    }
474
475    #[cfg(feature = "v4_16")]
476    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
477    #[doc(alias = "stride")]
478    pub fn connect_stride_notify<F: Fn(&Self) + Send + Sync + 'static>(
479        &self,
480        f: F,
481    ) -> SignalHandlerId {
482        unsafe extern "C" fn notify_stride_trampoline<
483            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
484        >(
485            this: *mut ffi::GdkMemoryTextureBuilder,
486            _param_spec: glib::ffi::gpointer,
487            f: glib::ffi::gpointer,
488        ) {
489            let f: &F = &*(f as *const F);
490            f(&from_glib_borrow(this))
491        }
492        unsafe {
493            let f: Box_<F> = Box_::new(f);
494            connect_raw(
495                self.as_ptr() as *mut _,
496                b"notify::stride\0".as_ptr() as *const _,
497                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
498                    notify_stride_trampoline::<F> as *const (),
499                )),
500                Box_::into_raw(f),
501            )
502        }
503    }
504
505    #[cfg(feature = "v4_16")]
506    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
507    #[doc(alias = "update-region")]
508    pub fn connect_update_region_notify<F: Fn(&Self) + Send + Sync + 'static>(
509        &self,
510        f: F,
511    ) -> SignalHandlerId {
512        unsafe extern "C" fn notify_update_region_trampoline<
513            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
514        >(
515            this: *mut ffi::GdkMemoryTextureBuilder,
516            _param_spec: glib::ffi::gpointer,
517            f: glib::ffi::gpointer,
518        ) {
519            let f: &F = &*(f as *const F);
520            f(&from_glib_borrow(this))
521        }
522        unsafe {
523            let f: Box_<F> = Box_::new(f);
524            connect_raw(
525                self.as_ptr() as *mut _,
526                b"notify::update-region\0".as_ptr() as *const _,
527                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
528                    notify_update_region_trampoline::<F> as *const (),
529                )),
530                Box_::into_raw(f),
531            )
532        }
533    }
534
535    #[cfg(feature = "v4_16")]
536    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
537    #[doc(alias = "update-texture")]
538    pub fn connect_update_texture_notify<F: Fn(&Self) + Send + Sync + 'static>(
539        &self,
540        f: F,
541    ) -> SignalHandlerId {
542        unsafe extern "C" fn notify_update_texture_trampoline<
543            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
544        >(
545            this: *mut ffi::GdkMemoryTextureBuilder,
546            _param_spec: glib::ffi::gpointer,
547            f: glib::ffi::gpointer,
548        ) {
549            let f: &F = &*(f as *const F);
550            f(&from_glib_borrow(this))
551        }
552        unsafe {
553            let f: Box_<F> = Box_::new(f);
554            connect_raw(
555                self.as_ptr() as *mut _,
556                b"notify::update-texture\0".as_ptr() as *const _,
557                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
558                    notify_update_texture_trampoline::<F> as *const (),
559                )),
560                Box_::into_raw(f),
561            )
562        }
563    }
564
565    #[cfg(feature = "v4_16")]
566    #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
567    #[doc(alias = "width")]
568    pub fn connect_width_notify<F: Fn(&Self) + Send + Sync + 'static>(
569        &self,
570        f: F,
571    ) -> SignalHandlerId {
572        unsafe extern "C" fn notify_width_trampoline<
573            F: Fn(&MemoryTextureBuilder) + Send + Sync + 'static,
574        >(
575            this: *mut ffi::GdkMemoryTextureBuilder,
576            _param_spec: glib::ffi::gpointer,
577            f: glib::ffi::gpointer,
578        ) {
579            let f: &F = &*(f as *const F);
580            f(&from_glib_borrow(this))
581        }
582        unsafe {
583            let f: Box_<F> = Box_::new(f);
584            connect_raw(
585                self.as_ptr() as *mut _,
586                b"notify::width\0".as_ptr() as *const _,
587                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
588                    notify_width_trampoline::<F> as *const (),
589                )),
590                Box_::into_raw(f),
591            )
592        }
593    }
594}
595
596#[cfg(feature = "v4_16")]
597#[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
598impl Default for MemoryTextureBuilder {
599    fn default() -> Self {
600        Self::new()
601    }
602}
603
604unsafe impl Send for MemoryTextureBuilder {}
605unsafe impl Sync for MemoryTextureBuilder {}