diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5c110feb7..42d804a31 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D2X-Rebirth Changelog +20111103 +-------- +include/ui.h, ui/button.c, ui/dialog.c, ui/gadget.c, ui/scroll.c, ui/userbox.c: Make B1_JUST_PRESSED event-based, leave ui_dialog_do_gadgets early if a key makes another gadget current, make ui_button_do fully event-responsive (but won't *send* events yet) + 20111103 -------- main/net_udp.c, main/net_udp.h: Do not attempt to check for MULTI_PROTO_VERSION when requesting lite_info diff --git a/include/ui.h b/include/ui.h index deacf9314..4d1972dcd 100644 --- a/include/ui.h +++ b/include/ui.h @@ -243,7 +243,7 @@ typedef struct { #define B1_PRESSED (Mouse.b1_status & BUTTON_PRESSED) #define B1_RELEASED (Mouse.b1_status & BUTTON_RELEASED) -#define B1_JUST_PRESSED (Mouse.b1_status & BUTTON_JUST_PRESSED) +#define B1_JUST_PRESSED (event->type == EVENT_MOUSE_BUTTON_DOWN && event_mouse_get_button(event) == 0) #define B1_JUST_RELEASED (Mouse.b1_status & BUTTON_JUST_RELEASED) #define B1_DOUBLE_CLICKED (Mouse.b1_status & BUTTON_DOUBLE_CLICKED) diff --git a/ui/button.c b/ui/button.c index aeb556d2d..1689bca9f 100644 --- a/ui/button.c +++ b/ui/button.c @@ -26,6 +26,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "event.h" #include "gr.h" #include "ui.h" +#include "mouse.h" #include "key.h" #define Middle(x) ((2*(x)+1)/4) @@ -130,65 +131,63 @@ UI_GADGET_BUTTON * ui_add_gadget_button( UI_DIALOG * dlg, short x, short y, shor int ui_button_do( UI_GADGET_BUTTON * button, d_event *event ) { - int OnMe, ButtonLastSelected; - int keypress = 0; int rval = 0; - if (event->type == EVENT_KEY_COMMAND) - keypress = event_key_get(event); - - OnMe = ui_mouse_on_gadget( (UI_GADGET *)button ); - button->oldposition = button->position; + button->pressed = 0; - if (selected_gadget != NULL) + if (event->type == EVENT_MOUSE_BUTTON_DOWN || event->type == EVENT_MOUSE_BUTTON_UP) { - if (selected_gadget->kind==1) - ButtonLastSelected = 1; - else - ButtonLastSelected = 0; - } else - ButtonLastSelected = 1; + int OnMe; + OnMe = ui_mouse_on_gadget( (UI_GADGET *)button ); - if ( B1_PRESSED && OnMe && ButtonLastSelected ) - { + if (B1_JUST_PRESSED && OnMe) + { + button->position = 1; + rval = 1; + } + else if (B1_JUST_RELEASED) + { + if ((button->position == 1) && OnMe) + button->pressed = 1; - button->position = 1; - } else { - button->position = 0; - } - - if (keypress == button->hotkey ) - { - button->position = 2; - last_keypress = 0; - } - - if ((keypress == button->hotkey1) && button->user_function1 ) - { - button->user_function1(); - last_keypress = 0; + button->position = 0; + } } - //if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) ) - // button->position = 2; + if (event->type == EVENT_KEY_COMMAND) + { + int keypress; + + keypress = event_key_get(event); - if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) && ((keypress==KEY_SPACEBAR) || (keypress==KEY_ENTER)) ) - button->position = 2; - - if (CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) - if ((button->oldposition==2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) ) + if ((keypress == button->hotkey) || + ((keypress == button->hotkey1) && button->user_function1) || + ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) && ((keypress==KEY_SPACEBAR) || (keypress==KEY_ENTER)) )) + { button->position = 2; + rval = 1; + } + } + else if (event->type == EVENT_KEY_RELEASE) + { + int keypress; + + keypress = event_key_get(event); + + button->position = 0; - button->pressed = 0; + if ((keypress == button->hotkey) || + ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) && ((keypress==KEY_SPACEBAR) || (keypress==KEY_ENTER)) )) + button->pressed = 1; - if (button->position==0) { - if ( (button->oldposition==1) && OnMe ) - button->pressed = 1; - if ( (button->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)button) ) - button->pressed = 1; + if ((keypress == button->hotkey1) && button->user_function1) + { + button->user_function1(); + rval = 1; + } } ui_draw_button( button ); @@ -196,6 +195,7 @@ int ui_button_do( UI_GADGET_BUTTON * button, d_event *event ) if (button->pressed && button->user_function ) { button->user_function(); + rval = 1; } return rval; diff --git a/ui/dialog.c b/ui/dialog.c index 12a9e309b..231b0117b 100644 --- a/ui/dialog.c +++ b/ui/dialog.c @@ -233,6 +233,7 @@ int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) break; case EVENT_KEY_COMMAND: + case EVENT_KEY_RELEASE: return ui_dialog_do_gadgets(dlg, event); break; diff --git a/ui/gadget.c b/ui/gadget.c index b1253ceec..2cc273690 100644 --- a/ui/gadget.c +++ b/ui/gadget.c @@ -263,6 +263,9 @@ int ui_dialog_do_gadgets(UI_DIALOG * dlg, d_event *event) if (tmp1 != NULL ) tmp1->status = 1; rval = 1; + + if (keypress) + return rval; } tmp = dlg->gadget; diff --git a/ui/scroll.c b/ui/scroll.c index 539ebb5e4..cb8d5f924 100644 --- a/ui/scroll.c +++ b/ui/scroll.c @@ -23,6 +23,7 @@ static char rcsid[] = "$Id: scroll.c,v 1.1.1.1 2006/03/17 19:52:16 zicodxx Exp $ #include "event.h" #include "gr.h" #include "ui.h" +#include "mouse.h" #include "key.h" #include "timer.h" diff --git a/ui/userbox.c b/ui/userbox.c index 8605c6769..f2a6e20ab 100644 --- a/ui/userbox.c +++ b/ui/userbox.c @@ -24,6 +24,7 @@ static char rcsid[] = "$Id: userbox.c,v 1.1.1.1 2006/03/17 19:52:22 zicodxx Exp #include "event.h" #include "gr.h" #include "ui.h" +#include "mouse.h" #include "key.h" void ui_draw_userbox( UI_GADGET_USERBOX * userbox )