--- previous/src/gui-sdl/dlgFileSelect.c 2018/04/24 19:26:14 1.1.1.2 +++ previous/src/gui-sdl/dlgFileSelect.c 2018/04/24 19:34:40 1.1.1.4 @@ -295,15 +295,16 @@ static void DlgFileSelect_ManageScrollba oldMouseY = y; /* Verifiy if scrollbar is in correct inferior boundary */ - if (scrollbar_Ypos < 0) - scrollbar_Ypos = 0.0; + if (scrollbar_Ypos < 0) { + scrollbar_Ypos = 0.0; + } - /* Verifiy if scrollbar is in correct superior boundary */ - b = (int) (scrollbar_Ypos * ((float)entries/(float)(SGFS_NUMENTRIES-2)) + 0.5); - if (b+SGFS_NUMENTRIES >= entries) { - ypos = entries - SGFS_NUMENTRIES; - DlgFileSelect_Convert_ypos_to_scrollbar_Ypos(); - } + /* Verifiy if scrollbar is in correct superior boundary */ + b = (int) (scrollbar_Ypos * ((float)entries/(float)(SGFS_NUMENTRIES-2)) + 0.5); + if (b+SGFS_NUMENTRIES >= entries) { + ypos = entries - SGFS_NUMENTRIES; + DlgFileSelect_Convert_ypos_to_scrollbar_Ypos(); + } refreshentries = true; } @@ -318,12 +319,12 @@ static void DlgFileSelect_HandleSdlEvent int oldypos = ypos; switch (pEvent->type) { - case SDL_MOUSEBUTTONDOWN: - if (pEvent->button.button == SDL_BUTTON_WHEELUP) - DlgFileSelect_ScrollUp(); - else if (pEvent->button.button == SDL_BUTTON_WHEELDOWN) - DlgFileSelect_ScrollDown(); - break; + case SDL_MOUSEWHEEL: + if (pEvent->wheel.y>0) + DlgFileSelect_ScrollUp(); + else if (pEvent->wheel.y<0) + DlgFileSelect_ScrollDown(); + break; case SDL_KEYDOWN: switch (pEvent->key.keysym.sym) { @@ -874,3 +875,39 @@ bool SDLGui_FileConfSelect(char *dlgname } return false; } + + +/*-----------------------------------------------------------------------*/ +/** + * Let user browse for a directory, confname is used as default. + * + * If no directory is selected, or there's some problem with it, + * return false and clear dlgname & confname. + * Otherwise return true, set dlgname & confname to the directory name + * (dlgname is shrinked & limited to maxlen and confname is assumed + * to have FILENAME_MAX amount of space). + */ + +bool SDLGui_DirectorySelect(char *dlgname, char *confname, int maxlen) +{ + char *selname; + + selname = SDLGui_FileSelect(confname, NULL, false); + if (selname) + { + File_MakeValidPathName(selname); + + if (File_DirExists(selname)) + { + strncpy(confname, selname, FILENAME_MAX); + File_ShrinkName(dlgname, selname, maxlen); + } + else + { + dlgname[0] = confname[0] = 0; + } + free(selname); + return true; + } + return false; +}