animate/legacy/interval.rs
1use glib::{
2 object as gobject,
3 object::{Cast, IsA},
4 signal::{connect_raw, SignalHandlerId},
5 translate::*,
6 StaticType, Value,
7};
8use std::boxed::Box as Box_;
9use std::{fmt, mem::transmute};
10// use Scriptable;
11
12// TODO: , @implements Scriptable
13glib_wrapper! {
14 pub struct Interval(Object<ffi::ClutterInterval, ffi::ClutterIntervalClass, IntervalClass>) @extends gobject::InitiallyUnowned;
15
16 match fn {
17 get_type => || ffi::clutter_interval_get_type(),
18 }
19}
20
21impl Interval {
22 //pub fn new(gtype: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Interval {
23 // unsafe { TODO: call clutter_sys:clutter_interval_new() }
24 //}
25
26 pub fn with_values(
27 gtype: glib::types::Type,
28 initial: Option<&glib::Value>,
29 final_: Option<&glib::Value>,
30 ) -> Interval {
31 unsafe {
32 from_glib_none(ffi::clutter_interval_new_with_values(
33 gtype.to_glib(),
34 initial.to_glib_none().0,
35 final_.to_glib_none().0,
36 ))
37 }
38 }
39
40 //pub fn register_progress_func<P: Fn(&glib::Value, &glib::Value, f64, &glib::Value) -> bool + 'static>(value_type: glib::types::Type, func: P) {
41 // unsafe { TODO: call clutter_sys:clutter_interval_register_progress_func() }
42 //}
43}
44
45/// Trait containing all `Interval` methods.
46///
47/// # Implementors
48///
49/// [`Interval`](struct.Interval.html)
50pub trait IntervalExt: 'static {
51 /// Creates a copy of `self`.
52 ///
53 /// # Returns
54 ///
55 /// the newly created `Interval`
56 fn clone(&self) -> Option<Interval>;
57
58 /// Computes the value between the `self` boundaries given the
59 /// progress `factor`
60 ///
61 /// Unlike `IntervalExt::compute_value`, this function will
62 /// return a const pointer to the computed value
63 ///
64 /// You should use this function if you immediately pass the computed
65 /// value to another function that makes a copy of it, like
66 /// `gobject::ObjectExt::set_property`
67 /// ## `factor`
68 /// the progress factor, between 0 and 1
69 ///
70 /// # Returns
71 ///
72 /// a pointer to the computed value,
73 /// or `None` if the computation was not successfull
74 fn compute(&self, factor: f64) -> Option<glib::Value>;
75
76 /// Computes the value between the `self` boundaries given the
77 /// progress `factor` and copies it into `value`.
78 /// ## `factor`
79 /// the progress factor, between 0 and 1
80 /// ## `value`
81 /// return location for an initialized `gobject::Value`
82 ///
83 /// # Returns
84 ///
85 /// `true` if the operation was successful
86 fn compute_value(&self, factor: f64) -> Option<glib::Value>;
87
88 /// Retrieves the final value of `self` and copies
89 /// it into `value`.
90 ///
91 /// The passed `gobject::Value` must be initialized to the value held by
92 /// the `Interval`.
93 /// ## `value`
94 /// a `gobject::Value`
95 fn get_final_value(&self) -> glib::Value;
96
97 /// Retrieves the initial value of `self` and copies
98 /// it into `value`.
99 ///
100 /// The passed `gobject::Value` must be initialized to the value held by
101 /// the `Interval`.
102 /// ## `value`
103 /// a `gobject::Value`
104 fn get_initial_value(&self) -> glib::Value;
105
106 //fn get_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
107
108 /// Retrieves the `glib::Type` of the values inside `self`.
109 ///
110 /// # Returns
111 ///
112 /// the type of the value, or G_TYPE_INVALID
113 fn get_value_type(&self) -> glib::types::Type;
114
115 /// Checks if the `self` has a valid initial and final values.
116 ///
117 /// # Returns
118 ///
119 /// `true` if the `Interval` has an initial and
120 /// final values, and `false` otherwise
121 fn is_valid(&self) -> bool;
122
123 /// Gets the pointer to the final value of `self`
124 ///
125 /// # Returns
126 ///
127 /// the final value of the interval.
128 /// The value is owned by the `Interval` and it should not be
129 /// modified or freed
130 fn peek_final_value(&self) -> Option<glib::Value>;
131
132 /// Gets the pointer to the initial value of `self`
133 ///
134 /// # Returns
135 ///
136 /// the initial value of the interval.
137 /// The value is owned by the `Interval` and it should not be
138 /// modified or freed
139 fn peek_initial_value(&self) -> Option<glib::Value>;
140
141 //fn set_final(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
142
143 /// Sets the final value of `self` to `value`. The value is
144 /// copied inside the `Interval`.
145 /// ## `value`
146 /// a `gobject::Value`
147 fn set_final_value(&self, value: &glib::Value);
148
149 //fn set_initial(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
150
151 /// Sets the initial value of `self` to `value`. The value is copied
152 /// inside the `Interval`.
153 /// ## `value`
154 /// a `gobject::Value`
155 fn set_initial_value(&self, value: &glib::Value);
156
157 //fn set_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
158
159 // /// Validates the initial and final values of `self` against
160 // /// a `gobject::ParamSpec`.
161 // /// ## `pspec`
162 // /// a `gobject::ParamSpec`
163 // ///
164 // /// # Returns
165 // ///
166 // /// `true` if the `Interval` is valid, `false` otherwise
167 // fn validate<P: IsA<glib::ParamSpec>>(&self, pspec: &P) -> bool;
168
169 // /// The final value of the interval.
170 // fn get_property_final(&self) -> Option<glib::Value>;
171
172 // /// The initial value of the interval.
173 // fn get_property_initial(&self) -> Option<glib::Value>;
174
175 fn connect_property_final_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
176
177 fn connect_property_initial_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
178}
179
180impl<O: IsA<Interval>> IntervalExt for O {
181 fn clone(&self) -> Option<Interval> {
182 unsafe { from_glib_full(ffi::clutter_interval_clone(self.as_ref().to_glib_none().0)) }
183 }
184
185 fn compute(&self, factor: f64) -> Option<glib::Value> {
186 unsafe {
187 from_glib_none(ffi::clutter_interval_compute(
188 self.as_ref().to_glib_none().0,
189 factor,
190 ))
191 }
192 }
193
194 fn compute_value(&self, factor: f64) -> Option<glib::Value> {
195 unsafe {
196 let mut value = glib::Value::uninitialized();
197 let ret = from_glib(ffi::clutter_interval_compute_value(
198 self.as_ref().to_glib_none().0,
199 factor,
200 value.to_glib_none_mut().0,
201 ));
202 if ret {
203 Some(value)
204 } else {
205 None
206 }
207 }
208 }
209
210 fn get_final_value(&self) -> glib::Value {
211 unsafe {
212 let mut value = glib::Value::uninitialized();
213 ffi::clutter_interval_get_final_value(
214 self.as_ref().to_glib_none().0,
215 value.to_glib_none_mut().0,
216 );
217 value
218 }
219 }
220
221 fn get_initial_value(&self) -> glib::Value {
222 unsafe {
223 let mut value = glib::Value::uninitialized();
224 ffi::clutter_interval_get_initial_value(
225 self.as_ref().to_glib_none().0,
226 value.to_glib_none_mut().0,
227 );
228 value
229 }
230 }
231
232 //fn get_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
233 // unsafe { TODO: call clutter_sys:clutter_interval_get_interval() }
234 //}
235
236 fn get_value_type(&self) -> glib::types::Type {
237 unsafe {
238 from_glib(ffi::clutter_interval_get_value_type(
239 self.as_ref().to_glib_none().0,
240 ))
241 }
242 }
243
244 fn is_valid(&self) -> bool {
245 unsafe {
246 from_glib(ffi::clutter_interval_is_valid(
247 self.as_ref().to_glib_none().0,
248 ))
249 }
250 }
251
252 fn peek_final_value(&self) -> Option<glib::Value> {
253 unsafe {
254 from_glib_none(ffi::clutter_interval_peek_final_value(
255 self.as_ref().to_glib_none().0,
256 ))
257 }
258 }
259
260 fn peek_initial_value(&self) -> Option<glib::Value> {
261 unsafe {
262 from_glib_none(ffi::clutter_interval_peek_initial_value(
263 self.as_ref().to_glib_none().0,
264 ))
265 }
266 }
267
268 //fn set_final(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
269 // unsafe { TODO: call clutter_sys:clutter_interval_set_final() }
270 //}
271
272 fn set_final_value(&self, value: &glib::Value) {
273 unsafe {
274 ffi::clutter_interval_set_final_value(
275 self.as_ref().to_glib_none().0,
276 value.to_glib_none().0,
277 );
278 }
279 }
280
281 //fn set_initial(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
282 // unsafe { TODO: call clutter_sys:clutter_interval_set_initial() }
283 //}
284
285 fn set_initial_value(&self, value: &glib::Value) {
286 unsafe {
287 ffi::clutter_interval_set_initial_value(
288 self.as_ref().to_glib_none().0,
289 value.to_glib_none().0,
290 );
291 }
292 }
293
294 //fn set_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
295 // unsafe { TODO: call clutter_sys:clutter_interval_set_interval() }
296 //}
297
298 // fn validate<P: IsA<glib::ParamSpec>>(&self, pspec: &P) -> bool {
299 // unsafe {
300 // from_glib(ffi::clutter_interval_validate(
301 // self.as_ref().to_glib_none().0,
302 // pspec.as_ref().to_glib_none().0,
303 // ))
304 // }
305 // }
306
307 // fn get_property_final(&self) -> Option<glib::Value> {
308 // unsafe {
309 // let mut value = Value::from_type(<glib::Value as StaticType>::static_type());
310 // gobject_sys::g_object_get_property(
311 // self.to_glib_none().0 as *mut gobject_sys::GObject,
312 // b"final\0".as_ptr() as *const _,
313 // value.to_glib_none_mut().0,
314 // );
315 // value
316 // .get()
317 // .expect("Return Value for property `final` getter")
318 // }
319 // }
320
321 // fn get_property_initial(&self) -> Option<glib::Value> {
322 // unsafe {
323 // let mut value = Value::from_type(<glib::Value as StaticType>::static_type());
324 // gobject_sys::g_object_get_property(
325 // self.to_glib_none().0 as *mut gobject_sys::GObject,
326 // b"initial\0".as_ptr() as *const _,
327 // value.to_glib_none_mut().0,
328 // );
329 // value
330 // .get()
331 // .expect("Return Value for property `initial` getter")
332 // }
333 // }
334
335 fn connect_property_final_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
336 unsafe extern "C" fn notify_final_trampoline<P, F: Fn(&P) + 'static>(
337 this: *mut ffi::ClutterInterval,
338 _param_spec: glib_sys::gpointer,
339 f: glib_sys::gpointer,
340 ) where
341 P: IsA<Interval>,
342 {
343 let f: &F = &*(f as *const F);
344 f(&Interval::from_glib_borrow(this).unsafe_cast_ref())
345 }
346 unsafe {
347 let f: Box_<F> = Box_::new(f);
348 connect_raw(
349 self.as_ptr() as *mut _,
350 b"notify::final\0".as_ptr() as *const _,
351 Some(transmute::<_, unsafe extern "C" fn()>(
352 notify_final_trampoline::<Self, F> as *const (),
353 )),
354 Box_::into_raw(f),
355 )
356 }
357 }
358
359 fn connect_property_initial_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
360 unsafe extern "C" fn notify_initial_trampoline<P, F: Fn(&P) + 'static>(
361 this: *mut ffi::ClutterInterval,
362 _param_spec: glib_sys::gpointer,
363 f: glib_sys::gpointer,
364 ) where
365 P: IsA<Interval>,
366 {
367 let f: &F = &*(f as *const F);
368 f(&Interval::from_glib_borrow(this).unsafe_cast_ref())
369 }
370 unsafe {
371 let f: Box_<F> = Box_::new(f);
372 connect_raw(
373 self.as_ptr() as *mut _,
374 b"notify::initial\0".as_ptr() as *const _,
375 Some(transmute::<_, unsafe extern "C" fn()>(
376 notify_initial_trampoline::<Self, F> as *const (),
377 )),
378 Box_::into_raw(f),
379 )
380 }
381 }
382}
383
384impl fmt::Display for Interval {
385 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
386 write!(f, "Interval")
387 }
388}