Set the correct scroll position for the listbox when it's shown

This commit is contained in:
kreatordxx 2010-02-06 01:41:38 +00:00
parent f730b25932
commit 55a6e7f97e
2 changed files with 25 additions and 18 deletions

View file

@ -3,6 +3,7 @@ D2X-Rebirth Changelog
20100206
--------
main/newmenu.c: Reset last_palette_loaded in nm_draw_background1 as before, it's needed for using the right palette when advancing a level
main/newmenu.c: Set the correct scroll position for the listbox when it's shown
20100205
--------

View file

@ -1734,6 +1734,28 @@ void listbox_delete_item(listbox *lb, int item)
}
}
void update_scroll_position(listbox *lb)
{
if (lb->citem<0)
lb->citem=0;
if (lb->citem>=lb->nitems)
lb->citem = lb->nitems-1;
if (lb->citem< lb->first_item)
lb->first_item = lb->citem;
if (lb->citem>=( lb->first_item+LB_ITEMS_ON_SCREEN))
lb->first_item = lb->citem-LB_ITEMS_ON_SCREEN+1;
if (lb->nitems <= LB_ITEMS_ON_SCREEN )
lb->first_item = 0;
if (lb->first_item>lb->nitems-LB_ITEMS_ON_SCREEN)
lb->first_item = lb->nitems-LB_ITEMS_ON_SCREEN;
if (lb->first_item < 0 ) lb->first_item = 0;
}
int listbox_key_command(window *wind, d_event *event, listbox *lb)
{
int key = ((d_event_keycommand *)event)->keycode;
@ -1817,24 +1839,7 @@ int listbox_key_command(window *wind, d_event *event, listbox *lb)
}
}
if (lb->citem<0)
lb->citem=0;
if (lb->citem>=lb->nitems)
lb->citem = lb->nitems-1;
if (lb->citem< lb->first_item)
lb->first_item = lb->citem;
if (lb->citem>=( lb->first_item+LB_ITEMS_ON_SCREEN))
lb->first_item = lb->citem-LB_ITEMS_ON_SCREEN+1;
if (lb->nitems <= LB_ITEMS_ON_SCREEN )
lb->first_item = 0;
if (lb->first_item>lb->nitems-LB_ITEMS_ON_SCREEN)
lb->first_item = lb->nitems-LB_ITEMS_ON_SCREEN;
if (lb->first_item < 0 ) lb->first_item = 0;
update_scroll_position(lb);
return rval;
}
@ -2060,6 +2065,7 @@ int newmenu_listbox1( char * title, int nitems, char * items[], int allow_abort_
if ( lb->citem >= nitems ) lb->citem = 0;
lb->first_item = 0;
update_scroll_position(lb);
lb->mouse_state = lb->omouse_state = 0; //dblclick_flag = 0;