Browse code

Scrollable left pane

Dario Rodriguez authored on 05/03/2025 21:11:23
Showing 1 changed files
... ...
@@ -18,6 +18,7 @@
18 18
  *               Basic image loading.
19 19
  *               Show big image on hover.
20 20
  *               Preserve aspect ratio of big image.
21
+ *      20250305 Scrollable left pane.
21 22
  *
22 23
  * Author: Dario Rodriguez dario@darionomono.com
23 24
  * (c) Dario Rodriguez 2025
... ...
@@ -73,6 +74,10 @@
73 74
 #define UNROLLXYWH(xywh) (xywh).x,(xywh).y,(xywh).w,(xywh).h
74 75
 #endif
75 76
 
77
+#ifndef UNROLLWHXY
78
+#define UNROLLWHXY(xywh) (xywh).w,(xywh).h,(xywh).x,(xywh).y
79
+#endif
80
+
76 81
 #ifndef __linux__
77 82
 /* the old raylib used in the windows build lacks this function */
78 83
 bool IsImageValid(Image image)
... ...
@@ -121,8 +126,10 @@ typedef struct menubar_t {
121 126
 
122 127
 typedef struct thumb_t {
123 128
         xywh_t xywh;
129
+        xywh_t screenxywh;
124 130
         Texture2D texture;
125 131
         int has_texture;
132
+        int has_failedload;
126 133
 } thumb_t;
127 134
 
128 135
 typedef struct listingdata_t {
... ...
@@ -138,6 +145,8 @@ typedef struct listing_t {
138 145
         int sizebuf;
139 146
         int usedbuf;
140 147
         char *buf;
148
+        int has_leftxywh;
149
+        int has_rightxywh;
141 150
 } listing_t;
142 151
 
143 152
 typedef struct dirdata_t {
... ...
@@ -159,11 +168,12 @@ typedef struct body_t {
159 168
         font_t *ptrfont;
160 169
         font_t *ptrfontbig;
161 170
         font_t *ptrfonthuge;
162
-        char currenttexture[1024];
171
+        char currenttexture[2048];
163 172
         Texture2D texture;
164 173
         int texturew;
165 174
         int textureh;
166 175
         int has_texture;
176
+        int has_failedload;
167 177
 } body_t;
168 178
 
169 179
 typedef struct im_t {
... ...
@@ -190,7 +200,7 @@ void im_menubar_free(menubar_t *menubar);
190 200
 int im_menubar_mouse(menubar_t *menubar, Vector2 mousepos, int lmbpressed, int lmbreleased, int lmbdown, int *click_avail, char **sel_menu, char **sel_submenu);
191 201
 int im_menubar_draw(menubar_t *menubar, int windowwidth, int windowheight);
192 202
 
193
-body_t *im_body_init(int x, int y, font_t *font, font_t *fontbig, font_t *fonthuge, int leftsize, char *rootdir);
203
+body_t *im_body_init(int x, int y, font_t *font, font_t *fontbig, font_t *fonthuge, int leftsize, char *rootdir, int windowwidth, int windowheight);
194 204
 void im_body_free(body_t *body);
195 205
 
196 206
 int im_body_add(body_t *body,char *dir);
... ...
@@ -200,6 +210,7 @@ int im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int windowwidth, i
200 210
 
201 211
 int listing_get(listing_t *listing, char *pathprefix, char *path, int flag_sort);
202 212
 void listing_freedata(listing_t *listing);
213
+int listing_fillxywh(listing_t *listing, font_t *font, int w, int sidelen, int is_left);
203 214
 
204 215
 int imutil_menu_count(char *menus);
205 216
 char *imutil_menu_get(char *menus, int targetn, int *len);
... ...
@@ -310,7 +321,7 @@ im_init(char *menus, char *rootdir)
310 321
           || (im->fontbig=im_font_init(FONTBIGSIZE))==NULL
311 322
           || (im->fonthuge=im_font_init(FONTHUGESIZE))==NULL
312 323
           || (im->menubar=im_menubar_init(menus,im->font))==NULL
313
-          || (im->body=im_body_init(0,im->menubar->height, im->font, im->fontbig, im->fonthuge, LEFTSIZE, rootdir))==NULL
324
+          || (im->body=im_body_init(0,im->menubar->height, im->font, im->fontbig, im->fonthuge, LEFTSIZE, rootdir,im->w,im->h))==NULL
314 325
         ) {
315 326
                 im_free(im),im=NULL;
316 327
                 return(NULL); /* insuf. mem. */
... ...
@@ -609,7 +620,7 @@ im_menubar_draw(menubar_t *menubar, int windowwidth, int windowheight)
609 620
 }
610 621
 
611 622
 body_t *
612
-im_body_init(int x, int y, font_t *font, font_t *fontbig, font_t *fonthuge, int leftsize, char *rootdir)
623
+im_body_init(int x, int y, font_t *font, font_t *fontbig, font_t *fonthuge, int leftsize, char *rootdir, int windowwidth, int windowheight)
613 624
 {
614 625
         body_t *body;
615 626
         static char sep[]={SEP};
... ...
@@ -621,7 +632,7 @@ im_body_init(int x, int y, font_t *font, font_t *fontbig, font_t *fonthuge, int
621 632
                 im_body_free(body),body=NULL;
622 633
                 return(NULL);
623 634
         }
624
-        FILLXY(body->xywh,x,y);
635
+        FILLXYWH(body->xywh,x,y,windowwidth-x,windowheight-y);
625 636
         body->leftsize=leftsize;
626 637
         body->ptrfont=font;
627 638
         body->ptrfontbig=fontbig;
... ...
@@ -653,7 +664,9 @@ im_body_free(body_t *body)
653 664
         }
654 665
         if(body->has_texture) {
655 666
                 UnloadTexture(body->texture);
667
+                body->currenttexture[0]='\0';
656 668
                 body->has_texture=0;
669
+                body->has_failedload=0;
657 670
         }
658 671
         free(body),body=NULL;
659 672
         return;
... ...
@@ -753,59 +766,89 @@ im_body_mouse(body_t *body, Vector2 mousepos, int lmbpressed, int lmbreleased, i
753 766
 int
754 767
 im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int windowwidth, int windowheight)
755 768
 {
756
-        int i,x,y,k,margin,righty;
769
+        int i,k,margin,righty;
770
+        int lastx,lasty;
757 771
         dirdata_t *dirdata;
758 772
         listingdata_t *elem;
759 773
         Vector2 v2,m2;
760 774
         font_t *font,*fontbig,*fonthuge;
761 775
         int is_leftside;
762 776
         int flag_skiprightside;
777
+        int xoff,yoff;
778
+        thumb_t *thumb;
763 779
         if(body==NULL)
764 780
                 return(-1);
781
+#if 1
782
+#warning TESTING LEFTSCROLL
783
+body->leftscrollpos=(int) mousepos.y;
784
+{
785
+ static int lastlsp=-1;
786
+ if(body->leftscrollpos!=lastlsp) {
787
+  lastlsp=body->leftscrollpos;
788
+  fprintf(stderr,"leftscrollpos:%i\n",body->leftscrollpos);
789
+ }
790
+}
791
+#endif
765 792
         font=body->ptrfont;
766 793
         fontbig=body->ptrfontbig;
767 794
         fonthuge=body->ptrfonthuge;
768
-        FILLWH(body->xywh,windowwidth-body->xywh.x,windowheight-body->xywh.y);
769 795
         FILLXYWH(body->backxywh,0,0,0,0);
796
+        margin=font->height/4;
797
+        /* calculate positions */
798
+        for(i=0;i<body->sizedirdata;i++) {
799
+                if(body->dirdata[i]==NULL)
800
+                        continue;
801
+                if(body->dirdata[i]->listing.has_rightxywh==0) {
802
+                        int sidelen;
803
+                        sidelen=body->dirdata[i]->height-(fontbig->height+fontbig->height/4+font->height+margin*4+fontbig->height/4);
804
+                        listing_fillxywh(&(body->dirdata[i]->listing),body->ptrfont,body->xywh.w-(body->xywh.x+body->leftsize),sidelen,0);
805
+                        body->dirdata[i]->listing.has_rightxywh=1;
806
+                }
807
+                if(i==body->currentdirdata && body->dirdata[i]->listing.has_leftxywh==0) {
808
+                        listing_fillxywh(&(body->dirdata[i]->listing),body->ptrfont,body->leftsize,LEFTIMAGESIDELEN,1);
809
+                        body->dirdata[i]->listing.has_leftxywh=1;
810
+                }
811
+        }
770 812
         /* draw left side background */
771 813
         DrawRectangle(body->xywh.x,body->xywh.y,body->leftsize, body->xywh.h, (Color){ 215, 215, 215, 255 } );
772 814
         /* draw right side background */
773 815
         DrawRectangle(body->xywh.x+body->leftsize,body->xywh.y,body->xywh.w-body->leftsize, body->xywh.h, (Color){ 227, 227, 227, 255 } );
774 816
         /* first pass, draw leftside, second pass, draw all of rightside */
775 817
         for(is_leftside=1,flag_skiprightside=0;is_leftside>=0 && flag_skiprightside==0;is_leftside--) {
776
-                for(i=(is_leftside)?body->currentdirdata:0,y=righty=body->xywh.y;(is_leftside && i==body->currentdirdata) || (!is_leftside && i<body->sizedirdata);i++) {
777
-                        int x0,y0,x1,y1;
818
+                for(i=(is_leftside)?body->currentdirdata:0,righty=body->xywh.y;(is_leftside && i==body->currentdirdata) || (!is_leftside && i<body->sizedirdata);i++) {
778 819
                         int sidelen;
779 820
                         if((dirdata=body->dirdata[i])==NULL)
780 821
                                 continue;
781 822
                         if(is_leftside && !(i==body->currentdirdata))
782 823
                                 continue; /* this element is not in leftside */
783
-                        margin=font->height/4;
784 824
                         sidelen=(is_leftside)?LEFTIMAGESIDELEN:dirdata->height-(fontbig->height+fontbig->height/4+font->height+margin*4+fontbig->height/4);
785 825
                         /* draw left side back arrow if is_leftside and not in root dir */
786 826
                         if(is_leftside && !(dirdata->dirname[0]=='\0' || strcmp(dirdata->dirname,SEP)==0)) {
787 827
                                 m2=MeasureTextEx(fontbig->font,UTF8DOWNARROW,fontbig->height,0);
788 828
                                 v2.x=(float) (body->xywh.x+fontbig->height/2);
789
-                                v2.y=(float) (body->xywh.y+fontbig->height/4+(fontbig->height-v2.x)/2);
829
+                                v2.y=(float) (body->xywh.y+fontbig->height/4+(fontbig->height-v2.x)/2)-body->leftscrollpos;
790 830
                                 FILLXYWH(body->backxywh,v2.x-fontbig->height/4,v2.y-fontbig->height/8,m2.x+fontbig->height/4,m2.x+fontbig->height/4);
791 831
 #if 0
792 832
 DrawTexture(fontbig->font.texture, 0, 0, WHITE); /* font glyphs -- see https://github.com/raysan5/raylib/issues/2022 */
793 833
 DrawRectangle(UNROLLXYWH(body->backxywh),((Color){ 0,255,0,255 })); /* hit zone */
794 834
 #endif
795
-                                DrawTextPro(fontbig->font,UTF8DOWNARROW,(Vector2){v2.x+m2.x,v2.y},(Vector2){0,0},90.0,fontbig->height,0,(Color){65,65,65,255});
835
+                                if((v2.y+fontbig->height)>=0)
836
+                                        DrawTextPro(fontbig->font,UTF8DOWNARROW,(Vector2){v2.x+m2.x,v2.y},(Vector2){0,0},90.0,fontbig->height,0,(Color){65,65,65,255});
796 837
                         }
797 838
                         if(is_leftside) {
798 839
                                 /* ...dirname */
799
-                                m2=MeasureTextEx(fontbig->font,dirdata->dirname,fontbig->height,0);
800
-                                v2.x=(float) (body->xywh.x+fontbig->height/2)+(body->leftsize-(body->xywh.x+fontbig->height)-m2.x)/2;
801
-                                v2.y=(float) (body->xywh.y+fontbig->height/4);
802
-                                DrawTextEx(fontbig->font
803
-                                  ,dirdata->dirname
804
-                                  ,v2
805
-                                  ,fontbig->height
806
-                                  ,0
807
-                                  ,(Color){ 65, 65, 65, 255 }
808
-                                );
840
+                                v2.y=(float) (body->xywh.y+fontbig->height/4-body->leftscrollpos);
841
+                                if((v2.y+fontbig->height)>=0) {
842
+                                        m2=MeasureTextEx(fontbig->font,dirdata->dirname,fontbig->height,0);
843
+                                        v2.x=(float) (body->xywh.x+fontbig->height/2)+(body->leftsize-(body->xywh.x+fontbig->height)-m2.x)/2;
844
+                                        DrawTextEx(fontbig->font
845
+                                          ,dirdata->dirname
846
+                                          ,v2
847
+                                          ,fontbig->height
848
+                                          ,0
849
+                                          ,(Color){ 65, 65, 65, 255 }
850
+                                        );
851
+                                }
809 852
                         } else { /* rightside */
810 853
                                 /* ...bg */
811 854
                                 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 }));
... ...
@@ -821,166 +864,160 @@ DrawRectangle(UNROLLXYWH(body->backxywh),((Color){ 0,255,0,255 })); /* hit zone
821 864
                                 );
822 865
                         }
823 866
                         /* directories */
824
-                        if(is_leftside) {
825
-                                x0=body->xywh.x+font->height/2;
826
-                                x1=body->xywh.x+body->leftsize-DEFAULTDIRDATATRIANGLEW-font->height/2;
827
-                                y0=body->xywh.y+font->height/4+m2.y+font->height/2;
828
-                                y1=body->xywh.y+body->xywh.h-DEFAULTDIRDATATRIANGLEW-font->height/2;
829
-                        } else {
830
-                                x0=body->xywh.x+body->leftsize+fontbig->height/2;
831
-                                x1=body->xywh.x+body->xywh.w-font->height/2;
832
-                                y0=righty+fontbig->height/4+fontbig->height+margin;
833
-                                y1=y0+margin*2+font->height-1;
834
-                        }
835
-                        for(k=0,x=x0,y=y0;k<dirdata->listing.usedelems;k++) {
836
-                                Color c=(is_leftside)?((Color){ 65, 65, 65, 255 }):((Color){ 240, 240, 240, 255 });
867
+                        xoff=((is_leftside)?0:body->leftsize);
868
+                        yoff=((is_leftside)?body->xywh.y:righty)+fontbig->height/4+fontbig->height+font->height/4-(is_leftside?body->leftscrollpos:0);
869
+                        if(is_leftside && dirdata->dirname[0]=='\0')
870
+                                yoff-=fontbig->height/4+fontbig->height;
871
+                        for(k=0,lastx=lasty=0;k<dirdata->listing.usedelems;k++) {
837 872
                                 elem=dirdata->listing.elems+k;
838
-                                if(elem->name[0]!='d' || strcmp(elem->name,"d.")==0 || strcmp(elem->name,"d..")==0)
839
-                                        continue;
840
-                                if(y>y1)
873
+                                thumb=(is_leftside)?&(elem->left):&(elem->right);
874
+                                if(elem->name[0]!='d' || strcmp(elem->name,"d.")==0 || strcmp(elem->name,"d..")==0) {
875
+                                        if(elem->name[0]=='d')
876
+                                                FILLXYWH(thumb->screenxywh,0,0,0,0);
841 877
                                         continue;
842
-                                m2=MeasureTextEx(font->font,elem->name+1,font->height,0);
843
-                                if((x+margin*2+m2.x)>x1) {
844
-                                        if(!is_leftside) {
845
-                                                DrawTextEx(fonthuge->font
846
-                                                  ,"..."
847
-                                                  ,(Vector2) {x+margin,y+(fontbig->height-fonthuge->height)}
848
-                                                  ,fonthuge->height
849
-                                                  ,0
850
-                                                  ,c
851
-                                                );
852
-                                         }
853
-                                        x=x0,y+=font->height+margin*2+font->height/4;
854
-                                        if(y>y1)
855
-                                                continue;
856 878
                                 }
857
-                                if(is_leftside) {
858
-                                        FILLXYWH(elem->left.xywh,x,y,margin*2+m2.x,margin*2+font->height);
859
-                                        DrawRectangleLines(UNROLLXYWH(elem->left.xywh),c);
860
-                                } else {
861
-                                        FILLXYWH(elem->right.xywh,x,y,margin*2+m2.x,margin*2+font->height);
862
-                                        DrawRectangleLines(UNROLLXYWH(elem->right.xywh),c);
879
+                                if((thumb->xywh.y+yoff)>(body->xywh.y+body->xywh.h) || thumb->xywh.w==0 || thumb->xywh.h==0) {
880
+#warning TODO: if !is_leftside, draw "..." in huge font using lastx,lasty as reference
881
+                                        break;
882
+                                }
883
+                                if((thumb->xywh.y+yoff+thumb->xywh.h)<0) {
884
+                                        FILLXYWH(thumb->screenxywh,0,0,0,0);
885
+                                        continue;
863 886
                                 }
864
-                                DrawTextEx(font->font,elem->name+1,(Vector2){x+margin,y+margin},font->height,0,c);
865
-                                x+=margin*2+m2.x+font->height/4;
887
+                                FILLXYWH(thumb->screenxywh,thumb->xywh.x+xoff,thumb->xywh.y+yoff,thumb->xywh.w,thumb->xywh.h);
888
+                                DrawRectangleLines(UNROLLXYWH(thumb->screenxywh),((Color){ 65, 65, 65, 255 }));
889
+                                DrawTextEx(font->font,elem->name+1,(Vector2){thumb->screenxywh.x+margin,thumb->screenxywh.y+margin},font->height,0,((Color){ 65, 65, 65, 255 }));
890
+                                lastx=thumb->screenxywh.x+thumb->screenxywh.w,lasty=thumb->screenxywh.y+thumb->screenxywh.h;
866 891
                         }
867
-                        /* files */
868
-                        if(is_leftside) {
869
-                                y0=(x==x0)?y:y+font->height+margin*2+font->height/4;
870
-                                sidelen=LEFTIMAGESIDELEN;
871
-                        } else {
872
-                                y0=righty+dirdata->height-sidelen-margin-fontbig->height/4;
873
-                                y1=y0+sidelen+margin;
874
-                                x0-=margin;
892
+                        for(;k<dirdata->listing.usedelems;k++) {
893
+                                elem=dirdata->listing.elems+k;
894
+                                if(elem->name[0]!='d')
895
+                                        continue;
896
+                                thumb=(is_leftside)?&(elem->left):&(elem->right);
897
+                                FILLXYWH(thumb->screenxywh,0,0,0,0);
875 898
                         }
876
-                        for(k=0,x=x0,y=y0;k<dirdata->listing.usedelems;k++) {
899
+                        /* files */
900
+                        for(k=0,lastx=lasty=0;k<dirdata->listing.usedelems;k++) {
901
+                                Texture2D *te;
902
+                                xywh_t *xywh;
877 903
                                 elem=dirdata->listing.elems+k;
904
+                                thumb=(is_leftside)?&(elem->left):&(elem->right);
905
+                                xywh=&(thumb->xywh);
906
+                                te=&(thumb->texture);
907
+                                int has_imagedrawn;
878 908
                                 if(elem->name[0]!='f' && elem->name[0]!='l')
879 909
                                         continue;
880
-                                if(y>y1)
881
-                                        continue;
882
-                                if((x+margin*2+sidelen)>x1) {
883
-                                        if(!is_leftside) {
884
-                                                DrawTextEx(fonthuge->font
885
-                                                  ,"..."
886
-                                                  ,(Vector2) {x+margin,y+(sidelen-fonthuge->height)}
887
-                                                  ,fonthuge->height
888
-                                                  ,0
889
-                                                  ,(Color){ 0,0,0,64 }
890
-                                                );
891
-                                         }
892
-                                        x=x0,y+=sidelen+margin*2;
893
-                                        if(y>y1)
894
-                                                continue;
910
+                                if((xywh->y+yoff)>(body->xywh.y+body->xywh.h) || xywh->w==0 || xywh->h==0) {
911
+#warning TODO: if !is_leftside, draw "..." in huge font using lastx,lasty as reference
912
+                                        break;
895 913
                                 }
896
-                                if(is_leftside) {
897
-                                        FILLXYWH(elem->left.xywh,x+margin,y+margin,sidelen,sidelen);
898
-                                        DrawRectangle(UNROLLXYWH(elem->left.xywh),((Color){0,0,0,64}));
899
-                                } else {
900
-                                        FILLXYWH(elem->right.xywh,x+margin,y+margin,sidelen,sidelen);
901
-                                        DrawRectangle(UNROLLXYWH(elem->right.xywh),((Color){0,0,0,64}));
914
+                                /* show image */
915
+                                has_imagedrawn=0;
916
+#if 1
917
+                                if(is_imagefilename(elem->name+1)) {
918
+                                        if(thumb->has_texture==0) {
919
+                                                Image im;
920
+                                                char fullpath[2048];
921
+                                                snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
922
+                                                fullpath[sizeof(fullpath)-1]='\0';
923
+                                                im=LoadImage(fullpath);
924
+                                                if(IsImageValid(im)) {
925
+#if 1
926
+fprintf(stderr,"Loaded %s\n",fullpath);
927
+#endif
928
+                                                        ImageResize(&im,sidelen,sidelen);
929
+                                                        *te=LoadTextureFromImage(im);
930
+                                                        UnloadImage(im);
931
+                                                        thumb->has_texture=1;
932
+                                                }
933
+                                        }
934
+                                        if(thumb->has_texture!=0) {
935
+                                                FILLXYWH(thumb->screenxywh,xywh->x+xoff,xywh->y+yoff,xywh->w,xywh->h);
936
+                                                DrawTexture(*te,thumb->screenxywh.x,thumb->screenxywh.y,WHITE);
937
+                                                has_imagedrawn=1;
938
+                                                lastx=xywh->x+xywh->w,lasty=xywh->y+xywh->h+yoff;
939
+                                                if(is_leftside && lmbdown==0 && is_imutil_insidexywh(mousepos,&(thumb->screenxywh))) {
940
+                                                        /* draw image in rightside */
941
+                                                        char path[2048];
942
+                                                        int maxw,maxh;
943
+                                                        snprintf(path,sizeof(path),"%s/%s",dirdata->dirname,elem->name+1);
944
+                                                        path[sizeof(path)-1]='\0';
945
+                                                        maxw=windowwidth-(body->leftsize-DEFAULTDIRDATATRIANGLEW);
946
+                                                        maxh=windowheight-body->xywh.y;
947
+                                                        if((body->has_texture==0 && !(body->has_failedload && strcmp(body->currenttexture,path)==0))
948
+                                                          || strcmp(body->currenttexture,path)!=0
949
+                                                        ) {
950
+                                                                Image im;
951
+                                                                int neww,newh;
952
+                                                                char fullpath[2048];
953
+                                                                if(body->has_texture) {
954
+                                                                        UnloadTexture(body->texture);
955
+                                                                        body->currenttexture[0]='\0';
956
+                                                                        body->has_texture=0;
957
+                                                                        body->has_failedload=0;
958
+                                                                }
959
+                                                                snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
960
+                                                                fullpath[sizeof(fullpath)-1]='\0';
961
+                                                                im=LoadImage(fullpath);
962
+                                                                if(IsImageValid(im)) {
963
+                                                                        im_util_aspectmaximize(im.width,im.height,maxw,maxh,&neww,&newh);
964
+                                                                        ImageResize(&im,neww,newh);
965
+                                                                        body->texture=LoadTextureFromImage(im);
966
+                                                                        UnloadImage(im);
967
+                                                                        strncpy(body->currenttexture,fullpath,sizeof(body->currenttexture));
968
+                                                                        body->currenttexture[sizeof(body->currenttexture)-1]='\0';
969
+                                                                        body->has_texture=1;
970
+                                                                        body->has_failedload=0;
971
+                                                                        body->texturew=neww;
972
+                                                                        body->textureh=newh;
973
+                                                                } else {
974
+                                                                        strncpy(body->currenttexture,fullpath,sizeof(body->currenttexture));
975
+                                                                        body->currenttexture[sizeof(body->currenttexture)-1]='\0';
976
+                                                                        body->has_texture=0;
977
+                                                                        body->has_failedload=1;
978
+                                                                }
979
+                                                        }
980
+                                                        if(body->has_texture) {
981
+                                                                int x0,y0;
982
+                                                                x0=body->leftsize-DEFAULTDIRDATATRIANGLEW;
983
+                                                                y0=body->xywh.y;
984
+                                                                DrawRectangle(x0,y0,maxw,maxh,(Color){ 215, 215, 215, 255 } );
985
+                                                                DrawTexture(body->texture,x0+(maxw-body->texturew)/2,y0+(maxh-body->textureh)/2,WHITE);
986
+                                                                flag_skiprightside=1;
987
+                                                        }
988
+                                                }
989
+                                        }
902 990
                                 }
903
-                                {
991
+#endif
992
+                                if(has_imagedrawn==0) {
904 993
                                         char *ptr;
905 994
                                         char shortname[1024];
906 995
                                         xywh_t *pos;
907 996
                                         int l;
908
-                                        Texture2D *te;
909
-                                        int *has_texture;
910 997
                                         font_t *myfont=(is_leftside)?fonthuge:font;
911 998
                                         pos=is_leftside?&(elem->left.xywh):&(elem->right.xywh);
912
-                                        te=is_leftside?&(elem->left.texture):&(elem->right.texture);
913
-                                        has_texture=is_leftside?&(elem->left.has_texture):&(elem->right.has_texture);
999
+                                        FILLXYWH(thumb->screenxywh,xywh->x+xoff,xywh->y+yoff,xywh->w,xywh->h);
1000
+                                        DrawRectangle(UNROLLXYWH(thumb->screenxywh),((Color){0,0,0,64}));
914 1001
                                         if((ptr=strchr(elem->name+1,'.'))!=NULL) {
915 1002
                                                 m2=MeasureTextEx(myfont->font,ptr,myfont->height,0);
916
-                                                DrawTextEx(myfont->font,ptr,(Vector2){x+margin+(sidelen-m2.x)/2,y+(font->height)/2+margin+(sidelen-myfont->height)/2},myfont->height,0,(Color){ 0,0,0,96 });
1003
+                                                DrawTextEx(myfont->font,ptr,(Vector2){xywh->x+xoff+(sidelen-m2.x)/2,xywh->y+yoff+(font->height)/2+(xywh->w-myfont->height)/2},myfont->height,0,(Color){ 0,0,0,96 });
917 1004
                                         }
918 1005
                                         ptr=(ptr==NULL)?elem->name+1:ptr;
919 1006
                                         l=(ptr-(elem->name+1));
920 1007
                                         l=(l>=sizeof(shortname))?sizeof(shortname)-1:l;
921 1008
                                         memcpy(shortname,elem->name+1,l);
922 1009
                                         shortname[l]='\0';
923
-                                        DrawRectangle(pos->x,pos->y,pos->w,font->height+font->height/2,((Color){0,0,0,64}));
924
-                                        DrawTextEx(font->font,shortname,(Vector2){pos->x+font->height/4,pos->y+font->height/4},font->height,0,(Color){ 192,192,192,255 });
925
-                                        /* show image */
926
-                                        if(is_imagefilename(elem->name+1)) {
927
-                                                if(*has_texture==0) {
928
-                                                        Image im;
929
-                                                        char fullpath[2048];
930
-                                                        snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
931
-                                                        fullpath[sizeof(fullpath)-1]='\0';
932
-                                                        im=LoadImage(fullpath);
933
-                                                        if(IsImageValid(im)) {
934
-                                                                ImageResize(&im,sidelen,sidelen);
935
-                                                                *te=LoadTextureFromImage(im);
936
-                                                                UnloadImage(im);
937
-                                                                *has_texture=1;
938
-                                                        }
939
-                                                }
940
-                                                if(*has_texture!=0) {
941
-                                                        DrawTexture(*te,pos->x,pos->y,WHITE);
942
-                                                        if(is_leftside && lmbdown==0 && is_imutil_insidexywh(mousepos,pos)) {
943
-                                                                /* draw image in rightside */
944
-                                                                char path[2048];
945
-                                                                int maxw,maxh;
946
-                                                                snprintf(path,sizeof(path),"%s/%s",dirdata->dirname,elem->name+1);
947
-                                                                path[sizeof(path)-1]='\0';
948
-                                                                maxw=windowwidth-(body->leftsize-DEFAULTDIRDATATRIANGLEW);
949
-                                                                maxh=windowheight-body->xywh.y;
950
-                                                                if(body->has_texture==0 || strcmp(body->currenttexture,path)!=0) {
951
-                                                                        Image im;
952
-                                                                        int neww,newh;
953
-                                                                        char fullpath[2048];
954
-                                                                        if(body->has_texture) {
955
-                                                                                UnloadTexture(body->texture);
956
-                                                                                body->has_texture=0;
957
-                                                                        }
958
-                                                                        snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
959
-                                                                        fullpath[sizeof(fullpath)-1]='\0';
960
-                                                                        im=LoadImage(fullpath);
961
-                                                                        if(IsImageValid(im)) {
962
-                                                                                im_util_aspectmaximize(im.width,im.height,maxw,maxh,&neww,&newh);
963
-                                                                                ImageResize(&im,neww,newh);
964
-                                                                                body->texture=LoadTextureFromImage(im);
965
-                                                                                UnloadImage(im);
966
-                                                                                body->has_texture=1;
967
-                                                                                body->texturew=neww;
968
-                                                                                body->textureh=newh;
969
-                                                                        }
970
-                                                                }
971
-                                                                if(body->has_texture) {
972
-                                                                        int x0,y0;
973
-                                                                        x0=body->leftsize-DEFAULTDIRDATATRIANGLEW;
974
-                                                                        y0=body->xywh.y;
975
-                                                                        DrawRectangle(x0,y0,maxw,maxh,(Color){ 215, 215, 215, 255 } );
976
-                                                                        DrawTexture(body->texture,x0+(maxw-body->texturew)/2,y0+(maxh-body->textureh)/2,WHITE);
977
-                                                                        flag_skiprightside=1;
978
-                                                                }
979
-                                                        }
980
-                                                }
981
-                                        }
1010
+                                        DrawRectangle(pos->x+xoff,pos->y+yoff,pos->w,font->height+font->height/2,((Color){0,0,0,64}));
1011
+                                        DrawTextEx(font->font,shortname,(Vector2){pos->x+xoff+font->height/4,pos->y+yoff+font->height/4},font->height,0,(Color){ 192,192,192,255 });
1012
+                                        lastx=xywh->x+xoff+xywh->w,lasty=xywh->y+yoff+xywh->h;
982 1013
                                 }
983
-                                x+=margin*2+sidelen;
1014
+                        }
1015
+                        for(;k<dirdata->listing.usedelems;k++) {
1016
+                                elem=dirdata->listing.elems+k;
1017
+                                if(elem->name[0]!='f' && elem->name[0]!='l')
1018
+                                        continue;
1019
+                                thumb=(is_leftside)?&(elem->left):&(elem->right);
1020
+                                FILLXYWH(thumb->screenxywh,0,0,0,0);
984 1021
                         }
985 1022
                         /* ...finishing touchs */
986 1023
                         if(is_leftside) {
... ...
@@ -1182,15 +1219,18 @@ listing_get(listing_t *listing, char *pathprefix, char *parampath, int flag_sort
1182 1219
                 if(ld->left.has_texture) {
1183 1220
                         UnloadTexture(ld->left.texture);
1184 1221
                         ld->left.has_texture=0;
1222
+                        ld->left.has_failedload=0;
1185 1223
                 }
1186 1224
                 if(ld->right.has_texture) {
1187 1225
                         UnloadTexture(ld->right.texture);
1188 1226
                         ld->right.has_texture=0;
1227
+                        ld->right.has_failedload=0;
1189 1228
                 }
1190 1229
         }
1191 1230
         /* reset struct */
1192 1231
         listing->usedelems=listing->usedbuf=0;
1193 1232
         memset(listing->elems,0,sizeof(listingdata_t)*listing->sizeelems);
1233
+        listing->has_leftxywh=listing->has_rightxywh=0;
1194 1234
         /* fill listing */
1195 1235
         if(pathprefix==NULL && parampath==NULL)
1196 1236
                 return(-1); /* nothing to fill */
... ...
@@ -1289,10 +1329,12 @@ listing_freedata(listing_t *listing)
1289 1329
                         if(ld->left.has_texture) {
1290 1330
                                 UnloadTexture(ld->left.texture);
1291 1331
                                 ld->left.has_texture=0;
1332
+                                ld->left.has_failedload=0;
1292 1333
                         }
1293 1334
                         if(ld->right.has_texture) {
1294 1335
                                 UnloadTexture(ld->right.texture);
1295 1336
                                 ld->right.has_texture=0;
1337
+                                ld->right.has_failedload=0;
1296 1338
                         }
1297 1339
                 }
1298 1340
                 free(listing->elems),listing->elems=NULL,listing->sizeelems=listing->usedelems=0;
... ...
@@ -1302,6 +1344,70 @@ listing_freedata(listing_t *listing)
1302 1344
         return;
1303 1345
 }
1304 1346
 
1347
+int
1348
+listing_fillxywh(listing_t *listing, font_t *font, int w, int sidelen, int is_leftside)
1349
+{
1350
+        int x0,y0,x1;
1351
+        int k,x,y;
1352
+        Vector2 m2;
1353
+        int margin;
1354
+        listingdata_t *elem;
1355
+        thumb_t *thumb;
1356
+        if(listing==NULL || font==NULL)
1357
+                return(-1); /* sanity check failed */
1358
+        margin=font->height/4;
1359
+        /* directories */
1360
+        if(is_leftside) {
1361
+                x0=font->height/2;
1362
+                x1=w-DEFAULTDIRDATATRIANGLEW-font->height/2;
1363
+                y0=0;
1364
+        } else {
1365
+                x0=FONTBIGSIZE/2;
1366
+                x1=w-font->height/2;
1367
+                y0=0;
1368
+        }
1369
+        for(k=0,x=x0,y=y0;k<listing->usedelems;k++) {
1370
+                elem=listing->elems+k;
1371
+                thumb=(is_leftside)?&(elem->left):&(elem->right);
1372
+                if(elem->name[0]!='d' || strcmp(elem->name,"d.")==0 || strcmp(elem->name,"d..")==0)
1373
+                        continue;
1374
+                m2=MeasureTextEx(font->font,elem->name+1,font->height,0);
1375
+                if((x+margin*2+m2.x)>x1 && !(is_leftside==0 && y>y0))
1376
+                        x=x0,y+=font->height+margin*2+font->height/4;
1377
+                if(is_leftside==0 && y>y0) {
1378
+                        FILLXYWH(thumb->xywh,0,0,0,0);
1379
+                        continue;
1380
+                }
1381
+                FILLXYWH(thumb->xywh,x,y,margin*2+m2.x,margin*2+font->height);
1382
+                x+=margin*2+m2.x+font->height/4;
1383
+        }
1384
+        y+=((x==x0)?0:font->height+margin*2+font->height/4);
1385
+        /* files */
1386
+        if(is_leftside)
1387
+                y0=y;
1388
+        else
1389
+                y0+=margin*2+font->height+margin;
1390
+        for(k=0,x=x0,y=y0;k<listing->usedelems;k++) {
1391
+                elem=listing->elems+k;
1392
+                thumb=(is_leftside)?&(elem->left):&(elem->right);
1393
+                if(elem->name[0]!='f' && elem->name[0]!='l')
1394
+                        continue;
1395
+                if(!is_leftside && y>y0) {
1396
+                        FILLXYWH(thumb->xywh,0,0,0,0);
1397
+                        continue;
1398
+                }
1399
+                if((x+margin*2+sidelen)>x1 && !(is_leftside==0 && y>y0))
1400
+                        x=x0,y+=sidelen+margin*2;
1401
+                if(is_leftside==0 && y>y0) {
1402
+                        FILLXYWH(thumb->xywh,0,0,0,0);
1403
+                        continue;
1404
+                }
1405
+                FILLXYWH(thumb->xywh,x,y,sidelen,sidelen);
1406
+                x+=margin*2+sidelen;
1407
+        }
1408
+        return(0);
1409
+}
1410
+
1305 1411
 int
1306 1412
 is_imagefilename(char *filename)
1307 1413
 {