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