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
use crate::subclass::prelude::*;
use crate::SymbolicPaintable;
use gdk::subclass::prelude::PaintableImpl;
use glib::translate::*;
use glib::Cast;
pub trait SymbolicPaintableImpl: PaintableImpl {
fn snapshot_symbolic(
&self,
snapshot: &gdk::Snapshot,
width: f64,
height: f64,
colors: &[gdk::RGBA],
) {
self.parent_snapshot_symbolic(snapshot, width, height, colors)
}
}
pub trait SymbolicPaintableImplExt: ObjectSubclass {
fn parent_snapshot_symbolic(
&self,
_snapshot: &gdk::Snapshot,
_width: f64,
_height: f64,
_colors: &[gdk::RGBA],
);
}
impl<T: SymbolicPaintableImpl> SymbolicPaintableImplExt for T {
fn parent_snapshot_symbolic(
&self,
snapshot: &gdk::Snapshot,
width: f64,
height: f64,
colors: &[gdk::RGBA],
) {
unsafe {
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<SymbolicPaintable>()
as *const ffi::GtkSymbolicPaintableInterface;
let func = (*parent_iface).snapshot_symbolic.unwrap();
func(
self.obj()
.unsafe_cast_ref::<SymbolicPaintable>()
.to_glib_none()
.0,
snapshot.to_glib_none().0,
width,
height,
colors.to_glib_none().0,
colors.len() as _,
)
}
}
}
unsafe impl<T: SymbolicPaintableImpl> IsImplementable<T> for SymbolicPaintable {
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();
assert!(
crate::rt::is_initialized(),
"GTK has to be initialized first"
);
iface.snapshot_symbolic = Some(symbolic_paintable_snapshot_symbolic::<T>);
}
}
unsafe extern "C" fn symbolic_paintable_snapshot_symbolic<T: SymbolicPaintableImpl>(
paintable: *mut ffi::GtkSymbolicPaintable,
snapshotptr: *mut gdk::ffi::GdkSnapshot,
width: f64,
height: f64,
colors: *const gdk::ffi::GdkRGBA,
n_colors: usize,
) {
let instance = &*(paintable as *mut T::Instance);
let imp = instance.imp();
let snapshot: Borrowed<gdk::Snapshot> = from_glib_borrow(snapshotptr);
imp.snapshot_symbolic(
&snapshot,
width,
height,
if n_colors == 0 {
&[]
} else {
std::slice::from_raw_parts(colors as *const gdk::RGBA, n_colors)
},
)
}