Making menus recreated on the fly in case resolution or font-size changes; Removing arguments to pass width and height to menu which was not used except on one IPX menu; Fixing measurement of menu strings of type NM_TYPE_INPUT_MENU; Fixing slight bug in freeing IPX netlist

This commit is contained in:
zicodxx 2010-06-23 11:44:12 +00:00
parent c935ecfa99
commit 171386bc24
5 changed files with 853 additions and 863 deletions

View file

@ -1,5 +1,9 @@
D2X-Rebirth Changelog
20100623
--------
main/menu.c, main/newmenu.c, main/newmenu.h, main/net_ipx.c: Making menus recreated on the fly in case resolution or font-size changes; Removing arguments to pass width and height to menu which was not used except on one IPX menu; Fixing measurement of menu strings of type NM_TYPE_INPUT_MENU; Fixing slight bug in freeing IPX netlist
20100622
--------
main/titles.c: Make sure GAME_FONT is set when reading out briefing text so char dimensions will always be stored correctly

View file

@ -543,7 +543,7 @@ int DoMenu()
create_main_menu(m, menu_choice, &num_options); // may have to change, eg, maybe selected pilot and no save games.
newmenu_do3( "", NULL, num_options, m, (int (*)(newmenu *, d_event *, void *))main_menu_handler, menu_choice, 0, Menu_pcx_name, -1, -1);
newmenu_do3( "", NULL, num_options, m, (int (*)(newmenu *, d_event *, void *))main_menu_handler, menu_choice, 0, Menu_pcx_name);
return 0;
}
@ -1061,8 +1061,6 @@ void change_res()
gr_set_mode(Game_screen_mode);
init_cockpit();
game_init_render_buffers(SM_W(screen_mode), SM_H(screen_mode), VR_NONE);
window_close(window_get_front()); // close options dialog - it will be messy with a different resolution
do_options_menu(); // reopen it
}
int input_menuset(newmenu *menu, d_event *event, void *userdata)
@ -1503,7 +1501,7 @@ void do_multi_player_menu()
#endif
#endif
newmenu_do3( NULL, TXT_MULTIPLAYER, num_options, m, (int (*)(newmenu *, d_event *, void *))multi_player_menu_handler, menu_choice, 0, NULL, -1, -1 );
newmenu_do3( NULL, TXT_MULTIPLAYER, num_options, m, (int (*)(newmenu *, d_event *, void *))multi_player_menu_handler, menu_choice, 0, NULL );
}
#endif
@ -1540,5 +1538,5 @@ void do_options_menu()
// Fall back to main event loop
// Allows clean closing and re-opening when resolution changes
newmenu_do3( NULL, TXT_OPTIONS, 11, m, options_menuset, NULL, 0, NULL, -1, -1 );
newmenu_do3( NULL, TXT_OPTIONS, 11, m, options_menuset, NULL, 0, NULL );
}

View file

@ -3908,7 +3908,7 @@ int net_ipx_join_poll( newmenu *menu, d_event *event, void *menu_text )
case EVENT_WINDOW_CLOSE:
SurfingNet=0;
d_free(menu_text);
d_free(menu);
d_free(menus);
if (!Game_wind)
Network_status = NETSTAT_MENU; // they cancelled

View file

@ -75,6 +75,7 @@ struct newmenu
{
window *wind;
int x,y,w,h;
int swidth, sheight, fntscalex, fntscaley; // with these we check if resolution or fonts have changed so menu structure can be recreated
char *title;
char *subtitle;
int nitems;
@ -97,7 +98,7 @@ grs_bitmap *nm_background_sub = NULL;
ubyte MenuReordering=0;
ubyte SurfingNet=0;
newmenu *newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename, int width, int height, int TinyMode );
newmenu *newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename, int TinyMode );
void newmenu_close() {
if (nm_background.bm_data)
@ -311,41 +312,10 @@ void nm_rstring( int w1,int x, int y, char * s )
gr_string( x-w, y, s );
}
//for text items, constantly redraw cursor (to achieve flash)
void update_cursor( newmenu_item *item, int ScrollOffset)
{
int w,h,aw;
fix time = timer_get_fixed_seconds();
int x,y;
char * text = item->text;
Assert(item->type==NM_TYPE_INPUT_MENU || item->type==NM_TYPE_INPUT);
gr_get_string_size(" ", &w, &h, &aw );
// even with variable char widths and a box that goes over the whole screen, we maybe never get more than 75 chars on the line
if (strlen(text)>75)
text+=strlen(text)-75;
while( *text ) {
gr_get_string_size(text, &w, &h, &aw );
if ( w > item->w-FSPACX(10) )
text++;
else
break;
}
if (*text==0)
w = 0;
x = item->x+w; y = item->y - LINE_SPACING*ScrollOffset;
if (time & 0x8000)
gr_string( x, y, CURSOR_STRING );
else {
gr_setcolor( BM_XRGB(0,0,0) );
gr_rect( x, y, x+FSPACX(7), y+h );
}
}
void nm_string_inputbox( int w, int x, int y, char * text, int current )
{
int w1,h1,aw;
fix time = timer_get_fixed_seconds();
// even with variable char widths and a box that goes over the whole screen, we maybe never get more than 75 chars on the line
if (strlen(text)>75)
@ -362,10 +332,9 @@ void nm_string_inputbox( int w, int x, int y, char * text, int current )
nm_string_black( w, x, y, text );
if ( current ) {
if ( current && time & 0x8000 )
gr_string( x+w1, y, CURSOR_STRING );
}
}
void draw_item( newmenu_item *item, int is_current, int tiny )
{
@ -487,7 +456,7 @@ int newmenu_do( char * title, char * subtitle, int nitems, newmenu_item * item,
newmenu *newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata )
{
return newmenu_do4( title, subtitle, nitems, item, subfunction, userdata, 0, NULL, -1, -1, 1 );
return newmenu_do4( title, subtitle, nitems, item, subfunction, userdata, 0, NULL, 1 );
}
@ -503,7 +472,7 @@ int newmenu_do2( char * title, char * subtitle, int nitems, newmenu_item * item,
window *wind;
int rval = -1;
menu = newmenu_do3( title, subtitle, nitems, item, subfunction, userdata, citem, filename, -1, -1 );
menu = newmenu_do3( title, subtitle, nitems, item, subfunction, userdata, citem, filename );
if (!menu)
return -1;
@ -526,15 +495,15 @@ int newmenu_do2( char * title, char * subtitle, int nitems, newmenu_item * item,
return rval;
}
newmenu *newmenu_do3( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename, int width, int height )
newmenu *newmenu_do3( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename )
{
set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
return newmenu_do4( title, subtitle, nitems, item, subfunction, userdata, citem, filename, width, height, 0 );
return newmenu_do4( title, subtitle, nitems, item, subfunction, userdata, citem, filename, 0 );
}
newmenu *newmenu_do_fixedfont( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename, int width, int height){
newmenu *newmenu_do_fixedfont( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename){
set_screen_mode(SCREEN_MENU);//hafta set the screen mode before calling or fonts might get changed/freed up if screen res changes
return newmenu_do4( title, subtitle, nitems, item, subfunction, userdata, citem, filename, width, height, 0);
return newmenu_do4( title, subtitle, nitems, item, subfunction, userdata, citem, filename, 0);
}
@ -1154,6 +1123,231 @@ int newmenu_key_command(window *wind, d_event *event, newmenu *menu)
return rval;
}
void newmenu_create_structure( newmenu *menu )
{
int i,j,aw, tw, th, twidth,fm,right_offset;
int nmenus, nothers;
grs_font *save_font;
grs_canvas *save_canvas;
int string_width, string_height, average_width;
save_canvas = grd_curcanv;
gr_set_current_canvas(NULL);
save_font = grd_curcanv->cv_font;
tw = th = 0;
if ( menu->title ) {
gr_set_curfont(HUGE_FONT);
gr_get_string_size(menu->title,&string_width,&string_height,&average_width );
tw = string_width;
th = string_height;
}
if ( menu->subtitle ) {
gr_set_curfont(MEDIUM3_FONT);
gr_get_string_size(menu->subtitle,&string_width,&string_height,&average_width );
if (string_width > tw )
tw = string_width;
th += string_height;
}
th += FSPACY(5); //put some space between titles & body
if (menu->tiny_mode)
gr_set_curfont(GAME_FONT);
else
gr_set_curfont(MEDIUM1_FONT);
menu->w = aw = 0;
menu->h = th;
nmenus = nothers = 0;
// Find menu height & width (store in w,h)
for (i=0; i<menu->nitems; i++ ) {
menu->items[i].y = menu->h;
gr_get_string_size(menu->items[i].text,&string_width,&string_height,&average_width );
menu->items[i].right_offset = 0;
menu->items[i].saved_text[0] = '\0';
if ( menu->items[i].type == NM_TYPE_SLIDER ) {
int index,w1,h1,aw1;
nothers++;
index = sprintf( menu->items[i].saved_text, "%s", SLIDER_LEFT );
for (j=0; j<(menu->items[i].max_value-menu->items[i].min_value+1); j++ ) {
index+= sprintf( menu->items[i].saved_text + index, "%s", SLIDER_MIDDLE );
}
sprintf( menu->items[i].saved_text + index, "%s", SLIDER_RIGHT );
gr_get_string_size(menu->items[i].saved_text,&w1,&h1,&aw1 );
string_width += w1 + aw;
}
if ( menu->items[i].type == NM_TYPE_MENU ) {
nmenus++;
}
if ( menu->items[i].type == NM_TYPE_CHECK ) {
int w1,h1,aw1;
nothers++;
gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
menu->items[i].right_offset = w1;
gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
if (w1 > menu->items[i].right_offset)
menu->items[i].right_offset = w1;
}
if (menu->items[i].type == NM_TYPE_RADIO ) {
int w1,h1,aw1;
nothers++;
gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
menu->items[i].right_offset = w1;
gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
if (w1 > menu->items[i].right_offset)
menu->items[i].right_offset = w1;
}
if (menu->items[i].type==NM_TYPE_NUMBER ) {
int w1,h1,aw1;
char test_text[20];
nothers++;
sprintf( test_text, "%d", menu->items[i].max_value );
gr_get_string_size( test_text, &w1, &h1, &aw1 );
menu->items[i].right_offset = w1;
sprintf( test_text, "%d", menu->items[i].min_value );
gr_get_string_size( test_text, &w1, &h1, &aw1 );
if ( w1 > menu->items[i].right_offset)
menu->items[i].right_offset = w1;
}
if ((menu->items[i].type == NM_TYPE_INPUT) || (menu->items[i].type == NM_TYPE_INPUT_MENU))
{
Assert( strlen(menu->items[i].text) < NM_MAX_TEXT_LEN );
strcpy(menu->items[i].saved_text, menu->items[i].text );
string_width = menu->items[i].text_len*FSPACX(8)+menu->items[i].text_len;
if ( menu->items[i].type == NM_TYPE_INPUT && string_width > MAX_TEXT_WIDTH )
string_width = MAX_TEXT_WIDTH;
menu->items[i].value = -1;
menu->items[i].group = 0;
if (menu->items[i].type == NM_TYPE_INPUT_MENU)
nmenus++;
else
nothers++;
}
menu->items[i].w = string_width;
menu->items[i].h = string_height;
if ( string_width > menu->w )
menu->w = string_width; // Save maximum width
if ( average_width > aw )
aw = average_width;
menu->h += string_height+FSPACY(1); // Find the height of all strings
}
if (!menu->tiny_mode && i > menu->max_on_menu)
{
menu->is_scroll_box=1;
menu->h=((menu->max_on_menu+(menu->subtitle?1:0))*LINE_SPACING);
menu->max_displayable=menu->max_on_menu;
// if our last citem was > menu->max_on_menu, make sure we re-scroll when we call this menu again
if (menu->citem > menu->max_on_menu-4)
{
menu->scroll_offset = menu->citem - (menu->max_on_menu-4);
if (menu->scroll_offset + menu->max_on_menu > menu->nitems)
menu->scroll_offset = menu->nitems - menu->max_on_menu;
}
}
else
{
menu->is_scroll_box=0;
menu->max_on_menu=i;
}
right_offset=0;
for (i=0; i<menu->nitems; i++ ) {
menu->items[i].w = menu->w;
if (menu->items[i].right_offset > right_offset )
right_offset = menu->items[i].right_offset;
}
menu->w += right_offset;
twidth = 0;
if ( tw > menu->w ) {
twidth = ( tw - menu->w )/2;
menu->w = tw;
}
// Find min point of menu border
menu->w += BORDERX*2;
menu->h += BORDERY*2;
menu->x = (GWIDTH-menu->w)/2;
menu->y = (GHEIGHT-menu->h)/2;
if ( menu->x < 0 ) menu->x = 0;
if ( menu->y < 0 ) menu->y = 0;
nm_draw_background1( menu->filename );
// Update all item's x & y values.
for (i=0; i<menu->nitems; i++ ) {
menu->items[i].x = BORDERX + twidth + right_offset;
menu->items[i].y += BORDERY;
if ( menu->items[i].type==NM_TYPE_RADIO ) {
fm = -1; // find first marked one
for ( j=0; j<menu->nitems; j++ ) {
if ( menu->items[j].type==NM_TYPE_RADIO && menu->items[j].group==menu->items[i].group ) {
if (fm==-1 && menu->items[j].value)
fm = j;
menu->items[j].value = 0;
}
}
if ( fm>=0 )
menu->items[fm].value=1;
else
menu->items[i].value=1;
}
}
if (menu->citem != -1)
{
if (menu->citem < 0 ) menu->citem = 0;
if (menu->citem > menu->nitems-1 ) menu->citem = menu->nitems-1;
#ifdef NEWMENU_MOUSE
menu->dblclick_flag = 1;
#endif
i = 0;
while ( menu->items[menu->citem].type==NM_TYPE_TEXT ) {
menu->citem++;
i++;
if (menu->citem >= menu->nitems ) {
menu->citem=0;
}
if (i > menu->nitems ) {
menu->citem=0;
menu->all_text=1;
break;
}
}
}
menu->mouse_state = 0;
menu->swidth = SWIDTH;
menu->sheight = SHEIGHT;
menu->fntscalex = FNTScaleX;
menu->fntscaley = FNTScaleY;
gr_set_curfont(save_font);
gr_set_current_canvas(save_canvas);
}
int newmenu_draw(window *wind, newmenu *menu)
{
grs_canvas *menu_canvas = window_get_canvas(wind), *save_canvas = grd_curcanv;
@ -1161,6 +1355,15 @@ int newmenu_draw(window *wind, newmenu *menu)
int i;
int string_width, string_height, average_width;
if (menu->swidth != SWIDTH || menu->sheight != SHEIGHT || menu->fntscalex != FNTScaleX || menu->fntscalex != FNTScaleY)
{
newmenu_create_structure ( menu );
if (menu_canvas)
{
gr_init_sub_canvas(menu_canvas, &grd_curscreen->sc_canvas, menu->x, menu->y, menu->w, menu->h);
}
}
gr_set_current_canvas( NULL );
nm_draw_background1(menu->filename);
if (menu->filename == NULL)
@ -1225,11 +1428,6 @@ int newmenu_draw(window *wind, newmenu *menu)
}
if (wind == window_get_front())
for (i=menu->scroll_offset; i<menu->max_displayable+menu->scroll_offset; i++ )
if (i==menu->citem && (menu->items[i].type==NM_TYPE_INPUT || (menu->items[i].type==NM_TYPE_INPUT_MENU && menu->items[i].group)))
update_cursor( &menu->items[i],menu->scroll_offset);
{
d_event event;
@ -1316,15 +1514,11 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu)
return 0;
}
newmenu *newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename, int width, int height, int TinyMode )
newmenu *newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char * filename, int TinyMode )
{
window *wind = NULL;
newmenu *menu;
int i,j,aw, tw, th, twidth,fm,right_offset;
int nmenus, nothers;
grs_font * save_font;
int string_width, string_height, average_width;
grs_canvas *menu_canvas, *save_canvas;
grs_canvas *menu_canvas;
MALLOC(menu, newmenu, 1);
@ -1359,176 +1553,7 @@ newmenu *newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item *
menu->max_displayable=nitems;
save_canvas = grd_curcanv;
gr_set_current_canvas(NULL);
save_font = grd_curcanv->cv_font;
tw = th = 0;
if ( title ) {
gr_set_curfont(HUGE_FONT);
gr_get_string_size(title,&string_width,&string_height,&average_width );
tw = string_width;
th = string_height;
}
if ( subtitle ) {
gr_set_curfont(MEDIUM3_FONT);
gr_get_string_size(subtitle,&string_width,&string_height,&average_width );
if (string_width > tw )
tw = string_width;
th += string_height;
}
th += FSPACY(5); //put some space between titles & body
if (TinyMode)
gr_set_curfont(GAME_FONT);
else
gr_set_curfont(MEDIUM1_FONT);
menu->w = aw = 0;
menu->h = th;
nmenus = nothers = 0;
// Find menu height & width (store in w,h)
for (i=0; i<nitems; i++ ) {
item[i].y = menu->h;
gr_get_string_size(item[i].text,&string_width,&string_height,&average_width );
item[i].right_offset = 0;
item[i].saved_text[0] = '\0';
if ( item[i].type == NM_TYPE_SLIDER ) {
int index,w1,h1,aw1;
nothers++;
index = sprintf( item[i].saved_text, "%s", SLIDER_LEFT );
for (j=0; j<(item[i].max_value-item[i].min_value+1); j++ ) {
index+= sprintf( item[i].saved_text + index, "%s", SLIDER_MIDDLE );
}
sprintf( item[i].saved_text + index, "%s", SLIDER_RIGHT );
gr_get_string_size(item[i].saved_text,&w1,&h1,&aw1 );
string_width += w1 + aw;
}
if ( item[i].type == NM_TYPE_MENU ) {
nmenus++;
}
if ( item[i].type == NM_TYPE_CHECK ) {
int w1,h1,aw1;
nothers++;
gr_get_string_size(NORMAL_CHECK_BOX, &w1, &h1, &aw1 );
item[i].right_offset = w1;
gr_get_string_size(CHECKED_CHECK_BOX, &w1, &h1, &aw1 );
if (w1 > item[i].right_offset)
item[i].right_offset = w1;
}
if (item[i].type == NM_TYPE_RADIO ) {
int w1,h1,aw1;
nothers++;
gr_get_string_size(NORMAL_RADIO_BOX, &w1, &h1, &aw1 );
item[i].right_offset = w1;
gr_get_string_size(CHECKED_RADIO_BOX, &w1, &h1, &aw1 );
if (w1 > item[i].right_offset)
item[i].right_offset = w1;
}
if (item[i].type==NM_TYPE_NUMBER ) {
int w1,h1,aw1;
char test_text[20];
nothers++;
sprintf( test_text, "%d", item[i].max_value );
gr_get_string_size( test_text, &w1, &h1, &aw1 );
item[i].right_offset = w1;
sprintf( test_text, "%d", item[i].min_value );
gr_get_string_size( test_text, &w1, &h1, &aw1 );
if ( w1 > item[i].right_offset)
item[i].right_offset = w1;
}
if ((item[i].type == NM_TYPE_INPUT) || (item[i].type == NM_TYPE_INPUT_MENU))
{
Assert( strlen(item[i].text) < NM_MAX_TEXT_LEN );
strcpy(item[i].saved_text, item[i].text );
string_width = item[i].text_len*FSPACX(8)+item[i].text_len;
if ( string_width > MAX_TEXT_WIDTH )
string_width = MAX_TEXT_WIDTH;
item[i].value = -1;
item[i].group = 0;
if (item[i].type == NM_TYPE_INPUT_MENU)
nmenus++;
else
nothers++;
}
item[i].w = string_width;
item[i].h = string_height;
if ( string_width > menu->w )
menu->w = string_width; // Save maximum width
if ( average_width > aw )
aw = average_width;
menu->h += string_height+FSPACY(1); // Find the height of all strings
}
if (!TinyMode && i > menu->max_on_menu)
{
menu->is_scroll_box=1;
menu->h=((menu->max_on_menu+(subtitle?1:0))*LINE_SPACING);
menu->max_displayable=menu->max_on_menu;
// if our last citem was > menu->max_on_menu, make sure we re-scroll when we call this menu again
if (citem > menu->max_on_menu-4)
{
menu->scroll_offset = citem - (menu->max_on_menu-4);
if (menu->scroll_offset + menu->max_on_menu > nitems)
menu->scroll_offset = nitems - menu->max_on_menu;
}
}
else
{
menu->is_scroll_box=0;
menu->max_on_menu=i;
}
right_offset=0;
if ( width > -1 )
menu->w = width;
if ( height > -1 )
menu->h = height;
for (i=0; i<nitems; i++ ) {
item[i].w = menu->w;
if (item[i].right_offset > right_offset )
right_offset = item[i].right_offset;
}
menu->w += right_offset;
twidth = 0;
if ( tw > menu->w ) {
twidth = ( tw - menu->w )/2;
menu->w = tw;
}
// Find min point of menu border
menu->w += BORDERX*2;
menu->h += BORDERY*2;
menu->x = (GWIDTH-menu->w)/2;
menu->y = (GHEIGHT-menu->h)/2;
if ( menu->x < 0 ) menu->x = 0;
if ( menu->y < 0 ) menu->y = 0;
nm_draw_background1( menu->filename );
newmenu_create_structure(menu);
// Create the basic window
if (menu)
@ -1539,59 +1564,8 @@ newmenu *newmenu_do4( char * title, char * subtitle, int nitems, newmenu_item *
return NULL;
}
menu->wind = wind;
menu_canvas = window_get_canvas(wind);
gr_set_curfont(save_font);
gr_set_current_canvas(menu_canvas);
// Update all item's x & y values.
for (i=0; i<nitems; i++ ) {
item[i].x = BORDERX + twidth + right_offset;
item[i].y += BORDERY;
if ( item[i].type==NM_TYPE_RADIO ) {
fm = -1; // find first marked one
for ( j=0; j<nitems; j++ ) {
if ( item[j].type==NM_TYPE_RADIO && item[j].group==item[i].group ) {
if (fm==-1 && item[j].value)
fm = j;
item[j].value = 0;
}
}
if ( fm>=0 )
item[fm].value=1;
else
item[i].value=1;
}
}
if (citem==-1) {
menu->citem = -1;
} else {
if (citem < 0 ) citem = 0;
if (citem > nitems-1 ) citem = nitems-1;
menu->citem = citem;
#ifdef NEWMENU_MOUSE
menu->dblclick_flag = 1;
#endif
while ( item[menu->citem].type==NM_TYPE_TEXT ) {
menu->citem++;
if (menu->citem >= nitems ) {
menu->citem=0;
}
if (menu->citem == citem ) {
menu->citem=0;
menu->all_text=1;
break;
}
}
}
menu->mouse_state = 0;
gr_set_current_canvas(save_canvas);
return menu;
}
@ -1683,6 +1657,7 @@ struct listbox
int (*listbox_callback)(listbox *lb, d_event *event, void *userdata);
int citem, first_item;
int box_w, height, box_x, box_y, title_height;
int swidth, sheight, fntscalex, fntscaley; // with these we check if resolution or fonts have changed so listbox structure can be recreated
int mouse_state;
void *userdata;
};
@ -1871,10 +1846,56 @@ int listbox_key_command(window *wind, d_event *event, listbox *lb)
return rval;
}
void listbox_create_structure( listbox *lb)
{
int i = 0;
gr_set_current_canvas(NULL);
gr_set_curfont(MEDIUM3_FONT);
lb->box_w = 0;
for (i=0; i<lb->nitems; i++ ) {
int w, h, aw;
gr_get_string_size( lb->item[i], &w, &h, &aw );
if ( w > lb->box_w )
lb->box_w = w+FSPACX(10);
}
lb->height = LINE_SPACING * LB_ITEMS_ON_SCREEN;
{
int w, h, aw;
gr_get_string_size( lb->title, &w, &h, &aw );
if ( w > lb->box_w )
lb->box_w = w;
lb->title_height = h+FSPACY(5);
}
lb->box_x = (grd_curcanv->cv_bitmap.bm_w-lb->box_w)/2;
lb->box_y = (grd_curcanv->cv_bitmap.bm_h-(lb->height+lb->title_height))/2 + lb->title_height;
if ( lb->box_y < lb->title_height )
lb->box_y = lb->title_height;
if ( lb->citem < 0 ) lb->citem = 0;
if ( lb->citem >= lb->nitems ) lb->citem = 0;
lb->first_item = 0;
update_scroll_position(lb);
lb->mouse_state = 0; //dblclick_flag = 0;
lb->swidth = SWIDTH;
lb->sheight = SHEIGHT;
lb->fntscalex = FNTScaleX;
lb->fntscaley = FNTScaleY;
}
int listbox_draw(window *wind, listbox *lb)
{
int i;
if (lb->swidth != SWIDTH || lb->sheight != SHEIGHT || lb->fntscalex != FNTScaleX || lb->fntscalex != FNTScaleY)
listbox_create_structure ( lb );
gr_set_current_canvas(NULL);
nm_draw_background( lb->box_x-BORDERX,lb->box_y-lb->title_height-BORDERY,lb->box_x+lb->box_w+BORDERX,lb->box_y+lb->height+BORDERY );
gr_set_curfont(MEDIUM3_FONT);
@ -1981,7 +2002,6 @@ listbox *newmenu_listbox1( char * title, int nitems, char * items[], int allow_a
{
listbox *lb;
window *wind;
int i;
MALLOC(lb, listbox, 1);
@ -1994,35 +2014,12 @@ listbox *newmenu_listbox1( char * title, int nitems, char * items[], int allow_a
lb->title = title;
lb->nitems = nitems;
lb->item = items;
lb->citem = default_item;
lb->allow_abort_flag = allow_abort_flag;
lb->listbox_callback = listbox_callback;
lb->userdata = userdata;
gr_set_current_canvas(NULL);
gr_set_curfont(MEDIUM3_FONT);
lb->box_w = 0;
for (i=0; i<nitems; i++ ) {
int w, h, aw;
gr_get_string_size( items[i], &w, &h, &aw );
if ( w > lb->box_w )
lb->box_w = w+FSPACX(10);
}
lb->height = LINE_SPACING * LB_ITEMS_ON_SCREEN;
{
int w, h, aw;
gr_get_string_size( title, &w, &h, &aw );
if ( w > lb->box_w )
lb->box_w = w;
lb->title_height = h+FSPACY(5);
}
lb->box_x = (grd_curcanv->cv_bitmap.bm_w-lb->box_w)/2;
lb->box_y = (grd_curcanv->cv_bitmap.bm_h-(lb->height+lb->title_height))/2 + lb->title_height;
if ( lb->box_y < lb->title_height )
lb->box_y = lb->title_height;
listbox_create_structure(lb);
wind = window_create(&grd_curscreen->sc_canvas, lb->box_x-BORDERX, lb->box_y-lb->title_height-BORDERY, lb->box_w+2*BORDERX, lb->height+2*BORDERY, (int (*)(window *, d_event *, void *))listbox_handler, lb);
if (!wind)
@ -2032,15 +2029,6 @@ listbox *newmenu_listbox1( char * title, int nitems, char * items[], int allow_a
return NULL;
}
lb->citem = default_item;
if ( lb->citem < 0 ) lb->citem = 0;
if ( lb->citem >= nitems ) lb->citem = 0;
lb->first_item = 0;
update_scroll_position(lb);
lb->mouse_state = 0; //dblclick_flag = 0;
return lb;
}
@ -2069,6 +2057,6 @@ newmenu *nm_messagebox_fixedfont( char *title, int nchoices, ... )
Assert(strlen(nm_text) < MESSAGEBOX_TEXT_SIZE );
return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, NULL, 0, NULL, -1, -1 );
return newmenu_do_fixedfont( title, nm_text, nchoices, nm_message_items, NULL, NULL, 0, NULL );
}
//end this section addition - Victor Rachels

View file

@ -68,8 +68,8 @@ extern int newmenu_do1(char *title, char *subtitle, int nitems, newmenu_item *it
// Same as above, only you can pass through what background bitmap to use.
extern int newmenu_do2(char *title, char *subtitle, int nitems, newmenu_item *item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char *filename);
// Same as above, only you can pass through the width and height
extern newmenu *newmenu_do3(char *title, char *subtitle, int nitems, newmenu_item *item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char *filename, int width, int height);
// Same as above, but returns menu instead of citem
extern newmenu *newmenu_do3(char *title, char *subtitle, int nitems, newmenu_item *item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata, int citem, char *filename);
// Tiny menu with GAME_FONT
extern newmenu *newmenu_dotiny(char * title, char * subtitle, int nitems, newmenu_item * item, int (*subfunction)(newmenu *menu, d_event *event, void *userdata), void *userdata);