...
|
...
|
@@ -94,10 +94,16 @@ typedef struct menubar_t {
|
94
|
94
|
font_t *ptrfont;
|
95
|
95
|
} menubar_t;
|
96
|
96
|
|
|
97
|
+typedef struct listingdata_t {
|
|
98
|
+ xywh_t leftxywh;
|
|
99
|
+ xywh_t xywh;
|
|
100
|
+ char *name; /* first byte in the name is the type, next is the name, i.e. a directory is "dhome" and a file is "f.bashrc" (this is done for easier sorting) */
|
|
101
|
+} listingdata_t;
|
|
102
|
+
|
97
|
103
|
typedef struct listing_t {
|
98
|
104
|
int sizeelems;
|
99
|
105
|
int usedelems;
|
100
|
|
- char **elems; /* first byte in the elem is the type, next is the name, i.e. a directory is "dhome" and a file is "f.bashrc" */
|
|
106
|
+ listingdata_t *elems;
|
101
|
107
|
int sizebuf;
|
102
|
108
|
int usedbuf;
|
103
|
109
|
char *buf;
|
...
|
...
|
@@ -229,7 +235,7 @@ fprintf(stderr,"SELECTED: \"%s\"->\"%s\"\n",sel_menu,sel_submenu);
|
229
|
235
|
v2.x=(float) (im->font->height/2);
|
230
|
236
|
v2.y=(float) ((im->font->height+im->font->height/2)*i+(im->font->height/4));
|
231
|
237
|
DrawTextEx(im->font->font
|
232
|
|
- ,listing.elems[j]
|
|
238
|
+ ,listing.elems[j].name
|
233
|
239
|
,v2
|
234
|
240
|
,im->font->height
|
235
|
241
|
,0
|
...
|
...
|
@@ -653,8 +659,10 @@ im_body_draw(body_t *body, int windowwidth, int windowheight)
|
653
|
659
|
{
|
654
|
660
|
int i,x,y,k,margin,righty;
|
655
|
661
|
dirdata_t *dirdata;
|
|
662
|
+ listingdata_t *elem;
|
656
|
663
|
Vector2 v2,m2;
|
657
|
664
|
font_t *font,*fontbig,*fonthuge;
|
|
665
|
+ int is_leftside;
|
658
|
666
|
if(body==NULL)
|
659
|
667
|
return(-1);
|
660
|
668
|
font=body->ptrfont;
|
...
|
...
|
@@ -669,66 +677,90 @@ im_body_draw(body_t *body, int windowwidth, int windowheight)
|
669
|
677
|
for(i=0,y=righty=body->xywh.y;i<body->sizedirdata;i++) {
|
670
|
678
|
if((dirdata=body->dirdata[i])==NULL)
|
671
|
679
|
continue;
|
672
|
|
- /* draw left side if appropiate */
|
673
|
|
- if(i==body->currentdirdata) {
|
|
680
|
+ /* two passes for each dirdata, first leftside, then rightside */
|
|
681
|
+ for(is_leftside=1;is_leftside>=0;is_leftside--) {
|
674
|
682
|
int x0,y0,x1,y1;
|
675
|
|
- /* draw left side */
|
676
|
|
- /* ...back arrow */
|
677
|
|
- v2.x=(float) (body->xywh.x+fontbig->height/2);
|
678
|
|
- v2.y=(float) (body->xywh.y+fontbig->height/4);
|
679
|
|
- m2=MeasureTextEx(fontbig->font,UTF8DOWNARROW,fontbig->height,0);
|
680
|
|
- FILLXYWH(body->backxywh,v2.x-fontbig->height/4,v2.y-fontbig->height/8,m2.x+fontbig->height/4,m2.x+fontbig->height/4);
|
|
683
|
+ if(is_leftside && !(i==body->currentdirdata))
|
|
684
|
+ continue; /* this element is not in leftside */
|
|
685
|
+ if(is_leftside) {
|
|
686
|
+ /* draw left side back arrow */
|
|
687
|
+ v2.x=(float) (body->xywh.x+fontbig->height/2);
|
|
688
|
+ v2.y=(float) (body->xywh.y+fontbig->height/4);
|
|
689
|
+ m2=MeasureTextEx(fontbig->font,UTF8DOWNARROW,fontbig->height,0);
|
|
690
|
+ FILLXYWH(body->backxywh,v2.x-fontbig->height/4,v2.y-fontbig->height/8,m2.x+fontbig->height/4,m2.x+fontbig->height/4);
|
681
|
691
|
#if 0
|
682
|
692
|
DrawTexture(fontbig->font.texture, 0, 0, WHITE); /* font glyphs -- see https://github.com/raysan5/raylib/issues/2022 */
|
683
|
693
|
DrawRectangle(UNROLLXYWH(body->backxywh),((Color){ 0,255,0,255 })); /* hit zone */
|
684
|
694
|
#endif
|
685
|
|
- DrawTextPro(fontbig->font,UTF8DOWNARROW,(Vector2){v2.x+m2.x,v2.y},(Vector2){0,0},90.0,fontbig->height,0,(Color){65,65,65,255});
|
686
|
|
- /* ...dirname */
|
687
|
|
- m2=MeasureTextEx(fontbig->font,dirdata->dirname,fontbig->height,0);
|
688
|
|
- v2.x=(float) (body->xywh.x+fontbig->height/2)+(body->leftsize-(body->xywh.x+fontbig->height)-m2.x)/2;
|
689
|
|
- v2.y=(float) (body->xywh.y+fontbig->height/4);
|
690
|
|
- DrawTextEx(fontbig->font
|
691
|
|
- ,dirdata->dirname
|
692
|
|
- ,v2
|
693
|
|
- ,fontbig->height
|
694
|
|
- ,0
|
695
|
|
- ,(Color){ 65, 65, 65, 255 }
|
696
|
|
- );
|
|
695
|
+ DrawTextPro(fontbig->font,UTF8DOWNARROW,(Vector2){v2.x+m2.x,v2.y},(Vector2){0,0},90.0,fontbig->height,0,(Color){65,65,65,255});
|
|
696
|
+ }
|
|
697
|
+ if(is_leftside) {
|
|
698
|
+ /* ...dirname */
|
|
699
|
+ m2=MeasureTextEx(fontbig->font,dirdata->dirname,fontbig->height,0);
|
|
700
|
+ v2.x=(float) (body->xywh.x+fontbig->height/2)+(body->leftsize-(body->xywh.x+fontbig->height)-m2.x)/2;
|
|
701
|
+ v2.y=(float) (body->xywh.y+fontbig->height/4);
|
|
702
|
+ DrawTextEx(fontbig->font
|
|
703
|
+ ,dirdata->dirname
|
|
704
|
+ ,v2
|
|
705
|
+ ,fontbig->height
|
|
706
|
+ ,0
|
|
707
|
+ ,(Color){ 65, 65, 65, 255 }
|
|
708
|
+ );
|
|
709
|
+ } else { /* rightside */
|
|
710
|
+ /* ...bg */
|
|
711
|
+ DrawRectangle(body->xywh.x+body->leftsize,righty,body->xywh.w-body->leftsize, dirdata->height,(i==body->currentdirdata)?((Color){ 168, 168, 168, 255 }):((Color){ 227, 227, 227, 255 }));
|
|
712
|
+ /* ...bottom separator */
|
|
713
|
+ DrawRectangle(body->xywh.x+body->leftsize,righty+dirdata->height-1,body->xywh.w-body->leftsize, 1, (Color){ 221, 221, 221, 255 } );
|
|
714
|
+ /* ...dirname */
|
|
715
|
+ DrawTextEx(fontbig->font
|
|
716
|
+ ,dirdata->dirname
|
|
717
|
+ ,(Vector2) {body->xywh.x+body->leftsize+fontbig->height/2,righty+fontbig->height/4}
|
|
718
|
+ ,fontbig->height
|
|
719
|
+ ,0
|
|
720
|
+ ,(Color){ 65, 65, 65, 255 }
|
|
721
|
+ );
|
|
722
|
+ }
|
697
|
723
|
/* directories */
|
698
|
|
- x0=body->xywh.x+font->height/2;
|
699
|
|
- x1=body->xywh.x+body->leftsize-font->height/2;
|
700
|
|
- y0=body->xywh.y+font->height/4+m2.y+font->height/2;
|
701
|
|
- y1=body->xywh.y+body->xywh.h-font->height/2;
|
|
724
|
+ if(is_leftside) {
|
|
725
|
+ x0=body->xywh.x+font->height/2;
|
|
726
|
+ x1=body->xywh.x+body->leftsize-font->height/2;
|
|
727
|
+ y0=body->xywh.y+font->height/4+m2.y+font->height/2;
|
|
728
|
+ y1=body->xywh.y+body->xywh.h-DEFAULTDIRDATATRIANGLEW-font->height/2;
|
|
729
|
+ } else {
|
|
730
|
+ x0=body->xywh.x+body->leftsize+font->height/2;
|
|
731
|
+ x1=body->xywh.x+body->xywh.w-font->height/2;
|
|
732
|
+ y0=righty+fontbig->height/2+m2.y+font->height/4;
|
|
733
|
+ y1=y0+margin*2+font->height-1;
|
|
734
|
+ }
|
702
|
735
|
margin=font->height/4;
|
703
|
736
|
for(k=0,x=x0,y=y0;k<dirdata->listing.usedelems;k++) {
|
704
|
|
- m2=MeasureTextEx(font->font,dirdata->listing.elems[k]+1,font->height,0);
|
705
|
|
- if((x+margin*2+m2.x)>x1)
|
|
737
|
+ elem=dirdata->listing.elems+k;
|
|
738
|
+ if(elem->name[0]!='d' || strcmp(elem->name,"d.")==0 || strcmp(elem->name,"d..")==0)
|
|
739
|
+ continue;
|
|
740
|
+ if(y>y1)
|
|
741
|
+ continue;
|
|
742
|
+ m2=MeasureTextEx(font->font,elem->name+1,font->height,0);
|
|
743
|
+ if((x+margin*2+m2.x)>x1) {
|
706
|
744
|
x=x0,y+=font->height+margin*2+font->height/4;
|
707
|
|
-#warning TODO: store the bounding box of the element
|
708
|
|
- DrawRectangleLines(x,y,margin*2+m2.x,margin*2+font->height,((Color){0,0,0,255}));
|
709
|
|
- DrawTextEx(font->font,dirdata->listing.elems[k]+1,(Vector2){x+margin,y+margin},font->height,0,(Color){ 65, 65, 65, 255 });
|
|
745
|
+ if(y>y1)
|
|
746
|
+ continue;
|
|
747
|
+ }
|
|
748
|
+ FILLXYWH(elem->leftxywh,x,y,margin*2+m2.x,margin*2+font->height);
|
|
749
|
+ DrawRectangleLines(UNROLLXYWH(elem->leftxywh),((Color){0,0,0,255}));
|
|
750
|
+ DrawTextEx(font->font,elem->name+1,(Vector2){x+margin,y+margin},font->height,0,(Color){ 65, 65, 65, 255 });
|
710
|
751
|
x+=margin*2+m2.x+font->height/4;
|
711
|
752
|
}
|
712
|
753
|
|
713
|
|
-#warning TODO
|
714
|
|
- /* draw right side "current" marker inside left side area */
|
715
|
|
- DrawTriangle((Vector2){((float)body->xywh.x)+body->leftsize,((float)righty)}, (Vector2){((float)body->xywh.x)+body->leftsize-DEFAULTDIRDATATRIANGLEW,((float)righty)+dirdata->height/2}, (Vector2){((float)body->xywh.x)+body->leftsize,((float)righty)+dirdata->height-1}, (Color){ 168, 168, 168, 255 } );
|
|
754
|
+#warning TODO SHOW FILES
|
|
755
|
+ /* ...finishing touchs */
|
|
756
|
+ if(is_leftside) {
|
|
757
|
+ /* draw right side "current" marker inside left side area */
|
|
758
|
+ DrawTriangle((Vector2){((float)body->xywh.x)+body->leftsize,((float)righty)}, (Vector2){((float)body->xywh.x)+body->leftsize-DEFAULTDIRDATATRIANGLEW,((float)righty)+dirdata->height/2}, (Vector2){((float)body->xywh.x)+body->leftsize,((float)righty)+dirdata->height-1}, (Color){ 168, 168, 168, 255 } );
|
|
759
|
+ } else {
|
|
760
|
+ /* advance to next element */
|
|
761
|
+ righty+=dirdata->height;
|
|
762
|
+ }
|
716
|
763
|
}
|
717
|
|
- /* draw right side */
|
718
|
|
- /* ...bg */
|
719
|
|
- DrawRectangle(body->xywh.x+body->leftsize,righty,body->xywh.w-body->leftsize, dirdata->height,(i==body->currentdirdata)?((Color){ 168, 168, 168, 255 }):((Color){ 227, 227, 227, 255 }));
|
720
|
|
- /* ...bottom separator */
|
721
|
|
- DrawRectangle(body->xywh.x+body->leftsize,righty+dirdata->height-1,body->xywh.w-body->leftsize, 1, (Color){ 221, 221, 221, 255 } );
|
722
|
|
- /* ...dirname */
|
723
|
|
- DrawTextEx(fontbig->font
|
724
|
|
- ,dirdata->dirname
|
725
|
|
- ,(Vector2) {body->xywh.x+body->leftsize+fontbig->height/2,righty+fontbig->height/4}
|
726
|
|
- ,fontbig->height
|
727
|
|
- ,0
|
728
|
|
- ,(Color){ 65, 65, 65, 255 }
|
729
|
|
- );
|
730
|
|
- /* advance to next element */
|
731
|
|
- righty+=dirdata->height;
|
732
|
764
|
}
|
733
|
765
|
#if 0
|
734
|
766
|
/* example from menubar */
|
...
|
...
|
@@ -942,7 +974,7 @@ getcodepoints(int *sizecodepoints)
|
942
|
974
|
static int
|
943
|
975
|
strptrcmp(void *a,void *b)
|
944
|
976
|
{
|
945
|
|
- return(strcmp(*((char **)a),*((char **)b)));
|
|
977
|
+ return(strcmp(((listingdata_t *)a)->name,((listingdata_t *)b)->name));
|
946
|
978
|
}
|
947
|
979
|
|
948
|
980
|
int
|
...
|
...
|
@@ -956,6 +988,7 @@ listing_get(listing_t *listing, char *pathprefix, char *parampath, int flag_sort
|
956
|
988
|
if(listing==NULL)
|
957
|
989
|
return(-1); /* sanity check failed */
|
958
|
990
|
listing->usedelems=listing->usedbuf=0;
|
|
991
|
+ memset(listing->elems,0,sizeof(listingdata_t)*listing->sizeelems);
|
959
|
992
|
if(pathprefix==NULL && parampath==NULL)
|
960
|
993
|
return(-1); /* nothing to fill */
|
961
|
994
|
snprintf(path,sizeof(path),"%s%s%s",(pathprefix!=NULL)?pathprefix:"",SEP,(parampath!=NULL)?parampath:"");
|
...
|
...
|
@@ -998,12 +1031,13 @@ listing_get(listing_t *listing, char *pathprefix, char *parampath, int flag_sort
|
998
|
1031
|
}
|
999
|
1032
|
/* check for space for this elem (and get space if necessary) */
|
1000
|
1033
|
if(listing->usedelems==listing->sizeelems) {
|
1001
|
|
- char **newelems;
|
1002
|
|
- if((newelems=realloc(listing->elems,sizeof(char *)*(listing->sizeelems+BLOCKLISTINGELEMS)))==NULL) {
|
|
1034
|
+ listingdata_t *newelems;
|
|
1035
|
+ if((newelems=realloc(listing->elems,sizeof(listingdata_t)*(listing->sizeelems+BLOCKLISTINGELEMS)))==NULL) {
|
1003
|
1036
|
closedir(d),d=NULL;
|
1004
|
1037
|
return(-1); /* insuf. mem. */
|
1005
|
1038
|
}
|
1006
|
1039
|
listing->elems=newelems;
|
|
1040
|
+ memset(listing->elems+listing->sizeelems,0,sizeof(listingdata_t)*BLOCKLISTINGELEMS);
|
1007
|
1041
|
listing->sizeelems+=BLOCKLISTINGELEMS;
|
1008
|
1042
|
}
|
1009
|
1043
|
/* check for space for this elem data (and get space if necessary) */
|
...
|
...
|
@@ -1021,21 +1055,21 @@ listing_get(listing_t *listing, char *pathprefix, char *parampath, int flag_sort
|
1021
|
1055
|
}
|
1022
|
1056
|
/* the elem data buffer has a new pointer, fix previous entries */
|
1023
|
1057
|
for(i=0;i<listing->usedelems;i++) {
|
1024
|
|
- off=(listing->elems[i])-listing->buf;
|
1025
|
|
- listing->elems[i]=newbuf+off;
|
|
1058
|
+ off=(listing->elems[i].name)-listing->buf;
|
|
1059
|
+ listing->elems[i].name=newbuf+off;
|
1026
|
1060
|
}
|
1027
|
1061
|
listing->buf=newbuf;
|
1028
|
1062
|
listing->sizebuf+=BLOCKLISTINGELEMS;
|
1029
|
1063
|
}
|
1030
|
1064
|
/* store the data */
|
1031
|
|
- listing->elems[listing->usedelems++]=listing->buf+listing->usedbuf;
|
|
1065
|
+ listing->elems[listing->usedelems++].name=listing->buf+listing->usedbuf;
|
1032
|
1066
|
listing->buf[listing->usedbuf++]=dtype;
|
1033
|
1067
|
memcpy(listing->buf+listing->usedbuf,de->d_name,l+1);
|
1034
|
1068
|
listing->usedbuf+=l+1;
|
1035
|
1069
|
}
|
1036
|
1070
|
closedir(d),d=NULL;
|
1037
|
1071
|
if(flag_sort)
|
1038
|
|
- qsort(listing->elems,listing->usedelems,sizeof(char *),(int (*)(const void *, const void *)) strptrcmp);
|
|
1072
|
+ qsort(listing->elems,listing->usedelems,sizeof(listingdata_t ),(int (*)(const void *, const void *)) strptrcmp);
|
1039
|
1073
|
return(0);
|
1040
|
1074
|
}
|
1041
|
1075
|
|