From 55a6e7f97eb9cb6941c8c8f1dc56e32e9239dd81 Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Sat, 6 Feb 2010 01:41:38 +0000 Subject: [PATCH] Set the correct scroll position for the listbox when it's shown --- CHANGELOG.txt | 1 + main/newmenu.c | 42 ++++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8792b42fb..e9fc9a527 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 -------- diff --git a/main/newmenu.c b/main/newmenu.c index af6f8bd0e..0bb75e705 100644 --- a/main/newmenu.c +++ b/main/newmenu.c @@ -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;