mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
notcurses-view: switch between blitters with 0--8 #671
This commit is contained in:
parent
c0f820db94
commit
a8beaf8e56
@ -2210,13 +2210,13 @@ API char* ncvisual_subtitle(const struct ncvisual* ncv);
|
||||
// Called for each frame rendered from 'ncv'. If anything but 0 is returned,
|
||||
// the streaming operation ceases immediately, and that value is propagated out.
|
||||
// The recommended absolute display time target is passed in 'tspec'.
|
||||
typedef int (*streamcb)(struct ncplane*, struct ncvisual*,
|
||||
typedef int (*streamcb)(struct ncvisual*, struct ncvisual_options*,
|
||||
const struct timespec*, void*);
|
||||
|
||||
// Shut up and display my frames! Provide as an argument to ncvisual_stream().
|
||||
// If you'd like subtitles to be decoded, provide an ncplane as the curry. If the
|
||||
// curry is NULL, subtitles will not be displayed.
|
||||
int ncvisual_simple_streamer(struct ncplane* n, struct ncvisual* ncv,
|
||||
API int ncvisual_simple_streamer(struct ncvisual* ncv, struct ncvisual_options* vopts,
|
||||
const struct timespec* tspec, void* curry);
|
||||
|
||||
// Stream the entirety of the media, according to its own timing. Blocking,
|
||||
|
@ -168,10 +168,11 @@ int demo_nanosleep(struct notcurses* nc, const struct timespec *ts);
|
||||
int demo_nanosleep_abstime(struct notcurses* nc, const struct timespec* ts);
|
||||
|
||||
static inline int
|
||||
demo_simple_streamer(struct ncplane* nc, struct ncvisual* ncv __attribute__ ((unused)),
|
||||
demo_simple_streamer(struct ncvisual* ncv __attribute__ ((unused)),
|
||||
struct ncvisual_options* vopts,
|
||||
const struct timespec* tspec, void* curry __attribute__ ((unused))){
|
||||
DEMO_RENDER(ncplane_notcurses(nc));
|
||||
return demo_nanosleep_abstime(ncplane_notcurses(nc), tspec);
|
||||
DEMO_RENDER(ncplane_notcurses(vopts->n));
|
||||
return demo_nanosleep_abstime(ncplane_notcurses(vopts->n), tspec);
|
||||
}
|
||||
|
||||
// simple fadecb that makes proper use of demo_render() and demo_nanosleep()
|
||||
|
@ -9,10 +9,11 @@ static struct ncvisual* chncv;
|
||||
|
||||
// called in the context of the ncvisual streamer of samoa.avi
|
||||
static int
|
||||
perframe(struct ncplane* n, struct ncvisual* ncv __attribute__ ((unused)),
|
||||
perframe(struct ncvisual* ncv __attribute__ ((unused)),
|
||||
struct ncvisual_options* vopts,
|
||||
const struct timespec* abstime, void* vthree){
|
||||
int* three = vthree; // move up one every three callbacks
|
||||
DEMO_RENDER(ncplane_notcurses(n));
|
||||
DEMO_RENDER(ncplane_notcurses(vopts->n));
|
||||
if(y < targy){
|
||||
return 0;
|
||||
}
|
||||
|
@ -52,9 +52,10 @@ make_slider(struct notcurses* nc, int dimy, int dimx){
|
||||
}
|
||||
|
||||
static int
|
||||
perframecb(struct ncplane* stdn, struct ncvisual* ncv __attribute__ ((unused)),
|
||||
perframecb(struct ncvisual* ncv __attribute__ ((unused)),
|
||||
struct ncvisual_options* vopts,
|
||||
const struct timespec* tspec, void* vnewplane){
|
||||
struct notcurses* nc = ncplane_notcurses(stdn);
|
||||
struct notcurses* nc = ncplane_notcurses(vopts->n);
|
||||
static int frameno = 0;
|
||||
int y, x;
|
||||
struct ncplane* n = vnewplane;
|
||||
|
@ -410,21 +410,21 @@ braille_blit(ncplane* nc, int placey, int placex, int linesize,
|
||||
// be replaced with some real blitter implementation by the calling widget.
|
||||
const struct blitset notcurses_blitters[] = {
|
||||
{ .geom = NCBLIT_8x1, .width = 1, .height = 8, .egcs = L" ▁▂▃▄▅▆▇█",
|
||||
.blit = NULL, .fill = false, },
|
||||
.blit = tria_blit, .fill = false, }, // FIXME
|
||||
{ .geom = NCBLIT_1x1, .width = 1, .height = 1, .egcs = L" █",
|
||||
.blit = tria_blit_ascii,.fill = false, },
|
||||
{ .geom = NCBLIT_2x1, .width = 1, .height = 2, .egcs = L" ▄█",
|
||||
.blit = tria_blit, .fill = false, },
|
||||
{ .geom = NCBLIT_1x1x4, .width = 1, .height = 4, .egcs = L" ▒░▓█",
|
||||
.blit = NULL, .fill = false, },
|
||||
.blit = tria_blit, .fill = false, }, // FIXME
|
||||
{ .geom = NCBLIT_2x2, .width = 2, .height = 2, .egcs = L" ▗▐▖▄▟▌▙█",
|
||||
.blit = quadrant_blit, .fill = false, },
|
||||
{ .geom = NCBLIT_4x1, .width = 1, .height = 4, .egcs = L" ▂▄▆█",
|
||||
.blit = NULL, .fill = false, },
|
||||
.blit = tria_blit, .fill = false, }, // FIXME
|
||||
{ .geom = NCBLIT_BRAILLE, .width = 2, .height = 4, .egcs = L"⠀⡀⡄⡆⡇⢀⣀⣄⣆⣇⢠⣠⣤⣦⣧⢰⣰⣴⣶⣷⢸⣸⣼⣾⣿",
|
||||
.blit = braille_blit, .fill = true, },
|
||||
{ .geom = NCBLIT_SIXEL, .width = 1, .height = 6, .egcs = L"",
|
||||
.blit = NULL, .fill = true, },
|
||||
.blit = tria_blit, .fill = true, }, // FIXME
|
||||
{ .geom = 0, .width = 0, .height = 0, .egcs = NULL,
|
||||
.blit = NULL, .fill = false, },
|
||||
};
|
||||
|
@ -15,15 +15,11 @@ lookup_blitset(const struct notcurses* nc, ncblitter_e setid, bool may_degrade)
|
||||
}
|
||||
const struct blitset* bset = notcurses_blitters;
|
||||
while(bset->egcs){
|
||||
if(bset->geom == setid && bset->blit){
|
||||
if(bset->geom == setid){
|
||||
return bset;
|
||||
}
|
||||
++bset;
|
||||
}
|
||||
// handle other currently-invalid blitters via degrade
|
||||
if(may_degrade){
|
||||
return lookup_blitset(nc, NCBLIT_2x1, true);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -371,9 +371,9 @@ int ncvisual_stream(notcurses* nc, ncvisual* ncv, nc_err_e* ncerr,
|
||||
ns_to_timespec(schedns, &abstime);
|
||||
int r;
|
||||
if(streamer){
|
||||
r = streamer(newn, ncv, &abstime, curry);
|
||||
r = streamer(ncv, &activevopts, &abstime, curry);
|
||||
}else{
|
||||
r = ncvisual_simple_streamer(activevopts.n, ncv, &abstime, curry);
|
||||
r = ncvisual_simple_streamer(ncv, &activevopts, &abstime, curry);
|
||||
}
|
||||
if(r){
|
||||
if(activevopts.n != vopts->n){
|
||||
|
@ -503,9 +503,9 @@ auto ncvisual_destroy(ncvisual* ncv) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
auto ncvisual_simple_streamer(ncplane* n, ncvisual* ncv, const timespec* tspec,
|
||||
void* curry) -> int {
|
||||
if(notcurses_render(ncplane_notcurses(n))){
|
||||
auto ncvisual_simple_streamer(ncvisual* ncv, struct ncvisual_options* vopts,
|
||||
const timespec* tspec, void* curry) -> int {
|
||||
if(notcurses_render(ncplane_notcurses(vopts->n))){
|
||||
return -1;
|
||||
}
|
||||
int ret = 0;
|
||||
|
@ -44,14 +44,14 @@ ns_to_timespec(uint64_t ns, struct timespec* ts){
|
||||
static struct ncplane* subtitle_plane = nullptr;
|
||||
|
||||
// frame count is in the curry. original time is kept in n's userptr.
|
||||
auto perframe(struct ncplane* n, struct ncvisual* ncv,
|
||||
auto perframe(struct ncvisual* ncv, struct ncvisual_options* vopts,
|
||||
const struct timespec* abstime, void* vframecount) -> int {
|
||||
NotCurses &nc = NotCurses::get_instance ();
|
||||
auto start = static_cast<struct timespec*>(ncplane_userptr(n));
|
||||
auto start = static_cast<struct timespec*>(ncplane_userptr(vopts->n));
|
||||
if(!start){
|
||||
start = new struct timespec;
|
||||
clock_gettime(CLOCK_MONOTONIC, start);
|
||||
ncplane_set_userptr(n, start);
|
||||
ncplane_set_userptr(vopts->n, start);
|
||||
}
|
||||
std::unique_ptr<Plane> stdn(nc.get_stdplane());
|
||||
int* framecount = static_cast<int*>(vframecount);
|
||||
@ -66,7 +66,7 @@ auto perframe(struct ncplane* n, struct ncvisual* ncv,
|
||||
if(subtitle){
|
||||
if(!subtitle_plane){
|
||||
int dimx, dimy;
|
||||
ncplane_dim_yx(n, &dimy, &dimx);
|
||||
ncplane_dim_yx(vopts->n, &dimy, &dimx);
|
||||
subtitle_plane = ncplane_new(nc, 1, dimx, dimy - 1, 0, nullptr);
|
||||
uint64_t channels = 0;
|
||||
channels_set_fg_alpha(&channels, CELL_ALPHA_TRANSPARENT);
|
||||
@ -94,7 +94,7 @@ auto perframe(struct ncplane* n, struct ncvisual* ncv,
|
||||
}
|
||||
int dimx, dimy, oldx, oldy;
|
||||
nc.get_term_dim(&dimy, &dimx);
|
||||
ncplane_dim_yx(n, &oldy, &oldx);
|
||||
ncplane_dim_yx(vopts->n, &oldy, &oldx);
|
||||
struct timespec interval;
|
||||
clock_gettime(CLOCK_MONOTONIC, &interval);
|
||||
uint64_t nsnow = timespec_to_ns(&interval);
|
||||
@ -107,7 +107,8 @@ auto perframe(struct ncplane* n, struct ncvisual* ncv,
|
||||
return 0;
|
||||
}
|
||||
if(keyp >= '0' && keyp <= '8'){ // FIXME eliminate ctrl/alt
|
||||
// FIXME change blitter -- how?
|
||||
vopts->blitter = static_cast<ncblitter_e>(keyp - '0');
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user