Browse code

Add show using all window with right button

Dario Rodriguez authored on 11/03/2025 20:08:02
Showing 1 changed files
... ...
@@ -22,6 +22,8 @@
22 22
  *      20250308 Show statustooltip on image hover.
23 23
  *               Scrollwheel support for leftside.
24 24
  *               Fix thumb aspect ratio.
25
+ *      20250311 Fix bug because of stray CloseWindow() call.
26
+ *               Add show using all window with right button.
25 27
  *
26 28
  * Author: Dario Rodriguez dario@darionomono.com
27 29
  * (c) Dario Rodriguez 2025
... ...
@@ -161,6 +163,15 @@ typedef struct dirdata_t {
161 163
         listing_t listing;
162 164
 } dirdata_t;
163 165
 
166
+typedef struct texture_t {
167
+        char currentpath[2048];
168
+        Texture2D texture;
169
+        int texturew;
170
+        int textureh;
171
+        int has_texture;
172
+        int has_failedload;
173
+} texture_t;
174
+
164 175
 typedef struct body_t {
165 176
         char *rootdir;
166 177
         xywh_t xywh;
... ...
@@ -174,12 +185,8 @@ typedef struct body_t {
174 185
         font_t *ptrfont;
175 186
         font_t *ptrfontbig;
176 187
         font_t *ptrfonthuge;
177
-        char currenttexture[2048];
178
-        Texture2D texture;
179
-        int texturew;
180
-        int textureh;
181
-        int has_texture;
182
-        int has_failedload;
188
+        texture_t texture;
189
+        texture_t bigtexture;
183 190
 } body_t;
184 191
 
185 192
 typedef struct im_t {
... ...
@@ -212,12 +219,16 @@ void im_body_free(body_t *body);
212 219
 int im_body_add(body_t *body,char *dir);
213 220
 
214 221
 int im_body_mouse(body_t *body, Vector2 mousepos, Vector2 wheel, int lmbpressed, int lmbreleased, int lmbdown, int *click_avail);
215
-int im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int windowwidth, int windowheight);
222
+int im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int rmbdown, int windowwidth, int windowheight);
216 223
 
217 224
 int listing_get(listing_t *listing, char *pathprefix, char *path, int flag_sort);
218 225
 void listing_freedata(listing_t *listing);
219 226
 int listing_fillxywh(listing_t *listing, font_t *font, int w, int sidelen, int is_left);
220 227
 
228
+int texture_load(texture_t *texture, char *fullpath, int maxw, int maxh);
229
+int texture_draw(texture_t *texture, int x0, int y0, int maxw, int maxh);
230
+int texture_freedata(texture_t *texture);
231
+
221 232
 int imutil_menu_count(char *menus);
222 233
 char *imutil_menu_get(char *menus, int targetn, int *len);
223 234
 int imutil_submenu_count(char *menus);
... ...
@@ -235,7 +246,7 @@ main(int argc, char *argv[])
235 246
         im_t *im;
236 247
         Vector2 mousepos,wheel;
237 248
         int flag_ignorelmb;
238
-        int lmbpressed,lmbreleased,lmbdown;
249
+        int lmbpressed,lmbreleased,lmbdown,rmbdown;
239 250
         int click_avail;
240 251
         char *sel_menu,*sel_submenu;
241 252
         if((im=im_init("Fichero\nAjustes\nSalir\n\nEditar\nNuevo directorio\n\nAyuda\nInformación sobre el programa\n\n",ROOTDIR))==NULL) {
... ...
@@ -248,6 +259,7 @@ main(int argc, char *argv[])
248 259
                 lmbpressed=IsMouseButtonPressed(0);
249 260
                 lmbreleased=IsMouseButtonReleased(0);
250 261
                 lmbdown=IsMouseButtonDown(0);
262
+                rmbdown=IsMouseButtonDown(1);
251 263
                 click_avail=1;
252 264
                 /* process clicks on menus */
253 265
                 if(click_avail) {
... ...
@@ -266,7 +278,7 @@ fprintf(stderr,"SELECTED: \"%s\"->\"%s\"\n",sel_menu,sel_submenu);
266 278
                 /* draw screen contents */
267 279
                 BeginDrawing();
268 280
                 ClearBackground(RAYWHITE);
269
-                im_body_draw(im->body,mousepos,lmbdown,im->w,im->h);
281
+                im_body_draw(im->body,mousepos,lmbdown,rmbdown,im->w,im->h);
270 282
                 im_menubar_draw(im->menubar,im->w,im->h);
271 283
 #if 0
272 284
 {
... ...
@@ -352,10 +364,8 @@ im_free(im_t *im)
352 364
                 im_font_free(im->fontbig),im->fontbig=NULL;
353 365
         if(im->fonthuge!=NULL)
354 366
                 im_font_free(im->fonthuge),im->fonthuge=NULL;
355
-#if 1 /* not working as intended */
356 367
         if(im->windowinit)
357 368
                 CloseWindow(),im->windowinit=0;
358
-#endif
359 369
         free(im),im=NULL;
360 370
         return;
361 371
 }
... ...
@@ -666,12 +676,8 @@ im_body_free(body_t *body)
666 676
                 }
667 677
                 free(body->dirdata),body->dirdata=NULL,body->sizedirdata=0;
668 678
         }
669
-        if(body->has_texture) {
670
-                UnloadTexture(body->texture);
671
-                body->currenttexture[0]='\0';
672
-                body->has_texture=0;
673
-                body->has_failedload=0;
674
-        }
679
+        texture_freedata(&(body->texture));
680
+        texture_freedata(&(body->bigtexture));
675 681
         if(body->rootdir!=NULL)
676 682
                 free(body->rootdir),body->rootdir=NULL;
677 683
         free(body),body=NULL;
... ...
@@ -778,7 +784,7 @@ im_body_mouse(body_t *body, Vector2 mousepos, Vector2 wheel, int lmbpressed, int
778 784
 }
779 785
 
780 786
 int
781
-im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int windowwidth, int windowheight)
787
+im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int rmbdown, int windowwidth, int windowheight)
782 788
 {
783 789
         int i,k,margin,righty;
784 790
         int lastx,lasty;
... ...
@@ -788,6 +794,7 @@ im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int windowwidth, int w
788 794
         font_t *font,*fontbig,*fonthuge;
789 795
         int is_leftside;
790 796
         int flag_skiprightside;
797
+        int flag_skipall;
791 798
         int xoff,yoff;
792 799
         thumb_t *thumb;
793 800
         char statustooltip[1024];
... ...
@@ -819,8 +826,8 @@ im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int windowwidth, int w
819 826
         DrawRectangle(body->xywh.x+body->leftsize,body->xywh.y,body->xywh.w-body->leftsize, body->xywh.h, (Color){ 227, 227, 227, 255 } );
820 827
         /* first pass, draw leftside, second pass, draw all of rightside */
821 828
         statustooltip[0]='\0';
822
-        for(is_leftside=1,flag_skiprightside=0;is_leftside>=0 && flag_skiprightside==0;is_leftside--) {
823
-                for(i=(is_leftside)?body->currentdirdata:0,righty=body->xywh.y;(is_leftside && i==body->currentdirdata) || (!is_leftside && i<body->sizedirdata);i++) {
829
+        for(is_leftside=1,flag_skiprightside=flag_skipall=0;is_leftside>=0 && flag_skiprightside==0 && flag_skipall==0;is_leftside--) {
830
+                for(i=(is_leftside)?body->currentdirdata:0,righty=body->xywh.y;flag_skipall==0 && ((is_leftside && i==body->currentdirdata) || (!is_leftside && i<body->sizedirdata));i++) {
824 831
                         int sidelen;
825 832
                         if((dirdata=body->dirdata[i])==NULL)
826 833
                                 continue;
... ...
@@ -962,56 +969,49 @@ fprintf(stderr,"elem:\"%s\" sidelen:%i old:%ix%i new:%ix%i\n",elem->name+1,sidel
962 969
                                                 DrawTexture(*te,thumb->screenxywh.x,thumb->screenxywh.y,WHITE);
963 970
                                                 has_imagedrawn=1;
964 971
                                                 lastx=xywh->x+xywh->w,lasty=xywh->y+xywh->h+yoff;
965
-                                                if(is_leftside && lmbdown==0 && is_imutil_insidexywh(mousepos,&(thumb->screenxywh),margin)) {
972
+                                                if(is_leftside && lmbdown==0 && rmbdown==0 && is_imutil_insidexywh(mousepos,&(thumb->screenxywh),margin)) {
966 973
                                                         /* draw image in rightside */
967
-                                                        char path[2048];
974
+                                                        char fullpath[2048];
968 975
                                                         int maxw,maxh;
969
-                                                        snprintf(path,sizeof(path),"%s/%s",dirdata->dirname,elem->name+1);
970
-                                                        path[sizeof(path)-1]='\0';
971 976
                                                         maxw=windowwidth-(body->leftsize-DEFAULTDIRDATATRIANGLEW);
972 977
                                                         maxh=windowheight-body->xywh.y;
973
-                                                        if((body->has_texture==0 && !(body->has_failedload && strcmp(body->currenttexture,path)==0))
974
-                                                          || strcmp(body->currenttexture,path)!=0
978
+                                                        snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
979
+                                                        fullpath[sizeof(fullpath)-1]='\0';
980
+                                                        if((body->texture.has_texture==0 && !(body->texture.has_failedload && strcmp(body->texture.currentpath,fullpath)==0))
981
+                                                          || strcmp(body->texture.currentpath,fullpath)!=0
975 982
                                                         ) {
976
-                                                                Image im;
977
-                                                                int neww,newh;
978
-                                                                char fullpath[2048];
979
-                                                                if(body->has_texture) {
980
-                                                                        UnloadTexture(body->texture);
981
-                                                                        body->currenttexture[0]='\0';
982
-                                                                        body->has_texture=0;
983
-                                                                        body->has_failedload=0;
984
-                                                                }
985
-                                                                snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
986
-                                                                fullpath[sizeof(fullpath)-1]='\0';
987
-                                                                im=LoadImage(fullpath);
988
-                                                                if(IsImageValid(im)) {
989
-                                                                        im_util_aspectmaximize(im.width,im.height,maxw,maxh,&neww,&newh);
990
-                                                                        ImageResize(&im,neww,newh);
991
-                                                                        body->texture=LoadTextureFromImage(im);
992
-                                                                        UnloadImage(im);
993
-                                                                        strncpy(body->currenttexture,fullpath,sizeof(body->currenttexture));
994
-                                                                        body->currenttexture[sizeof(body->currenttexture)-1]='\0';
995
-                                                                        body->has_texture=1;
996
-                                                                        body->has_failedload=0;
997
-                                                                        body->texturew=neww;
998
-                                                                        body->textureh=newh;
999
-                                                                } else {
1000
-                                                                        strncpy(body->currenttexture,fullpath,sizeof(body->currenttexture));
1001
-                                                                        body->currenttexture[sizeof(body->currenttexture)-1]='\0';
1002
-                                                                        body->has_texture=0;
1003
-                                                                        body->has_failedload=1;
1004
-                                                                }
983
+                                                                texture_load(&(body->texture),fullpath,maxw,maxh);
1005 984
                                                         }
1006
-                                                        if(body->has_texture) {
985
+                                                        if(body->texture.has_texture && strcmp(body->texture.currentpath,fullpath)==0) {
1007 986
                                                                 int x0,y0;
1008 987
                                                                 x0=body->leftsize-DEFAULTDIRDATATRIANGLEW;
1009 988
                                                                 y0=body->xywh.y;
1010
-                                                                DrawRectangle(x0,y0,maxw,maxh,(Color){ 215, 215, 215, 255 } );
1011
-                                                                DrawTexture(body->texture,x0+(maxw-body->texturew)/2,y0+(maxh-body->textureh)/2,WHITE);
989
+                                                                texture_draw(&(body->texture),x0,y0,maxw,maxh);
1012 990
                                                                 flag_skiprightside=1;
1013 991
                                                         }
1014 992
                                                 }
993
+                                                if(is_leftside && lmbdown==0 && rmbdown!=0 && is_imutil_insidexywh(mousepos,&(thumb->screenxywh),margin)) {
994
+                                                        /* draw image in full screen */
995
+                                                        char fullpath[2048];
996
+                                                        int maxw,maxh;
997
+                                                        maxw=windowwidth;
998
+                                                        maxh=windowheight-body->xywh.y;
999
+                                                        snprintf(fullpath,sizeof(fullpath),"%s/%s/%s",body->rootdir,dirdata->dirname,elem->name+1);
1000
+                                                        fullpath[sizeof(fullpath)-1]='\0';
1001
+                                                        if((body->bigtexture.has_texture==0 && !(body->bigtexture.has_failedload && strcmp(body->bigtexture.currentpath,fullpath)==0))
1002
+                                                          || strcmp(body->bigtexture.currentpath,fullpath)!=0
1003
+                                                        ) {
1004
+                                                                texture_load(&(body->bigtexture),fullpath,maxw,maxh);
1005
+                                                        }
1006
+                                                        if(body->bigtexture.has_texture && strcmp(body->bigtexture.currentpath,fullpath)==0) {
1007
+                                                                int x0,y0;
1008
+                                                                x0=0;
1009
+                                                                y0=body->xywh.y;
1010
+                                                                texture_draw(&(body->bigtexture),x0,y0,maxw,maxh);
1011
+                                                                flag_skipall=1;
1012
+                                                                break;
1013
+                                                        }
1014
+                                                }
1015 1015
                                         }
1016 1016
                                 }
1017 1017
                                 if(has_imagedrawn==0) {
... ...
@@ -1065,6 +1065,65 @@ fprintf(stderr,"elem:\"%s\" sidelen:%i old:%ix%i new:%ix%i\n",elem->name+1,sidel
1065 1065
         return(0);
1066 1066
 }
1067 1067
 
1068
+int
1069
+texture_load(texture_t *texture, char *fullpath, int maxw, int maxh)
1070
+{ 
1071
+        Image im;
1072
+        int neww,newh;
1073
+        if(texture==NULL || fullpath==NULL)
1074
+                return(-1); /* sanity check failed */
1075
+        if(texture->has_texture) {
1076
+                UnloadTexture(texture->texture);
1077
+                texture->currentpath[0]='\0';
1078
+                texture->has_texture=0;
1079
+                texture->has_failedload=0;
1080
+        }
1081
+        texture->currentpath[0]='\0';
1082
+        im=LoadImage(fullpath);
1083
+        if(IsImageValid(im)) {
1084
+                im_util_aspectmaximize(im.width,im.height,maxw,maxh,&neww,&newh);
1085
+                ImageResize(&im,neww,newh);
1086
+                texture->texture=LoadTextureFromImage(im);
1087
+                UnloadImage(im);
1088
+                strncpy(texture->currentpath,fullpath,sizeof(texture->currentpath));
1089
+                texture->currentpath[sizeof(texture->currentpath)-1]='\0';
1090
+                texture->has_texture=1;
1091
+                texture->has_failedload=0;
1092
+                texture->texturew=neww;
1093
+                texture->textureh=newh;
1094
+        } else {
1095
+                strncpy(texture->currentpath,fullpath,sizeof(texture->currentpath));
1096
+                texture->currentpath[sizeof(texture->currentpath)-1]='\0';
1097
+                texture->has_texture=0;
1098
+                texture->has_failedload=1;
1099
+        }
1100
+        return(0);
1101
+}
1102
+
1103
+int
1104
+texture_draw(texture_t *texture, int x0, int y0, int maxw, int maxh)
1105
+{
1106
+        if(texture==NULL || texture->has_texture==0)
1107
+                return(-1); /* sanity check failed */
1108
+        DrawRectangle(x0,y0,maxw,maxh,(Color){ 215, 215, 215, 255 } );
1109
+        DrawTexture(texture->texture,x0+(maxw-texture->texturew)/2,y0+(maxh-texture->textureh)/2,WHITE);
1110
+        return(0);
1111
+}
1112
+
1113
+int
1114
+texture_freedata(texture_t *texture)
1115
+{
1116
+        if(texture==NULL)
1117
+                return(-1); /* sanity check failed */
1118
+        if(texture->has_texture) {
1119
+                UnloadTexture(texture->texture);
1120
+                texture->currentpath[0]='\0';
1121
+                texture->has_texture=0;
1122
+                texture->has_failedload=0;
1123
+        }
1124
+        return(0);
1125
+}
1126
+
1068 1127
 int
1069 1128
 imutil_menu_count(char *menus)
1070 1129
 {