mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
rust: add direct-image example
This commit is contained in:
parent
490f517bd9
commit
e22232774d
@ -2,6 +2,8 @@
|
||||
d = "doc --no-deps"
|
||||
do = "doc --no-deps --open"
|
||||
|
||||
re = "run --example"
|
||||
|
||||
# TEST
|
||||
# fix IO errors: https://github.com/dankamongmen/notcurses/issues/766
|
||||
t = "test -- --test-threads 1 --nocapture"
|
||||
|
BIN
rust/examples/direct-image.png
Normal file
BIN
rust/examples/direct-image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 435 B |
36
rust/examples/direct-image.rs
Normal file
36
rust/examples/direct-image.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use std::ffi::CString;
|
||||
|
||||
use libnotcurses_sys as nc;
|
||||
|
||||
extern "C" {
|
||||
fn libc_stdout() -> *mut nc::_IO_FILE;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let _ = libc::setlocale(libc::LC_ALL, CString::new("").unwrap().as_ptr());
|
||||
let ncd: *mut nc::ncdirect = nc::ncdirect_init(std::ptr::null(), libc_stdout());
|
||||
|
||||
render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_1x1);
|
||||
render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_2x1);
|
||||
render_image(&mut *ncd, nc::ncblitter_e_NCBLIT_BRAILLE);
|
||||
|
||||
nc::ncdirect_stop(ncd);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_image(ncd: &mut nc::ncdirect, blit: nc::ncblitter_e) {
|
||||
unsafe {
|
||||
if nc::ncdirect_render_image(
|
||||
ncd,
|
||||
CString::new("direct-image.png").unwrap().as_ptr(),
|
||||
nc::ncalign_e_NCALIGN_CENTER,
|
||||
blit,
|
||||
nc::ncscale_e_NCSCALE_NONE,
|
||||
) != 0
|
||||
{
|
||||
panic!("ERR: ncdirect_render_image. \
|
||||
Make sure you are running this example from the examples folder");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user