55
66#include " SDL_gui.h"
77
8- extern " C"
9- {
10- void SDL_DC_EmulateMouse (SDL_bool value);
8+ extern " C" {
9+ void SDL_DC_EmulateMouse (SDL_bool value);
1110}
1211
1312GUI_FileManager::GUI_FileManager (const char *aname, const char *path, int x, int y, int w, int h)
@@ -21,10 +20,12 @@ GUI_FileManager::GUI_FileManager(const char *aname, const char *path, int x, int
2120 item_area.x = 0 ;
2221 item_area.y = 0 ;
2322
24- item_normal = new GUI_Surface (" normal" , SDL_HWSURFACE, item_area.w , item_area.h , 16 , 0x00FF0000 , 0x0000FF00 , 0x000000FF , 0xFF000000 );
25- item_highlight = new GUI_Surface (" highlight" , SDL_HWSURFACE, item_area.w , item_area.h , 16 , 0x00FF0000 , 0x0000FF00 , 0x000000FF , 0xFF000000 );
26- item_disabled = new GUI_Surface (" disabled" , SDL_HWSURFACE, item_area.w , item_area.h , 16 , 0x00FF0000 , 0x0000FF00 , 0x000000FF , 0xFF000000 );
27- item_pressed = new GUI_Surface (" pressed" , SDL_HWSURFACE, item_area.w , item_area.h , 16 , 0x00FF0000 , 0x0000FF00 , 0x000000FF , 0xFF000000 );
23+ SDL_PixelFormat *format = GUI_GetScreen ()->GetSurface ()->GetSurface ()->format ;
24+
25+ item_normal = new GUI_Surface (" normal" , SDL_HWSURFACE, item_area.w , item_area.h , format->BitsPerPixel , format->Rmask , format->Gmask , format->Bmask , format->Amask );
26+ item_highlight = new GUI_Surface (" highlight" , SDL_HWSURFACE, item_area.w , item_area.h , format->BitsPerPixel , format->Rmask , format->Gmask , format->Bmask , format->Amask );
27+ item_disabled = new GUI_Surface (" disabled" , SDL_HWSURFACE, item_area.w , item_area.h , format->BitsPerPixel , format->Rmask , format->Gmask , format->Bmask , format->Amask );
28+ item_pressed = new GUI_Surface (" pressed" , SDL_HWSURFACE, item_area.w , item_area.h , format->BitsPerPixel , format->Rmask , format->Gmask , format->Bmask , format->Amask );
2829
2930 item_normal->Fill (NULL , 0xFF000000 );
3031 item_highlight->Fill (NULL , 0x00FFFFFF );
@@ -137,7 +138,12 @@ void GUI_FileManager::AdjustScrollbar(GUI_Object * sender) {
137138
138139 int scroll_pos = scrollbar->GetVerticalPosition ();
139140 int scroll_height = scrollbar->GetHeight () - scrollbar->GetKnobImage ()->GetHeight ();
140- panel->SetYOffset (scroll_pos * ((cont_height / scroll_height) + 1 ));
141+
142+ if (scroll_height > 0 ) {
143+ panel->SetYOffset ((int )(scroll_pos * (float )cont_height / scroll_height));
144+ } else {
145+ panel->SetYOffset (0 );
146+ }
141147
142148 if (scroll_pos <= 0 ) {
143149 button_up->SetEnabled (0 );
@@ -150,7 +156,6 @@ void GUI_FileManager::AdjustScrollbar(GUI_Object * sender) {
150156 button_down->SetEnabled (1 );
151157 }
152158
153- thd_sleep (100 );
154159}
155160
156161void GUI_FileManager::ScrollbarButtonEvent (GUI_Object * sender) {
@@ -193,7 +198,12 @@ void GUI_FileManager::ScrollbarButtonEvent(GUI_Object * sender) {
193198 }
194199
195200 scrollbar->SetVerticalPosition (scroll_pos);
196- panel->SetYOffset (scroll_pos * ((cont_height / scroll_height) + 1 ));
201+
202+ if (scroll_height > 0 ) {
203+ panel->SetYOffset ((int )(scroll_pos * (float )cont_height / scroll_height));
204+ } else {
205+ panel->SetYOffset (0 );
206+ }
197207}
198208
199209
@@ -274,7 +284,11 @@ void GUI_FileManager::Scan()
274284 dirent_t *ent;
275285 dirent_t *sorts = (dirent_t *) malloc (sizeof (dirent_t ));
276286 int n = 0 ;
277-
287+
288+ if (sorts == NULL ) {
289+ return ;
290+ }
291+
278292 f = fs_open (cur_path, O_RDONLY | O_DIR);
279293
280294 if (f == FILEHND_INVALID)
@@ -283,7 +297,7 @@ void GUI_FileManager::Scan()
283297 free (sorts);
284298 return ;
285299 }
286-
300+
287301 panel->RemoveAllWidgets ();
288302 panel->SetYOffset (0 );
289303
@@ -324,10 +338,10 @@ void GUI_FileManager::Scan()
324338 AddItem (sorts[i].name , sorts[i].size , sorts[i].time , sorts[i].attr );
325339 }
326340 }
341+ rescan = 0 ;
327342
328343 free (sorts);
329344 fs_close (f);
330- rescan = 0 ;
331345}
332346
333347void GUI_FileManager::ReScan () {
@@ -697,12 +711,18 @@ int GUI_FileManager::Event(const SDL_Event *event, int xoffset, int yoffset) {
697711 case 1 : // Analog joystick
698712 if (flags & WIDGET_PRESSED) {
699713
714+ int val = event->jaxis .value ;
715+
716+ int sleep_time = 158 - abs (val);
717+ if (sleep_time > 0 ) {
718+ thd_sleep (sleep_time);
719+ }
720+
700721 int scroll_height = scrollbar->GetHeight () - scrollbar->GetKnobImage ()->GetHeight ();
701722 int sp_old = scrollbar->GetVerticalPosition ();
702723 int sp = sp_old;
703- int val = event->jaxis .value ;
704724 int step = (scroll_height / panel->GetWidgetCount ());
705- step += abs (val) / 8 ;
725+ step += ( abs (val) - 16 ) / 10 ;
706726
707727 if (val < 0 ) {
708728 sp -= step;
0 commit comments