Browse code

Draw image placeholders

Dario Rodriguez authored on 25/02/2025 17:32:53
Showing 1 changed files
... ...
@@ -10,6 +10,8 @@
10 10
  *      20250216 Modularize menu handling.
11 11
  *      20250222 Able to list files.
12 12
  *      20250223 Draw pane titles and main dir list.
13
+ *      20250224 Draw right dir list and store elem positions.
14
+ *      20250225 Draw image placeholders
13 15
  *
14 16
  * Author: Dario Rodriguez dario@darionomono.com
15 17
  * (c) Dario Rodriguez 2025
... ...
@@ -35,6 +37,7 @@
35 37
 #define LEFTSIZE 720
36 38
 #define DEFAULTDIRDATAHEIGHT 150
37 39
 #define DEFAULTDIRDATATRIANGLEW 35
40
+#define LEFTIMAGESIDELEN 150
38 41
 
39 42
 #define FONTSIZE 18
40 43
 #define FONTBIGSIZE 32
... ...
@@ -680,6 +683,7 @@ im_body_draw(body_t *body, int windowwidth, int windowheight)
680 683
                 /* two passes for each dirdata, first leftside, then rightside */
681 684
                 for(is_leftside=1;is_leftside>=0;is_leftside--) {
682 685
                         int x0,y0,x1,y1;
686
+                        int sidelen;
683 687
                         if(is_leftside && !(i==body->currentdirdata))
684 688
                                 continue; /* this element is not in leftside */
685 689
                         if(is_leftside) {
... ...
@@ -727,9 +731,9 @@ DrawRectangle(UNROLLXYWH(body->backxywh),((Color){ 0,255,0,255 })); /* hit zone
727 731
                                 y0=body->xywh.y+font->height/4+m2.y+font->height/2;
728 732
                                 y1=body->xywh.y+body->xywh.h-DEFAULTDIRDATATRIANGLEW-font->height/2;
729 733
                         } else {
730
-                                x0=body->xywh.x+body->leftsize+font->height/2;
734
+                                x0=body->xywh.x+body->leftsize+fontbig->height/2;
731 735
                                 x1=body->xywh.x+body->xywh.w-font->height/2;
732
-                                y0=righty+fontbig->height/2+m2.y+font->height/4;
736
+                                y0=righty+fontbig->height/4+fontbig->height+font->height/4;
733 737
                                 y1=y0+margin*2+font->height-1;
734 738
                         }
735 739
                         margin=font->height/4;
... ...
@@ -741,17 +745,85 @@ DrawRectangle(UNROLLXYWH(body->backxywh),((Color){ 0,255,0,255 })); /* hit zone
741 745
                                         continue;
742 746
                                 m2=MeasureTextEx(font->font,elem->name+1,font->height,0);
743 747
                                 if((x+margin*2+m2.x)>x1) {
748
+                                        if(!is_leftside) {
749
+                                                DrawTextEx(fonthuge->font
750
+                                                  ,"..."
751
+                                                  ,(Vector2) {x+margin,y+(fontbig->height-fonthuge->height)}
752
+                                                  ,fonthuge->height
753
+                                                  ,0
754
+                                                  ,(Color){ 65, 65, 65, 255 }
755
+                                                );
756
+                                         }
744 757
                                         x=x0,y+=font->height+margin*2+font->height/4;
745 758
                                         if(y>y1)
746 759
                                                 continue;
747 760
                                 }
748
-                                FILLXYWH(elem->leftxywh,x,y,margin*2+m2.x,margin*2+font->height);
749
-                                DrawRectangleLines(UNROLLXYWH(elem->leftxywh),((Color){0,0,0,255}));
761
+                                if(is_leftside) {
762
+                                        FILLXYWH(elem->leftxywh,x,y,margin*2+m2.x,margin*2+font->height);
763
+                                        DrawRectangleLines(UNROLLXYWH(elem->leftxywh),((Color){0,0,0,255}));
764
+                                } else {
765
+                                        FILLXYWH(elem->xywh,x,y,margin*2+m2.x,margin*2+font->height);
766
+                                        DrawRectangleLines(UNROLLXYWH(elem->xywh),((Color){0,0,0,255}));
767
+                                }
750 768
                                 DrawTextEx(font->font,elem->name+1,(Vector2){x+margin,y+margin},font->height,0,(Color){ 65, 65, 65, 255 });
751 769
                                 x+=margin*2+m2.x+font->height/4;
752 770
                         }
753
-
754
-#warning TODO SHOW FILES
771
+                        /* files */
772
+                        if(is_leftside) {
773
+                                y0=(x==x0)?y:y+font->height+margin*2+font->height/4;
774
+                                sidelen=LEFTIMAGESIDELEN;
775
+                        } else {
776
+                                y0=righty; //y0+margin*2+font->height+font->height/2;
777
+                                y1=righty+dirdata->height-fontbig->height/4;
778
+                                sidelen=y1-y0-1;
779
+                        }
780
+                        for(k=0,x=x0,y=y0;k<dirdata->listing.usedelems;k++) {
781
+                                elem=dirdata->listing.elems+k;
782
+                                if(elem->name[0]!='f' && elem->name[0]!='l')
783
+                                        continue;
784
+                                if(y>y1)
785
+                                        continue;
786
+                                if((x+margin*2+sidelen)>x1) {
787
+                                        if(!is_leftside) {
788
+                                                DrawTextEx(fonthuge->font
789
+                                                  ,"..."
790
+                                                  ,(Vector2) {x+margin,y+(sidelen-fonthuge->height)}
791
+                                                  ,fonthuge->height
792
+                                                  ,0
793
+                                                  ,(Color){ 65, 65, 65, 255 }
794
+                                                );
795
+                                         }
796
+                                        x=x0,y+=sidelen+margin*2;
797
+                                        if(y>y1)
798
+                                                continue;
799
+                                }
800
+                                if(is_leftside) {
801
+                                        FILLXYWH(elem->leftxywh,x+margin,y+margin,sidelen,sidelen);
802
+                                        DrawRectangle(UNROLLXYWH(elem->leftxywh),((Color){0,0,0,64}));
803
+                                } else {
804
+                                        FILLXYWH(elem->xywh,x+margin,y+margin,sidelen,sidelen);
805
+                                        DrawRectangle(UNROLLXYWH(elem->xywh),((Color){0,0,0,64}));
806
+                                }
807
+                                {
808
+                                        char *ptr;
809
+                                        char shortname[1024];
810
+                                        xywh_t *pos;
811
+                                        int l;
812
+                                        pos=is_leftside?&(elem->leftxywh):&(elem->xywh);
813
+                                        if((ptr=strchr(elem->name+1,'.'))!=NULL) {
814
+                                                m2=MeasureTextEx(fonthuge->font,ptr,fonthuge->height,0);
815
+                                                DrawTextEx(fonthuge->font,ptr,(Vector2){x+margin+(sidelen-m2.x)/2,y+margin+(sidelen-fonthuge->height)/2},fonthuge->height,0,(Color){ 65, 65, 65, 255 });
816
+                                        }
817
+                                        ptr=(ptr==NULL)?elem->name+1:ptr;
818
+                                        l=(ptr-(elem->name+1));
819
+                                        l=(l>=sizeof(shortname))?sizeof(shortname)-1:l;
820
+                                        memcpy(shortname,elem->name+1,l);
821
+                                        shortname[l]='\0';
822
+                                        DrawRectangle(pos->x,pos->y,pos->w,font->height+font->height/2,((Color){0,0,0,64}));
823
+                                        DrawTextEx(font->font,shortname,(Vector2){pos->x+font->height/4,pos->y+font->height/4},font->height,0,(Color){ 255, 255, 255, 255 });
824
+                                }
825
+                                x+=margin*2+sidelen;
826
+                        }
755 827
                         /* ...finishing touchs */
756 828
                         if(is_leftside) {
757 829
                                 /* draw right side "current" marker inside left side area */