...
|
...
|
@@ -34,6 +34,7 @@
|
34
|
34
|
* 20250330 Refine background loading.
|
35
|
35
|
* 20250413 Background loading for windows target.
|
36
|
36
|
* 20250420 Fix background loading for windows target.
|
|
37
|
+ * 20250427 Start move image functionality.
|
37
|
38
|
*
|
38
|
39
|
* Author: Dario Rodriguez dario@darionomono.com
|
39
|
40
|
* (c) Dario Rodriguez 2025
|
...
|
...
|
@@ -265,6 +266,7 @@ typedef struct body_t {
|
265
|
266
|
xywh_t dirdataadd;
|
266
|
267
|
Font roundedbox;
|
267
|
268
|
bg_t *bg;
|
|
269
|
+ char selectedpath[2048];
|
268
|
270
|
} body_t;
|
269
|
271
|
|
270
|
272
|
typedef struct im_t {
|
...
|
...
|
@@ -295,6 +297,8 @@ body_t *im_body_init(int x, int y, font_t *font, font_t *fontbig, font_t *fonthu
|
295
|
297
|
void im_body_free(body_t *body);
|
296
|
298
|
|
297
|
299
|
int im_body_add(body_t *body,char *dir);
|
|
300
|
+int im_body_tryselect(body_t *body, Vector2 mousepos);
|
|
301
|
+
|
298
|
302
|
|
299
|
303
|
int im_body_mouse(body_t *body, Vector2 mousepos, Vector2 wheel, int lmbpressed, int lmbreleased, int lmbdown, int *click_avail);
|
300
|
304
|
int im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int rmbdown, int windowwidth, int windowheight, int *needs_nextredraw, int scrollspeed);
|
...
|
...
|
@@ -363,6 +367,7 @@ main(int argc, char *argv[])
|
363
|
367
|
needs_nextredraw=1;
|
364
|
368
|
scrollstart=0;
|
365
|
369
|
is_scrolling=0;
|
|
370
|
+ im->body->selectedpath[0]='\0';
|
366
|
371
|
while(!WindowShouldClose()) {
|
367
|
372
|
imutil_fpsreset();
|
368
|
373
|
oldmousepos=mousepos;
|
...
|
...
|
@@ -399,8 +404,12 @@ main(int argc, char *argv[])
|
399
|
404
|
}
|
400
|
405
|
t=scrollstartpos.x-mousepos.x;
|
401
|
406
|
t=(t<0)?-t:t;
|
402
|
|
- if(t>SCROLLTHRESHOLD)
|
|
407
|
+ if(t>SCROLLTHRESHOLD) {
|
403
|
408
|
is_scrolling=0,scrollstart=0;
|
|
409
|
+ im_body_tryselect(im->body,scrollstartpos);
|
|
410
|
+ if(im->body->selectedpath[0]!='\0')
|
|
411
|
+ click_avail=0;
|
|
412
|
+ }
|
404
|
413
|
}
|
405
|
414
|
if(is_scrolling) {
|
406
|
415
|
long long tcur,tdif;
|
...
|
...
|
@@ -668,7 +677,7 @@ im_menubar_mouse(menubar_t *menubar, Vector2 mousepos, int lmbpressed, int lmbre
|
668
|
677
|
*sel_menu=NULL;
|
669
|
678
|
*sel_submenu=NULL;
|
670
|
679
|
flag_outsideall=1;
|
671
|
|
-#if 1
|
|
680
|
+#if 0
|
672
|
681
|
if(lmbpressed || lmbdown)
|
673
|
682
|
fprintf(stderr,"in_menubar_mouse: lmbpressed:%i lmbdown:%i\n",lmbpressed,lmbdown);
|
674
|
683
|
#endif
|
...
|
...
|
@@ -896,6 +905,30 @@ im_body_add(body_t *body,char *dir)
|
896
|
905
|
return(0);
|
897
|
906
|
}
|
898
|
907
|
|
|
908
|
+int
|
|
909
|
+im_body_tryselect(body_t *body, Vector2 mousepos)
|
|
910
|
+{
|
|
911
|
+ int i;
|
|
912
|
+ listing_t *listing;
|
|
913
|
+ listingdata_t *elem;
|
|
914
|
+ if(body==NULL || body->currentdirdata<0 || body->currentdirdata>=body->sizedirdata || body->dirdata[body->currentdirdata]==NULL || body->currentdirdata>=body->sizedirdata)
|
|
915
|
+ return(-1); /* sanity check failed */
|
|
916
|
+ body->selectedpath[0]='\0';
|
|
917
|
+ if(!is_imutil_insidexywh(mousepos,&(body->xywh),0) || mousepos.x>body->leftsize)
|
|
918
|
+ return(-1); /* outside leftside */
|
|
919
|
+ listing=&(body->dirdata[body->currentdirdata]->listing);
|
|
920
|
+ for(i=0;i<listing->usedelems;i++) {
|
|
921
|
+ elem=listing->elems+i;
|
|
922
|
+ if(is_imutil_insidexywh(mousepos,&(elem->left.screenxywh),0)) {
|
|
923
|
+ strncpy(body->selectedpath,elem->name,sizeof(body->selectedpath));
|
|
924
|
+ body->selectedpath[sizeof(body->selectedpath)-1]='\0';
|
|
925
|
+ return(0); /* found */
|
|
926
|
+ }
|
|
927
|
+ }
|
|
928
|
+ return(-1); /* no thumbnail found for pos */
|
|
929
|
+}
|
|
930
|
+
|
|
931
|
+
|
899
|
932
|
int
|
900
|
933
|
im_body_mouse(body_t *body, Vector2 mousepos, Vector2 wheel, int lmbpressed, int lmbreleased, int lmbdown, int *click_avail)
|
901
|
934
|
{
|
...
|
...
|
@@ -922,7 +955,7 @@ im_body_mouse(body_t *body, Vector2 mousepos, Vector2 wheel, int lmbpressed, int
|
922
|
955
|
return(0); /* nothing else to do */
|
923
|
956
|
}
|
924
|
957
|
margin=body->ptrfont->height/4;
|
925
|
|
- if(body->is_displayingtexture && lmbreleased && is_imutil_insidexywh(mousepos,&(body->texture.source),margin)) {
|
|
958
|
+ if(body->is_displayingtexture && lmbreleased && is_imutil_insidexywh(mousepos,&(body->texture.source),margin) && body->selectedpath[0]=='\0') {
|
926
|
959
|
body->flag_drawbigtexture=1;
|
927
|
960
|
return(0); /* nothing else to do */
|
928
|
961
|
}
|
...
|
...
|
@@ -970,28 +1003,51 @@ im_body_mouse(body_t *body, Vector2 mousepos, Vector2 wheel, int lmbpressed, int
|
970
|
1003
|
return(0);
|
971
|
1004
|
}
|
972
|
1005
|
}
|
973
|
|
- /* dirdata select */
|
974
|
|
- if(mousepos.x>body->leftsize && mousepos.y>body->xywh.y) {
|
975
|
|
- int righty;
|
976
|
|
- for(righty=body->xywh.y,i=0;i<body->sizedirdata;i++) {
|
977
|
|
- if(body->dirdata[i]==NULL)
|
978
|
|
- continue;
|
979
|
|
- if(mousepos.y>=righty && mousepos.y<(righty+body->dirdata[i]->height) && i!=body->currentdirdata) {
|
980
|
|
- body->currentdirdata=i;
|
981
|
|
- *click_avail=0;
|
982
|
|
- return(0);
|
|
1006
|
+ /* dirdata processing */
|
|
1007
|
+ if(body->selectedpath[0]=='\0') {
|
|
1008
|
+ /* dirdata select */
|
|
1009
|
+ if(mousepos.x>body->leftsize && mousepos.y>body->xywh.y) {
|
|
1010
|
+ int righty;
|
|
1011
|
+ for(righty=body->xywh.y,i=0;i<body->sizedirdata;i++) {
|
|
1012
|
+ if(body->dirdata[i]==NULL)
|
|
1013
|
+ continue;
|
|
1014
|
+ if(mousepos.y>=righty && mousepos.y<(righty+body->dirdata[i]->height) && i!=body->currentdirdata) {
|
|
1015
|
+ body->currentdirdata=i;
|
|
1016
|
+ *click_avail=0;
|
|
1017
|
+ return(0);
|
|
1018
|
+ }
|
|
1019
|
+ righty+=body->dirdata[i]->height;
|
983
|
1020
|
}
|
984
|
|
- righty+=body->dirdata[i]->height;
|
985
|
1021
|
}
|
|
1022
|
+ /* detect click on "add dirdata" button */
|
|
1023
|
+ if(is_imutil_insidexywh(mousepos,&(body->dirdataadd),0)) {
|
|
1024
|
+ im_body_add(body,body->dirdata[body->currentdirdata]->dirname);
|
|
1025
|
+ *click_avail=0;
|
|
1026
|
+ return(0);
|
|
1027
|
+ }
|
|
1028
|
+ /* dirdata remove */
|
|
1029
|
+#warning TODO
|
986
|
1030
|
}
|
987
|
|
- /* detect click on "add dirdata" button */
|
988
|
|
- if(is_imutil_insidexywh(mousepos,&(body->dirdataadd),0)) {
|
989
|
|
- im_body_add(body,body->dirdata[body->currentdirdata]->dirname);
|
990
|
|
- *click_avail=0;
|
991
|
|
- return(0);
|
992
|
|
- }
|
993
|
|
- /* dirdata remove */
|
|
1031
|
+ /* unselect selectedpath */
|
|
1032
|
+ if(lmbpressed==0 && body->selectedpath[0]!='\0') {
|
|
1033
|
+ if(mousepos.x>body->leftsize && mousepos.y>body->xywh.y) {
|
|
1034
|
+ int righty;
|
|
1035
|
+ for(righty=body->xywh.y,i=0;i<body->sizedirdata;i++) {
|
|
1036
|
+ if(body->dirdata[i]==NULL)
|
|
1037
|
+ continue;
|
|
1038
|
+ if(mousepos.y>=righty && mousepos.y<(righty+body->dirdata[i]->height) && i!=body->currentdirdata && strcmp(body->dirdata[i]->dirname,body->dirdata[body->currentdirdata]->dirname)!=0) {
|
994
|
1039
|
#warning TODO
|
|
1040
|
+#if 1
|
|
1041
|
+fprintf(stderr,"WOULD MOVE \"%s/%s\" to \"%s\"\n",body->dirdata[body->currentdirdata]->dirname,body->selectedpath+1,body->dirdata[i]->dirname);
|
|
1042
|
+#endif
|
|
1043
|
+ *click_avail=0;
|
|
1044
|
+ break;
|
|
1045
|
+ }
|
|
1046
|
+ righty+=body->dirdata[i]->height;
|
|
1047
|
+ }
|
|
1048
|
+ }
|
|
1049
|
+ body->selectedpath[0]='\0';
|
|
1050
|
+ }
|
995
|
1051
|
return(0);
|
996
|
1052
|
}
|
997
|
1053
|
|
...
|
...
|
@@ -1010,6 +1066,7 @@ im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int rmbdown, int windo
|
1010
|
1066
|
int xoff,yoff;
|
1011
|
1067
|
thumb_t *thumb;
|
1012
|
1068
|
char statustooltip[1024];
|
|
1069
|
+ thumb_t *selectedthumb;
|
1013
|
1070
|
if(body==NULL)
|
1014
|
1071
|
return(-1);
|
1015
|
1072
|
font=body->ptrfont;
|
...
|
...
|
@@ -1018,6 +1075,7 @@ im_body_draw(body_t *body, Vector2 mousepos, int lmbdown, int rmbdown, int windo
|
1018
|
1075
|
FILLXYWH(body->backxywh,0,0,0,0);
|
1019
|
1076
|
margin=font->height/4;
|
1020
|
1077
|
body->is_displayingtexture=0;
|
|
1078
|
+ selectedthumb=NULL;
|
1021
|
1079
|
/* if we are displaying a full screenimage... */
|
1022
|
1080
|
if(body->flag_drawbigtexture && body->texture.has_texture) {
|
1023
|
1081
|
/* draw image in full screen */
|
...
|
...
|
@@ -1256,6 +1314,17 @@ fprintf(stderr,"elem:\"%s\" sidelen:%i old:%ix%i new:%ix%i\n",elem->name+1,sidel
|
1256
|
1314
|
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 });
|
1257
|
1315
|
lastx=xywh->x+xoff+xywh->w,lasty=xywh->y+yoff+xywh->h;
|
1258
|
1316
|
}
|
|
1317
|
+ /* show selected rectangle */
|
|
1318
|
+ if(is_leftside && strcmp(body->selectedpath,elem->name)==0) {
|
|
1319
|
+ Color c=((Color){0,0,255,64});
|
|
1320
|
+ DrawRectangle(UNROLLXYWH(thumb->screenxywh),c);
|
|
1321
|
+ c=((Color){0,0,255,255});
|
|
1322
|
+ DrawRectangle(thumb->screenxywh.x,thumb->screenxywh.y,thumb->screenxywh.w,2,c);
|
|
1323
|
+ DrawRectangle(thumb->screenxywh.x,thumb->screenxywh.y+2,2,thumb->screenxywh.h-4,c);
|
|
1324
|
+ DrawRectangle(thumb->screenxywh.x+thumb->screenxywh.w-2,thumb->screenxywh.y+2,2,thumb->screenxywh.h-4,c);
|
|
1325
|
+ DrawRectangle(thumb->screenxywh.x,thumb->screenxywh.y+thumb->screenxywh.h-2,thumb->screenxywh.w,2,c);
|
|
1326
|
+ selectedthumb=thumb;
|
|
1327
|
+ }
|
1259
|
1328
|
}
|
1260
|
1329
|
for(;k<dirdata->listing.usedelems;k++) {
|
1261
|
1330
|
elem=dirdata->listing.elems+k;
|
...
|
...
|
@@ -1271,6 +1340,16 @@ fprintf(stderr,"elem:\"%s\" sidelen:%i old:%ix%i new:%ix%i\n",elem->name+1,sidel
|
1271
|
1340
|
if(i==body->currentdirdata) {
|
1272
|
1341
|
/* draw right side "current" marker inside left side area */
|
1273
|
1342
|
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 } );
|
|
1343
|
+ } else if(body->selectedpath[0]!='\0' && mousepos.x>body->leftsize && mousepos.y>=righty && mousepos.y<(righty+dirdata->height) && strcmp(body->dirdata[i]->dirname,body->dirdata[body->currentdirdata]->dirname)!=0) {
|
|
1344
|
+ xywh_t xywh;
|
|
1345
|
+ Color c=((Color){0,0,255,64});
|
|
1346
|
+ FILLXYWH(xywh,body->leftsize,righty,body->xywh.w-body->leftsize,dirdata->height);
|
|
1347
|
+ DrawRectangle(UNROLLXYWH(xywh),c);
|
|
1348
|
+ c=((Color){0,0,255,255});
|
|
1349
|
+ DrawRectangle(xywh.x,xywh.y,xywh.w,2,c);
|
|
1350
|
+ DrawRectangle(xywh.x,xywh.y+2,2,xywh.h-4,c);
|
|
1351
|
+ DrawRectangle(xywh.x+xywh.w-2,xywh.y+2,2,xywh.h-4,c);
|
|
1352
|
+ DrawRectangle(xywh.x,xywh.y+xywh.h-2,xywh.w,2,c);
|
1274
|
1353
|
}
|
1275
|
1354
|
/* advance to next element */
|
1276
|
1355
|
righty+=dirdata->height;
|
...
|
...
|
@@ -1306,6 +1385,12 @@ fprintf(stderr,"elem:\"%s\" sidelen:%i old:%ix%i new:%ix%i\n",elem->name+1,sidel
|
1306
|
1385
|
} else {
|
1307
|
1386
|
memset(&(body->dirdataadd),0,sizeof(body->dirdataadd));
|
1308
|
1387
|
}
|
|
1388
|
+ /* if moving elem, show line from orig to mousepos */
|
|
1389
|
+ if(body->selectedpath[0]!='\0' && selectedthumb!=NULL) {
|
|
1390
|
+ Color c=((Color){0,0,255,255});
|
|
1391
|
+ DrawLineEx((Vector2){(float)(selectedthumb->screenxywh.x+selectedthumb->screenxywh.w/2),(float)(selectedthumb->screenxywh.y+selectedthumb->screenxywh.h/2)},mousepos,2.0,c);
|
|
1392
|
+ }
|
|
1393
|
+ /* show tooltip */
|
1309
|
1394
|
if(statustooltip[0]!='\0') {
|
1310
|
1395
|
m2=MeasureTextEx(font->font,statustooltip,font->height,0);
|
1311
|
1396
|
DrawRectangle(0,windowheight-1-margin*2-font->height,m2.x+margin*2,font->height+margin*2,((Color){0,0,0,96}));
|