notcurses/rust/examples/direct-image.rs

37 lines
927 B
Rust
Raw Normal View History

2020-11-16 22:53:07 +00:00
//! Example 'direct-image'
//!
//! Explore image rendering in direct mode
2020-11-15 21:43:22 +00:00
use std::ffi::CString;
2020-08-12 15:53:50 +00:00
2020-11-16 22:53:07 +00:00
// This time we are gonna use the notcurses library through the `sys` namespace
use libnotcurses_sys as sys;
2020-08-12 15:53:50 +00:00
fn main() {
unsafe {
2020-11-16 22:53:07 +00:00
let ncd = sys::NcDirect::new();
2020-08-12 15:53:50 +00:00
2020-11-16 22:53:07 +00:00
render_image(&mut *ncd, sys::NCBLIT_1x1);
render_image(&mut *ncd, sys::NCBLIT_2x1);
render_image(&mut *ncd, sys::NCBLIT_BRAILLE);
2020-08-12 15:53:50 +00:00
2020-11-16 22:53:07 +00:00
sys::ncdirect_stop(ncd);
2020-08-12 15:53:50 +00:00
}
}
2020-11-16 22:53:07 +00:00
fn render_image(ncd: &mut sys::NcDirect, blit: sys::NcBlitter) {
2020-08-12 15:53:50 +00:00
unsafe {
2020-11-16 22:53:07 +00:00
if sys::ncdirect_render_image(
2020-08-12 15:53:50 +00:00
ncd,
2020-08-17 15:54:07 +00:00
CString::new("image-16x16.png").unwrap().as_ptr(),
2020-11-16 22:53:07 +00:00
sys::NCALIGN_CENTER,
2020-08-12 15:53:50 +00:00
blit,
2020-11-16 22:53:07 +00:00
sys::NCSCALE_NONE,
2020-08-12 15:53:50 +00:00
) != 0
{
2020-11-16 22:53:07 +00:00
panic!("ERR: ncdirect_render_image. Make sure \
you are running this example from the examples folder");
2020-08-12 15:53:50 +00:00
}
}
}