2006-03-20 17:12:09 +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
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef RCS
|
|
|
|
static char rcsid[] = "$Id: popup.c,v 1.1.1.1 2006/03/17 19:52:22 zicodxx Exp $";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "fix.h"
|
|
|
|
#include "pstypes.h"
|
|
|
|
#include "gr.h"
|
2011-01-14 09:51:13 +00:00
|
|
|
#include "event.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "ui.h"
|
2012-01-09 15:17:10 +00:00
|
|
|
#include "u_mem.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "mouse.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define MENU_BORDER 2
|
|
|
|
#define MENU_VERT_SPACING 2
|
|
|
|
|
2012-01-09 15:17:10 +00:00
|
|
|
typedef struct popup
|
|
|
|
{
|
|
|
|
UI_GADGET_BUTTON *button_g[10];
|
|
|
|
int *choice;
|
|
|
|
int num_buttons;
|
|
|
|
} popup;
|
|
|
|
|
|
|
|
static int popup_handler(UI_DIALOG *dlg, d_event *event, popup *p)
|
|
|
|
{
|
|
|
|
short i;
|
|
|
|
|
|
|
|
for (i=0; i<p->num_buttons; i++ )
|
|
|
|
{
|
2012-03-05 11:08:41 +00:00
|
|
|
if (GADGET_PRESSED(p->button_g[i]))
|
2012-01-09 15:17:10 +00:00
|
|
|
{
|
|
|
|
*(p->choice) = i+1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (*(p->choice)==0) && B1_JUST_RELEASED )
|
|
|
|
{
|
|
|
|
*(p->choice) = -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2012-01-09 15:17:10 +00:00
|
|
|
// Use: Left button (button 0) goes down, then up, then this is called
|
|
|
|
// as opposed to straight after the button goes down, holding down
|
|
|
|
// until an option is chosen.
|
|
|
|
// This is like the 'modern' behaviour of popup menus and also happens
|
|
|
|
// to be easier to implement because of the button code.
|
|
|
|
// Recommended for use in conjunction with a button gadget,
|
|
|
|
// i.e. when that button is pressed, call PopupMenu,
|
|
|
|
// update the button's text then the value in question.
|
2006-03-20 17:12:09 +00:00
|
|
|
int PopupMenu( int NumButtons, char * text[] )
|
|
|
|
{
|
2011-01-17 14:42:18 +00:00
|
|
|
UI_DIALOG * dlg;
|
2012-01-09 15:17:10 +00:00
|
|
|
popup *p;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
char * Button[10];
|
|
|
|
|
|
|
|
int button_width, button_height, width, height;
|
|
|
|
|
|
|
|
short i, x, y;
|
|
|
|
short w, h;
|
|
|
|
|
|
|
|
int choice;
|
|
|
|
|
2012-01-09 15:17:10 +00:00
|
|
|
MALLOC(p, popup, 1);
|
|
|
|
|
|
|
|
p->num_buttons = NumButtons;
|
|
|
|
p->choice = &choice;
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
if ((NumButtons < 1) || (NumButtons>10))
|
|
|
|
{
|
2012-01-09 15:17:10 +00:00
|
|
|
d_free(p);
|
2006-03-20 17:12:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
button_width = button_height = 0;
|
|
|
|
|
|
|
|
gr_set_current_canvas( &grd_curscreen->sc_canvas );
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-01-09 15:17:10 +00:00
|
|
|
{
|
|
|
|
int mx, my, mz;
|
|
|
|
|
|
|
|
mouse_get_pos(&mx, &my, &mz);
|
|
|
|
x = mx - width/2;
|
|
|
|
y = my - (MENU_BORDER+3) - button_height/2;
|
|
|
|
}
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
w = grd_curscreen->sc_w;
|
|
|
|
h = grd_curscreen->sc_h;
|
|
|
|
|
|
|
|
if (x < 0 ) {
|
|
|
|
x = 0;
|
2012-01-09 15:17:10 +00:00
|
|
|
//Mouse.x = x + width / 2;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (x+width-1) >= w ) {
|
|
|
|
x = w - width;
|
2012-01-09 15:17:10 +00:00
|
|
|
//Mouse.x = x + width / 2;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (y < 0 ) {
|
|
|
|
y = 0;
|
2012-01-09 15:17:10 +00:00
|
|
|
//Mouse.y = y + (MENU_BORDER+3) + button_height/2;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (y+height-1) >= h ) {
|
|
|
|
y = h - height;
|
2012-01-09 15:17:10 +00:00
|
|
|
//Mouse.y = y + (MENU_BORDER+3) + button_height/2;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 15:17:10 +00:00
|
|
|
dlg = ui_create_dialog( x, y, width, height, DF_DIALOG | DF_MODAL, (int (*)(UI_DIALOG *, d_event *, void *))popup_handler, p );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//mouse_set_pos(Mouse.x, Mouse.y);
|
|
|
|
|
|
|
|
x = MENU_BORDER+3;
|
|
|
|
y = MENU_BORDER+3;
|
|
|
|
|
|
|
|
for (i=0; i<NumButtons; i++ )
|
|
|
|
{
|
2012-01-09 15:17:10 +00:00
|
|
|
p->button_g[i] = ui_add_gadget_button( dlg, x, y, button_width, button_height, Button[i], NULL );
|
2006-03-20 17:12:09 +00:00
|
|
|
y += button_height+MENU_VERT_SPACING;
|
|
|
|
}
|
|
|
|
|
|
|
|
choice = 0;
|
|
|
|
|
|
|
|
while(choice==0)
|
2011-01-14 09:51:13 +00:00
|
|
|
event_process();
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2011-01-17 14:42:18 +00:00
|
|
|
ui_close_dialog(dlg);
|
2012-01-09 15:17:10 +00:00
|
|
|
d_free(p);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
return choice;
|
|
|
|
}
|
|
|
|
|