use crate::{Actor, Animatable, Container, Event, Group, Perspective, PickMode};
use glib::{
object as gobject,
object::{Cast, IsA},
signal::{connect_raw, SignalHandlerId},
translate::*,
GString, StaticType, Value,
};
use std::boxed::Box as Box_;
use std::{fmt, mem, mem::transmute};
glib_wrapper! {
pub struct Stage(Object<ffi::ClutterStage, ffi::ClutterStageClass, StageClass>) @extends Group, Actor, gobject::InitiallyUnowned, @implements Animatable, Container;
match fn {
get_type => || ffi::clutter_stage_get_type(),
}
}
impl Stage {
pub fn new() -> Stage {
unsafe { Actor::from_glib_none(ffi::clutter_stage_new()).unsafe_cast() }
}
}
impl Default for Stage {
fn default() -> Self {
Self::new()
}
}
pub trait StageExt: 'static {
fn ensure_current(&self);
fn ensure_redraw(&self);
fn ensure_viewport(&self);
fn event(&self, event: &mut Event) -> bool;
fn get_accept_focus(&self) -> bool;
fn get_actor_at_pos(&self, pick_mode: PickMode, x: i32, y: i32) -> Option<Actor>;
fn get_fullscreen(&self) -> bool;
fn get_key_focus(&self) -> Option<Actor>;
fn get_minimum_size(&self) -> (u32, u32);
fn get_motion_events_enabled(&self) -> bool;
fn get_no_clear_hint(&self) -> bool;
fn get_perspective(&self) -> Perspective;
fn get_redraw_clip_bounds(&self) -> cairo::RectangleInt;
fn get_throttle_motion_events(&self) -> bool;
fn get_title(&self) -> Option<GString>;
fn get_use_alpha(&self) -> bool;
fn get_user_resizable(&self) -> bool;
fn hide_cursor(&self);
fn set_accept_focus(&self, accept_focus: bool);
fn set_fullscreen(&self, fullscreen: bool);
fn set_key_focus<P: IsA<Actor>>(&self, actor: Option<&P>);
fn set_minimum_size(&self, width: u32, height: u32);
fn set_motion_events_enabled(&self, enabled: bool);
fn set_no_clear_hint(&self, no_clear: bool);
fn set_perspective(&self, perspective: &mut Perspective);
fn set_throttle_motion_events(&self, throttle: bool);
fn set_title(&self, title: &str);
fn set_use_alpha(&self, use_alpha: bool);
fn set_user_resizable(&self, resizable: bool);
fn show_cursor(&self);
fn get_property_cursor_visible(&self) -> bool;
fn set_property_cursor_visible(&self, cursor_visible: bool);
fn get_property_fullscreen_set(&self) -> bool;
fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_after_paint<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_delete_event<F: Fn(&Self, &Event) -> bool + 'static>(&self, f: F)
-> SignalHandlerId;
fn connect_fullscreen<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_unfullscreen<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_accept_focus_notify<F: Fn(&Self) + 'static>(&self, f: F)
-> SignalHandlerId;
fn connect_property_cursor_visible_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_fullscreen_set_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_key_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_no_clear_hint_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
fn connect_property_perspective_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_user_resizable_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId;
}
impl<O: IsA<Stage>> StageExt for O {
fn ensure_current(&self) {
unsafe {
ffi::clutter_stage_ensure_current(self.as_ref().to_glib_none().0);
}
}
fn ensure_redraw(&self) {
unsafe {
ffi::clutter_stage_ensure_redraw(self.as_ref().to_glib_none().0);
}
}
fn ensure_viewport(&self) {
unsafe {
ffi::clutter_stage_ensure_viewport(self.as_ref().to_glib_none().0);
}
}
fn event(&self, event: &mut Event) -> bool {
unsafe {
from_glib(ffi::clutter_stage_event(
self.as_ref().to_glib_none().0,
event.to_glib_none_mut().0,
))
}
}
fn get_accept_focus(&self) -> bool {
unsafe {
from_glib(ffi::clutter_stage_get_accept_focus(
self.as_ref().to_glib_none().0,
))
}
}
fn get_actor_at_pos(&self, pick_mode: PickMode, x: i32, y: i32) -> Option<Actor> {
unsafe {
from_glib_none(ffi::clutter_stage_get_actor_at_pos(
self.as_ref().to_glib_none().0,
pick_mode.to_glib(),
x,
y,
))
}
}
fn get_fullscreen(&self) -> bool {
unsafe {
from_glib(ffi::clutter_stage_get_fullscreen(
self.as_ref().to_glib_none().0,
))
}
}
fn get_key_focus(&self) -> Option<Actor> {
unsafe {
from_glib_none(ffi::clutter_stage_get_key_focus(
self.as_ref().to_glib_none().0,
))
}
}
fn get_minimum_size(&self) -> (u32, u32) {
unsafe {
let mut width = mem::MaybeUninit::uninit();
let mut height = mem::MaybeUninit::uninit();
ffi::clutter_stage_get_minimum_size(
self.as_ref().to_glib_none().0,
width.as_mut_ptr(),
height.as_mut_ptr(),
);
let width = width.assume_init();
let height = height.assume_init();
(width, height)
}
}
fn get_motion_events_enabled(&self) -> bool {
unsafe {
from_glib(ffi::clutter_stage_get_motion_events_enabled(
self.as_ref().to_glib_none().0,
))
}
}
fn get_no_clear_hint(&self) -> bool {
unsafe {
from_glib(ffi::clutter_stage_get_no_clear_hint(
self.as_ref().to_glib_none().0,
))
}
}
fn get_perspective(&self) -> Perspective {
unsafe {
let mut perspective = Perspective::uninitialized();
ffi::clutter_stage_get_perspective(
self.as_ref().to_glib_none().0,
perspective.to_glib_none_mut().0,
);
perspective
}
}
fn get_redraw_clip_bounds(&self) -> cairo::RectangleInt {
unsafe {
let mut clip = cairo::RectangleInt::uninitialized();
ffi::clutter_stage_get_redraw_clip_bounds(
self.as_ref().to_glib_none().0,
clip.to_glib_none_mut().0,
);
clip
}
}
fn get_throttle_motion_events(&self) -> bool {
unsafe {
from_glib(ffi::clutter_stage_get_throttle_motion_events(
self.as_ref().to_glib_none().0,
))
}
}
fn get_title(&self) -> Option<GString> {
unsafe { from_glib_none(ffi::clutter_stage_get_title(self.as_ref().to_glib_none().0)) }
}
fn get_use_alpha(&self) -> bool {
unsafe {
from_glib(ffi::clutter_stage_get_use_alpha(
self.as_ref().to_glib_none().0,
))
}
}
fn get_user_resizable(&self) -> bool {
unsafe {
from_glib(ffi::clutter_stage_get_user_resizable(
self.as_ref().to_glib_none().0,
))
}
}
fn hide_cursor(&self) {
unsafe {
ffi::clutter_stage_hide_cursor(self.as_ref().to_glib_none().0);
}
}
fn set_accept_focus(&self, accept_focus: bool) {
unsafe {
ffi::clutter_stage_set_accept_focus(
self.as_ref().to_glib_none().0,
accept_focus.to_glib(),
);
}
}
fn set_fullscreen(&self, fullscreen: bool) {
unsafe {
ffi::clutter_stage_set_fullscreen(self.as_ref().to_glib_none().0, fullscreen.to_glib());
}
}
fn set_key_focus<P: IsA<Actor>>(&self, actor: Option<&P>) {
unsafe {
ffi::clutter_stage_set_key_focus(
self.as_ref().to_glib_none().0,
actor.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
fn set_minimum_size(&self, width: u32, height: u32) {
unsafe {
ffi::clutter_stage_set_minimum_size(self.as_ref().to_glib_none().0, width, height);
}
}
fn set_motion_events_enabled(&self, enabled: bool) {
unsafe {
ffi::clutter_stage_set_motion_events_enabled(
self.as_ref().to_glib_none().0,
enabled.to_glib(),
);
}
}
fn set_no_clear_hint(&self, no_clear: bool) {
unsafe {
ffi::clutter_stage_set_no_clear_hint(
self.as_ref().to_glib_none().0,
no_clear.to_glib(),
);
}
}
fn set_perspective(&self, perspective: &mut Perspective) {
unsafe {
ffi::clutter_stage_set_perspective(
self.as_ref().to_glib_none().0,
perspective.to_glib_none_mut().0,
);
}
}
fn set_throttle_motion_events(&self, throttle: bool) {
unsafe {
ffi::clutter_stage_set_throttle_motion_events(
self.as_ref().to_glib_none().0,
throttle.to_glib(),
);
}
}
fn set_title(&self, title: &str) {
unsafe {
ffi::clutter_stage_set_title(self.as_ref().to_glib_none().0, title.to_glib_none().0);
}
}
fn set_use_alpha(&self, use_alpha: bool) {
unsafe {
ffi::clutter_stage_set_use_alpha(self.as_ref().to_glib_none().0, use_alpha.to_glib());
}
}
fn set_user_resizable(&self, resizable: bool) {
unsafe {
ffi::clutter_stage_set_user_resizable(
self.as_ref().to_glib_none().0,
resizable.to_glib(),
);
}
}
fn show_cursor(&self) {
unsafe {
ffi::clutter_stage_show_cursor(self.as_ref().to_glib_none().0);
}
}
fn get_property_cursor_visible(&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"cursor-visible\0".as_ptr() as *const _,
value.to_glib_none_mut().0,
);
value
.get()
.expect("Return Value for property `cursor-visible` getter")
.unwrap()
}
}
fn set_property_cursor_visible(&self, cursor_visible: bool) {
unsafe {
gobject_sys::g_object_set_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"cursor-visible\0".as_ptr() as *const _,
Value::from(&cursor_visible).to_glib_none().0,
);
}
}
fn get_property_fullscreen_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"fullscreen-set\0".as_ptr() as *const _,
value.to_glib_none_mut().0,
);
value
.get()
.expect("Return Value for property `fullscreen-set` getter")
.unwrap()
}
}
fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn activate_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"activate\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
activate_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_after_paint<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn after_paint_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"after-paint\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
after_paint_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_deactivate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn deactivate_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"deactivate\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
deactivate_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_delete_event<F: Fn(&Self, &Event) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn delete_event_trampoline<P, F: Fn(&P, &Event) -> bool + 'static>(
this: *mut ffi::ClutterStage,
event: *mut ffi::ClutterEvent,
f: glib_sys::gpointer,
) -> glib_sys::gboolean
where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(
&Stage::from_glib_borrow(this).unsafe_cast_ref(),
&from_glib_none(event),
)
.to_glib()
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"delete-event\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
delete_event_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_fullscreen<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn fullscreen_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"fullscreen\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
fullscreen_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_unfullscreen<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn unfullscreen_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"unfullscreen\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
unfullscreen_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_accept_focus_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_accept_focus_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::accept-focus\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_accept_focus_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_cursor_visible_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_cursor_visible_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::cursor-visible\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_cursor_visible_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_fullscreen_set_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_fullscreen_set_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::fullscreen-set\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_fullscreen_set_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_key_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_key_focus_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::key-focus\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_key_focus_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_no_clear_hint_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_no_clear_hint_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::no-clear-hint\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_no_clear_hint_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_perspective_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_perspective_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::perspective\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_perspective_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_title_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::title\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_title_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_use_alpha_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_use_alpha_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::use-alpha\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_use_alpha_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
fn connect_property_user_resizable_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_user_resizable_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterStage,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<Stage>,
{
let f: &F = &*(f as *const F);
f(&Stage::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::user-resizable\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_user_resizable_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for Stage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Stage")
}
}