Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
reel.c File Reference
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "internal.h"
Include dependency graph for reel.c:

Go to the source code of this file.

Enumerations

enum  direction_e { DIRECTION_UP , DIRECTION_DOWN }
 

Functions

int ncreel_del (ncreel *nr, struct nctablet *t)
 
int ncreel_redraw (ncreel *nr)
 
ncplanenctablet_plane (nctablet *t)
 
ncplanencreel_plane (ncreel *nr)
 
ncreelncreel_create (ncplane *n, const ncreel_options *ropts)
 
nctabletncreel_add (ncreel *nr, nctablet *after, nctablet *before, tabletcb cbfxn, void *opaque)
 
void ncreel_destroy (ncreel *nreel)
 
void * nctablet_userptr (nctablet *t)
 
int ncreel_tabletcount (const ncreel *nreel)
 
nctabletncreel_focused (ncreel *nr)
 
nctabletncreel_next (ncreel *nr)
 
nctabletncreel_prev (ncreel *nr)
 
bool ncreel_offer_input (ncreel *n, const ncinput *nc)
 

Enumeration Type Documentation

◆ direction_e

Enumerator
DIRECTION_UP 
DIRECTION_DOWN 

Definition at line 7 of file reel.c.

7 {
10} direction_e; // current direction of travel
direction_e
Definition reel.c:7
@ DIRECTION_DOWN
Definition reel.c:9
@ DIRECTION_UP
Definition reel.c:8

Function Documentation

◆ ncreel_add()

nctablet * ncreel_add ( ncreel nr,
nctablet after,
nctablet before,
tabletcb  cbfxn,
void *  opaque 
)

Definition at line 838 of file reel.c.

839 {
840 nctablet* t;
841 if(after && before){
842 if(after->next != before || before->prev != after){
843 logerror("bad before (%p) / after (%p) spec", before, after);
844 return NULL;
845 }
846 }else if(!after && !before){
847 // This way, without user interaction or any specification, new tablets are
848 // inserted at the "end" relative to the focus. The first one to be added
849 // gets and keeps the focus. New ones will go on the bottom, until we run
850 // out of space. New tablets are then created off-screen.
851 before = nr->tablets;
852 }
853 if((t = malloc(sizeof(*t))) == NULL){
854 return NULL;
855 }
856//fprintf(stderr, "--------->NEW TABLET %p\n", t);
857 if(after){
858 t->next = after->next;
859 after->next = t;
860 t->prev = after;
861 t->next->prev = t;
862 }else if(before){
863 t->prev = before->prev;
864 before->prev = t;
865 t->next = before;
866 t->prev->next = t;
867 }else{ // we're the first tablet
868 t->prev = t->next = t;
869 nr->tablets = t;
870 }
871 t->cbfxn = cbfxn;
872 t->curry = opaque;
873 ++nr->tabletcount;
874 t->p = NULL;
875 t->cbp = NULL;
876 ncreel_redraw(nr);
877 return t;
878}
#define logerror(fmt,...)
Definition logging.h:32
int ncreel_redraw(ncreel *nr)
Definition reel.c:677
int tabletcount
Definition internal.h:189
nctablet * tablets
Definition internal.h:183
ncplane * cbp
Definition internal.h:171
struct nctablet * prev
Definition internal.h:173
void * curry
Definition internal.h:175
ncplane * p
Definition internal.h:170
tabletcb cbfxn
Definition internal.h:174
struct nctablet * next
Definition internal.h:172
return NULL
Definition termdesc.h:229
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreel_create()

ncreel * ncreel_create ( ncplane n,
const ncreel_options ropts 
)

Definition at line 807 of file reel.c.

807 {
808 ncreel_options zeroed = {0};
809 ncreel* nr;
810 if(!ropts){
811 ropts = &zeroed;
812 }
813 if(!validate_ncreel_opts(n, ropts)){
814 return NULL;
815 }
816 if((nr = malloc(sizeof(*nr))) == NULL){
817 return NULL;
818 }
819 nr->tablets = NULL;
820 nr->tabletcount = 0;
821 nr->direction = LASTDIRECTION_DOWN; // draw down after the initial tablet
822 memcpy(&nr->ropts, ropts, sizeof(*ropts));
823 nr->p = n;
824 nr->vft = NULL;
825 if(ncplane_set_widget(nr->p, nr, (void(*)(void*))ncreel_destroy)){
826 ncplane_destroy(nr->p);
827 free(nr);
828 return NULL;
829 }
830 if(ncreel_redraw(nr)){
831 ncplane_destroy(nr->p);
832 free(nr);
833 return NULL;
834 }
835 return nr;
836}
free(duplicated)
int ncplane_destroy(ncplane *ncp)
Definition notcurses.c:1018
vopts n
Definition notcurses.h:3502
void ncreel_destroy(ncreel *nreel)
Definition reel.c:880
ncreel_options ropts
Definition internal.h:190
ncplane * p
Definition internal.h:179
nctablet * vft
Definition internal.h:184
enum ncreel::@1 direction
Here is the call graph for this function:

◆ ncreel_del()

int ncreel_del ( ncreel nr,
struct nctablet t 
)

Definition at line 285 of file reel.c.

285 {
286 if(t == NULL){
287 return -1;
288 }
289 if(nr->tablets == t){
290 if((nr->tablets = t->next) == t){
291 nr->tablets = NULL;
292 }
293 // FIXME ought set direction based on actual location of replacement tablet
294 nr->direction = LASTDIRECTION_DOWN;
295 }
296 if(nr->vft == t){
297 clean_reel(nr); // maybe just make nr->tablets the vft?
298 }
299 nctablet_delete_internal(t);
300 --nr->tabletcount;
301 ncreel_redraw(nr);
302 return 0;
303}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreel_destroy()

void ncreel_destroy ( ncreel nreel)

Definition at line 880 of file reel.c.

880 {
881 if(nreel){
882 if(ncplane_set_widget(nreel->p, NULL, NULL) == 0){
883 nctablet* t;
884 while( (t = nreel->tablets) ){
885 ncreel_del(nreel, t);
886 }
887 ncplane_destroy(nreel->p);
888 }
889 free(nreel);
890 }
891}
int ncreel_del(ncreel *nr, struct nctablet *t)
Definition reel.c:285
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreel_focused()

nctablet * ncreel_focused ( ncreel nr)

Definition at line 901 of file reel.c.

901 {
902 return nr->tablets;
903}
Here is the caller graph for this function:

◆ ncreel_next()

nctablet * ncreel_next ( ncreel nr)

Definition at line 905 of file reel.c.

905 {
906 if(nr->tablets){
907 nr->tablets = nr->tablets->next;
908//fprintf(stderr, "---------------> moved to next, %p to %p <----------\n", nr->tablets->prev, nr->tablets);
909 nr->direction = LASTDIRECTION_DOWN;
910 ncreel_redraw(nr);
911 }
912 return nr->tablets;
913}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreel_offer_input()

bool ncreel_offer_input ( ncreel n,
const ncinput nc 
)

Definition at line 925 of file reel.c.

925 {
926 if(nc->evtype == NCTYPE_RELEASE){
927 return false;
928 }
929 if(nc->id == NCKEY_UP){
930 ncreel_prev(n);
931 return true;
932 }else if(nc->id == NCKEY_DOWN){
933 ncreel_next(n);
934 return true;
935 }else if(nc->id == NCKEY_SCROLL_UP){
936 ncreel_prev(n);
937 return true;
938 }else if(nc->id == NCKEY_SCROLL_DOWN){
939 ncreel_next(n);
940 return true;
941 }
942 // FIXME page up/page down
943 // FIXME end/home (when not using infinite scrolling)
944 return false;
945}
#define NCKEY_SCROLL_UP
Definition nckeys.h:192
#define NCKEY_SCROLL_DOWN
Definition nckeys.h:193
#define NCKEY_UP
Definition nckeys.h:37
#define NCKEY_DOWN
Definition nckeys.h:39
@ NCTYPE_RELEASE
Definition notcurses.h:1198
nctablet * ncreel_prev(ncreel *nr)
Definition reel.c:915
nctablet * ncreel_next(ncreel *nr)
Definition reel.c:905
ncintype_e evtype
Definition notcurses.h:1218
uint32_t id
Definition notcurses.h:1210
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreel_plane()

ncplane * ncreel_plane ( ncreel nr)

Definition at line 803 of file reel.c.

803 {
804 return nr->p;
805}

◆ ncreel_prev()

nctablet * ncreel_prev ( ncreel nr)

Definition at line 915 of file reel.c.

915 {
916 if(nr->tablets){
917 nr->tablets = nr->tablets->prev;
918//fprintf(stderr, "----------------> moved to prev, %p to %p <----------\n", nr->tablets->next, nr->tablets);
919 nr->direction = LASTDIRECTION_UP;
920 ncreel_redraw(nr);
921 }
922 return nr->tablets;
923}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreel_redraw()

int ncreel_redraw ( ncreel nr)

Definition at line 677 of file reel.c.

677 {
678//fprintf(stderr, "\n--------> BEGIN REDRAW <--------\n");
679 nctablet* focused = nr->tablets;
680 int fulcrum; // target line
681 if(nr->direction == LASTDIRECTION_UP){
682 // case i iff the last direction was UP, and either the focused tablet is
683 // not visible, or below the visibly-focused tablet, or there is no
684 // visibly-focused tablet.
685 if(!focused || !focused->p || !nr->vft){
686 fulcrum = 0;
687//fprintf(stderr, "case i fulcrum %d\n", fulcrum);
688 }else{
689 int focy, vfty;
690 ncplane_yx(focused->p, &focy, NULL);
691 ncplane_yx(nr->vft->p, &vfty, NULL);
692 if(focy > vfty){
693 fulcrum = 0;
694//fprintf(stderr, "case i fulcrum %d (%d %d) %p %p\n", fulcrum, focy, vfty, focused, nr->vft);
695 }else{
696 ncplane_yx(focused->p, &fulcrum, NULL); // case iii
697//fprintf(stderr, "case iii fulcrum %d (%d %d) %p %p lastdir: %d\n", fulcrum, focy, vfty, focused, nr->vft, nr->direction);
698 }
699 }
700 }else{
701 // case ii iff the last direction was DOWN, and either the focused tablet
702 // is not visible, or above the visibly-focused tablet, or there is no
703 // visibly-focused tablet.
704 if(!focused || !focused->p || !nr->vft){
705 fulcrum = ncplane_dim_y(nr->p) - 1;
706//fprintf(stderr, "case ii fulcrum %d\n", fulcrum);
707 }else{
708 int focy, vfty;
709//fprintf(stderr, "focused: %p\n", focused);
710 ncplane_yx(focused->p, &focy, NULL);
711 ncplane_yx(nr->vft->p, &vfty, NULL);
712 if(focy < vfty){
713 fulcrum = ncplane_dim_y(nr->p) - 1;
714//fprintf(stderr, "case ii fulcrum %d (%d %d) %p %p\n", fulcrum, focy, vfty, focused, nr->vft);
715 }else{
716 ncplane_yx(focused->p, &fulcrum, NULL); // case iii
717//fprintf(stderr, "case iiib fulcrum %d (%d %d) %p %p lastdir: %d\n", fulcrum, focy, vfty, focused, nr->vft, nr->direction);
718 }
719 }
720 }
721 clean_reel(nr);
722 if(focused){
723//fprintf(stderr, "drawing focused tablet %p dir: %d fulcrum: %d!\n", focused, nr->direction, fulcrum);
724 if(ncreel_draw_tablet(nr, focused, fulcrum, fulcrum, DIRECTION_DOWN)){
725 logerror("error drawing tablet");
726 return -1;
727 }
728//fprintf(stderr, "drew focused tablet %p -> %p lastdir: %d!\n", focused, focused->p, nr->direction);
729 nctablet* otherend = focused;
730 int frontiertop, frontierbottom;
731 ncplane_yx(nr->tablets->p, &frontiertop, NULL);
732 frontierbottom = frontiertop + ncplane_dim_y(nr->tablets->p) + 1;
733 frontiertop -= 2;
734 if(nr->direction == LASTDIRECTION_DOWN){
735 otherend = draw_previous_tablets(nr, otherend, &frontiertop, frontierbottom);
736 if(otherend == NULL){
737 logerror("error drawing higher tablets");
738 return -1;
739 }
740 otherend = draw_following_tablets(nr, otherend, frontiertop, &frontierbottom);
741 }else{ // DIRECTION_UP
742 otherend = draw_previous_tablets(nr, otherend, &frontiertop, frontierbottom);
743 if(otherend == NULL){
744 logerror("error drawing higher tablets");
745 return -1;
746 }
747 otherend = draw_following_tablets(nr, otherend, frontiertop, &frontierbottom);
748 }
749 if(otherend == NULL){
750 logerror("error drawing following tablets");
751 return -1;
752 }
753//notcurses_debug(ncplane_notcurses(nr->p), stderr);
754 if(tighten_reel(nr)){
755 logerror("error tightening reel");
756 return -1;
757 }
758//notcurses_debug(ncplane_notcurses(nr->p), stderr);
759 }
760 nr->vft = nr->tablets; // update the visually-focused tablet pointer
761//fprintf(stderr, "DONE ARRANGING\n");
762 if(draw_ncreel_borders(nr)){
763 logerror("error drawing reel borders");
764 return -1; // enforces specified dimensional minima
765 }
766 return 0;
767}
void ncplane_yx(const ncplane *n, int *y, int *x)
Definition notcurses.c:2448
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncreel_tabletcount()

int ncreel_tabletcount ( const ncreel nreel)

Definition at line 897 of file reel.c.

897 {
898 return nreel->tabletcount;
899}
Here is the caller graph for this function:

◆ nctablet_plane()

ncplane * nctablet_plane ( nctablet t)

Definition at line 799 of file reel.c.

799 {
800 return t->cbp;
801}

◆ nctablet_userptr()

void * nctablet_userptr ( nctablet t)

Definition at line 893 of file reel.c.

893 {
894 return t->curry;
895}
Here is the caller graph for this function: