1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
use glib::{
    object as gobject,
    object::{Cast, IsA},
    signal::{connect_raw, SignalHandlerId},
    translate::*,
    StaticType, Value,
};
use std::boxed::Box as Box_;
use std::{fmt, mem::transmute};
// use Scriptable;

// TODO: , @implements Scriptable
glib_wrapper! {
    pub struct Interval(Object<ffi::ClutterInterval, ffi::ClutterIntervalClass, IntervalClass>) @extends gobject::InitiallyUnowned;

    match fn {
        get_type => || ffi::clutter_interval_get_type(),
    }
}

impl Interval {
    //pub fn new(gtype: glib::types::Type, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> Interval {
    //    unsafe { TODO: call clutter_sys:clutter_interval_new() }
    //}

    pub fn with_values(
        gtype: glib::types::Type,
        initial: Option<&glib::Value>,
        final_: Option<&glib::Value>,
    ) -> Interval {
        unsafe {
            from_glib_none(ffi::clutter_interval_new_with_values(
                gtype.to_glib(),
                initial.to_glib_none().0,
                final_.to_glib_none().0,
            ))
        }
    }

    //pub fn register_progress_func<P: Fn(&glib::Value, &glib::Value, f64, &glib::Value) -> bool + 'static>(value_type: glib::types::Type, func: P) {
    //    unsafe { TODO: call clutter_sys:clutter_interval_register_progress_func() }
    //}
}

pub const NONE_INTERVAL: Option<&Interval> = None;

/// Trait containing all `Interval` methods.
///
/// # Implementors
///
/// [`Interval`](struct.Interval.html)
pub trait IntervalExt: 'static {
    /// Creates a copy of `self`.
    ///
    /// # Returns
    ///
    /// the newly created `Interval`
    fn clone(&self) -> Option<Interval>;

    /// Computes the value between the `self` boundaries given the
    /// progress `factor`
    ///
    /// Unlike `IntervalExt::compute_value`, this function will
    /// return a const pointer to the computed value
    ///
    /// You should use this function if you immediately pass the computed
    /// value to another function that makes a copy of it, like
    /// `gobject::ObjectExt::set_property`
    /// ## `factor`
    /// the progress factor, between 0 and 1
    ///
    /// # Returns
    ///
    /// a pointer to the computed value,
    ///  or `None` if the computation was not successfull
    fn compute(&self, factor: f64) -> Option<glib::Value>;

    /// Computes the value between the `self` boundaries given the
    /// progress `factor` and copies it into `value`.
    /// ## `factor`
    /// the progress factor, between 0 and 1
    /// ## `value`
    /// return location for an initialized `gobject::Value`
    ///
    /// # Returns
    ///
    /// `true` if the operation was successful
    fn compute_value(&self, factor: f64) -> Option<glib::Value>;

    /// Retrieves the final value of `self` and copies
    /// it into `value`.
    ///
    /// The passed `gobject::Value` must be initialized to the value held by
    /// the `Interval`.
    /// ## `value`
    /// a `gobject::Value`
    fn get_final_value(&self) -> glib::Value;

    /// Retrieves the initial value of `self` and copies
    /// it into `value`.
    ///
    /// The passed `gobject::Value` must be initialized to the value held by
    /// the `Interval`.
    /// ## `value`
    /// a `gobject::Value`
    fn get_initial_value(&self) -> glib::Value;

    //fn get_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Retrieves the `glib::Type` of the values inside `self`.
    ///
    /// # Returns
    ///
    /// the type of the value, or G_TYPE_INVALID
    fn get_value_type(&self) -> glib::types::Type;

    /// Checks if the `self` has a valid initial and final values.
    ///
    /// # Returns
    ///
    /// `true` if the `Interval` has an initial and
    ///  final values, and `false` otherwise
    fn is_valid(&self) -> bool;

    /// Gets the pointer to the final value of `self`
    ///
    /// # Returns
    ///
    /// the final value of the interval.
    ///  The value is owned by the `Interval` and it should not be
    ///  modified or freed
    fn peek_final_value(&self) -> Option<glib::Value>;

    /// Gets the pointer to the initial value of `self`
    ///
    /// # Returns
    ///
    /// the initial value of the interval.
    ///  The value is owned by the `Interval` and it should not be
    ///  modified or freed
    fn peek_initial_value(&self) -> Option<glib::Value>;

    //fn set_final(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Sets the final value of `self` to `value`. The value is
    /// copied inside the `Interval`.
    /// ## `value`
    /// a `gobject::Value`
    fn set_final_value(&self, value: &glib::Value);

    //fn set_initial(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    /// Sets the initial value of `self` to `value`. The value is copied
    /// inside the `Interval`.
    /// ## `value`
    /// a `gobject::Value`
    fn set_initial_value(&self, value: &glib::Value);

    //fn set_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

    // /// Validates the initial and final values of `self` against
    // /// a `gobject::ParamSpec`.
    // /// ## `pspec`
    // /// a `gobject::ParamSpec`
    // ///
    // /// # Returns
    // ///
    // /// `true` if the `Interval` is valid, `false` otherwise
    // fn validate<P: IsA<glib::ParamSpec>>(&self, pspec: &P) -> bool;

    // /// The final value of the interval.
    // fn get_property_final(&self) -> Option<glib::Value>;

    // /// The initial value of the interval.
    // fn get_property_initial(&self) -> Option<glib::Value>;

    fn connect_property_final_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_initial_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Interval>> IntervalExt for O {
    fn clone(&self) -> Option<Interval> {
        unsafe { from_glib_full(ffi::clutter_interval_clone(self.as_ref().to_glib_none().0)) }
    }

    fn compute(&self, factor: f64) -> Option<glib::Value> {
        unsafe {
            from_glib_none(ffi::clutter_interval_compute(
                self.as_ref().to_glib_none().0,
                factor,
            ))
        }
    }

    fn compute_value(&self, factor: f64) -> Option<glib::Value> {
        unsafe {
            let mut value = glib::Value::uninitialized();
            let ret = from_glib(ffi::clutter_interval_compute_value(
                self.as_ref().to_glib_none().0,
                factor,
                value.to_glib_none_mut().0,
            ));
            if ret {
                Some(value)
            } else {
                None
            }
        }
    }

    fn get_final_value(&self) -> glib::Value {
        unsafe {
            let mut value = glib::Value::uninitialized();
            ffi::clutter_interval_get_final_value(
                self.as_ref().to_glib_none().0,
                value.to_glib_none_mut().0,
            );
            value
        }
    }

    fn get_initial_value(&self) -> glib::Value {
        unsafe {
            let mut value = glib::Value::uninitialized();
            ffi::clutter_interval_get_initial_value(
                self.as_ref().to_glib_none().0,
                value.to_glib_none_mut().0,
            );
            value
        }
    }

    //fn get_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call clutter_sys:clutter_interval_get_interval() }
    //}

    fn get_value_type(&self) -> glib::types::Type {
        unsafe {
            from_glib(ffi::clutter_interval_get_value_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn is_valid(&self) -> bool {
        unsafe {
            from_glib(ffi::clutter_interval_is_valid(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn peek_final_value(&self) -> Option<glib::Value> {
        unsafe {
            from_glib_none(ffi::clutter_interval_peek_final_value(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn peek_initial_value(&self) -> Option<glib::Value> {
        unsafe {
            from_glib_none(ffi::clutter_interval_peek_initial_value(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //fn set_final(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call clutter_sys:clutter_interval_set_final() }
    //}

    fn set_final_value(&self, value: &glib::Value) {
        unsafe {
            ffi::clutter_interval_set_final_value(
                self.as_ref().to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    //fn set_initial(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call clutter_sys:clutter_interval_set_initial() }
    //}

    fn set_initial_value(&self, value: &glib::Value) {
        unsafe {
            ffi::clutter_interval_set_initial_value(
                self.as_ref().to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    //fn set_interval(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
    //    unsafe { TODO: call clutter_sys:clutter_interval_set_interval() }
    //}

    // fn validate<P: IsA<glib::ParamSpec>>(&self, pspec: &P) -> bool {
    //     unsafe {
    //         from_glib(ffi::clutter_interval_validate(
    //             self.as_ref().to_glib_none().0,
    //             pspec.as_ref().to_glib_none().0,
    //         ))
    //     }
    // }

    // fn get_property_final(&self) -> Option<glib::Value> {
    //     unsafe {
    //         let mut value = Value::from_type(<glib::Value as StaticType>::static_type());
    //         gobject_sys::g_object_get_property(
    //             self.to_glib_none().0 as *mut gobject_sys::GObject,
    //             b"final\0".as_ptr() as *const _,
    //             value.to_glib_none_mut().0,
    //         );
    //         value
    //             .get()
    //             .expect("Return Value for property `final` getter")
    //     }
    // }

    // fn get_property_initial(&self) -> Option<glib::Value> {
    //     unsafe {
    //         let mut value = Value::from_type(<glib::Value as StaticType>::static_type());
    //         gobject_sys::g_object_get_property(
    //             self.to_glib_none().0 as *mut gobject_sys::GObject,
    //             b"initial\0".as_ptr() as *const _,
    //             value.to_glib_none_mut().0,
    //         );
    //         value
    //             .get()
    //             .expect("Return Value for property `initial` getter")
    //     }
    // }

    fn connect_property_final_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_final_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::ClutterInterval,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Interval>,
        {
            let f: &F = &*(f as *const F);
            f(&Interval::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::final\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_final_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_initial_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_initial_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ffi::ClutterInterval,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Interval>,
        {
            let f: &F = &*(f as *const F);
            f(&Interval::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::initial\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_initial_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Interval {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Interval")
    }
}