2010-12-24 04:26:24 +00:00
|
|
|
/* $Id: menu.c,v 1.1.1.1 2006/03/17 19:52:19 zicodxx Exp $ */
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
2010-12-24 04:26:24 +00:00
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
2006-03-20 16:43:15 +00:00
|
|
|
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef RCS
|
2010-12-24 04:26:24 +00:00
|
|
|
static char rcsid[] = "$Id: menu.c,v 1.1.1.1 2006/03/17 19:52:19 zicodxx Exp $";
|
2006-03-20 16:43:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "u_mem.h"
|
|
|
|
#include "fix.h"
|
2008-01-02 03:37:13 +00:00
|
|
|
#include "pstypes.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "gr.h"
|
2011-01-13 04:36:19 +00:00
|
|
|
#include "event.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include "ui.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define MENU_BORDER 2
|
|
|
|
#define MENU_VERT_SPACING 2
|
|
|
|
|
|
|
|
int MenuX( int x, int y, int NumButtons, char * text[] )
|
|
|
|
{
|
2011-01-17 14:41:05 +00:00
|
|
|
UI_DIALOG * dlg;
|
2006-03-20 16:43:15 +00:00
|
|
|
UI_GADGET_BUTTON ** ButtonG;
|
|
|
|
char ** Button;
|
|
|
|
|
|
|
|
int button_width, button_height, width, height;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
|
2010-12-24 04:26:24 +00:00
|
|
|
ButtonG = (UI_GADGET_BUTTON **) d_malloc(sizeof(UI_GADGET_BUTTON *)*NumButtons);
|
|
|
|
Button = (char **) d_malloc(sizeof(char *)*NumButtons);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
button_width = button_height = 0;
|
|
|
|
|
|
|
|
for (i=0; i<NumButtons; i++ )
|
|
|
|
{
|
|
|
|
Button[i] = text[i];
|
|
|
|
|
|
|
|
ui_get_button_size( Button[i], &width, &height );
|
|
|
|
|
|
|
|
if ( width > button_width ) button_width = width;
|
|
|
|
if ( height > button_height ) button_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = button_width + 2*(MENU_BORDER+3);
|
|
|
|
|
|
|
|
height = (button_height*NumButtons) + (MENU_VERT_SPACING*(NumButtons-1)) ;
|
|
|
|
height += (MENU_BORDER+3) * 2;
|
|
|
|
|
|
|
|
w = grd_curscreen->sc_w;
|
|
|
|
h = grd_curscreen->sc_h;
|
|
|
|
|
|
|
|
if ( x == -1 ) x = Mouse.x - width/2;
|
|
|
|
if ( y == -1 ) y = Mouse.y;
|
|
|
|
|
|
|
|
if (x < 0 ) {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (x+width-1) >= w ) {
|
|
|
|
x = w - width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y < 0 ) {
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (y+height-1) >= h ) {
|
|
|
|
y = h - height;
|
|
|
|
}
|
|
|
|
|
2011-10-09 10:31:44 +00:00
|
|
|
dlg = ui_create_dialog( x, y, width, height, DF_FILLED | DF_SAVE_BG | DF_MODAL, NULL, NULL );
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
x = MENU_BORDER+3;
|
|
|
|
y = MENU_BORDER+3;
|
|
|
|
|
|
|
|
for (i=0; i<NumButtons; i++ )
|
|
|
|
{
|
2011-01-17 14:41:05 +00:00
|
|
|
ButtonG[i] = ui_add_gadget_button( dlg, x, y, button_width, button_height, Button[i], NULL );
|
2006-03-20 16:43:15 +00:00
|
|
|
y += button_height+MENU_VERT_SPACING;
|
|
|
|
}
|
|
|
|
|
|
|
|
choice = 0;
|
|
|
|
|
|
|
|
while(choice==0)
|
|
|
|
{
|
2011-01-13 04:36:19 +00:00
|
|
|
event_process();
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
for (i=0; i<NumButtons; i++ )
|
|
|
|
{
|
|
|
|
if (ButtonG[i]->pressed) {
|
|
|
|
choice = i+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (choice==0) && B1_JUST_RELEASED ) {
|
|
|
|
choice = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:41:05 +00:00
|
|
|
ui_close_dialog(dlg);
|
2008-01-23 17:25:09 +00:00
|
|
|
d_free(Button);
|
|
|
|
d_free(ButtonG);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
return choice;
|
|
|
|
|
|
|
|
}
|
|
|
|
|