mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
Merge branch 'master' into joseluis-patch-1
This commit is contained in:
commit
e7ad2829e9
@ -2361,6 +2361,8 @@ API int ncblit_bgrx(const void* data, int linesize,
|
||||
// The ncpixel API facilitates direct management of the pixels within an
|
||||
// ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render
|
||||
// them down to terminal graphics in ncvisual_render()).
|
||||
|
||||
// Extract the 8-bit alpha component from a pixel
|
||||
static inline uint32_t
|
||||
ncpixel(int r, int g, int b){
|
||||
if(r < 0) r = 0;
|
||||
@ -2372,26 +2374,31 @@ ncpixel(int r, int g, int b){
|
||||
return 0xff000000ul | r | (b << 8u) | (g << 16u);
|
||||
}
|
||||
|
||||
// Extract the 8-bit alpha component from a pixel
|
||||
static inline unsigned
|
||||
ncpixel_a(uint32_t pixel){
|
||||
return (pixel & 0xff0000fful) >> 24u;
|
||||
}
|
||||
|
||||
// Extract the 8 bit red component from a pixel
|
||||
static inline unsigned
|
||||
ncpixel_r(uint32_t pixel){
|
||||
return (pixel & 0x000000fful);
|
||||
}
|
||||
|
||||
// Extract the 8 bit green component from a pixel
|
||||
static inline unsigned
|
||||
ncpixel_g(uint32_t pixel){
|
||||
return (pixel & 0x00ff0000ul) >> 16u;
|
||||
}
|
||||
|
||||
// Extract the 8 bit blue component from a pixel
|
||||
static inline unsigned
|
||||
ncpixel_b(uint32_t pixel){
|
||||
return (pixel & 0x0000ff00ul) >> 8u;
|
||||
}
|
||||
|
||||
// Set the 8-bit alpha component of a pixel
|
||||
static inline int
|
||||
ncpixel_set_a(uint32_t* pixel, int a){
|
||||
if(a > 255 || a < 0){
|
||||
@ -2401,6 +2408,7 @@ ncpixel_set_a(uint32_t* pixel, int a){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set the 8-bit red component of a pixel
|
||||
static inline int
|
||||
ncpixel_set_r(uint32_t* pixel, int r){
|
||||
if(r > 255 || r < 0){
|
||||
@ -2410,6 +2418,7 @@ ncpixel_set_r(uint32_t* pixel, int r){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set the 8-bit green component of a pixel
|
||||
static inline int
|
||||
ncpixel_set_g(uint32_t* pixel, int g){
|
||||
if(g > 255 || g < 0){
|
||||
@ -2419,6 +2428,7 @@ ncpixel_set_g(uint32_t* pixel, int g){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Set the 8-bit blue component of a pixel
|
||||
static inline int
|
||||
ncpixel_set_b(uint32_t* pixel, int b){
|
||||
if(b > 255 || b < 0){
|
||||
@ -2597,14 +2607,14 @@ API void notcurses_cursor_disable(struct notcurses* nc);
|
||||
// Palette API. Some terminals only support 256 colors, but allow the full
|
||||
// palette to be specified with arbitrary RGB colors. In all cases, it's more
|
||||
// performant to use indexed colors, since it's much less data to write to the
|
||||
// terminal. If you can limit yourself to 256 colors, that' probably best.
|
||||
// terminal. If you can limit yourself to 256 colors, that's probably best.
|
||||
|
||||
typedef struct palette256 {
|
||||
// We store the RGB values as a regular ol' channel
|
||||
uint32_t chans[NCPALETTESIZE];
|
||||
} palette256;
|
||||
|
||||
// Create a new palette store. It will be initialized with notcurses's best
|
||||
// Create a new palette store. It will be initialized with notcurses' best
|
||||
// knowledge of the currently configured palette.
|
||||
API palette256* palette256_new(struct notcurses* nc);
|
||||
|
||||
|
@ -8,9 +8,9 @@
|
||||
// - cells_rounded_box
|
||||
//
|
||||
// static inline functions to reimplement: 45
|
||||
// ------------------------------------------
|
||||
// - finished : ±2
|
||||
// - remaining: 43
|
||||
// ------------------------------------------ (done / wont / remaining)
|
||||
// - implement : 2 / 0 / 43
|
||||
// - unit tests: 0 / 0 / 45
|
||||
// --------------- (+) implemented (#) + unit test (x) wont implement
|
||||
// cell_bchannel
|
||||
// cell_bg
|
||||
@ -449,3 +449,15 @@ pub fn cells_load_box(
|
||||
// cell_bg_palindex_p(const cell* cl){
|
||||
// return channels_bg_palindex_p(cl->channels);
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::ffi;
|
||||
// use serial_test::serial;
|
||||
/*
|
||||
#[test]
|
||||
#[serial]
|
||||
fn () {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -6,6 +6,9 @@
|
||||
// - `channel_set_rgb()`
|
||||
// - `channels_set_fg_rgb()`
|
||||
// - `channels_set_bg_rgb()`
|
||||
// - `channel_set()`
|
||||
// - `channels_set_fg()`
|
||||
// - `channels_set_bg()`
|
||||
//
|
||||
// - NOTE: These functions were therefore deemed unnecessary to implement:
|
||||
// - `channel_set_rgb_clipped()`
|
||||
@ -14,9 +17,6 @@
|
||||
//
|
||||
// - These functions still return an integer error result:
|
||||
// - `channel_set_alpha()`
|
||||
// - `channel_set_rgb()`
|
||||
// - `channels_set_fg()`
|
||||
// - `channels_set_bg()`
|
||||
// - `channels_set_fg_alpha()`
|
||||
// - `channels_set_bg_alpha()`
|
||||
// ---------------------------------------------------------------------------------------
|
||||
@ -25,9 +25,9 @@
|
||||
// ------------------------------------------
|
||||
//
|
||||
// static inline functions to reimplement: 38
|
||||
// ------------------------------------------
|
||||
// - finished : 37
|
||||
// - remaining: 1
|
||||
// ------------------------------------------ (done / wont / remaining)
|
||||
// - implement : 34 / 3 / 1
|
||||
// - unit tests: 14 / 0 / 21
|
||||
// --------------- (+) implemented (#) + unit test (x) wont implement
|
||||
//#channel_alpha
|
||||
//#channel_b
|
||||
@ -109,15 +109,11 @@ pub fn channel_set_rgb(channel: &mut Channel, r: Color, g: Color, b: Color) {
|
||||
*channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | rgb;
|
||||
}
|
||||
|
||||
/// Same as chennel_set_rgb(), but provide an assembled, packed 24 bits of rgb.
|
||||
/// Same as channel_set_rgb(), but provide an assembled, packed 24 bits of rgb.
|
||||
// TODO: TEST
|
||||
#[inline]
|
||||
pub fn channel_set(channel: &mut Channel, rgb: Rgb) -> IntResult {
|
||||
if rgb > 0xffffff_u32 {
|
||||
return -1;
|
||||
}
|
||||
*channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | rgb;
|
||||
0
|
||||
pub fn channel_set(channel: &mut Channel, rgb: Rgb) {
|
||||
*channel = (*channel & !ffi::CELL_BG_RGB_MASK) | ffi::CELL_BGDEFAULT_MASK | (rgb & 0x00ffffff);
|
||||
}
|
||||
|
||||
/// Extract the 2-bit alpha component from a 32-bit channel.
|
||||
@ -258,16 +254,13 @@ pub fn channels_set_fg_rgb(channels: &mut ChannelPair, r: Color, g: Color, b: Co
|
||||
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
|
||||
}
|
||||
|
||||
/// Same as channels_set_fg_rgb but but set an assembled 24 bit channel at once.
|
||||
/// Same as channels_set_fg_rgb but set an assembled 24 bit channel at once.
|
||||
// TODO: TEST
|
||||
#[inline]
|
||||
pub fn channels_set_fg(channels: &mut ChannelPair, rgb: Rgb) -> IntResult {
|
||||
pub fn channels_set_fg(channels: &mut ChannelPair, rgb: Rgb) {
|
||||
let mut channel = channels_fchannel(*channels);
|
||||
if channel_set(&mut channel, rgb) < 0 {
|
||||
return -1;
|
||||
}
|
||||
channel_set(&mut channel, rgb);
|
||||
*channels = (channel as u64) << 32 | *channels & 0xffffffff_u64;
|
||||
0
|
||||
}
|
||||
|
||||
/// Set the r, g, and b channels for the background component of this 64-bit
|
||||
@ -280,16 +273,13 @@ pub fn channels_set_bg_rgb(channels: &mut ChannelPair, r: Color, g: Color, b: Co
|
||||
channels_set_bchannel(channels, channel);
|
||||
}
|
||||
|
||||
/// Same as channels_set_bg_rgb but but set an assembled 24 bit channel at once.
|
||||
/// Same as channels_set_bg_rgb but set an assembled 24 bit channel at once.
|
||||
// TODO: TEST
|
||||
#[inline]
|
||||
pub fn channels_set_bg(channels: &mut ChannelPair, rgb: Rgb) -> IntResult {
|
||||
pub fn channels_set_bg(channels: &mut ChannelPair, rgb: Rgb) {
|
||||
let mut channel = channels_bchannel(*channels);
|
||||
if channel_set(&mut channel, rgb) < 0 {
|
||||
return -1;
|
||||
}
|
||||
channel_set(&mut channel, rgb);
|
||||
channels_set_bchannel(channels, channel);
|
||||
0
|
||||
}
|
||||
|
||||
/// Set the 2-bit alpha component of the foreground channel.
|
||||
@ -370,7 +360,6 @@ pub fn channels_set_bg_default(channels: &mut ChannelPair) -> ChannelPair {
|
||||
*channels
|
||||
}
|
||||
|
||||
|
||||
/// Returns the result of blending two channels. 'blends' indicates how heavily
|
||||
/// 'c1' ought be weighed. If 'blends' is 0, 'c1' will be entirely replaced by
|
||||
/// 'c2'. If 'c1' is otherwise the default color, 'c1' will not be touched,
|
||||
@ -408,7 +397,6 @@ pub fn channels_set_bg_default(channels: &mut ChannelPair) -> ChannelPair {
|
||||
// return c1;
|
||||
// }
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{ffi, Channel, ChannelPair};
|
||||
|
@ -1,8 +1,10 @@
|
||||
// functions already exported by bindgen : 0
|
||||
// ------------------------------------------
|
||||
//
|
||||
// static inline functions to reimplement: 2
|
||||
// - finished : 2
|
||||
// - remaining: 0
|
||||
// ------------------------------------------ (done / wont / remaining)
|
||||
// - implement : 2 / 0 / 0
|
||||
// - unit tests: 0 / 0 / 2
|
||||
// --------------- (+) implemented (#) + unit test (x) wont implement
|
||||
//+nckey_mouse_p
|
||||
//+nckey_supppuab_p
|
||||
@ -11,12 +13,24 @@ use crate as ffi;
|
||||
|
||||
/// Is this char32_t a Supplementary Private Use Area-B codepoint?
|
||||
#[inline]
|
||||
pub fn nckey_supppuab_p(w: u32)-> bool {
|
||||
pub fn nckey_supppuab_p(w: u32) -> bool {
|
||||
w >= 0x100000 && w <= 0x10fffd
|
||||
}
|
||||
|
||||
/// Is the event a synthesized mouse event?
|
||||
#[inline]
|
||||
pub fn nckey_mouse_p(r: u32)-> bool {
|
||||
pub fn nckey_mouse_p(r: u32) -> bool {
|
||||
r >= ffi::NCKEY_BUTTON1 && r <= ffi::NCKEY_RELEASE
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::ffi;
|
||||
// use serial_test::serial;
|
||||
/*
|
||||
#[test]
|
||||
#[serial]
|
||||
fn () {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -4,126 +4,128 @@
|
||||
// - https://github.com/rust-lang/rust-bindgen/issues/316
|
||||
// - https://github.com/jethrogb/rust-cexpr/pull/15
|
||||
|
||||
pub const fn suppuabize(w: u32) -> u32 {w + 0x100000}
|
||||
pub const fn suppuabize(w: u32) -> u32 {
|
||||
w + 0x100000
|
||||
}
|
||||
|
||||
pub const NCKEY_INVALID :u32 = suppuabize(0);
|
||||
pub const NCKEY_INVALID: u32 = suppuabize(0);
|
||||
///generated interally in response to SIGWINCH
|
||||
pub const NCKEY_RESIZE :u32 = suppuabize(1);
|
||||
pub const NCKEY_UP :u32 = suppuabize(2);
|
||||
pub const NCKEY_RIGHT :u32 = suppuabize(3);
|
||||
pub const NCKEY_DOWN :u32 = suppuabize(4);
|
||||
pub const NCKEY_LEFT :u32 = suppuabize(5);
|
||||
pub const NCKEY_INS :u32 = suppuabize(6);
|
||||
pub const NCKEY_DEL :u32 = suppuabize(7);
|
||||
pub const NCKEY_RESIZE: u32 = suppuabize(1);
|
||||
pub const NCKEY_UP: u32 = suppuabize(2);
|
||||
pub const NCKEY_RIGHT: u32 = suppuabize(3);
|
||||
pub const NCKEY_DOWN: u32 = suppuabize(4);
|
||||
pub const NCKEY_LEFT: u32 = suppuabize(5);
|
||||
pub const NCKEY_INS: u32 = suppuabize(6);
|
||||
pub const NCKEY_DEL: u32 = suppuabize(7);
|
||||
/// backspace (sometimes)
|
||||
pub const NCKEY_BACKSPACE :u32 = suppuabize(8);
|
||||
pub const NCKEY_PGDOWN :u32 = suppuabize(9);
|
||||
pub const NCKEY_PGUP :u32 = suppuabize(10);
|
||||
pub const NCKEY_HOME :u32 = suppuabize(11);
|
||||
pub const NCKEY_END :u32 = suppuabize(12);
|
||||
pub const NCKEY_F00 :u32 = suppuabize(20);
|
||||
pub const NCKEY_F01 :u32 = suppuabize(21);
|
||||
pub const NCKEY_F02 :u32 = suppuabize(22);
|
||||
pub const NCKEY_F03 :u32 = suppuabize(23);
|
||||
pub const NCKEY_F04 :u32 = suppuabize(24);
|
||||
pub const NCKEY_F05 :u32 = suppuabize(25);
|
||||
pub const NCKEY_F06 :u32 = suppuabize(26);
|
||||
pub const NCKEY_F07 :u32 = suppuabize(27);
|
||||
pub const NCKEY_F08 :u32 = suppuabize(28);
|
||||
pub const NCKEY_F09 :u32 = suppuabize(29);
|
||||
pub const NCKEY_F10 :u32 = suppuabize(30);
|
||||
pub const NCKEY_F11 :u32 = suppuabize(31);
|
||||
pub const NCKEY_F12 :u32 = suppuabize(32);
|
||||
pub const NCKEY_F13 :u32 = suppuabize(33);
|
||||
pub const NCKEY_F14 :u32 = suppuabize(34);
|
||||
pub const NCKEY_F15 :u32 = suppuabize(35);
|
||||
pub const NCKEY_F16 :u32 = suppuabize(36);
|
||||
pub const NCKEY_F17 :u32 = suppuabize(37);
|
||||
pub const NCKEY_F18 :u32 = suppuabize(38);
|
||||
pub const NCKEY_F19 :u32 = suppuabize(39);
|
||||
pub const NCKEY_F20 :u32 = suppuabize(40);
|
||||
pub const NCKEY_F21 :u32 = suppuabize(41);
|
||||
pub const NCKEY_F22 :u32 = suppuabize(42);
|
||||
pub const NCKEY_F23 :u32 = suppuabize(43);
|
||||
pub const NCKEY_F24 :u32 = suppuabize(44);
|
||||
pub const NCKEY_F25 :u32 = suppuabize(45);
|
||||
pub const NCKEY_F26 :u32 = suppuabize(46);
|
||||
pub const NCKEY_F27 :u32 = suppuabize(47);
|
||||
pub const NCKEY_F28 :u32 = suppuabize(48);
|
||||
pub const NCKEY_F29 :u32 = suppuabize(49);
|
||||
pub const NCKEY_F30 :u32 = suppuabize(50);
|
||||
pub const NCKEY_F31 :u32 = suppuabize(51);
|
||||
pub const NCKEY_F32 :u32 = suppuabize(52);
|
||||
pub const NCKEY_F33 :u32 = suppuabize(53);
|
||||
pub const NCKEY_F34 :u32 = suppuabize(54);
|
||||
pub const NCKEY_F35 :u32 = suppuabize(55);
|
||||
pub const NCKEY_F36 :u32 = suppuabize(56);
|
||||
pub const NCKEY_F37 :u32 = suppuabize(57);
|
||||
pub const NCKEY_F38 :u32 = suppuabize(58);
|
||||
pub const NCKEY_F39 :u32 = suppuabize(59);
|
||||
pub const NCKEY_F40 :u32 = suppuabize(60);
|
||||
pub const NCKEY_F41 :u32 = suppuabize(61);
|
||||
pub const NCKEY_F42 :u32 = suppuabize(62);
|
||||
pub const NCKEY_F43 :u32 = suppuabize(63);
|
||||
pub const NCKEY_F44 :u32 = suppuabize(64);
|
||||
pub const NCKEY_F45 :u32 = suppuabize(65);
|
||||
pub const NCKEY_F46 :u32 = suppuabize(66);
|
||||
pub const NCKEY_F47 :u32 = suppuabize(67);
|
||||
pub const NCKEY_F48 :u32 = suppuabize(68);
|
||||
pub const NCKEY_F49 :u32 = suppuabize(69);
|
||||
pub const NCKEY_F50 :u32 = suppuabize(70);
|
||||
pub const NCKEY_F51 :u32 = suppuabize(71);
|
||||
pub const NCKEY_F52 :u32 = suppuabize(72);
|
||||
pub const NCKEY_F53 :u32 = suppuabize(73);
|
||||
pub const NCKEY_F54 :u32 = suppuabize(74);
|
||||
pub const NCKEY_F55 :u32 = suppuabize(75);
|
||||
pub const NCKEY_F56 :u32 = suppuabize(76);
|
||||
pub const NCKEY_F57 :u32 = suppuabize(77);
|
||||
pub const NCKEY_F58 :u32 = suppuabize(78);
|
||||
pub const NCKEY_F59 :u32 = suppuabize(79);
|
||||
pub const NCKEY_F60 :u32 = suppuabize(80);
|
||||
pub const NCKEY_BACKSPACE: u32 = suppuabize(8);
|
||||
pub const NCKEY_PGDOWN: u32 = suppuabize(9);
|
||||
pub const NCKEY_PGUP: u32 = suppuabize(10);
|
||||
pub const NCKEY_HOME: u32 = suppuabize(11);
|
||||
pub const NCKEY_END: u32 = suppuabize(12);
|
||||
pub const NCKEY_F00: u32 = suppuabize(20);
|
||||
pub const NCKEY_F01: u32 = suppuabize(21);
|
||||
pub const NCKEY_F02: u32 = suppuabize(22);
|
||||
pub const NCKEY_F03: u32 = suppuabize(23);
|
||||
pub const NCKEY_F04: u32 = suppuabize(24);
|
||||
pub const NCKEY_F05: u32 = suppuabize(25);
|
||||
pub const NCKEY_F06: u32 = suppuabize(26);
|
||||
pub const NCKEY_F07: u32 = suppuabize(27);
|
||||
pub const NCKEY_F08: u32 = suppuabize(28);
|
||||
pub const NCKEY_F09: u32 = suppuabize(29);
|
||||
pub const NCKEY_F10: u32 = suppuabize(30);
|
||||
pub const NCKEY_F11: u32 = suppuabize(31);
|
||||
pub const NCKEY_F12: u32 = suppuabize(32);
|
||||
pub const NCKEY_F13: u32 = suppuabize(33);
|
||||
pub const NCKEY_F14: u32 = suppuabize(34);
|
||||
pub const NCKEY_F15: u32 = suppuabize(35);
|
||||
pub const NCKEY_F16: u32 = suppuabize(36);
|
||||
pub const NCKEY_F17: u32 = suppuabize(37);
|
||||
pub const NCKEY_F18: u32 = suppuabize(38);
|
||||
pub const NCKEY_F19: u32 = suppuabize(39);
|
||||
pub const NCKEY_F20: u32 = suppuabize(40);
|
||||
pub const NCKEY_F21: u32 = suppuabize(41);
|
||||
pub const NCKEY_F22: u32 = suppuabize(42);
|
||||
pub const NCKEY_F23: u32 = suppuabize(43);
|
||||
pub const NCKEY_F24: u32 = suppuabize(44);
|
||||
pub const NCKEY_F25: u32 = suppuabize(45);
|
||||
pub const NCKEY_F26: u32 = suppuabize(46);
|
||||
pub const NCKEY_F27: u32 = suppuabize(47);
|
||||
pub const NCKEY_F28: u32 = suppuabize(48);
|
||||
pub const NCKEY_F29: u32 = suppuabize(49);
|
||||
pub const NCKEY_F30: u32 = suppuabize(50);
|
||||
pub const NCKEY_F31: u32 = suppuabize(51);
|
||||
pub const NCKEY_F32: u32 = suppuabize(52);
|
||||
pub const NCKEY_F33: u32 = suppuabize(53);
|
||||
pub const NCKEY_F34: u32 = suppuabize(54);
|
||||
pub const NCKEY_F35: u32 = suppuabize(55);
|
||||
pub const NCKEY_F36: u32 = suppuabize(56);
|
||||
pub const NCKEY_F37: u32 = suppuabize(57);
|
||||
pub const NCKEY_F38: u32 = suppuabize(58);
|
||||
pub const NCKEY_F39: u32 = suppuabize(59);
|
||||
pub const NCKEY_F40: u32 = suppuabize(60);
|
||||
pub const NCKEY_F41: u32 = suppuabize(61);
|
||||
pub const NCKEY_F42: u32 = suppuabize(62);
|
||||
pub const NCKEY_F43: u32 = suppuabize(63);
|
||||
pub const NCKEY_F44: u32 = suppuabize(64);
|
||||
pub const NCKEY_F45: u32 = suppuabize(65);
|
||||
pub const NCKEY_F46: u32 = suppuabize(66);
|
||||
pub const NCKEY_F47: u32 = suppuabize(67);
|
||||
pub const NCKEY_F48: u32 = suppuabize(68);
|
||||
pub const NCKEY_F49: u32 = suppuabize(69);
|
||||
pub const NCKEY_F50: u32 = suppuabize(70);
|
||||
pub const NCKEY_F51: u32 = suppuabize(71);
|
||||
pub const NCKEY_F52: u32 = suppuabize(72);
|
||||
pub const NCKEY_F53: u32 = suppuabize(73);
|
||||
pub const NCKEY_F54: u32 = suppuabize(74);
|
||||
pub const NCKEY_F55: u32 = suppuabize(75);
|
||||
pub const NCKEY_F56: u32 = suppuabize(76);
|
||||
pub const NCKEY_F57: u32 = suppuabize(77);
|
||||
pub const NCKEY_F58: u32 = suppuabize(78);
|
||||
pub const NCKEY_F59: u32 = suppuabize(79);
|
||||
pub const NCKEY_F60: u32 = suppuabize(80);
|
||||
|
||||
// ... leave room for up to 100 function keys, egads
|
||||
|
||||
pub const NCKEY_ENTER :u32 = suppuabize(121);
|
||||
pub const NCKEY_ENTER: u32 = suppuabize(121);
|
||||
/// "clear-screen or erase"
|
||||
pub const NCKEY_CLS :u32 = suppuabize(122);
|
||||
pub const NCKEY_CLS: u32 = suppuabize(122);
|
||||
/// down + left on keypad
|
||||
pub const NCKEY_DLEFT :u32 = suppuabize(123);
|
||||
pub const NCKEY_DRIGHT :u32 = suppuabize(124);
|
||||
pub const NCKEY_DLEFT: u32 = suppuabize(123);
|
||||
pub const NCKEY_DRIGHT: u32 = suppuabize(124);
|
||||
/// up + left on keypad
|
||||
pub const NCKEY_ULEFT :u32 = suppuabize(125);
|
||||
pub const NCKEY_URIGHT :u32 = suppuabize(126);
|
||||
pub const NCKEY_ULEFT: u32 = suppuabize(125);
|
||||
pub const NCKEY_URIGHT: u32 = suppuabize(126);
|
||||
/// the most truly neutral of keypresses
|
||||
pub const NCKEY_CENTER :u32 = suppuabize(127);
|
||||
pub const NCKEY_BEGIN :u32 = suppuabize(128);
|
||||
pub const NCKEY_CANCEL :u32 = suppuabize(129);
|
||||
pub const NCKEY_CLOSE :u32 = suppuabize(130);
|
||||
pub const NCKEY_COMMAND :u32 = suppuabize(131);
|
||||
pub const NCKEY_COPY :u32 = suppuabize(132);
|
||||
pub const NCKEY_EXIT :u32 = suppuabize(133);
|
||||
pub const NCKEY_PRINT :u32 = suppuabize(134);
|
||||
pub const NCKEY_REFRESH :u32 = suppuabize(135);
|
||||
pub const NCKEY_CENTER: u32 = suppuabize(127);
|
||||
pub const NCKEY_BEGIN: u32 = suppuabize(128);
|
||||
pub const NCKEY_CANCEL: u32 = suppuabize(129);
|
||||
pub const NCKEY_CLOSE: u32 = suppuabize(130);
|
||||
pub const NCKEY_COMMAND: u32 = suppuabize(131);
|
||||
pub const NCKEY_COPY: u32 = suppuabize(132);
|
||||
pub const NCKEY_EXIT: u32 = suppuabize(133);
|
||||
pub const NCKEY_PRINT: u32 = suppuabize(134);
|
||||
pub const NCKEY_REFRESH: u32 = suppuabize(135);
|
||||
//
|
||||
// Mouse events. We try to encode some details into the char32_t (i.e. which
|
||||
// button was pressed);, but some is embedded in the ncinput event. The release
|
||||
// event is generic across buttons; callers must maintain state, if they care.
|
||||
pub const NCKEY_BUTTON1 :u32 = suppuabize(201);
|
||||
pub const NCKEY_BUTTON2 :u32 = suppuabize(202);
|
||||
pub const NCKEY_BUTTON3 :u32 = suppuabize(203);
|
||||
pub const NCKEY_BUTTON1: u32 = suppuabize(201);
|
||||
pub const NCKEY_BUTTON2: u32 = suppuabize(202);
|
||||
pub const NCKEY_BUTTON3: u32 = suppuabize(203);
|
||||
/// scrollwheel up
|
||||
pub const NCKEY_BUTTON4 :u32 = suppuabize(204);
|
||||
pub const NCKEY_BUTTON4: u32 = suppuabize(204);
|
||||
/// scrollwheel down
|
||||
pub const NCKEY_BUTTON5 :u32 = suppuabize(205);
|
||||
pub const NCKEY_BUTTON6 :u32 = suppuabize(206);
|
||||
pub const NCKEY_BUTTON7 :u32 = suppuabize(207);
|
||||
pub const NCKEY_BUTTON8 :u32 = suppuabize(208);
|
||||
pub const NCKEY_BUTTON9 :u32 = suppuabize(209);
|
||||
pub const NCKEY_BUTTON10 :u32 = suppuabize(210);
|
||||
pub const NCKEY_BUTTON11 :u32 = suppuabize(211);
|
||||
pub const NCKEY_RELEASE :u32 = suppuabize(212);
|
||||
pub const NCKEY_BUTTON5: u32 = suppuabize(205);
|
||||
pub const NCKEY_BUTTON6: u32 = suppuabize(206);
|
||||
pub const NCKEY_BUTTON7: u32 = suppuabize(207);
|
||||
pub const NCKEY_BUTTON8: u32 = suppuabize(208);
|
||||
pub const NCKEY_BUTTON9: u32 = suppuabize(209);
|
||||
pub const NCKEY_BUTTON10: u32 = suppuabize(210);
|
||||
pub const NCKEY_BUTTON11: u32 = suppuabize(211);
|
||||
pub const NCKEY_RELEASE: u32 = suppuabize(212);
|
||||
|
||||
// Synonyms (so far as we're concerned)
|
||||
pub const NCKEY_SCROLL_UP :u32 = NCKEY_BUTTON4;
|
||||
pub const NCKEY_SCROLL_DOWN :u32 = NCKEY_BUTTON5;
|
||||
pub const NCKEY_RETURN :u32 = NCKEY_ENTER;
|
||||
pub const NCKEY_SCROLL_UP: u32 = NCKEY_BUTTON4;
|
||||
pub const NCKEY_SCROLL_DOWN: u32 = NCKEY_BUTTON5;
|
||||
pub const NCKEY_RETURN: u32 = NCKEY_ENTER;
|
||||
|
@ -37,20 +37,18 @@
|
||||
// notcurses_version_components
|
||||
//
|
||||
// static inline functions to reimplement: 4
|
||||
// -----------------------------------------
|
||||
// - finished : 0
|
||||
// - remaining: 4
|
||||
// ----------------------------------------- (done / wont / remaining)
|
||||
// - implement : 0 / 0 / 4
|
||||
// - unit tests: 0 / 0 / 4
|
||||
// --------------- (+) implemented (#) + unit test (x) wont implement
|
||||
// notcurses_getc_blocking
|
||||
// notcurses_getc_nblock
|
||||
// notcurses_stddim_yx
|
||||
// notcurses_term_dim_yx
|
||||
|
||||
|
||||
// use crate as ffi;
|
||||
// use crate::types::{ChannelPair, IntResult};
|
||||
|
||||
|
||||
// // 'ni' may be NULL if the caller is uninterested in event details. If no event
|
||||
// // is ready, returns 0.
|
||||
// static inline char32_t
|
||||
@ -84,3 +82,14 @@
|
||||
// ncplane_dim_yx(notcurses_stdplane_const(n), rows, cols);
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::ffi;
|
||||
// use serial_test::serial;
|
||||
/*
|
||||
#[test]
|
||||
#[serial]
|
||||
fn () {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// NOTE: These functions now can't fail and dont't have to return an error:
|
||||
// - `palette256_set_rgb()`
|
||||
// NOTE: Now none of these functions can't fail and therefore don't return errors.
|
||||
// ---------------------------------------------------------------------------------------
|
||||
//
|
||||
// functions already exported by bindgen : 3
|
||||
@ -10,35 +9,59 @@
|
||||
// palette256_use
|
||||
//
|
||||
// static inline functions to reimplement: 3
|
||||
// -----------------------------------------
|
||||
// - finished : 1
|
||||
// - remaining: 2
|
||||
// ----------------------------------------- (done / wont / remaining)
|
||||
// - implement : 1 / 0 / 2
|
||||
// - unit tests: 0 / 0 / 3
|
||||
// --------------- (+) implemented (#) + unit test (x) wont implement
|
||||
//+palette256_get_rgb
|
||||
// palette256_set
|
||||
// palette256_set_rgb
|
||||
//+palette256_set
|
||||
//+palette256_set_rgb
|
||||
|
||||
use crate as ffi;
|
||||
use crate::types::Color;
|
||||
use ffi::{Channel, PaletteIndex, Rgb};
|
||||
|
||||
/// Manipulate entries in the palette store 'p'. These are *not* locked.
|
||||
pub fn palette256_set_rgb(palette: &mut ffi::palette256, idx: usize, r: Color, g: Color, b: Color) {
|
||||
ffi::channel_set_rgb(&mut palette.chans[idx], r, g, b)
|
||||
/// Set the different color components of an entry inside a palette store.
|
||||
// TODO: TEST
|
||||
#[inline]
|
||||
pub fn palette256_set_rgb(
|
||||
palette: &mut ffi::palette256,
|
||||
idx: PaletteIndex,
|
||||
red: Color,
|
||||
green: Color,
|
||||
blue: Color,
|
||||
) {
|
||||
ffi::channel_set_rgb(&mut palette.chans[idx as usize], red, green, blue)
|
||||
}
|
||||
|
||||
// XXX: what is the return type?
|
||||
// static inline int
|
||||
// palette256_set(palette256* p, int idx, unsigned rgb){
|
||||
// if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){
|
||||
// return -1;
|
||||
// }
|
||||
// return channel_set(&p->chans[idx], rgb);
|
||||
// }
|
||||
/// Same as `palette256_set_rgb()` but set an assembled 24 bit channel at once.
|
||||
// TODO: TEST
|
||||
#[inline]
|
||||
pub fn palette256_set(palette: &mut ffi::palette256, idx: PaletteIndex, rgb: Rgb) {
|
||||
ffi::channel_set(&mut palette.chans[idx as usize], rgb);
|
||||
}
|
||||
|
||||
// static inline int
|
||||
// palette256_get_rgb(const palette256* p, int idx, unsigned* RESTRICT r, unsigned* RESTRICT g, unsigned* RESTRICT b){
|
||||
// if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){
|
||||
// return -1;
|
||||
// }
|
||||
// return channel_rgb(p->chans[idx], r, g, b);
|
||||
// }
|
||||
/// Extract the three 8-bit R/G/B components from an entry inside a palette store.
|
||||
// TODO: TEST
|
||||
#[inline]
|
||||
pub fn palette256_get_rgb(
|
||||
palette: &ffi::palette256,
|
||||
idx: PaletteIndex,
|
||||
red: &mut Color,
|
||||
green: &mut Color,
|
||||
blue: &mut Color,
|
||||
) -> Channel {
|
||||
ffi::channel_rgb(palette.chans[idx as usize], red, green, blue)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::ffi;
|
||||
// use serial_test::serial;
|
||||
/*
|
||||
#[test]
|
||||
#[serial]
|
||||
fn () {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -1,102 +1,94 @@
|
||||
//! The ncpixel API facilitates direct management of the pixels within an
|
||||
//! ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render
|
||||
//! them down to terminal graphics in ncvisual_render()).
|
||||
//
|
||||
// - NOTE: The pixel color & alpha components are u8 instead of u32.
|
||||
// Because of type enforcing, some runtime checks are now unnecessary.
|
||||
//
|
||||
// - NOTE: None of the functions can't fail anymore and don't have to return an error.
|
||||
//
|
||||
//
|
||||
// functions already exported by bindgen : 0
|
||||
// -----------------------------------------
|
||||
//
|
||||
// static inline functions to reimplement: 3
|
||||
// -----------------------------------------
|
||||
// - finished : 0
|
||||
// - remaining: 10
|
||||
// static inline functions to reimplement: 10
|
||||
// ------------------------------------------ (done / wont / remaining)
|
||||
// - implement : 10 / 0 / 0
|
||||
// - unit tests: 0 / 0 / 10
|
||||
// --------------- (+) implemented (#) + unit test (x) wont implement
|
||||
// ncpixel
|
||||
// ncpixel_a
|
||||
// ncpixel_b
|
||||
// ncpixel_g
|
||||
// ncpixel_r
|
||||
// ncpixel_set_a
|
||||
// ncpixel_set_b
|
||||
// ncpixel_set_g
|
||||
// ncpixel_set_r
|
||||
// ncpixel_set_rgb
|
||||
//+ncpixel
|
||||
//+ncpixel_a
|
||||
//+ncpixel_b
|
||||
//+ncpixel_g
|
||||
//+ncpixel_r
|
||||
//+ncpixel_set_a
|
||||
//+ncpixel_set_b
|
||||
//+ncpixel_set_g
|
||||
//+ncpixel_set_r
|
||||
//+ncpixel_set_rgb
|
||||
|
||||
use crate::types::{Color, Pixel};
|
||||
|
||||
// use crate as ffi;
|
||||
// use crate::types::{ChannelPair, IntResult};
|
||||
/// Get an RGB pixel from RGB values
|
||||
pub fn ncpixel(r: Color, g: Color, b: Color) -> Pixel {
|
||||
0xff000000 as Pixel | r as Pixel | (b as Pixel) << 8 | (g as Pixel) << 16
|
||||
}
|
||||
|
||||
/// Extract the 8-bit alpha component from a pixel
|
||||
pub fn ncpixel_a(pixel: Pixel) -> Color {
|
||||
((pixel & 0xff0000ff) >> 24) as Color
|
||||
}
|
||||
|
||||
// // The ncpixel API facilitates direct management of the pixels within an
|
||||
// // ncvisual (ncvisuals keep a backing store of 32-bit RGBA pixels, and render
|
||||
// // them down to terminal graphics in ncvisual_render()).
|
||||
// static inline uint32_t
|
||||
// ncpixel(int r, int g, int b){
|
||||
// if(r < 0) r = 0;
|
||||
// if(r > 255) r = 255;
|
||||
// if(g < 0) g = 0;
|
||||
// if(g > 255) g = 255;
|
||||
// if(b < 0) b = 0;
|
||||
// if(b > 255) b = 255;
|
||||
// return 0xff000000ul | r | (b << 8u) | (g << 16u);
|
||||
// }
|
||||
//
|
||||
// static inline unsigned
|
||||
// ncpixel_a(uint32_t pixel){
|
||||
// return (pixel & 0xff0000fful) >> 24u;
|
||||
// }
|
||||
//
|
||||
// static inline unsigned
|
||||
// ncpixel_r(uint32_t pixel){
|
||||
// return (pixel & 0x000000fful);
|
||||
// }
|
||||
//
|
||||
// static inline int
|
||||
// ncpixel_g(uint32_t pixel){
|
||||
// return (pixel & 0x00ff0000ul) >> 16u;
|
||||
// }
|
||||
//
|
||||
// static inline int
|
||||
// ncpixel_b(uint32_t pixel){
|
||||
// return (pixel & 0x0000ff00ul) >> 8u;
|
||||
// }
|
||||
//
|
||||
// static inline int
|
||||
// ncpixel_set_a(uint32_t* pixel, int a){
|
||||
// if(a > 255 || a < 0){
|
||||
// return -1;
|
||||
// }
|
||||
// *pixel = (*pixel & 0x00fffffful) | (a << 24u);
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// static inline int
|
||||
// ncpixel_set_r(uint32_t* pixel, int r){
|
||||
// if(r > 255 || r < 0){
|
||||
// return -1;
|
||||
// }
|
||||
// *pixel = (*pixel & 0xffffff00ul) | r;
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// static inline int
|
||||
// ncpixel_set_g(uint32_t* pixel, int g){
|
||||
// if(g > 255 || g < 0){
|
||||
// return -1;
|
||||
// }
|
||||
// *pixel = (*pixel & 0xff00fffful) | (g << 16u);
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// static inline int
|
||||
// ncpixel_set_b(uint32_t* pixel, int b){
|
||||
// if(b > 255 || b < 0){
|
||||
// return -1;
|
||||
// }
|
||||
// *pixel = (*pixel & 0xffff00fful) | (b << 8u);
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// // set the RGB values of an RGB pixel
|
||||
// static inline int
|
||||
// ncpixel_set_rgb(uint32_t* pixel, int r, int g, int b){
|
||||
// if(ncpixel_set_r(pixel, r) || ncpixel_set_g(pixel, g) || ncpixel_set_b(pixel, b)){
|
||||
// return -1;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
/// Extract the 8 bit green component from a pixel
|
||||
pub fn ncpixel_g(pixel: Pixel) -> Color {
|
||||
((pixel & 0x00ff0000) >> 16) as Color
|
||||
}
|
||||
|
||||
/// Extract the 8 bit blue component from a pixel
|
||||
pub fn ncpixel_b(pixel: Pixel) -> Color {
|
||||
((pixel & 0x0000ff00) >> 8) as Color
|
||||
}
|
||||
|
||||
/// Extract the 8 bit red component from a pixel
|
||||
pub fn ncpixel_r(pixel: Pixel) -> Color {
|
||||
(pixel & 0x000000ff) as Color
|
||||
}
|
||||
|
||||
/// Set the 8-bit alpha component of a pixel
|
||||
pub fn ncpixel_set_a(pixel: &mut Pixel, alpha: Color) {
|
||||
*pixel = (*pixel & 0x00ffffff) | ((alpha as Pixel) << 24);
|
||||
}
|
||||
|
||||
/// Set the 8-bit green component of a pixel
|
||||
pub fn ncpixel_set_g(pixel: &mut Pixel, green: Color) {
|
||||
*pixel = (*pixel & 0xff00ffff) | ((green as Pixel) << 16);
|
||||
}
|
||||
|
||||
/// Set the 8-bit blue component of a pixel
|
||||
pub fn ncpixel_set_b(pixel: &mut Pixel, blue: Color) {
|
||||
*pixel = (*pixel & 0xffff00ff) | ((blue as Pixel) << 8);
|
||||
}
|
||||
|
||||
/// Set the 8-bit red component of a pixel
|
||||
pub fn ncpixel_set_r(pixel: &mut Pixel, red: Color) {
|
||||
*pixel = (*pixel & 0xffffff00) | red as Pixel;
|
||||
}
|
||||
|
||||
/// set the RGB values of an RGB pixel
|
||||
pub fn ncpixel_set_rgb(pixel: &mut Pixel, red: Color, green: Color, blue: Color) {
|
||||
ncpixel_set_r(pixel, red);
|
||||
ncpixel_set_g(pixel, green);
|
||||
ncpixel_set_b(pixel, blue);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::ffi;
|
||||
// use serial_test::serial;
|
||||
/*
|
||||
#[test]
|
||||
#[serial]
|
||||
fn () {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -88,9 +88,9 @@
|
||||
// ncplane_yx
|
||||
//
|
||||
// static inline functions to reimplement: 42
|
||||
// ------------------------------------------
|
||||
// - finished : ±4
|
||||
// - remaining: 38
|
||||
// ------------------------------------------ (done / wont / remaining)
|
||||
// - implement : 4 / 0 / 38
|
||||
// - unit tests: 0 / 0 / 42
|
||||
// --------------- (+) implemented (#) + unit test (x) wont implement
|
||||
// ncplane_align
|
||||
// ncplane_at_cursor_cell
|
||||
@ -181,8 +181,6 @@ pub fn ncplane_perimeter(
|
||||
unsafe { ffi::ncplane_cursor_move_yx(plane, 0, 0) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// // Resize the plane, retaining what data we can (everything, unless we're
|
||||
// // shrinking in some dimension). Keep the origin where it is.
|
||||
// static inline int
|
||||
@ -652,3 +650,15 @@ pub fn ncplane_perimeter(
|
||||
// x + xlen - 1, ctlword);
|
||||
// }
|
||||
//
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::ffi;
|
||||
// use serial_test::serial;
|
||||
/*
|
||||
#[test]
|
||||
#[serial]
|
||||
fn () {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -3,4 +3,6 @@ pub type ChannelPair = u64;
|
||||
pub type Color = u8;
|
||||
pub type Rgb = u32;
|
||||
pub type Alpha = u32;
|
||||
pub type Pixel = u32;
|
||||
pub type PaletteIndex = u8;
|
||||
pub type IntResult = i32; // -1 == err
|
||||
|
Loading…
Reference in New Issue
Block a user