use crate::Content;
use glib::{
object::{Cast, IsA},
signal::{connect_raw, SignalHandlerId},
translate::*,
StaticType, Value,
};
use std::boxed::Box as Box_;
use std::{fmt, mem::transmute};
glib_wrapper! {
pub struct Canvas(Object<ffi::ClutterCanvas, ffi::ClutterCanvasClass, CanvasClass>) @implements Content;
match fn {
get_type => || ffi::clutter_canvas_get_type(),
}
}
impl Canvas {
pub fn new() -> Option<Content> {
unsafe { from_glib_full(ffi::clutter_canvas_new()) }
}
}
pub const NONE_CANVAS: Option<&Canvas> = None;
pub trait CanvasExt: 'static {
fn get_scale_factor(&self) -> i32;
fn set_scale_factor(&self, scale: i32);
fn set_size(&self, width: i32, height: i32) -> bool;
fn get_property_height(&self) -> i32;
fn set_property_height(&self, height: i32);
fn get_property_scale_factor_set(&self) -> bool;
fn get_property_width(&self) -> i32;
fn set_property_width(&self, width: i32);
fn connect_draw<F: Fn(&Self, &cairo::Context, i32, i32) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F)
-> SignalHandlerId;
fn connect_property_scale_factor_set_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Canvas>> CanvasExt for O {
fn get_scale_factor(&self) -> i32 {
unsafe { ffi::clutter_canvas_get_scale_factor(self.as_ref().to_glib_none().0) }
}
fn set_scale_factor(&self, scale: i32) {
unsafe {
ffi::clutter_canvas_set_scale_factor(self.as_ref().to_glib_none().0, scale);
}
}
fn set_size(&self, width: i32, height: i32) -> bool {
unsafe {
from_glib(ffi::clutter_canvas_set_size(
self.as_ref().to_glib_none().0,
width,
height,
))
}
}
fn get_property_height(&self) -> i32 {
unsafe {
let mut value = Value::from_type(<i32 as StaticType>::static_type());
gobject_sys::g_object_get_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"height\0".as_ptr() as *const _,
value.to_glib_none_mut().0,
);
value
.get()
.expect("Return Value for property `height` getter")
.unwrap()
}
}
fn set_property_height(&self, height: i32) {
unsafe {
gobject_sys::g_object_set_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"height\0".as_ptr() as *const _,
Value::from(&height).to_glib_none().0,
);
}
}
fn get_property_scale_factor_set(&self) -> bool {
unsafe {
let mut value = Value::from_type(<bool as StaticType>::static_type());
gobject_sys::g_object_get_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"scale-factor-set\0".as_ptr() as *const _,
value.to_glib_none_mut().0,
);
value
.get()
.expect("Return Value for property `scale-factor-set` getter")
.unwrap()
}
}
fn get_property_width(&self) -> i32 {
unsafe {
let mut value = Value::from_type(<i32 as StaticType>::static_type());
gobject_sys::g_object_get_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"width\0".as_ptr() as *const _,
value.to_glib_none_mut().0,
);
value
.get()
.expect("Return Value for property `width` getter")
.unwrap()
}
}
fn set_property_width(&self, width: i32) {
unsafe {
gobject_sys::g_object_set_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"width\0".as_ptr() as *const _,
Value::from(&width).to_glib_none().0,
);
}
}
fn connect_draw<F: Fn(&Self, &cairo::Context, i32, i32) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn draw_trampoline<
P,
F: Fn(&P, &cairo::Context, i32, i32) -> bool + 'static,
>(
this: *mut ffi::ClutterCanvas,
cr: *mut cairo_sys::cairo_t,
width: libc::c_int,
height: libc::c_int,
f: glib_sys::gpointer,
) -> glib_sys::gboolean
where
P: IsA<Canvas>,
{
let f: &F = &*(f as *const F);
f(
&Canvas::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_borrow(cr),
width,
height,
)
.to_glib()
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"draw\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
draw_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_height_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterCanvas,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Canvas>,
{
let f: &F = &*(f as *const F);
f(&Canvas::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::height\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_height_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_scale_factor_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_scale_factor_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterCanvas,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Canvas>,
{
let f: &F = &*(f as *const F);
f(&Canvas::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::scale-factor\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_scale_factor_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_scale_factor_set_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_scale_factor_set_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterCanvas,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Canvas>,
{
let f: &F = &*(f as *const F);
f(&Canvas::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::scale-factor-set\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_scale_factor_set_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_width_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterCanvas,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Canvas>,
{
let f: &F = &*(f as *const F);
f(&Canvas::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::width\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_width_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for Canvas {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Canvas")
}
}