rust: add new pixel geometry functionality

- add NcPlane method .pixelgeom.
- upgrade full-capabilities example.
- fix NcVisual method .blitter_geom docs.
- rustfmt
This commit is contained in:
joseLuís 2021-04-10 15:09:02 +02:00
parent 9dbcef9969
commit 1afe6f162e
7 changed files with 95 additions and 23 deletions

View File

@ -24,6 +24,9 @@ Palette size: {6:?}
nc.palette_size(),
);
let pixelgeom = nc.stdplane().pixelgeom();
println!("{:#?}", pixelgeom);
rsleep![&mut nc, 1];
Ok(())
}

View File

@ -332,6 +332,7 @@ pub use ffi::{
ncplane_abs_x,
ncplane_abs_y,
ncplane_abs_yx,
ncplane_as_rgba,
ncplane_at_cursor,
ncplane_at_cursor_cell,
ncplane_at_yx,
@ -373,6 +374,7 @@ pub use ffi::{
ncplane_on_styles,
ncplane_parent,
ncplane_parent_const,
ncplane_pixelgeom,
ncplane_polyfill_yx,
ncplane_pulse,
ncplane_putc_yx,
@ -395,7 +397,6 @@ pub use ffi::{
ncplane_resize_maximize,
ncplane_resize_realign,
ncplane_resizecb,
ncplane_as_rgba,
ncplane_rotate_ccw,
ncplane_rotate_cw,
ncplane_set_base,
@ -662,6 +663,7 @@ pub use ffi::{
pub use ffi::{
// functions
ncvisual_at_yx,
ncvisual_blitter_geom,
ncvisual_decode,
ncvisual_decode_loop,
ncvisual_destroy,
@ -669,7 +671,6 @@ pub use ffi::{
ncvisual_from_file,
ncvisual_from_plane,
ncvisual_from_rgba,
ncvisual_blitter_geom,
ncvisual_media_defblitter,
ncvisual_polyfill_yx,
ncvisual_render,

View File

@ -154,10 +154,10 @@ macro_rules! error_ref {
}
};
($ptr:expr, $msg:expr) => {
error_ref![$ptr, $msg, &*$ptr ];
error_ref![$ptr, $msg, &*$ptr];
};
($ptr:expr) => {
error_ref![$ptr, "", &*$ptr ];
error_ref![$ptr, "", &*$ptr];
};
}
@ -180,10 +180,10 @@ macro_rules! error_ref_mut {
}
};
($ptr:expr, $msg:expr) => {
error_ref_mut![$ptr, $msg, &mut *$ptr ];
error_ref_mut![$ptr, $msg, &mut *$ptr];
};
($ptr:expr) => {
error_ref_mut![$ptr, "", &mut *$ptr ];
error_ref_mut![$ptr, "", &mut *$ptr];
};
}

View File

@ -8,8 +8,8 @@ use core::{
use crate::{
cstring, error, error_ref, error_ref_mut, rstring, NcAlign, NcAlphaBits, NcBlitter, NcBoxMask,
NcCell, NcChannel, NcChannelPair, NcColor, NcDim, NcEgc, NcError, NcFadeCb, NcOffset,
NcPaletteIndex, NcPlane, NcPlaneOptions, NcResizeCb, NcResult, NcRgb, NcStyleMask, NcTime,
Notcurses, NCRESULT_ERR,
NcPaletteIndex, NcPixelGeometry, NcPlane, NcPlaneOptions, NcResizeCb, NcResult, NcRgb,
NcStyleMask, NcTime, Notcurses, NCRESULT_ERR,
};
/// # NcPlaneOptions Constructors
@ -1445,16 +1445,63 @@ impl NcPlane {
let mut pxdimx = 0;
let res_array = unsafe {
crate::ncplane_as_rgba(self, blitter, beg_y as i32, beg_x as i32, len_y2, len_x2, &mut pxdimy, &mut pxdimx)
crate::ncplane_as_rgba(
self,
blitter,
beg_y as i32,
beg_x as i32,
len_y2,
len_x2,
&mut pxdimy,
&mut pxdimx,
)
};
error_ref_mut![
res_array,
&format!["NcPlane.rgba({}, {}, {}, {:?}, {:?})", blitter, beg_y, beg_x, len_y, len_x],
&format![
"NcPlane.rgba({}, {}, {}, {:?}, {:?})",
blitter, beg_y, beg_x, len_y, len_x
],
from_raw_parts_mut(res_array, (pxdimy * pxdimx) as usize)
]
}
/// Returns an [NcPixelGeometry] structure filled with pixel geometry for
/// the display region, each cell, and the maximum displayable bitmap.
///
/// This function calls [notcurses_check_pixel_support], possibly leading to
/// an interrogation of the terminal.
///
/// *C style function: [ncplane_pixelgeom()][crate::ncplane_pixelgeom].*
pub fn pixelgeom(&mut self) -> NcPixelGeometry {
let mut pxy = 0;
let mut pxx = 0;
let mut celldimy = 0;
let mut celldimx = 0;
let mut maxbmapy = 0;
let mut maxbmapx = 0;
unsafe {
crate::ncplane_pixelgeom(
self,
&mut pxy,
&mut pxx,
&mut celldimy,
&mut celldimx,
&mut maxbmapy,
&mut maxbmapx,
);
}
NcPixelGeometry {
display_y: pxy as NcDim,
display_x: pxx as NcDim,
cell_y: celldimy as NcDim,
cell_x: celldimx as NcDim,
max_bitmap_y: maxbmapy as NcDim,
max_bitmap_x: maxbmapx as NcDim,
}
}
/// Realigns this NcPlane against its parent, using the alignment specified
/// at creation time.
///

View File

@ -1,11 +1,11 @@
//! `NcPlane`
// functions already exported by bindgen : 112
// functions already exported by bindgen : 113
// -------------------------------------------
// (X) wont: 6
// (D) depr: 4
// (#) test: 13
// (W) wrap: 82 of 102 (112 - 6 - 4)
// (W) wrap: 83 of 102 (112 - 6 - 4)
// -------------------------------------------
//W ncpile_bottom
//W# ncpile_create
@ -58,6 +58,7 @@
//W ncplane_on_styles
//W ncplane_parent
//W ncplane_parent_const
//W ncplane_pixelgeom
// ncplane_polyfill_yx
//W ncplane_pulse
// ncplane_putchar_stained
@ -182,6 +183,8 @@ mod reimplemented;
pub(crate) use helpers::*;
pub use reimplemented::*;
use crate::NcDim;
// NcPlane
/// Fundamental drawing surface.
///
@ -323,3 +326,18 @@ pub const NCBLIT_DEFAULT: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_D
///
/// See [Sixel in Wikipedia](https://en.wikipedia.org/wiki/Sixel).
pub const NCBLIT_PIXEL: NcBlitter = crate::bindings::ffi::ncblitter_e_NCBLIT_PIXEL;
/// Contains the pixel geometry information as returned by the
/// NcPlane.[pixelgeom()][NcPlane#method.pixelgeom] method.
///
/// If bitmaps are not supported, the fields max_bitmap_[yx] will be 0.
#[derive(Clone, Debug)]
pub struct NcPixelGeometry {
/// Geometry of the display region
pub display_y: NcDim,
pub display_x: NcDim,
pub cell_y: NcDim,
pub cell_x: NcDim,
pub max_bitmap_y: NcDim,
pub max_bitmap_x: NcDim,
}

View File

@ -13,7 +13,7 @@
//W ncvisual_from_file
//W ncvisual_from_plane
//W ncvisual_from_rgba
//W ncvisual_geom
//W ncvisual_blitter_geom
//W ncvisual_media_defblitter
//W ncvisual_polyfill_yx
//W ncvisual_render
@ -321,7 +321,7 @@ impl NcVisual {
///
/// Errors on invalid blitter in `options`. Scaling is taken into consideration.
///
/// *C style function: [ncvisual_geom()][crate::ncvisual_geom].*
/// *C style function: [ncvisual_blitter_geom()][crate::ncvisual_blitter_geom].*
pub fn geom(
&self,
nc: &Notcurses,
@ -333,7 +333,16 @@ impl NcVisual {
let mut to_x = 0;
let res = unsafe {
crate::ncvisual_blitter_geom(nc, self, options, &mut y, &mut x, &mut to_y, &mut to_x, null_mut())
crate::ncvisual_blitter_geom(
nc,
self,
options,
&mut y,
&mut x,
&mut to_y,
&mut to_x,
null_mut(),
)
};
error![
res,

View File

@ -7,15 +7,9 @@ PENDING changes
bindgen add:
- [ ] ncdirect_stream
- [x] ncplane_as_rgba
- [ ] nclane_pixelgeom
- [ ] ncvisual_blitter_geom
- [ ] ncvisual_geom
- [x] ncplane_pixelgeom
- [x] ncvisual_blitter_geom
bindgen del
- [x] ncplane_rgba
static add:
- [ ] ncplane_rgba
- [ ] ncvisual_geom
static del:
## ...