You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
notcurses/src/demo/xray.c

115 lines
4.3 KiB
C

5 years ago
#include "demo.h"
static const char* leg[] = {
" 88 88 88 88 88 88 88 ",
" \"\" 88 88 88 88 \"\" \"\" ,d ",
" 88 88 88 88 88 ",
" ,adPPYYba, 8b,dPPYba, 88 ,adPPYba, 88 ,d8 88,dPPYba, 88 ,adPPYYba, ,adPPYba, 88 ,d8 88 ,adPPYba, 88 8b,dPPYba, MM88MMM ",
" \"\" `Y8 88P' `\"8a 88 a8\" \"\" 88 ,a8\" 88P' \"8a 88 \"\" `Y8 a8\" \"\" 88 ,a8\" 88 a8\" \"8a 88 88P' `\"8a 88 ",
" ,adPPPPP88 88 88 88 8b 8888[ 88 d8 88 ,adPPPPP88 8b 8888[ 88 8b d8 88 88 88 88 ",
" 88, ,88 88 88 88 \"8a, ,aa 88`\"Yba, 88b, ,a8\" 88 88, ,88 \"8a, ,aa 88`\"Yba, 88 \"8a, ,a8\" 88 88 88 88, ",
" `\"8bbdP\"Y8 88 88 88 `\"Ybbd8\"' 88 `Y8a 8Y\"Ybbd8\"' 88 `\"8bbdP\"Y8 `\"Ybbd8\"' 88 `Y8a 88 `\"YbbdP\"' 88 88 88 \"Y888 ",
" ,88 ",
" 888P ",
};
static int
perframecb(struct notcurses* nc, struct ncvisual* ncv __attribute__ ((unused)),
void* vnewplane){
static struct ncplane* n = NULL;
static int startr = 0x80;
static int startg = 0xff;
static int startb = 0x80;
5 years ago
static int frameno = 0;
int dimx, dimy, y;
if(n == NULL){
struct ncplane* nstd = notcurses_stdplane(nc);
ncplane_dim_yx(nstd, &dimy, &dimx);
y = dimy - sizeof(leg) / sizeof(*leg);
// FIXME how will this plane be destroyed?
n = ncplane_new(nc, sizeof(leg) / sizeof(*leg), dimx, y, 0, NULL);
if(n == NULL){
return -1;
}
*(struct ncplane**)vnewplane = n;
}
5 years ago
ncplane_dim_yx(n, &dimy, &dimx);
y = 0;
cell c = CELL_SIMPLE_INITIALIZER(' ');
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT);
ncplane_set_base(n, &c);
ncplane_set_fg_alpha(n, CELL_ALPHA_BLEND);
ncplane_set_bg_alpha(n, CELL_ALPHA_BLEND);
// fg/bg rgbs are set within loop
5 years ago
int x = dimx - frameno;
for(size_t l = 0 ; l < sizeof(leg) / sizeof(*leg) ; ++l, ++y){
int r = startr;
int g = startg - (l * 0x8);
int b = startb;
5 years ago
ncplane_set_bg_rgb(n, l * 0x4, 0x20, l * 0x4);
int xoff = x;
while(xoff + (int)strlen(leg[l]) <= 0){
xoff += strlen(leg[l]);
}
do{
ncplane_set_fg_rgb(n, r, g, b);
5 years ago
int len = dimx - xoff;
if(xoff < 0){
len = strlen(leg[l]) + xoff;
}else if(xoff == 0){
int t = startr;
startr = startg;
startg = startb;
startb = t;
5 years ago
}
if(len > (int)strlen(leg[l])){
len = strlen(leg[l]);
}
if(len > dimx){
len = dimx;
}
int stroff = 0;
if(xoff < 0){
stroff = -xoff;
xoff = 0;
}
ncplane_printf_yx(n, y, xoff, "%*.*s", len, len, leg[l] + stroff);
xoff += len;
int t = r;
r = g;
g = b;
b = t;
5 years ago
}while(xoff < dimx);
}
++frameno;
demo_render(nc);
// FIXME we'll need some delay here
5 years ago
return 0;
}
int xray_demo(struct notcurses* nc){
int dimx, dimy;
struct ncplane* nstd = notcurses_stdplane(nc);
ncplane_dim_yx(nstd, &dimy, &dimx);
struct ncplane* n = ncplane_new(nc, dimy, dimx, 0, 0, NULL);
if(n == NULL){
return -1;
}
5 years ago
char* path = find_data("notcursesI.avi");
int averr;
struct ncvisual* ncv = ncplane_visual_open(n, path, &averr);
if(ncv == NULL){
return -1;
}
if(ncvisual_decode(ncv, &averr) == NULL){
return -1;
}
struct ncplane* newpanel = NULL;
ncvisual_stream(nc, ncv, &averr, perframecb, &newpanel);
5 years ago
ncvisual_destroy(ncv);
ncplane_destroy(n);
ncplane_destroy(newpanel);
5 years ago
return 0;
}