notcurses-ncreel: add </>/* operators

This commit is contained in:
nick black 2020-06-03 08:58:48 -04:00
parent b65437a53f
commit d41c6d3627
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
5 changed files with 35 additions and 14 deletions

View File

@ -1929,8 +1929,8 @@ int ncreel_del(struct ncreel* pr, struct nctablet* t);
// Delete the active tablet. Returns -1 if there are no tablets.
int ncreel_del_focused(struct ncreel* pr);
// Move to the specified location within the containing plane.
int ncreel_move(struct ncreel* pr, int x, int y);
// Move to the specified location.
int ncreel_move(struct ncreel* pr, int y, int x);
// Redraw the ncreel in its entirety, for instance after
// clearing the screen due to external corruption, or a SIGWINCH.

View File

@ -68,7 +68,7 @@ typedef struct ncreel_options {
**int ncreel_del_focused(struct ncreel* nr);**
**int ncreel_move(struct ncreel* nr, int x, int y);**
**int ncreel_move(struct ncreel* nr, int y, int x);**
**int ncreel_redraw(struct ncreel* nr);**

View File

@ -2358,8 +2358,8 @@ API int ncreel_del(struct ncreel* pr, struct nctablet* t);
// Delete the active tablet. Returns -1 if there are no tablets.
API int ncreel_del_focused(struct ncreel* pr);
// Move to the specified location within the containing WINDOW.
API int ncreel_move(struct ncreel* pr, int x, int y);
// Move to the specified location.
API int ncreel_move(struct ncreel* pr, int y, int x);
// Redraw the ncreel in its entirety, for instance after
// clearing the screen due to external corruption, or a SIGWINCH.

View File

@ -777,7 +777,7 @@ int ncreel_touch(ncreel* nr, nctablet* t){
// Move to some position relative to the current position
static int
move_tablet(ncplane* p, int deltax, int deltay){
move_tablet(ncplane* p, int deltay, int deltax){
int oldx, oldy;
ncplane_yx(p, &oldy, &oldx);
int x = oldx + deltax;
@ -790,15 +790,13 @@ nctablet* ncreel_focused(ncreel* nr){
return nr->tablets;
}
int ncreel_move(ncreel* nreel, int x, int y){
int ncreel_move(ncreel* nreel, int y, int x){
ncplane* w = nreel->p;
int oldx, oldy;
ncplane_yx(w, &oldy, &oldx);
const int deltax = x - oldx;
const int deltay = y - oldy;
if(move_tablet(nreel->p, deltax, deltay)){
ncplane_move_yx(nreel->p, oldy, oldx);
ncreel_redraw(nreel);
if(ncplane_move_yx(nreel->p, y, x)){
return -1;
}
if(nreel->tablets){
@ -807,14 +805,14 @@ int ncreel_move(ncreel* nreel, int x, int y){
if(t->p == NULL){
break;
}
move_tablet(t->p, deltax, deltay);
move_tablet(t->p, deltay, deltax);
}while((t = t->prev) != nreel->tablets);
if(t != nreel->tablets){ // don't repeat if we covered all tablets
for(t = nreel->tablets->next ; t != nreel->tablets ; t = t->next){
if(t->p == NULL){
break;
}
move_tablet(t->p, deltax, deltay);
move_tablet(t->p, deltay, deltax);
}
}
}

View File

@ -12,22 +12,33 @@ using namespace ncpp;
class TabletCtx {
public:
TabletCtx() : lines(rand() % 5 + 3) {}
TabletCtx() :
lines(rand() % 5 + 3),
rgb(rand() % 0x1000000) {}
int getLines() const {
return lines;
}
unsigned getRGB() const {
return rgb;
}
private:
int lines;
unsigned rgb;
unsigned id;
};
int tabletfxn(struct nctablet* _t, int begx, int begy, int maxx, int maxy,
bool cliptop){
(void)begx;
(void)begy;
(void)maxx;
(void)cliptop;
NcTablet *t = NcTablet::map_tablet (_t);
Plane* p = t->get_plane();
auto tctx = t->get_userptr<TabletCtx>();
p->erase();
Cell c(' ');
c.set_bg((((uintptr_t)t) % 0x1000000) + cliptop + begx + maxx);
c.set_bg(tctx->getRGB());
p->set_base_cell(c);
p->release(c);
return tctx->getLines() > maxy - begy ? maxy - begy : tctx->getLines();
@ -125,6 +136,7 @@ int runreels(NotCurses& nc, ncreel_options& nopts){
if(!nr || !nc.render()){
return -1;
}
int y, x;
char32_t key;
while((key = nc.getc(true)) != (char32_t)-1){
switch(key){
@ -138,6 +150,17 @@ int runreels(NotCurses& nc, ncreel_options& nopts){
case 'd':
nr->del_focused();
break;
case '*':
notcurses_debug(nc, stderr);
break;
case NCKEY_LEFT:
nr->get_plane()->get_yx(&y, &x);
nr->move(y, x - 1);
break;
case NCKEY_RIGHT:
nr->get_plane()->get_yx(&y, &x);
nr->move(y, x + 1);
break;
case NCKEY_UP:
nr->prev();
break;