in native/desktop-linux-sample/src/sample_linux.rs [301:332]
fn draw_software_drag_icon(data: &SoftwareDrawData, physical_size: PhysicalSize, scale: f64) {
const BYTES_PER_PIXEL: u8 = 4;
let canvas = {
let len = usize::try_from(physical_size.height.0 * data.stride).unwrap();
unsafe { std::slice::from_raw_parts_mut(data.canvas, len) }
};
let w = f64::from(physical_size.width.0);
let h = f64::from(physical_size.height.0);
let line_thickness = 5.0 * scale;
// Order of bytes in `pixel` is [b, g, r, a] (for the Argb8888 format)
for (pixel, i) in canvas.chunks_exact_mut(BYTES_PER_PIXEL.into()).zip(1u32..) {
let i = f64::from(i);
let x = i % w;
let y = (i / f64::from(data.stride)) * f64::from(BYTES_PER_PIXEL);
if between(x, line_thickness, line_thickness * 2.0) // left border
|| between(y, line_thickness, line_thickness * 2.0) // top border
|| between(x, line_thickness.mul_add(-2.0, w), w - line_thickness) // right border
|| between(y, line_thickness.mul_add(-2.0, h), h - line_thickness) // bottom border
|| between(x, (i / h) - (line_thickness / 2.0), (i / h) + (line_thickness / 2.0))
{
pixel[0] = 0;
pixel[1] = 0;
} else {
pixel[0] = 128;
pixel[1] = 128;
}
pixel[2] = 128;
pixel[3] = 128;
}
}