Pass the event to ui_dialog_do_gadgets and use it in that immediate function

This commit is contained in:
Chris Taylor 2011-10-23 17:07:18 +08:00
parent 87c8c25580
commit 5d6c06c723
4 changed files with 30 additions and 10 deletions

View file

@ -1,5 +1,9 @@
D1X-Rebirth Changelog
20111023
--------
include/ui.h, ui/dialog.c, ui/gadget.c: Pass the event to ui_dialog_do_gadgets and use it in that immediate function
20111009
--------
main/render.c: Initialise dyn_light using memset, fixing a warning

View file

@ -286,7 +286,7 @@ extern void ui_close_dialog( UI_DIALOG * dlg );
extern UI_GADGET * ui_gadget_add( UI_DIALOG * dlg, short kind, short x1, short y1, short x2, short y2 );
extern UI_GADGET_BUTTON * ui_add_gadget_button( UI_DIALOG * dlg, short x, short y, short w, short h, char * text, int (*function_to_call)(void) );
extern void ui_gadget_delete_all( UI_DIALOG * dlg );
extern void ui_dialog_do_gadgets( UI_DIALOG * dlg );
extern int ui_dialog_do_gadgets( UI_DIALOG * dlg, struct d_event *event );
extern void ui_draw_button( UI_GADGET_BUTTON * button );
extern int ui_mouse_on_gadget( UI_GADGET * gadget );

View file

@ -228,16 +228,16 @@ int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg)
case EVENT_MOUSE_BUTTON_DOWN:
case EVENT_MOUSE_BUTTON_UP:
/*return*/ ui_dialog_do_gadgets(dlg);
return ui_dialog_do_gadgets(dlg, event);
break;
case EVENT_KEY_COMMAND:
/*return*/ ui_dialog_do_gadgets(dlg);
return ui_dialog_do_gadgets(dlg, event);
break;
case EVENT_IDLE:
timer_delay2(50);
/*return*/ ui_dialog_do_gadgets(dlg);
return ui_dialog_do_gadgets(dlg, event);
break;
case EVENT_WINDOW_DRAW:

View file

@ -24,6 +24,7 @@ static char rcsid[] = "$Id: gadget.c,v 1.1.1.1 2006/03/17 19:52:21 zicodxx Exp $
#include "pstypes.h"
#include "gr.h"
#include "ui.h"
#include "event.h"
#include "error.h"
#include "key.h"
@ -124,6 +125,7 @@ void ui_gadget_delete_all( UI_DIALOG * dlg )
}
#if 0
int is_under_another_window( UI_DIALOG * dlg, UI_GADGET * gadget )
{
UI_DIALOG * temp;
@ -157,30 +159,40 @@ int is_under_another_window( UI_DIALOG * dlg, UI_GADGET * gadget )
}
return 0;
}
#endif
int ui_mouse_on_gadget( UI_GADGET * gadget )
{
if ((Mouse.x >= gadget->x1) && (Mouse.x <= gadget->x2-1) && (Mouse.y >= gadget->y1) && (Mouse.y <= gadget->y2-1) ) {
int x, y, z;
mouse_get_pos(&x, &y, &z);
if ((x >= gadget->x1) && (x <= gadget->x2-1) && (y >= gadget->y1) && (y <= gadget->y2-1) )
{
#if 0
if (is_under_another_window(CurWindow, gadget))
return 0;
#endif
return 1;
} else
return 0;
}
void ui_dialog_do_gadgets( UI_DIALOG * dlg )
int ui_dialog_do_gadgets(UI_DIALOG * dlg, d_event *event)
{
int keypress;
int keypress = 0;
UI_GADGET * tmp, * tmp1;
int z;
int rval = 0;
CurWindow = dlg;
keypress = last_keypress;
if (event->type == EVENT_KEY_COMMAND)
keypress = event_key_get(event);
tmp = dlg->gadget;
if (tmp == NULL ) return;
if (tmp == NULL) return;
if (selected_gadget==NULL)
selected_gadget = tmp;
@ -250,12 +262,14 @@ void ui_dialog_do_gadgets( UI_DIALOG * dlg )
dlg->keyboard_focus_gadget->status = 1;
if (tmp1 != NULL )
tmp1->status = 1;
rval = 1;
}
tmp = dlg->gadget;
do
{
if (!is_under_another_window( CurWindow, tmp )) {
//if (!is_under_another_window( CurWindow, tmp )) // not necessary as events are handled by the front window then propagate down
{
UI_DIALOG *curwindow_save=CurWindow;
switch( tmp->kind )
@ -294,6 +308,8 @@ void ui_dialog_do_gadgets( UI_DIALOG * dlg )
tmp = tmp->next;
} while( tmp != dlg->gadget );
return rval;
}