clutter/auto/
texture.rs

1// Scriptable
2use crate::{Actor, Animatable, Container};
3use glib::{
4    object as gobject,
5    object::{Cast, IsA},
6    signal::{connect_raw, SignalHandlerId},
7    translate::*,
8    StaticType, Value,
9};
10use std::boxed::Box as Box_;
11use std::{fmt, mem::transmute};
12
13// TODO: implements atk::ImplementorIface, Scriptable
14glib_wrapper! {
15    pub struct Texture(Object<ffi::ClutterTexture, ffi::ClutterTextureClass, TextureClass>) @extends Actor, gobject::InitiallyUnowned, @implements Animatable, Container;
16
17    match fn {
18        get_type => || ffi::clutter_texture_get_type(),
19    }
20}
21
22pub const NONE_TEXTURE: Option<&Texture> = None;
23
24/// Trait containing all `Texture` methods.
25///
26/// # Implementors
27///
28/// [`Texture`](struct.Texture.html)
29pub trait TextureExt: 'static {
30    fn get_property_disable_slicing(&self) -> bool;
31
32    //fn get_property_filter_quality(&self) -> /*Ignored*/TextureQuality;
33
34    //fn set_property_filter_quality(&self, filter_quality: /*Ignored*/TextureQuality);
35
36    fn get_property_keep_aspect_ratio(&self) -> bool;
37
38    fn set_property_keep_aspect_ratio(&self, keep_aspect_ratio: bool);
39
40    fn get_property_pick_with_alpha(&self) -> bool;
41
42    fn set_property_pick_with_alpha(&self, pick_with_alpha: bool);
43
44    fn get_property_pixel_format(&self) -> cogl::PixelFormat;
45
46    fn get_property_repeat_x(&self) -> bool;
47
48    fn set_property_repeat_x(&self, repeat_x: bool);
49
50    fn get_property_repeat_y(&self) -> bool;
51
52    fn set_property_repeat_y(&self, repeat_y: bool);
53
54    fn get_property_sync_size(&self) -> bool;
55
56    fn set_property_sync_size(&self, sync_size: bool);
57
58    fn get_property_tile_waste(&self) -> i32;
59
60    fn connect_property_filter_quality_notify<F: Fn(&Self) + 'static>(
61        &self,
62        f: F,
63    ) -> SignalHandlerId;
64
65    fn connect_property_keep_aspect_ratio_notify<F: Fn(&Self) + 'static>(
66        &self,
67        f: F,
68    ) -> SignalHandlerId;
69
70    fn connect_property_pick_with_alpha_notify<F: Fn(&Self) + 'static>(
71        &self,
72        f: F,
73    ) -> SignalHandlerId;
74
75    fn connect_property_pixel_format_notify<F: Fn(&Self) + 'static>(&self, f: F)
76        -> SignalHandlerId;
77
78    fn connect_property_repeat_x_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
79
80    fn connect_property_repeat_y_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
81
82    fn connect_property_sync_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
83
84    fn connect_property_tile_waste_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
85}
86
87impl<O: IsA<Texture>> TextureExt for O {
88    fn get_property_disable_slicing(&self) -> bool {
89        unsafe {
90            let mut value = Value::from_type(<bool as StaticType>::static_type());
91            gobject_sys::g_object_get_property(
92                self.to_glib_none().0 as *mut gobject_sys::GObject,
93                b"disable-slicing\0".as_ptr() as *const _,
94                value.to_glib_none_mut().0,
95            );
96            value
97                .get()
98                .expect("Return Value for property `disable-slicing` getter")
99                .unwrap()
100        }
101    }
102
103    //fn get_property_filter_quality(&self) -> /*Ignored*/TextureQuality {
104    //    unsafe {
105    //        let mut value = Value::from_type(</*Unknown type*/ as StaticType>::static_type());
106    //        gobject_sys::g_object_get_property(self.to_glib_none().0 as *mut gobject_sys::GObject, b"filter-quality\0".as_ptr() as *const _, value.to_glib_none_mut().0);
107    //        value.get().expect("Return Value for property `filter-quality` getter").unwrap()
108    //    }
109    //}
110
111    //fn set_property_filter_quality(&self, filter_quality: /*Ignored*/TextureQuality) {
112    //    unsafe {
113    //        gobject_sys::g_object_set_property(self.to_glib_none().0 as *mut gobject_sys::GObject, b"filter-quality\0".as_ptr() as *const _, Value::from(&filter_quality).to_glib_none().0);
114    //    }
115    //}
116
117    fn get_property_keep_aspect_ratio(&self) -> bool {
118        unsafe {
119            let mut value = Value::from_type(<bool as StaticType>::static_type());
120            gobject_sys::g_object_get_property(
121                self.to_glib_none().0 as *mut gobject_sys::GObject,
122                b"keep-aspect-ratio\0".as_ptr() as *const _,
123                value.to_glib_none_mut().0,
124            );
125            value
126                .get()
127                .expect("Return Value for property `keep-aspect-ratio` getter")
128                .unwrap()
129        }
130    }
131
132    fn set_property_keep_aspect_ratio(&self, keep_aspect_ratio: bool) {
133        unsafe {
134            gobject_sys::g_object_set_property(
135                self.to_glib_none().0 as *mut gobject_sys::GObject,
136                b"keep-aspect-ratio\0".as_ptr() as *const _,
137                Value::from(&keep_aspect_ratio).to_glib_none().0,
138            );
139        }
140    }
141
142    fn get_property_pick_with_alpha(&self) -> bool {
143        unsafe {
144            let mut value = Value::from_type(<bool as StaticType>::static_type());
145            gobject_sys::g_object_get_property(
146                self.to_glib_none().0 as *mut gobject_sys::GObject,
147                b"pick-with-alpha\0".as_ptr() as *const _,
148                value.to_glib_none_mut().0,
149            );
150            value
151                .get()
152                .expect("Return Value for property `pick-with-alpha` getter")
153                .unwrap()
154        }
155    }
156
157    fn set_property_pick_with_alpha(&self, pick_with_alpha: bool) {
158        unsafe {
159            gobject_sys::g_object_set_property(
160                self.to_glib_none().0 as *mut gobject_sys::GObject,
161                b"pick-with-alpha\0".as_ptr() as *const _,
162                Value::from(&pick_with_alpha).to_glib_none().0,
163            );
164        }
165    }
166
167    fn get_property_pixel_format(&self) -> cogl::PixelFormat {
168        unsafe {
169            let mut value = Value::from_type(<cogl::PixelFormat as StaticType>::static_type());
170            gobject_sys::g_object_get_property(
171                self.to_glib_none().0 as *mut gobject_sys::GObject,
172                b"pixel-format\0".as_ptr() as *const _,
173                value.to_glib_none_mut().0,
174            );
175            value
176                .get()
177                .expect("Return Value for property `pixel-format` getter")
178                .unwrap()
179        }
180    }
181
182    fn get_property_repeat_x(&self) -> bool {
183        unsafe {
184            let mut value = Value::from_type(<bool as StaticType>::static_type());
185            gobject_sys::g_object_get_property(
186                self.to_glib_none().0 as *mut gobject_sys::GObject,
187                b"repeat-x\0".as_ptr() as *const _,
188                value.to_glib_none_mut().0,
189            );
190            value
191                .get()
192                .expect("Return Value for property `repeat-x` getter")
193                .unwrap()
194        }
195    }
196
197    fn set_property_repeat_x(&self, repeat_x: bool) {
198        unsafe {
199            gobject_sys::g_object_set_property(
200                self.to_glib_none().0 as *mut gobject_sys::GObject,
201                b"repeat-x\0".as_ptr() as *const _,
202                Value::from(&repeat_x).to_glib_none().0,
203            );
204        }
205    }
206
207    fn get_property_repeat_y(&self) -> bool {
208        unsafe {
209            let mut value = Value::from_type(<bool as StaticType>::static_type());
210            gobject_sys::g_object_get_property(
211                self.to_glib_none().0 as *mut gobject_sys::GObject,
212                b"repeat-y\0".as_ptr() as *const _,
213                value.to_glib_none_mut().0,
214            );
215            value
216                .get()
217                .expect("Return Value for property `repeat-y` getter")
218                .unwrap()
219        }
220    }
221
222    fn set_property_repeat_y(&self, repeat_y: bool) {
223        unsafe {
224            gobject_sys::g_object_set_property(
225                self.to_glib_none().0 as *mut gobject_sys::GObject,
226                b"repeat-y\0".as_ptr() as *const _,
227                Value::from(&repeat_y).to_glib_none().0,
228            );
229        }
230    }
231
232    fn get_property_sync_size(&self) -> bool {
233        unsafe {
234            let mut value = Value::from_type(<bool as StaticType>::static_type());
235            gobject_sys::g_object_get_property(
236                self.to_glib_none().0 as *mut gobject_sys::GObject,
237                b"sync-size\0".as_ptr() as *const _,
238                value.to_glib_none_mut().0,
239            );
240            value
241                .get()
242                .expect("Return Value for property `sync-size` getter")
243                .unwrap()
244        }
245    }
246
247    fn set_property_sync_size(&self, sync_size: bool) {
248        unsafe {
249            gobject_sys::g_object_set_property(
250                self.to_glib_none().0 as *mut gobject_sys::GObject,
251                b"sync-size\0".as_ptr() as *const _,
252                Value::from(&sync_size).to_glib_none().0,
253            );
254        }
255    }
256
257    fn get_property_tile_waste(&self) -> i32 {
258        unsafe {
259            let mut value = Value::from_type(<i32 as StaticType>::static_type());
260            gobject_sys::g_object_get_property(
261                self.to_glib_none().0 as *mut gobject_sys::GObject,
262                b"tile-waste\0".as_ptr() as *const _,
263                value.to_glib_none_mut().0,
264            );
265            value
266                .get()
267                .expect("Return Value for property `tile-waste` getter")
268                .unwrap()
269        }
270    }
271
272    fn connect_property_filter_quality_notify<F: Fn(&Self) + 'static>(
273        &self,
274        f: F,
275    ) -> SignalHandlerId {
276        unsafe extern "C" fn notify_filter_quality_trampoline<P, F: Fn(&P) + 'static>(
277            this: *mut ffi::ClutterTexture,
278            _param_spec: glib_sys::gpointer,
279            f: glib_sys::gpointer,
280        ) where
281            P: IsA<Texture>,
282        {
283            let f: &F = &*(f as *const F);
284            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
285        }
286        unsafe {
287            let f: Box_<F> = Box_::new(f);
288            connect_raw(
289                self.as_ptr() as *mut _,
290                b"notify::filter-quality\0".as_ptr() as *const _,
291                Some(transmute::<_, unsafe extern "C" fn()>(
292                    notify_filter_quality_trampoline::<Self, F> as *const (),
293                )),
294                Box_::into_raw(f),
295            )
296        }
297    }
298
299    fn connect_property_keep_aspect_ratio_notify<F: Fn(&Self) + 'static>(
300        &self,
301        f: F,
302    ) -> SignalHandlerId {
303        unsafe extern "C" fn notify_keep_aspect_ratio_trampoline<P, F: Fn(&P) + 'static>(
304            this: *mut ffi::ClutterTexture,
305            _param_spec: glib_sys::gpointer,
306            f: glib_sys::gpointer,
307        ) where
308            P: IsA<Texture>,
309        {
310            let f: &F = &*(f as *const F);
311            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
312        }
313        unsafe {
314            let f: Box_<F> = Box_::new(f);
315            connect_raw(
316                self.as_ptr() as *mut _,
317                b"notify::keep-aspect-ratio\0".as_ptr() as *const _,
318                Some(transmute::<_, unsafe extern "C" fn()>(
319                    notify_keep_aspect_ratio_trampoline::<Self, F> as *const (),
320                )),
321                Box_::into_raw(f),
322            )
323        }
324    }
325
326    fn connect_property_pick_with_alpha_notify<F: Fn(&Self) + 'static>(
327        &self,
328        f: F,
329    ) -> SignalHandlerId {
330        unsafe extern "C" fn notify_pick_with_alpha_trampoline<P, F: Fn(&P) + 'static>(
331            this: *mut ffi::ClutterTexture,
332            _param_spec: glib_sys::gpointer,
333            f: glib_sys::gpointer,
334        ) where
335            P: IsA<Texture>,
336        {
337            let f: &F = &*(f as *const F);
338            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
339        }
340        unsafe {
341            let f: Box_<F> = Box_::new(f);
342            connect_raw(
343                self.as_ptr() as *mut _,
344                b"notify::pick-with-alpha\0".as_ptr() as *const _,
345                Some(transmute::<_, unsafe extern "C" fn()>(
346                    notify_pick_with_alpha_trampoline::<Self, F> as *const (),
347                )),
348                Box_::into_raw(f),
349            )
350        }
351    }
352
353    fn connect_property_pixel_format_notify<F: Fn(&Self) + 'static>(
354        &self,
355        f: F,
356    ) -> SignalHandlerId {
357        unsafe extern "C" fn notify_pixel_format_trampoline<P, F: Fn(&P) + 'static>(
358            this: *mut ffi::ClutterTexture,
359            _param_spec: glib_sys::gpointer,
360            f: glib_sys::gpointer,
361        ) where
362            P: IsA<Texture>,
363        {
364            let f: &F = &*(f as *const F);
365            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
366        }
367        unsafe {
368            let f: Box_<F> = Box_::new(f);
369            connect_raw(
370                self.as_ptr() as *mut _,
371                b"notify::pixel-format\0".as_ptr() as *const _,
372                Some(transmute::<_, unsafe extern "C" fn()>(
373                    notify_pixel_format_trampoline::<Self, F> as *const (),
374                )),
375                Box_::into_raw(f),
376            )
377        }
378    }
379
380    fn connect_property_repeat_x_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
381        unsafe extern "C" fn notify_repeat_x_trampoline<P, F: Fn(&P) + 'static>(
382            this: *mut ffi::ClutterTexture,
383            _param_spec: glib_sys::gpointer,
384            f: glib_sys::gpointer,
385        ) where
386            P: IsA<Texture>,
387        {
388            let f: &F = &*(f as *const F);
389            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
390        }
391        unsafe {
392            let f: Box_<F> = Box_::new(f);
393            connect_raw(
394                self.as_ptr() as *mut _,
395                b"notify::repeat-x\0".as_ptr() as *const _,
396                Some(transmute::<_, unsafe extern "C" fn()>(
397                    notify_repeat_x_trampoline::<Self, F> as *const (),
398                )),
399                Box_::into_raw(f),
400            )
401        }
402    }
403
404    fn connect_property_repeat_y_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
405        unsafe extern "C" fn notify_repeat_y_trampoline<P, F: Fn(&P) + 'static>(
406            this: *mut ffi::ClutterTexture,
407            _param_spec: glib_sys::gpointer,
408            f: glib_sys::gpointer,
409        ) where
410            P: IsA<Texture>,
411        {
412            let f: &F = &*(f as *const F);
413            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
414        }
415        unsafe {
416            let f: Box_<F> = Box_::new(f);
417            connect_raw(
418                self.as_ptr() as *mut _,
419                b"notify::repeat-y\0".as_ptr() as *const _,
420                Some(transmute::<_, unsafe extern "C" fn()>(
421                    notify_repeat_y_trampoline::<Self, F> as *const (),
422                )),
423                Box_::into_raw(f),
424            )
425        }
426    }
427
428    fn connect_property_sync_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
429        unsafe extern "C" fn notify_sync_size_trampoline<P, F: Fn(&P) + 'static>(
430            this: *mut ffi::ClutterTexture,
431            _param_spec: glib_sys::gpointer,
432            f: glib_sys::gpointer,
433        ) where
434            P: IsA<Texture>,
435        {
436            let f: &F = &*(f as *const F);
437            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
438        }
439        unsafe {
440            let f: Box_<F> = Box_::new(f);
441            connect_raw(
442                self.as_ptr() as *mut _,
443                b"notify::sync-size\0".as_ptr() as *const _,
444                Some(transmute::<_, unsafe extern "C" fn()>(
445                    notify_sync_size_trampoline::<Self, F> as *const (),
446                )),
447                Box_::into_raw(f),
448            )
449        }
450    }
451
452    fn connect_property_tile_waste_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
453        unsafe extern "C" fn notify_tile_waste_trampoline<P, F: Fn(&P) + 'static>(
454            this: *mut ffi::ClutterTexture,
455            _param_spec: glib_sys::gpointer,
456            f: glib_sys::gpointer,
457        ) where
458            P: IsA<Texture>,
459        {
460            let f: &F = &*(f as *const F);
461            f(&Texture::from_glib_borrow(this).unsafe_cast_ref())
462        }
463        unsafe {
464            let f: Box_<F> = Box_::new(f);
465            connect_raw(
466                self.as_ptr() as *mut _,
467                b"notify::tile-waste\0".as_ptr() as *const _,
468                Some(transmute::<_, unsafe extern "C" fn()>(
469                    notify_tile_waste_trampoline::<Self, F> as *const (),
470                )),
471                Box_::into_raw(f),
472            )
473        }
474    }
475}
476
477impl fmt::Display for Texture {
478    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
479        write!(f, "Texture")
480    }
481}