diff --git a/common/arch/sdl/window.cpp b/common/arch/sdl/window.cpp index f74755b97..e6e46e9d8 100644 --- a/common/arch/sdl/window.cpp +++ b/common/arch/sdl/window.cpp @@ -22,7 +22,7 @@ struct window { grs_canvas w_canv; // the window's canvas to draw to - int (*w_callback)(window *wind, d_event *event, void *data); // the event handler + window_event_result (*w_callback)(window *wind, d_event *event, void *data); // the event handler int w_visible; // whether it's visible int w_modal; // modal = accept all user input exclusively void *data; // whatever the user wants (eg menu data for 'newmenu' menus) @@ -71,12 +71,12 @@ int window_close(window *wind) { window *prev; d_event event; - int (*w_callback)(window *wind, d_event *event, void *data) = wind->w_callback; + window_event_result (*w_callback)(window *wind, d_event *event, void *data) = wind->w_callback; if (wind == window_get_front()) WINDOW_SEND_EVENT(wind, EVENT_WINDOW_DEACTIVATED); // Deactivate first - if (WINDOW_SEND_EVENT(wind, EVENT_WINDOW_CLOSE)) + if (WINDOW_SEND_EVENT(wind, EVENT_WINDOW_CLOSE) == window_event_result::handled) { // User 'handled' the event, cancelling close if (wind == window_get_front()) @@ -208,7 +208,7 @@ extern void window_update_canvases(void) wind->w_canv.cv_bitmap.bm_h); } -int window_send_event(window *wind, d_event *event) +window_event_result window_send_event(window *wind, d_event *event) { return wind->w_callback(wind, event, wind->data); } diff --git a/common/include/mouse.h b/common/include/mouse.h index c236953a8..241240014 100644 --- a/common/include/mouse.h +++ b/common/include/mouse.h @@ -17,9 +17,9 @@ #include "maths.h" #ifdef __cplusplus +#include "window.h" struct d_event; -struct window; struct SDL_MouseButtonEvent; struct SDL_MouseMotionEvent; @@ -51,7 +51,7 @@ extern void mouse_init(void); extern void mouse_close(void); extern int event_mouse_get_button(struct d_event *event); extern void mouse_get_pos( int *x, int *y, int *z ); -extern int mouse_in_window(struct window *wind); +window_event_result mouse_in_window(struct window *wind); extern void mouse_get_delta( int *dx, int *dy, int *dz ); extern void event_mouse_get_delta(struct d_event *event, int *dx, int *dy, int *dz); extern int mouse_get_btns(); diff --git a/common/include/ui.h b/common/include/ui.h index 7d014ed3b..bc49999b0 100644 --- a/common/include/ui.h +++ b/common/include/ui.h @@ -32,11 +32,11 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #ifdef __cplusplus #include "varutil.h" +#include "window.h" struct grs_bitmap; struct grs_canvas; struct grs_font; -struct window; struct UI_KEYPAD { char description[100]; @@ -271,16 +271,16 @@ 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, const char * text, int (*function_to_call)(void) ); extern void ui_gadget_delete_all( UI_DIALOG * dlg ); -extern int ui_gadget_send_event(UI_DIALOG *dlg, enum event_type type, UI_GADGET *gadget); +window_event_result ui_gadget_send_event(UI_DIALOG *dlg, enum event_type type, UI_GADGET *gadget); extern UI_GADGET *ui_event_get_gadget(struct d_event *event); -extern int ui_dialog_do_gadgets( UI_DIALOG * dlg, struct d_event *event ); +window_event_result ui_dialog_do_gadgets( UI_DIALOG * dlg, struct d_event *event ); extern void ui_draw_button( UI_DIALOG *dlg, UI_GADGET_BUTTON * button ); extern int ui_mouse_on_gadget( UI_GADGET * gadget ); -extern int ui_button_do( UI_DIALOG *dlg, UI_GADGET_BUTTON * button, struct d_event *event ); +window_event_result ui_button_do( UI_DIALOG *dlg, UI_GADGET_BUTTON * button, struct d_event *event ); -extern int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, struct d_event *event ); +window_event_result ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, struct d_event *event ); extern void ui_draw_listbox( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox ); extern UI_GADGET_LISTBOX *ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, short w, short h, short numitems, char **list); @@ -289,7 +289,7 @@ extern void ui_mega_process(); extern void ui_get_button_size( const char * text, int * width, int * height ); extern UI_GADGET_SCROLLBAR * ui_add_gadget_scrollbar( UI_DIALOG * dlg, short x, short y, short w, short h, int start, int stop, int position, int window_size ); -extern int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, struct d_event *event ); +window_event_result ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, struct d_event *event ); extern void ui_draw_scrollbar( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar ); @@ -299,12 +299,12 @@ extern void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, const char * forma extern void ui_draw_radio( UI_DIALOG *dlg, UI_GADGET_RADIO * radio ); extern UI_GADGET_RADIO * ui_add_gadget_radio( UI_DIALOG * dlg, short x, short y, short w, short h, short group, const char * text ); -extern int ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, struct d_event *event ); +window_event_result ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, struct d_event *event ); extern void ui_radio_set_value(UI_GADGET_RADIO *radio, int value); extern void ui_draw_checkbox( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox ); extern UI_GADGET_CHECKBOX * ui_add_gadget_checkbox( UI_DIALOG * dlg, short x, short y, short w, short h, short group, const char * text ); -extern int ui_checkbox_do( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox, struct d_event *event ); +window_event_result ui_checkbox_do( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox, struct d_event *event ); extern void ui_checkbox_check(UI_GADGET_CHECKBOX * checkbox, int check); extern UI_GADGET * ui_gadget_get_prev( UI_GADGET * gadget ); @@ -316,11 +316,11 @@ extern void ui_listbox_change(UI_DIALOG *dlg, UI_GADGET_LISTBOX *listbox, short extern void ui_draw_inputbox( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox ); extern UI_GADGET_INPUTBOX * ui_add_gadget_inputbox( UI_DIALOG * dlg, short x, short y, short w, short h, const char * text ); -extern int ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, struct d_event *event ); +window_event_result ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, struct d_event *event ); extern void ui_inputbox_set_text(UI_GADGET_INPUTBOX *inputbox, const char *text); -extern int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, struct d_event *event ); +window_event_result ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, struct d_event *event ); extern UI_GADGET_USERBOX * ui_add_gadget_userbox( UI_DIALOG * dlg, short x, short y, short w, short h ); extern void ui_draw_userbox( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox ); @@ -336,7 +336,7 @@ void * ui_malloc( int size ); void ui_free( void * buffer ); UI_GADGET_KEYTRAP * ui_add_gadget_keytrap( UI_DIALOG * dlg, int key_to_trap, int (*function_to_call)(void) ); -int ui_keytrap_do( UI_GADGET_KEYTRAP * keytrap, struct d_event *event ); +window_event_result ui_keytrap_do( UI_GADGET_KEYTRAP * keytrap, struct d_event *event ); #define UI_RECORD_MOUSE 1 #define UI_RECORD_KEYS 2 @@ -358,7 +358,7 @@ extern unsigned int ui_event_counter; int ui_get_file( char * filename, const char * Filespec ); void ui_draw_icon( UI_GADGET_ICON * icon ); -int ui_icon_do( UI_DIALOG *dlg, UI_GADGET_ICON * icon, struct d_event *event ); +window_event_result ui_icon_do( UI_DIALOG *dlg, UI_GADGET_ICON * icon, struct d_event *event ); UI_GADGET_ICON * ui_add_gadget_icon( UI_DIALOG * dlg, const char * text, short x, short y, short w, short h, int k,int (*f)(void) ); int DecodeKeyText( const char * text ); diff --git a/common/include/window.h b/common/include/window.h index 9abe9dfc8..b32dfb6f5 100644 --- a/common/include/window.h +++ b/common/include/window.h @@ -25,13 +25,22 @@ struct window; +enum class window_event_result +{ + // Window ignored event. Bubble up. + ignored, + // Window handled event. + handled, + close, +}; + void arch_init(void); template class window_subfunction_t { public: - typedef int (*type)(window *menu, d_event *event, T *userdata); + typedef window_event_result (*type)(window *menu, d_event *event, T *userdata); }; class unused_window_userdata_t; @@ -56,11 +65,11 @@ extern void window_set_visible(window *wind, int visible); extern int window_is_visible(window *wind); extern grs_canvas *window_get_canvas(window *wind); extern void window_update_canvases(void); -extern int window_send_event(window *wind, d_event *event); +window_event_result window_send_event(window *wind, d_event *event); extern void window_set_modal(window *wind, int modal); extern int window_is_modal(window *wind); -static inline int WINDOW_SEND_EVENT(window *w, d_event &event, const char *file, unsigned line, const char *e) +static inline window_event_result WINDOW_SEND_EVENT(window *w, d_event &event, const char *file, unsigned line, const char *e) { auto c = window_get_canvas(w); con_printf(CON_DEBUG, "%s:%u: sending event %s to window of dimensions %dx%d", file, line, e, c->cv_bitmap.bm_w, c->cv_bitmap.bm_h); diff --git a/common/main/automap.h b/common/main/automap.h index 9ba8f03b2..704f5d663 100644 --- a/common/main/automap.h +++ b/common/main/automap.h @@ -46,7 +46,7 @@ struct vms_vector; void DropBuddyMarker(object *objp); void InitMarkerInput(); -int MarkerInputMessage(int key); +window_event_result MarkerInputMessage(int key); static const std::size_t NUM_MARKERS = 16; static const std::size_t MARKER_MESSAGE_LEN = 40; diff --git a/common/main/game.h b/common/main/game.h index 7c217c68d..756788252 100644 --- a/common/main/game.h +++ b/common/main/game.h @@ -333,7 +333,7 @@ int allowed_to_fire_missile(void); void check_rear_view(void); window *game_setup(void); int create_special_path(void); -int ReadControls(d_event *event); +window_event_result ReadControls(d_event *event); void toggle_cockpit(void); void game_render_frame(); extern fix Show_view_text_timer; @@ -342,7 +342,7 @@ extern int Last_level_path_created; extern int force_cockpit_redraw; extern ubyte DemoDoingRight,DemoDoingLeft; extern fix64 Time_flash_last_played; -int game_handler(window *wind, d_event *event, unused_window_userdata_t *); +window_event_result game_handler(window *wind, d_event *event, unused_window_userdata_t *); #ifdef EDITOR void dump_used_textures_all(); diff --git a/common/main/multi.h b/common/main/multi.h index b7c82a8db..61e8738a1 100644 --- a/common/main/multi.h +++ b/common/main/multi.h @@ -331,7 +331,7 @@ extern int multi_quit_game; extern msgsend_state_t multi_sending_message[MAX_PLAYERS]; extern int multi_defining_message; -extern int multi_message_input_sub(int key); +window_event_result multi_message_input_sub(int key); extern void multi_send_message_start(); void multi_send_msgsend_state(msgsend_state_t state); extern int multi_powerup_is_4pack(int); diff --git a/common/ui/button.cpp b/common/ui/button.cpp index 839bf16ef..a6953e221 100644 --- a/common/ui/button.cpp +++ b/common/ui/button.cpp @@ -135,9 +135,9 @@ UI_GADGET_BUTTON * ui_add_gadget_button( UI_DIALOG * dlg, short x, short y, shor } -int ui_button_do(UI_DIALOG *dlg, UI_GADGET_BUTTON * button, d_event *event) +window_event_result ui_button_do(UI_DIALOG *dlg, UI_GADGET_BUTTON * button, d_event *event) { - int rval = 0; + window_event_result rval = window_event_result::ignored; button->oldposition = button->position; button->pressed = 0; @@ -151,7 +151,7 @@ int ui_button_do(UI_DIALOG *dlg, UI_GADGET_BUTTON * button, d_event *event) if (B1_JUST_PRESSED && OnMe) { button->position = 1; - rval = 1; + rval = window_event_result::handled; } else if (B1_JUST_RELEASED) { @@ -174,7 +174,7 @@ int ui_button_do(UI_DIALOG *dlg, UI_GADGET_BUTTON * button, d_event *event) ((dlg->keyboard_focus_gadget==(UI_GADGET *)button) && ((keypress==KEY_SPACEBAR) || (keypress==KEY_ENTER)) )) { button->position = 2; - rval = 1; + rval = window_event_result::handled; } } else if (event->type == EVENT_KEY_RELEASE) @@ -192,7 +192,7 @@ int ui_button_do(UI_DIALOG *dlg, UI_GADGET_BUTTON * button, d_event *event) if ((keypress == button->hotkey1) && button->user_function1) { button->user_function1(); - rval = 1; + rval = window_event_result::handled; } } @@ -202,12 +202,12 @@ int ui_button_do(UI_DIALOG *dlg, UI_GADGET_BUTTON * button, d_event *event) if (button->pressed && button->user_function ) { button->user_function(); - rval = 1; + return window_event_result::handled; } else if (button->pressed) { ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, (UI_GADGET *)button); - rval = 1; + return window_event_result::handled; } return rval; diff --git a/common/ui/checkbox.cpp b/common/ui/checkbox.cpp index 1227613ae..bc3da59f6 100644 --- a/common/ui/checkbox.cpp +++ b/common/ui/checkbox.cpp @@ -89,10 +89,8 @@ UI_GADGET_CHECKBOX * ui_add_gadget_checkbox( UI_DIALOG * dlg, short x, short y, } -int ui_checkbox_do( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox, d_event *event ) +window_event_result ui_checkbox_do( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox, d_event *event ) { - int rval = 0; - checkbox->oldposition = checkbox->position; checkbox->pressed = 0; @@ -105,7 +103,7 @@ int ui_checkbox_do( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox, d_event *even if (B1_JUST_PRESSED && OnMe) { checkbox->position = 1; - rval = 1; + return window_event_result::handled; } else if (B1_JUST_RELEASED) { @@ -126,7 +124,7 @@ int ui_checkbox_do( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox, d_event *even if ((dlg->keyboard_focus_gadget==(UI_GADGET *)checkbox) && ((key==KEY_SPACEBAR) || (key==KEY_ENTER)) ) { checkbox->position = 2; - rval = 1; + return window_event_result::handled; } } else if (event->type == EVENT_KEY_RELEASE) @@ -145,13 +143,13 @@ int ui_checkbox_do( UI_DIALOG *dlg, UI_GADGET_CHECKBOX * checkbox, d_event *even { checkbox->flag ^= 1; ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, (UI_GADGET *)checkbox); - rval = 1; + return window_event_result::handled; } if (event->type == EVENT_WINDOW_DRAW) ui_draw_checkbox( dlg, checkbox ); - return rval; + return window_event_result::ignored; } void ui_checkbox_check(UI_GADGET_CHECKBOX * checkbox, int check) diff --git a/common/ui/dialog.cpp b/common/ui/dialog.cpp index 236b6c5b2..be77247e2 100644 --- a/common/ui/dialog.cpp +++ b/common/ui/dialog.cpp @@ -166,21 +166,19 @@ static void ui_dialog_draw(UI_DIALOG *dlg) // The dialog handler borrows heavily from the newmenu_handler -static int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) +static window_event_result ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) { - int rval = 0; - if (event->type == EVENT_WINDOW_CLOSED || event->type == EVENT_WINDOW_ACTIVATED || event->type == EVENT_WINDOW_DEACTIVATED) - return 0; + return window_event_result::ignored; if (dlg->callback) if ((*dlg->callback)(dlg, event, dlg->userdata)) - return 1; // event handled + return window_event_result::handled; // event handled if (!window_exists(wind)) - return 1; + return window_event_result::handled; switch (event->type) { @@ -189,41 +187,32 @@ static int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) case EVENT_MOUSE_MOVED: /*return*/ ui_dialog_do_gadgets(dlg, event); if (!window_exists(wind)) - return 1; - - rval = mouse_in_window(dlg->wind); - break; - + return window_event_result::handled; + return mouse_in_window(dlg->wind); case EVENT_KEY_COMMAND: case EVENT_KEY_RELEASE: - rval = ui_dialog_do_gadgets(dlg, event); - break; - + return ui_dialog_do_gadgets(dlg, event); case EVENT_IDLE: timer_delay2(50); - rval = ui_dialog_do_gadgets(dlg, event); - break; - + return ui_dialog_do_gadgets(dlg, event); case EVENT_WINDOW_DRAW: { d_event event2 = { EVENT_UI_DIALOG_DRAW }; ui_dialog_draw(dlg); - rval = ui_dialog_do_gadgets(dlg, event); - window_send_event(wind, &event2); - break; + window_event_result rval = ui_dialog_do_gadgets(dlg, event); + if (rval != window_event_result::close) + window_send_event(wind, &event2); + return rval; } case EVENT_WINDOW_CLOSE: ui_gadget_delete_all(dlg); selected_gadget = NULL; d_free( dlg ); - break; - + return window_event_result::ignored; default: - break; + return window_event_result::ignored; } - - return rval; } template <> diff --git a/common/ui/gadget.cpp b/common/ui/gadget.cpp index 7394fb54f..3d8a0f8c0 100644 --- a/common/ui/gadget.cpp +++ b/common/ui/gadget.cpp @@ -193,43 +193,33 @@ int ui_mouse_on_gadget( UI_GADGET * gadget ) return 0; } -static int ui_gadget_do(UI_DIALOG *dlg, UI_GADGET *g, d_event *event) +static window_event_result ui_gadget_do(UI_DIALOG *dlg, UI_GADGET *g, d_event *event) { switch( g->kind ) { case 1: return ui_button_do(dlg, (UI_GADGET_BUTTON *)g, event); - break; case 2: return ui_listbox_do(dlg, (UI_GADGET_LISTBOX *)g, event); - break; case 3: return ui_scrollbar_do(dlg, (UI_GADGET_SCROLLBAR *)g, event); - break; case 4: return ui_radio_do(dlg, (UI_GADGET_RADIO *)g, event); - break; case 5: return ui_checkbox_do(dlg, (UI_GADGET_CHECKBOX *)g, event); - break; case 6: return ui_inputbox_do(dlg, (UI_GADGET_INPUTBOX *)g, event); - break; case 7: return ui_userbox_do(dlg, (UI_GADGET_USERBOX *)g, event); - break; case 8: return ui_keytrap_do((UI_GADGET_KEYTRAP *)g, event); - break; case 9: return ui_icon_do(dlg, (UI_GADGET_ICON *)g, event); - break; } - - return 0; + return window_event_result::ignored; } -int ui_gadget_send_event(UI_DIALOG *dlg, event_type type, UI_GADGET *gadget) +window_event_result ui_gadget_send_event(UI_DIALOG *dlg, event_type type, UI_GADGET *gadget) { event_gadget event; @@ -248,19 +238,18 @@ UI_GADGET *ui_event_get_gadget(d_event *event) return ((event_gadget *) event)->gadget; } -int ui_dialog_do_gadgets(UI_DIALOG * dlg, d_event *event) +window_event_result ui_dialog_do_gadgets(UI_DIALOG * dlg, d_event *event) { int keypress = 0; UI_GADGET * tmp, * tmp1; window *wind; - int rval = 0; if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); tmp = dlg->gadget; - if (tmp == NULL) return 0; + if (tmp == NULL) return window_event_result::ignored; if (selected_gadget==NULL) selected_gadget = tmp; @@ -324,13 +313,14 @@ int ui_dialog_do_gadgets(UI_DIALOG * dlg, d_event *event) } } + window_event_result rval = window_event_result::ignored; if (dlg->keyboard_focus_gadget != tmp1) { if (dlg->keyboard_focus_gadget != NULL ) dlg->keyboard_focus_gadget->status = 1; if (tmp1 != NULL ) tmp1->status = 1; - rval = 1; + rval = window_event_result::handled; if (keypress) return rval; diff --git a/common/ui/icon.cpp b/common/ui/icon.cpp index b14f2bc68..3a4fdb98e 100644 --- a/common/ui/icon.cpp +++ b/common/ui/icon.cpp @@ -114,13 +114,12 @@ UI_GADGET_ICON * ui_add_gadget_icon( UI_DIALOG * dlg, const char * text, short x } -int ui_icon_do( UI_DIALOG *dlg, UI_GADGET_ICON * icon, d_event *event ) +window_event_result ui_icon_do( UI_DIALOG *dlg, UI_GADGET_ICON * icon, d_event *event ) { - int rval = 0; - icon->oldposition = icon->position; icon->pressed = 0; + window_event_result rval = window_event_result::ignored; if (event->type == EVENT_MOUSE_BUTTON_DOWN || event->type == EVENT_MOUSE_BUTTON_UP) { int OnMe; @@ -130,7 +129,7 @@ int ui_icon_do( UI_DIALOG *dlg, UI_GADGET_ICON * icon, d_event *event ) if (B1_JUST_PRESSED && OnMe) { icon->position = 1; - rval = 1; + rval = window_event_result::handled; } else if (B1_JUST_RELEASED) { @@ -151,7 +150,7 @@ int ui_icon_do( UI_DIALOG *dlg, UI_GADGET_ICON * icon, d_event *event ) if (key == icon->trap_key) { icon->position = 1; - rval = 1; + rval = window_event_result::handled; } } else if (event->type == EVENT_KEY_RELEASE) @@ -171,7 +170,7 @@ int ui_icon_do( UI_DIALOG *dlg, UI_GADGET_ICON * icon, d_event *event ) icon->status = 1; icon->flag = (sbyte)icon->user_function(); ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, (UI_GADGET *)icon); - rval = 1; + rval = window_event_result::handled; } if (event->type == EVENT_WINDOW_DRAW) diff --git a/common/ui/inputbox.cpp b/common/ui/inputbox.cpp index e51538b30..1943e19cb 100644 --- a/common/ui/inputbox.cpp +++ b/common/ui/inputbox.cpp @@ -99,11 +99,10 @@ UI_GADGET_INPUTBOX * ui_add_gadget_inputbox( UI_DIALOG * dlg, short x, short y, } -int ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, d_event *event ) +window_event_result ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, d_event *event ) { unsigned char ascii; int keypress = 0; - int rval = 0; if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); @@ -111,6 +110,7 @@ int ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, d_event *even inputbox->oldposition = inputbox->position; inputbox->pressed=0; + window_event_result rval = window_event_result::ignored; if (dlg->keyboard_focus_gadget==(UI_GADGET *)inputbox) { switch( keypress ) @@ -124,13 +124,13 @@ int ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, d_event *even inputbox->text[inputbox->position] = 0; inputbox->status = 1; if (inputbox->first_time) inputbox->first_time = 0; - rval = 1; + rval = window_event_result::handled; break; case (KEY_ENTER): inputbox->pressed=1; inputbox->status = 1; if (inputbox->first_time) inputbox->first_time = 0; - rval = 1; + rval = window_event_result::handled; break; default: ascii = key_ascii(); @@ -142,7 +142,7 @@ int ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, d_event *even } inputbox->text[inputbox->position++] = ascii; inputbox->text[inputbox->position] = 0; - rval = 1; + rval = window_event_result::handled; } inputbox->status = 1; break; @@ -154,7 +154,7 @@ int ui_inputbox_do( UI_DIALOG *dlg, UI_GADGET_INPUTBOX * inputbox, d_event *even if (inputbox->pressed) { ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, (UI_GADGET *)inputbox); - rval = 1; + rval = window_event_result::handled; } if (event->type == EVENT_WINDOW_DRAW) diff --git a/common/ui/keytrap.cpp b/common/ui/keytrap.cpp index dab21dc9c..8133e0f4f 100644 --- a/common/ui/keytrap.cpp +++ b/common/ui/keytrap.cpp @@ -42,19 +42,16 @@ UI_GADGET_KEYTRAP * ui_add_gadget_keytrap( UI_DIALOG * dlg, int key_to_trap, int } -int ui_keytrap_do( UI_GADGET_KEYTRAP * keytrap, d_event *event ) +window_event_result ui_keytrap_do( UI_GADGET_KEYTRAP * keytrap, d_event *event ) { int keypress = 0; - int rval = 0; - if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); if ( keypress == keytrap->trap_key ) { keytrap->user_function(); - rval = 1; + return window_event_result::handled; } - - return rval; + return window_event_result::ignored; } diff --git a/common/ui/listbox.cpp b/common/ui/listbox.cpp index c5a47a41a..01d770dc3 100644 --- a/common/ui/listbox.cpp +++ b/common/ui/listbox.cpp @@ -153,16 +153,14 @@ UI_GADGET_LISTBOX * ui_add_gadget_listbox(UI_DIALOG *dlg, short x, short y, shor } -int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) +window_event_result ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) { int mitem, oldfakepos, kf; int keypress = 0; - int rval = 0; - if (event->type == EVENT_WINDOW_DRAW) { ui_draw_listbox( dlg, listbox ); - return 0; + return window_event_result::ignored; } if (event->type == EVENT_KEY_COMMAND) @@ -184,7 +182,7 @@ int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) dlg->keyboard_focus_gadget = ui_gadget_get_next((UI_GADGET *)listbox); } - return rval; + return window_event_result::ignored; } listbox->old_current_item = listbox->current_item; @@ -208,17 +206,18 @@ int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) if (B1_JUST_RELEASED) listbox->dragging = 0; + window_event_result rval = window_event_result::ignored; if (B1_JUST_PRESSED && ui_mouse_on_gadget( (UI_GADGET *)listbox )) { listbox->dragging = 1; - rval = 1; + rval = window_event_result::handled; } if ( dlg->keyboard_focus_gadget==(UI_GADGET *)listbox ) { if (keypress==KEY_ENTER) { listbox->selected_item = listbox->current_item; - rval = 1; + rval = window_event_result::handled; } kf = 0; @@ -254,7 +253,7 @@ int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) if (kf==1) { listbox->moved = 1; - rval = 1; + rval = window_event_result::handled; if (listbox->current_item<0) listbox->current_item=0; @@ -369,7 +368,7 @@ int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) if (B1_DOUBLE_CLICKED ) { listbox->selected_item = listbox->current_item; - rval = 1; + rval = window_event_result::handled; } } @@ -377,7 +376,7 @@ int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) if (listbox->moved || (listbox->selected_item > 0)) { ui_gadget_send_event(dlg, (listbox->selected_item > 0) ? EVENT_UI_LISTBOX_SELECTED : EVENT_UI_LISTBOX_MOVED, (UI_GADGET *)listbox); - rval = 1; + return window_event_result::handled; } return rval; diff --git a/common/ui/menubar.cpp b/common/ui/menubar.cpp index 06774c631..3a0f2640f 100644 --- a/common/ui/menubar.cpp +++ b/common/ui/menubar.cpp @@ -64,8 +64,8 @@ static int state; #define CMENU (Menu[0].CurrentItem+1) -static int menubar_handler(window *wind, d_event *event, MENU *menu); -static int menu_handler(window *wind, d_event *event, MENU *menu); +static window_event_result menubar_handler(window *wind, d_event *event, MENU *menu); +static window_event_result menu_handler(window *wind, d_event *event, MENU *menu); //------------------------- Show a menu item ------------------- @@ -270,7 +270,7 @@ static void menu_hide_all() static int state2_alt_down; -static int do_state_0(d_event *event) +static window_event_result do_state_0(d_event *event) { int i, j; int keypress = 0; @@ -299,7 +299,7 @@ static int do_state_0(d_event *event) menu_show( &Menu[ CMENU ] ); menu_show( &Menu[0] ); - return 1; + return window_event_result::handled; } } @@ -310,7 +310,7 @@ static int do_state_0(d_event *event) { if (Menu[i].Item[j].user_function) Menu[i].Item[j].user_function(); - return 1; + return window_event_result::handled; } } @@ -328,7 +328,7 @@ static int do_state_0(d_event *event) window_set_modal(Menu[0].wind, 1); menu_show( &Menu[0] ); - return 1; + return window_event_result::handled; } i = menu_check_mouse_item( &Menu[0] ); @@ -344,17 +344,16 @@ static int do_state_0(d_event *event) window_set_modal(Menu[0].wind, 0); menu_show( &Menu[ CMENU ] ); menu_show( &Menu[0] ); - return 1; + return window_event_result::handled; } - - return 0; + return window_event_result::ignored; } -static int do_state_1(d_event *event) +static window_event_result do_state_1(d_event *event) { int i; int keypress = 0; - int rval = 0; + window_event_result rval = window_event_result::ignored; if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); @@ -366,11 +365,7 @@ static int do_state_1(d_event *event) Menu[0].ShowBar = 1; Menu[0].Active = 1; menu_show( &Menu[0] ); -#if 0 - state = 0; - menu_hide_all(); -#endif - rval = 1; + rval = window_event_result::handled; } i = menu_match_keypress( &Menu[0], keypress ); @@ -387,7 +382,7 @@ static int do_state_1(d_event *event) menu_show( &Menu[ CMENU ] ); menu_show( &Menu[0] ); - rval = 1; + rval = window_event_result::handled; } i = menu_check_mouse_item( &Menu[0] ); @@ -396,7 +391,7 @@ static int do_state_1(d_event *event) { state = 0; menu_hide_all(); - rval = 1; + return window_event_result::handled; } if ( B1_JUST_PRESSED && (i > -1)) @@ -410,32 +405,31 @@ static int do_state_1(d_event *event) window_set_modal(Menu[0].wind, 0); menu_show( &Menu[ CMENU ] ); menu_show( &Menu[0] ); - rval = 1; + return window_event_result::handled; } return rval; } -static int do_state_2(d_event *event) +static window_event_result do_state_2(d_event *event) { int i; int keypress = 0; - int rval = 0; - + window_event_result rval = window_event_result::ignored; if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); if (keypress & KEY_ALTED) { state2_alt_down = 1; - rval = 1; + rval = window_event_result::handled; } if ((event->type == EVENT_KEY_RELEASE) && !(event_key_get(event) & KEY_ALTED) && state2_alt_down) { state = 0; menu_hide_all(); - rval = 1; + rval = window_event_result::handled; } switch( keypress ) @@ -443,22 +437,19 @@ static int do_state_2(d_event *event) case KEY_ESC: state = 0; menu_hide_all(); - rval = 1; - break; + return window_event_result::handled; case KEY_LEFT: case KEY_PAD4: i = Menu[0].CurrentItem-1; if (i < 0 ) i = Menu[0].NumItems-1; menu_move_bar_to( &Menu[0], i ); - rval = 1; - break; + return window_event_result::handled; case KEY_RIGHT: case KEY_PAD6: i = Menu[0].CurrentItem+1; if (i >= Menu[0].NumItems ) i = 0; menu_move_bar_to( &Menu[0], i ); - rval = 1; - break; + return window_event_result::handled; case KEY_ENTER: case KEY_PADENTER: case KEY_DOWN: @@ -470,8 +461,7 @@ static int do_state_2(d_event *event) window_set_modal(Menu[0].wind, 0); menu_show( &Menu[ 0 ] ); menu_show( &Menu[ CMENU ] ); - rval = 1; - break; + return window_event_result::handled; default: i = menu_match_keypress( &Menu[0], keypress ); @@ -487,8 +477,7 @@ static int do_state_2(d_event *event) Menu[0].ShowBar = 1; menu_show( &Menu[ CMENU ] ); menu_show( &Menu[0] ); - rval = 1; - break; + return window_event_result::handled; } i = menu_check_mouse_item( &Menu[0] ); @@ -497,8 +486,7 @@ static int do_state_2(d_event *event) { state = 0; menu_hide_all(); - rval = 1; - break; + return window_event_result::handled; } if (i > -1) @@ -512,8 +500,7 @@ static int do_state_2(d_event *event) Menu[0].ShowBar = 1; menu_show( &Menu[ CMENU ] ); menu_show( &Menu[0] ); - rval = 1; - break; + return window_event_result::handled; } } @@ -522,14 +509,13 @@ static int do_state_2(d_event *event) -static int menu_handler(window *wind, d_event *event, MENU *menu) +static window_event_result menu_handler(window *wind, d_event *event, MENU *menu) { int i; int keypress = 0; - int rval = 0; if (state != 3) - return 0; + return window_event_result::ignored; if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); @@ -538,9 +524,9 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) state = 0; menu_hide_all(); menu->wind = NULL; - return 0; + return window_event_result::ignored; } - + window_event_result rval = window_event_result::ignored; switch( keypress ) { case 0: @@ -548,7 +534,7 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) case KEY_ESC: state = 0; menu_hide_all(); - rval = 1; + rval = window_event_result::handled; break; case KEY_DOWN: case KEY_PAD2: @@ -559,7 +545,7 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) i = 0; } while( Menu[CMENU].Item[i].Text[0] == '-'); menu_move_bar_to( &Menu[ CMENU ], i ); - rval = 1; + rval = window_event_result::handled; break; case KEY_UP: case KEY_PAD8: @@ -571,7 +557,7 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) i = Menu[ CMENU ].NumItems-1; } while( Menu[CMENU].Item[i].Text[0] == '-'); menu_move_bar_to( &Menu[ CMENU ], i ); - rval = 1; + rval = window_event_result::handled; break; case KEY_RIGHT: case KEY_PAD6: @@ -582,7 +568,7 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) Menu[CMENU].ShowBar = 1; Menu[CMENU].Active = 1; menu_show( &Menu[CMENU] ); - rval = 1; + rval = window_event_result::handled; break; case KEY_LEFT: case KEY_PAD4: @@ -593,7 +579,7 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) Menu[ CMENU ].ShowBar = 1; Menu[CMENU].Active = 1; menu_show( &Menu[ CMENU ] ); - rval = 1; + rval = window_event_result::handled; break; case KEY_ENTER: case KEY_PADENTER: @@ -603,7 +589,7 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function) Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function(); - rval = 1; + rval = window_event_result::handled; break; default: @@ -617,7 +603,7 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function) Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function(); - rval = 1; + rval = window_event_result::handled; break; } } @@ -636,12 +622,12 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) if (Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function) Menu[CMENU].Item[ Menu[CMENU].CurrentItem ].user_function(); - rval = 1; + rval = window_event_result::handled; } else { menu_move_bar_to( &Menu[ CMENU ], i ); - rval = 1; + rval = window_event_result::handled; } } else { i = menu_check_mouse_item( &Menu[0] ); @@ -656,14 +642,14 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) menu_show( &Menu[ CMENU ] ); } - rval = 1; + rval = window_event_result::handled; } if ( B1_JUST_RELEASED ) { state = 0; menu_hide_all(); - rval = 1; + rval = window_event_result::handled; } } } @@ -671,20 +657,18 @@ static int menu_handler(window *wind, d_event *event, MENU *menu) if (event->type == EVENT_WINDOW_DRAW) { menu_draw(&Menu[CMENU]); - rval = 1; + return window_event_result::handled; } return rval; } -static int menubar_handler(window *wind, d_event *event, MENU *menu) +static window_event_result menubar_handler(window *wind, d_event *event, MENU *menu) { - int rval = 0; - if (event->type == EVENT_WINDOW_DRAW) { menu_draw(&Menu[0]); - return 1; + return window_event_result::handled; } else if (event->type == EVENT_WINDOW_CLOSE) { @@ -709,26 +693,18 @@ static int menubar_handler(window *wind, d_event *event, MENU *menu) switch (state) { case 0: - rval = do_state_0(event); - break; - + return do_state_0(event); case 1: - rval = do_state_1(event); - break; - + return do_state_1(event); case 2: - rval = do_state_2(event); - break; - + return do_state_2(event); case 3: break; - default: state = 0; menu_hide_all(); } - - return rval; + return window_event_result::ignored; } static void CommaParse( int n, char * dest, char * source ) diff --git a/common/ui/radio.cpp b/common/ui/radio.cpp index 4316ecb83..543e50167 100644 --- a/common/ui/radio.cpp +++ b/common/ui/radio.cpp @@ -92,15 +92,14 @@ UI_GADGET_RADIO * ui_add_gadget_radio( UI_DIALOG * dlg, short x, short y, short } -int ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, d_event *event ) +window_event_result ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, d_event *event ) { UI_GADGET * tmp; UI_GADGET_RADIO * tmpr; - int rval = 0; - radio->oldposition = radio->position; radio->pressed = 0; + window_event_result rval = window_event_result::ignored; if (event->type == EVENT_MOUSE_BUTTON_DOWN || event->type == EVENT_MOUSE_BUTTON_UP) { int OnMe; @@ -110,7 +109,7 @@ int ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, d_event *event ) if ( B1_JUST_PRESSED && OnMe) { radio->position = 1; - rval = 1; + rval = window_event_result::handled; } else if (B1_JUST_RELEASED) { @@ -131,7 +130,7 @@ int ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, d_event *event ) if ((dlg->keyboard_focus_gadget==(UI_GADGET *)radio) && ((key==KEY_SPACEBAR) || (key==KEY_ENTER)) ) { radio->position = 2; - rval = 1; + rval = window_event_result::handled; } } else if (event->type == EVENT_KEY_RELEASE) @@ -166,7 +165,7 @@ int ui_radio_do( UI_DIALOG *dlg, UI_GADGET_RADIO * radio, d_event *event ) } radio->flag = 1; ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, (UI_GADGET *)radio); - rval = 1; + rval = window_event_result::handled; } if (event->type == EVENT_WINDOW_DRAW) diff --git a/common/ui/scroll.cpp b/common/ui/scroll.cpp index 74dce0d50..b36a435d6 100644 --- a/common/ui/scroll.cpp +++ b/common/ui/scroll.cpp @@ -96,17 +96,17 @@ UI_GADGET_SCROLLBAR * ui_add_gadget_scrollbar( UI_DIALOG * dlg, short x, short y } -int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, d_event *event ) +window_event_result ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, d_event *event ) { int OnMe, OnSlider, keyfocus; int oldpos, op; int x, y, z; - int rval = 0; + window_event_result rval = window_event_result::ignored; if (event->type == EVENT_WINDOW_DRAW) { ui_draw_scrollbar( dlg, scrollbar ); - return 0; + return window_event_result::ignored; } keyfocus = 0; @@ -119,7 +119,7 @@ int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, d_event *e scrollbar->position = 0; scrollbar->fake_position = 0; ui_draw_scrollbar( dlg, scrollbar ); - return 0; + return window_event_result::ignored; } op = scrollbar->position; @@ -138,12 +138,12 @@ int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, d_event *e if (key & KEY_UP) { scrollbar->up_button->position = 2; - rval = 1; + rval = window_event_result::handled; } else if (key & KEY_DOWN) { scrollbar->down_button->position = 2; - rval = 1; + rval = window_event_result::handled; } } else if (keyfocus && event->type == EVENT_KEY_RELEASE) @@ -155,12 +155,12 @@ int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, d_event *e if (key & KEY_UP) { scrollbar->up_button->position = 0; - rval = 1; + rval = window_event_result::handled; } else if (key & KEY_DOWN) { scrollbar->down_button->position = 0; - rval = 1; + rval = window_event_result::handled; } } @@ -216,12 +216,12 @@ int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, d_event *e scrollbar->drag_x = x; scrollbar->drag_y = y; scrollbar->drag_starting = scrollbar->fake_position; - rval = 1; + rval = window_event_result::handled; } else if (B1_JUST_PRESSED && OnMe) { scrollbar->dragging = 2; // outside the slider - rval = 1; + rval = window_event_result::handled; } if ((scrollbar->dragging == 2) && OnMe && !OnSlider && (timer_query() > scrollbar->last_scrolled + 4)) @@ -285,7 +285,7 @@ int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, d_event *e if (scrollbar->moved) { ui_gadget_send_event(dlg, EVENT_UI_GADGET_PRESSED, (UI_GADGET *)scrollbar); - rval = 1; + rval = window_event_result::handled; } if (oldpos != scrollbar->fake_position) diff --git a/common/ui/userbox.cpp b/common/ui/userbox.cpp index d8fd35043..1426083db 100644 --- a/common/ui/userbox.cpp +++ b/common/ui/userbox.cpp @@ -76,12 +76,12 @@ UI_GADGET_USERBOX * ui_add_gadget_userbox( UI_DIALOG * dlg, short x, short y, sh } -int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) +window_event_result ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) { int OnMe, olddrag; int x, y, z; int keypress = 0; - int rval = 0; + window_event_result rval = window_event_result::ignored; if (event->type == EVENT_WINDOW_DRAW) ui_draw_userbox( dlg, userbox ); @@ -108,14 +108,14 @@ int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) userbox->b1_held_down = 1; userbox->b1_drag_x1 = x - userbox->x1; userbox->b1_drag_y1 = y - userbox->y1; - rval = 1; + rval = window_event_result::handled; } else if (B1_JUST_RELEASED) { if (userbox->b1_held_down) userbox->b1_clicked = 1; userbox->b1_held_down = 0; - rval = 1; + rval = window_event_result::handled; } if ( (event->type == EVENT_MOUSE_MOVED) && userbox->b1_held_down ) @@ -128,7 +128,7 @@ int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) if ( B1_DOUBLE_CLICKED ) { userbox->b1_double_clicked = 1; - rval = 1; + rval = window_event_result::handled; } else userbox->b1_double_clicked = 0; @@ -149,13 +149,13 @@ int ui_userbox_do( UI_DIALOG *dlg, UI_GADGET_USERBOX * userbox, d_event *event ) if (dlg->keyboard_focus_gadget==(UI_GADGET *)userbox) { userbox->keypress = keypress; - rval = 1; + rval = window_event_result::handled; } if (userbox->b1_clicked || userbox->b1_dragging) { ui_gadget_send_event(dlg, userbox->b1_clicked ? EVENT_UI_GADGET_PRESSED : EVENT_UI_USERBOX_DRAGGED, (UI_GADGET *)userbox); - rval = 1; + rval = window_event_result::handled; } return rval; diff --git a/d2x-rebirth/main/escort.cpp b/d2x-rebirth/main/escort.cpp index 4c36e095a..c14b66aaa 100644 --- a/d2x-rebirth/main/escort.cpp +++ b/d2x-rebirth/main/escort.cpp @@ -1626,7 +1626,7 @@ struct escort_menu char msg[300]; }; -static int escort_menu_keycommand(window *wind, d_event *event, escort_menu *menu) +static window_event_result escort_menu_keycommand(window *wind, d_event *event, escort_menu *menu) { int key; @@ -1648,13 +1648,11 @@ static int escort_menu_keycommand(window *wind, d_event *event, escort_menu *men set_escort_special_goal(key); Last_buddy_key = -1; window_close(wind); - return 1; - + return window_event_result::close; case KEY_ESC: case KEY_ENTER: window_close(wind); - return 1; - + return window_event_result::close; case KEY_T: { char msg[32]; int temp; @@ -1670,19 +1668,17 @@ static int escort_menu_keycommand(window *wind, d_event *event, escort_menu *men buddy_message("Messages %s.", msg); Buddy_messages_suppressed = temp; - window_close(wind); - return 1; + return window_event_result::close; } default: break; } - - return 0; + return window_event_result::ignored; } -static int escort_menu_handler(window *wind, d_event *event, escort_menu *menu) +static window_event_result escort_menu_handler(window *wind, d_event *event, escort_menu *menu) { switch (event->type) { @@ -1692,7 +1688,6 @@ static int escort_menu_handler(window *wind, d_event *event, escort_menu *menu) case EVENT_KEY_COMMAND: return escort_menu_keycommand(wind, event, menu); - case EVENT_IDLE: timer_delay2(50); break; @@ -1702,15 +1697,11 @@ static int escort_menu_handler(window *wind, d_event *event, escort_menu *menu) break; case EVENT_WINDOW_CLOSE: - return 0; // continue closing - break; - + return window_event_result::ignored; // continue closing default: - return 0; - break; + return window_event_result::ignored; } - - return 1; + return window_event_result::handled; } void do_escort_menu(void) diff --git a/d2x-rebirth/main/movie.cpp b/d2x-rebirth/main/movie.cpp index e8e3c3355..ec24352d4 100644 --- a/d2x-rebirth/main/movie.cpp +++ b/d2x-rebirth/main/movie.cpp @@ -264,19 +264,22 @@ struct movie int paused; }; -static int show_pause_message(window *wind, d_event *event, unused_window_userdata_t *) +static window_event_result show_pause_message(window *wind, d_event *event, unused_window_userdata_t *) { switch (event->type) { case EVENT_MOUSE_BUTTON_DOWN: if (event_mouse_get_button(event) != 0) - return 0; + return window_event_result::ignored; // else fall through case EVENT_KEY_COMMAND: if (!call_default_handler(event)) + { window_close(wind); - return 1; + return window_event_result::close; + } + return window_event_result::handled; case EVENT_WINDOW_DRAW: { @@ -300,11 +303,10 @@ static int show_pause_message(window *wind, d_event *event, unused_window_userda default: break; } - - return 0; + return window_event_result::ignored; } -static int MovieHandler(window *wind, d_event *event, movie *m) +static window_event_result MovieHandler(window *wind, d_event *event, movie *m) { int key; @@ -326,7 +328,7 @@ static int MovieHandler(window *wind, d_event *event, movie *m) if (key == KEY_ESC) { m->result = m->aborted = 1; window_close(wind); - return 1; + return window_event_result::close; } // If PAUSE pressed, then pause movie @@ -334,7 +336,7 @@ static int MovieHandler(window *wind, d_event *event, movie *m) { if (window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, show_pause_message, unused_window_userdata)) MVE_rmHoldMovie(); - return 1; + return window_event_result::handled; } break; @@ -345,7 +347,7 @@ static int MovieHandler(window *wind, d_event *event, movie *m) if (m->result) { window_close(wind); - return 1; + return window_event_result::close; } } @@ -365,8 +367,7 @@ static int MovieHandler(window *wind, d_event *event, movie *m) default: break; } - - return 0; + return window_event_result::ignored; } //returns status. see movie.h diff --git a/similar/arch/sdl/event.cpp b/similar/arch/sdl/event.cpp index c8560ae4c..ca4e6c601 100644 --- a/similar/arch/sdl/event.cpp +++ b/similar/arch/sdl/event.cpp @@ -124,9 +124,9 @@ int call_default_handler(d_event *event) void event_send(d_event *event) { window *wind; - int handled = 0; + window_event_result handled = window_event_result::ignored; - for (wind = window_get_front(); wind != NULL && !handled; wind = window_get_prev(wind)) + for (wind = window_get_front(); wind != NULL && handled == window_event_result::ignored; wind = window_get_prev(wind)) if (window_is_visible(wind)) { handled = window_send_event(wind, event); @@ -137,7 +137,7 @@ void event_send(d_event *event) break; } - if (!handled) + if (handled == window_event_result::ignored) call_default_handler(event); } diff --git a/similar/arch/sdl/mouse.cpp b/similar/arch/sdl/mouse.cpp index d3e81f008..82334ba0f 100644 --- a/similar/arch/sdl/mouse.cpp +++ b/similar/arch/sdl/mouse.cpp @@ -185,7 +185,7 @@ void mouse_get_pos( int *x, int *y, int *z ) *z=Mouse.z; } -int mouse_in_window(window *wind) +window_event_result mouse_in_window(window *wind) { grs_canvas *canv; @@ -193,7 +193,7 @@ int mouse_in_window(window *wind) return (Mouse.x >= canv->cv_bitmap.bm_x) && (Mouse.x <= canv->cv_bitmap.bm_x + canv->cv_bitmap.bm_w) && (Mouse.y >= canv->cv_bitmap.bm_y) && - (Mouse.y <= canv->cv_bitmap.bm_y + canv->cv_bitmap.bm_h); + (Mouse.y <= canv->cv_bitmap.bm_y + canv->cv_bitmap.bm_h) ? window_event_result::handled : window_event_result::ignored; } void mouse_get_delta( int *dx, int *dy, int *dz ) diff --git a/similar/editor/info.cpp b/similar/editor/info.cpp index ff06e6c1f..11e395d54 100644 --- a/similar/editor/info.cpp +++ b/similar/editor/info.cpp @@ -283,7 +283,7 @@ static void clear_pad_display(void) } // ------------------------------------------------------------------------------------ -static int info_display_all(window *wind, d_event *event, unused_window_userdata_t *) +static window_event_result info_display_all(window *wind, d_event *event, unused_window_userdata_t *) { static int old_padnum = -1; int padnum,show_all = 1; // always redraw @@ -316,8 +316,7 @@ static int info_display_all(window *wind, d_event *event, unused_window_userdata break; } grd_curcanv = save_canvas; - return 1; - + return window_event_result::handled; case EVENT_WINDOW_CLOSE: Pad_info = NULL; break; @@ -325,8 +324,7 @@ static int info_display_all(window *wind, d_event *event, unused_window_userdata default: break; } - - return 0; + return window_event_result::ignored; } // ------------------------------------------------------------------------------------ diff --git a/similar/main/automap.cpp b/similar/main/automap.cpp index 423fd9170..96b542d0c 100644 --- a/similar/main/automap.cpp +++ b/similar/main/automap.cpp @@ -636,7 +636,7 @@ static void recompute_automap_segment_visibility(automap *am) adjust_segment_limit(am, am->segment_limit); } -static int automap_key_command(window *wind, d_event *event, automap *am) +static window_event_result automap_key_command(window *wind, d_event *event, automap *am) { int c = event_key_get(event); #if defined(DXX_BUILD_DESCENT_II) @@ -649,17 +649,15 @@ static int automap_key_command(window *wind, d_event *event, automap *am) case KEY_PRINT_SCREEN: { gr_set_current_canvas(NULL); save_screen_shot(1); - return 1; + return window_event_result::handled; } - case KEY_ESC: if (am->leave_mode==0) { window_close(wind); - return 1; + return window_event_result::close; } - return 1; - + return window_event_result::handled; #if defined(DXX_BUILD_DESCENT_I) case KEY_ALTED+KEY_F: // Alt+F shows full map, if cheats enabled if (cheats.enabled) @@ -668,28 +666,27 @@ static int automap_key_command(window *wind, d_event *event, automap *am) // if cheat of map powerup, work with full depth recompute_automap_segment_visibility(am); } - return 1; + return window_event_result::handled; #endif #ifndef NDEBUG case KEY_DEBUGGED+KEY_F: { Automap_debug_show_all_segments = !Automap_debug_show_all_segments; recompute_automap_segment_visibility(am); } - return 1; + return window_event_result::handled; #endif - case KEY_F9: if (am->segment_limit > 1) { am->segment_limit--; adjust_segment_limit(am, am->segment_limit); } - return 1; + return window_event_result::handled; case KEY_F10: if (am->segment_limit < am->max_segments_away) { am->segment_limit++; adjust_segment_limit(am, am->segment_limit); } - return 1; + return window_event_result::handled; #if defined(DXX_BUILD_DESCENT_II) case KEY_1: case KEY_2: @@ -712,8 +709,7 @@ static int automap_key_command(window *wind, d_event *event, automap *am) if (MarkerObject[marker_num] != object_none) HighlightMarker=marker_num; } - return 1; - + return window_event_result::handled; case KEY_D+KEY_CTRLED: if (HighlightMarker > -1 && MarkerObject[HighlightMarker] != object_none) { gr_set_current_canvas(NULL); @@ -725,25 +721,23 @@ static int automap_key_command(window *wind, d_event *event, automap *am) } set_screen_mode(SCREEN_GAME); } - return 1; - + return window_event_result::handled; #ifndef RELEASE case KEY_F11: //KEY_COMMA: if (MarkerScale>.5) MarkerScale-=.5; - return 1; + return window_event_result::handled; case KEY_F12: //KEY_PERIOD: if (MarkerScale<30.0) MarkerScale+=.5; - return 1; + return window_event_result::handled; #endif #endif } - - return 0; + return window_event_result::ignored; } -static int automap_process_input(window *wind, d_event *event, automap *am) +static window_event_result automap_process_input(window *wind, d_event *event, automap *am) { vms_matrix tempm; @@ -755,7 +749,7 @@ static int automap_process_input(window *wind, d_event *event, automap *am) if ( !am->controls.state.automap && (am->leave_mode==1) ) { window_close(wind); - return 1; + return window_event_result::close; } if ( am->controls.state.automap) @@ -764,7 +758,7 @@ static int automap_process_input(window *wind, d_event *event, automap *am) if (am->leave_mode==0) { window_close(wind); - return 1; + return window_event_result::close; } } @@ -841,11 +835,10 @@ static int automap_process_input(window *wind, d_event *event, automap *am) clamp_fix_lh(am->viewDist, ZOOM_MIN_VALUE, ZOOM_MAX_VALUE); } - - return 0; + return window_event_result::ignored; } -static int automap_handler(window *wind, d_event *event, automap *am) +static window_event_result automap_handler(window *wind, d_event *event, automap *am) { switch (event->type) { @@ -868,12 +861,11 @@ static int automap_handler(window *wind, d_event *event, automap *am) case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_MOVED: case EVENT_KEY_RELEASE: - automap_process_input(wind, event, am); - break; + return automap_process_input(wind, event, am); case EVENT_KEY_COMMAND: { - int kret = automap_key_command(wind, event, am); - if (!kret) + window_event_result kret = automap_key_command(wind, event, am); + if (kret == window_event_result::ignored) automap_process_input(wind, event, am); return kret; } @@ -896,15 +888,14 @@ static int automap_handler(window *wind, d_event *event, automap *am) window_set_visible(Game_wind, 1); Automap_active = 0; multi_send_msgsend_state(msgsend_none); - return 0; // continue closing + return window_event_result::ignored; // continue closing break; default: - return 0; + return window_event_result::ignored; break; } - - return 1; + return window_event_result::handled; } void do_automap() @@ -1498,7 +1489,7 @@ void InitMarkerInput () key_toggle_repeat(1); } -int MarkerInputMessage(int key) +window_event_result MarkerInputMessage(int key) { switch( key ) { @@ -1532,11 +1523,9 @@ int MarkerInputMessage(int key) Marker_input[Marker_index++] = ascii; Marker_input[Marker_index] = 0; } - return 0; - break; + return window_event_result::ignored; } } - - return 1; + return window_event_result::handled; } #endif diff --git a/similar/main/console.cpp b/similar/main/console.cpp index cecf047b2..831a20f62 100644 --- a/similar/main/console.cpp +++ b/similar/main/console.cpp @@ -177,7 +177,7 @@ static void con_draw(void) gr_string(SWIDTH-FSPACX(110),FSPACY(1),"PAGE-UP/DOWN TO SCROLL"); } -static int con_handler(window *wind, d_event *event, unused_window_userdata_t *) +static window_event_result con_handler(window *wind, d_event *event, unused_window_userdata_t *) { int key; static fix64 last_scroll_time = 0; @@ -225,7 +225,7 @@ static int con_handler(window *wind, d_event *event, unused_window_userdata_t *) default: break; } - return 1; + return window_event_result::handled; case EVENT_WINDOW_DRAW: timer_delay2(50); @@ -249,10 +249,12 @@ static int con_handler(window *wind, d_event *event, unused_window_userdata_t *) con_state = CON_STATE_OPEN; else if (con_size <= 0) con_state = CON_STATE_CLOSED; - if (con_state == CON_STATE_CLOSED && wind) - window_close(wind); - con_draw(); + if (con_state == CON_STATE_CLOSED && wind) + { + window_close(wind); + return window_event_result::close; + } break; case EVENT_WINDOW_CLOSE: break; @@ -260,7 +262,7 @@ static int con_handler(window *wind, d_event *event, unused_window_userdata_t *) break; } - return 0; + return window_event_result::ignored; } void con_showup(void) diff --git a/similar/main/credits.cpp b/similar/main/credits.cpp index c5f084525..d12d23c28 100644 --- a/similar/main/credits.cpp +++ b/similar/main/credits.cpp @@ -78,7 +78,7 @@ struct credits grs_bitmap backdrop; }; -static int credits_handler(window *wind, d_event *event, credits *cr) +static window_event_result credits_handler(window *wind, d_event *event, credits *cr) { int j, l, y; char * tempp; @@ -87,15 +87,18 @@ static int credits_handler(window *wind, d_event *event, credits *cr) { case EVENT_KEY_COMMAND: if (!call_default_handler(event)) // if not print screen, debug etc + { window_close(wind); - return 1; + return window_event_result::close; + } + return window_event_result::handled; case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT) { window_close(wind); - return 1; + return window_event_result::close; } break; @@ -103,7 +106,7 @@ static int credits_handler(window *wind, d_event *event, credits *cr) if (cr->done>NUM_LINES) { window_close(wind); - return 0; + return window_event_result::close; } break; @@ -213,8 +216,7 @@ static int credits_handler(window *wind, d_event *event, credits *cr) default: break; } - - return 0; + return window_event_result::ignored; } //if filename passed is NULL, show normal credits diff --git a/similar/main/game.cpp b/similar/main/game.cpp index 2bb987232..95c3b2ecd 100644 --- a/similar/main/game.cpp +++ b/similar/main/game.cpp @@ -1059,7 +1059,7 @@ window *game_setup(void) window *Game_wind = NULL; // Event handler for the game -int game_handler(window *wind, d_event *event, unused_window_userdata_t *) +window_event_result game_handler(window *wind, d_event *event, unused_window_userdata_t *) { switch (event->type) { @@ -1154,8 +1154,7 @@ int game_handler(window *wind, d_event *event, unused_window_userdata_t *) default: break; } - - return 0; + return window_event_result::ignored; } // Initialise game, actually runs in main event loop diff --git a/similar/main/gamecntl.cpp b/similar/main/gamecntl.cpp index 5a4b56124..c9460708e 100644 --- a/similar/main/gamecntl.cpp +++ b/similar/main/gamecntl.cpp @@ -310,7 +310,7 @@ static void format_time(char *str, int secs_int) } //Process selected keys until game unpaused -static int pause_handler(window *wind, d_event *event, char *msg) +static window_event_result pause_handler(window *wind, d_event *event, char *msg) { int key; @@ -329,13 +329,13 @@ static int pause_handler(window *wind, d_event *event, char *msg) break; case KEY_ESC: window_close(wind); - return 1; + return window_event_result::close; case KEY_F1: show_help(); - return 1; + return window_event_result::handled; case KEY_PAUSE: window_close(wind); - return 1; + return window_event_result::close; default: break; } @@ -357,8 +357,7 @@ static int pause_handler(window *wind, d_event *event, char *msg) default: break; } - - return 0; + return window_event_result::ignored; } static int do_game_pause() @@ -706,7 +705,7 @@ dump_door_debugging_info() //this is for system-level keys, such as help, etc. //returns 1 if screen changed -static int HandleSystemKey(int key) +static window_event_result HandleSystemKey(int key) { if (!Player_is_dead) switch (key) @@ -723,9 +722,11 @@ static int HandleSystemKey(int key) int choice; choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME ); if (choice == 0) + { window_close(Game_wind); - - return 1; + return window_event_result::close; + } + return window_event_result::handled; } #if defined(DXX_BUILD_DESCENT_II) // fleshed these out because F1 and F2 aren't sequenctial keycodes on mac -- MWA @@ -733,11 +734,11 @@ static int HandleSystemKey(int key) KEY_MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_1:) case KEY_SHIFTED+KEY_F1: select_next_window_function(0); - return 1; + return window_event_result::handled; KEY_MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_2:) case KEY_SHIFTED+KEY_F2: select_next_window_function(1); - return 1; + return window_event_result::handled; #endif } @@ -930,14 +931,12 @@ static int HandleSystemKey(int key) break; default: - return 0; - break; + return window_event_result::ignored; } - - return 1; + return window_event_result::handled; } -static int HandleGameKey(int key) +static window_event_result HandleGameKey(int key) { switch (key) { #if defined(DXX_BUILD_DESCENT_II) @@ -958,10 +957,10 @@ static int HandleGameKey(int key) else HUD_init_message_literal(HM_DEFAULT, "No Guide-Bot in Multiplayer!"); game_flush_inputs(); - return 1; + return window_event_result::handled; } else - return 0; + return window_event_result::ignored; #endif case KEY_ALTED+KEY_F7: @@ -975,7 +974,7 @@ static int HandleGameKey(int key) case 2: HUD_init_message_literal(HM_DEFAULT, "Alternative HUD #2"); break; case 3: HUD_init_message_literal(HM_DEFAULT, "No HUD"); break; } - return 1; + return window_event_result::handled; KEY_MAC(case KEY_COMMAND+KEY_6:) case KEY_F6: @@ -984,7 +983,7 @@ static int HandleGameKey(int key) RefuseThisPlayer=1; HUD_init_message_literal(HM_MULTI, "Player accepted!"); } - return 1; + return window_event_result::handled; case KEY_ALTED + KEY_1: if (Netgame.RefusePlayers && WaitForRefuseAnswer && (Game_mode & GM_TEAM)) { @@ -993,7 +992,7 @@ static int HandleGameKey(int key) RefuseTeam=1; game_flush_inputs(); } - return 1; + return window_event_result::handled; case KEY_ALTED + KEY_2: if (Netgame.RefusePlayers && WaitForRefuseAnswer && (Game_mode & GM_TEAM)) { @@ -1002,11 +1001,11 @@ static int HandleGameKey(int key) RefuseTeam=2; game_flush_inputs(); } - return 1; + return window_event_result::handled; default: #if defined(DXX_BUILD_DESCENT_I) - return 0; + return window_event_result::ignored; #endif break; @@ -1038,13 +1037,13 @@ static int HandleGameKey(int key) break; default: - return 0; + return window_event_result::ignored; } else - return 0; + return window_event_result::ignored; #endif - return 1; + return window_event_result::handled; } #if defined(DXX_BUILD_DESCENT_II) @@ -1172,7 +1171,7 @@ static void kill_buddy(void) } #endif -static int HandleTestKey(int key) +static window_event_result HandleTestKey(int key) { switch (key) { @@ -1223,7 +1222,7 @@ static int HandleTestKey(int key) case KEY_DEBUGGED+KEY_X: Players[Player_num].lives++; break; // Extra life cheat key. case KEY_DEBUGGED+KEY_H: if (Player_is_dead) - return 0; + return window_event_result::ignored; Players[Player_num].flags ^= PLAYER_FLAGS_CLOAKED; if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED) { @@ -1245,7 +1244,7 @@ static int HandleTestKey(int key) window_set_visible(Game_wind, 0); // don't let the game do anything while we set the editor up init_editor(); window_close(Game_wind); - break; + return window_event_result::close; #if defined(DXX_BUILD_DESCENT_II) case KEY_Q + KEY_SHIFTED + KEY_DEBUGGED: { @@ -1358,7 +1357,7 @@ static int HandleTestKey(int key) case KEY_DEBUGGED+KEY_SHIFTED+KEY_B: if (Player_is_dead) - return 0; + return window_event_result::ignored; kill_and_so_forth(); break; @@ -1367,11 +1366,9 @@ static int HandleTestKey(int key) HUD_init_message(HM_DEFAULT, "GameTime %" PRIi64 " - Reset in 10 seconds!", GameTime64); break; default: - return 0; - break; + return window_event_result::ignored; } - - return 1; + return window_event_result::handled; } #endif //#ifndef RELEASE @@ -1428,13 +1425,13 @@ static const cheat_code cheat_codes[] = { { "bittersweet", &game_cheats::acid }, }; -static int FinalCheats(int key) +static window_event_result FinalCheats(int key) { static char cheat_buffer[CHEAT_MAX_LEN]; int (game_cheats::*gotcha); if (Game_mode & GM_MULTI) - return 0; + return window_event_result::ignored; for (unsigned i = 1; i < CHEAT_MAX_LEN; i++) cheat_buffer[i-1] = cheat_buffer[i]; @@ -1442,7 +1439,7 @@ static int FinalCheats(int key) for (unsigned i = 0;; i++) { if (i >= sizeof(cheat_codes) / sizeof(cheat_codes[0])) - return 0; + return window_event_result::ignored; int cheatlen = strlen(cheat_codes[i].string); Assert(cheatlen <= CHEAT_MAX_LEN); if (d_strnicmp(cheat_codes[i].string, cheat_buffer+CHEAT_MAX_LEN-cheatlen, cheatlen)==0) @@ -1450,7 +1447,7 @@ static int FinalCheats(int key) gotcha = cheat_codes[i].stateptr; #if defined(DXX_BUILD_DESCENT_I) if (!cheats.enabled && cheats.*gotcha != cheats.enabled) - return 0; + return window_event_result::ignored; if (!cheats.enabled) HUD_init_message_literal(HM_DEFAULT, TXT_CHEATS_ENABLED); #endif @@ -1704,7 +1701,7 @@ static int FinalCheats(int key) HUD_init_message_literal(HM_DEFAULT, cheats.acid?"Going up!":"Coming down!"); } - return 1; + return window_event_result::handled; } // Internal Cheat Menu @@ -1807,7 +1804,7 @@ static void play_test_sound() #endif //ifndef NDEBUG -int ReadControls(d_event *event) +window_event_result ReadControls(d_event *event) { int key; static ubyte exploding_flag=0; @@ -1824,7 +1821,7 @@ int ReadControls(d_event *event) } if (Player_is_dead && !( (Game_mode & GM_MULTI) && (multi_sending_message[Player_num] || multi_defining_message) )) if (HandleDeathInput(event)) - return 1; + return window_event_result::handled; if (Newdemo_state == ND_STATE_PLAYBACK) update_vcr_state(); @@ -1853,27 +1850,34 @@ int ReadControls(d_event *event) if (Endlevel_sequence) { if (HandleEndlevelKey(key)) - return 1; + return window_event_result::handled; } else if (Newdemo_state == ND_STATE_PLAYBACK ) { if (HandleDemoKey(key)) - return 1; + return window_event_result::handled; } else { - if (FinalCheats(key)) return 1; - if (HandleSystemKey(key)) return 1; - if (HandleGameKey(key)) return 1; + window_event_result r = FinalCheats(key); + if (r == window_event_result::ignored) + r = HandleSystemKey(key); + if (r == window_event_result::ignored) + r = HandleGameKey(key); + if (r != window_event_result::ignored) + return r; } #ifndef RELEASE - if (HandleTestKey(key)) - return 1; + { + window_event_result r = HandleTestKey(key); + if (r != window_event_result::ignored) + return r; + } #endif if (call_default_handler(event)) - return 1; + return window_event_result::handled; } if (!Endlevel_sequence && !Player_is_dead && (Newdemo_state != ND_STATE_PLAYBACK)) @@ -1890,13 +1894,10 @@ int ReadControls(d_event *event) if (!((Game_mode & GM_MULTI) && Control_center_destroyed && (Countdown_seconds_left < 10))) { do_automap(); - return 1; + return window_event_result::handled; } } - do_weapon_n_item_stuff(); } - - return 0; + return window_event_result::ignored; } - diff --git a/similar/main/kconfig.cpp b/similar/main/kconfig.cpp index c842aacbd..ce351b343 100644 --- a/similar/main/kconfig.cpp +++ b/similar/main/kconfig.cpp @@ -962,11 +962,11 @@ static inline int in_bounds(unsigned mx, unsigned my, unsigned x1, unsigned xw, return 1; } -static int kconfig_mouse(window *wind, d_event *event, kc_menu *menu) +static window_event_result kconfig_mouse(window *wind, d_event *event, kc_menu *menu) { grs_canvas * save_canvas = grd_curcanv; int mx, my, mz, x1, y1; - int rval = 0; + window_event_result rval = window_event_result::ignored; gr_set_current_canvas(window_get_canvas(wind)); @@ -981,7 +981,7 @@ static int kconfig_mouse(window *wind, d_event *event, kc_menu *menu) y1 = grd_curcanv->cv_bitmap.bm_y + FSPACY(menu->items[i].y); if (in_bounds(mx, my, x1, FSPACX(menu->items[i].w2), y1, item_height)) { menu->citem = i; - rval = 1; + rval = window_event_result::handled; break; } } @@ -996,13 +996,13 @@ static int kconfig_mouse(window *wind, d_event *event, kc_menu *menu) y1 = grd_curcanv->cv_bitmap.bm_y + FSPACY(menu->items[menu->citem].y); if (in_bounds(mx, my, x1, FSPACX(menu->items[menu->citem].w2), y1, item_height)) { kconfig_start_changing(menu); - rval = 1; + rval = window_event_result::handled; } else { // Click out of changing mode - kreatordxx menu->changing = 0; - rval = 1; + rval = window_event_result::handled; } } @@ -1018,7 +1018,7 @@ static void reset_mitem_values(kc_mitem (&m)[M], const ubyte (&c)[C]) m[i].value = c[i]; } -static int kconfig_key_command(window *wind, d_event *event, kc_menu *menu) +static window_event_result kconfig_key_command(window *wind, d_event *event, kc_menu *menu) { int k; @@ -1026,13 +1026,12 @@ static int kconfig_key_command(window *wind, d_event *event, kc_menu *menu) // when changing, process no keys instead of ESC if (menu->changing && (k != -2 && k != KEY_ESC)) - return 0; - + return window_event_result::ignored; switch (k) { case KEY_CTRLED+KEY_D: menu->mitems[menu->citem].value = 255; - return 1; + return window_event_result::handled; case KEY_CTRLED+KEY_R: if ( menu->items==kc_keyboard ) reset_mitem_values(kcm_keyboard, DefaultKeySettings[0]); @@ -1044,37 +1043,40 @@ static int kconfig_key_command(window *wind, d_event *event, kc_menu *menu) reset_mitem_values(kcm_mouse, DefaultKeySettings[2]); if ( menu->items==kc_rebirth ) reset_mitem_values(kcm_rebirth, DefaultKeySettingsRebirth); - return 1; + return window_event_result::handled; case KEY_DELETE: menu->mitems[menu->citem].value=255; - return 1; + return window_event_result::handled; case KEY_UP: case KEY_PAD8: menu->citem = menu->items[menu->citem].u; - return 1; + return window_event_result::handled; case KEY_DOWN: case KEY_PAD2: menu->citem = menu->items[menu->citem].d; - return 1; + return window_event_result::handled; case KEY_LEFT: case KEY_PAD4: menu->citem = menu->items[menu->citem].l; - return 1; + return window_event_result::handled; case KEY_RIGHT: case KEY_PAD6: menu->citem = menu->items[menu->citem].r; - return 1; + return window_event_result::handled; case KEY_ENTER: case KEY_PADENTER: kconfig_start_changing(menu); - return 1; + return window_event_result::handled; case -2: case KEY_ESC: if (menu->changing) menu->changing = 0; else + { window_close(wind); - return 1; + return window_event_result::close; + } + return window_event_result::handled; #ifdef TABLE_CREATION case KEY_F12: { PHYSFS_file * fp; @@ -1097,7 +1099,7 @@ static int kconfig_key_command(window *wind, d_event *event, kc_menu *menu) PHYSFS_close(fp); } - return 1; + return window_event_result::handled; #endif case 0: // some other event break; @@ -1105,11 +1107,10 @@ static int kconfig_key_command(window *wind, d_event *event, kc_menu *menu) default: break; } - - return 0; + return window_event_result::ignored; } -static int kconfig_handler(window *wind, d_event *event, kc_menu *menu) +static window_event_result kconfig_handler(window *wind, d_event *event, kc_menu *menu) { switch (event->type) { @@ -1131,17 +1132,20 @@ static int kconfig_handler(window *wind, d_event *event, kc_menu *menu) { kc_change_mousebutton(*menu, event, menu->mitems[menu->citem] ); menu->mouse_state = (event->type == EVENT_MOUSE_BUTTON_DOWN); - return 1; + return window_event_result::handled; } if (event_mouse_get_button(event) == MBTN_RIGHT) { if (!menu->changing) + { window_close(wind); - return 1; + return window_event_result::close; + } + return window_event_result::handled; } else if (event_mouse_get_button(event) != MBTN_LEFT) - return 0; + return window_event_result::ignored; menu->mouse_state = (event->type == EVENT_MOUSE_BUTTON_DOWN); return kconfig_mouse(wind, event, menu); @@ -1168,11 +1172,11 @@ static int kconfig_handler(window *wind, d_event *event, kc_menu *menu) case EVENT_KEY_COMMAND: { - int rval = kconfig_key_command(wind, event, menu); - if (rval) + window_event_result rval = kconfig_key_command(wind, event, menu); + if (rval != window_event_result::ignored) return rval; if (menu->changing && menu->items[menu->citem].type == BT_KEY) kc_change_key(*menu, event, menu->mitems[menu->citem]); - return 0; + return window_event_result::ignored; } case EVENT_IDLE: @@ -1203,15 +1207,14 @@ static int kconfig_handler(window *wind, d_event *event, kc_menu *menu) for (unsigned i=0; i < lengthof(kc_rebirth); i++) PlayerCfg.KeySettingsRebirth[i] = kcm_rebirth[i].value; - return 0; // continue closing + return window_event_result::ignored; // continue closing break; default: - return 0; + return window_event_result::ignored; break; } - - return 1; + return window_event_result::handled; } static void kconfig_sub(const char *litems, const kc_item * items,kc_mitem *mitems,int nitems, const char *title) diff --git a/similar/main/kmatrix.cpp b/similar/main/kmatrix.cpp index c4163c0f2..3e4ef1662 100644 --- a/similar/main/kmatrix.cpp +++ b/similar/main/kmatrix.cpp @@ -259,7 +259,7 @@ static void kmatrix_redraw_coop() gr_palette_load(gr_palette); } -static int kmatrix_handler(window *wind, d_event *event, kmatrix_screen *km) +static window_event_result kmatrix_handler(window *wind, d_event *event, kmatrix_screen *km) { int i = 0, k = 0, choice = 0; @@ -288,9 +288,9 @@ static int kmatrix_handler(window *wind, d_event *event, kmatrix_screen *km) window_close(wind); if (Game_wind) window_close(Game_wind); - return 1; + return window_event_result::close; } - return 1; + return window_event_result::handled; default: break; @@ -339,12 +339,12 @@ static int kmatrix_handler(window *wind, d_event *event, kmatrix_screen *km) window_close(wind); if (Game_wind) window_close(Game_wind); - return 0; + return window_event_result::close; } } #endif window_close(wind); - break; + return window_event_result::close; } kmatrix_redraw(km); @@ -363,8 +363,7 @@ static int kmatrix_handler(window *wind, d_event *event, kmatrix_screen *km) default: break; } - - return 0; + return window_event_result::ignored; } void kmatrix_view(int network) diff --git a/similar/main/menu.cpp b/similar/main/menu.cpp index 6ea12f702..9ed1d784d 100644 --- a/similar/main/menu.cpp +++ b/similar/main/menu.cpp @@ -2027,7 +2027,7 @@ void do_options_menu() } #ifndef RELEASE -static int polygon_models_viewer_handler(window *wind, d_event *event, unused_window_userdata_t *) +static window_event_result polygon_models_viewer_handler(window *wind, d_event *event, unused_window_userdata_t *) { static int view_idx = 0; int key = 0; @@ -2050,7 +2050,7 @@ static int polygon_models_viewer_handler(window *wind, d_event *event, unused_wi { case KEY_ESC: window_close(wind); - break; + return window_event_result::close; case KEY_SPACEBAR: view_idx ++; if (view_idx >= N_polygon_models) view_idx = 0; @@ -2084,7 +2084,7 @@ static int polygon_models_viewer_handler(window *wind, d_event *event, unused_wi default: break; } - return 1; + return window_event_result::handled; case EVENT_WINDOW_DRAW: timer_delay(F1_0/60); draw_model_picture(view_idx, &ang); @@ -2099,8 +2099,7 @@ static int polygon_models_viewer_handler(window *wind, d_event *event, unused_wi default: break; } - - return 0; + return window_event_result::ignored; } static void polygon_models_viewer() @@ -2117,7 +2116,7 @@ static void polygon_models_viewer() event_process(); } -static int gamebitmaps_viewer_handler(window *wind, d_event *event, unused_window_userdata_t *) +static window_event_result gamebitmaps_viewer_handler(window *wind, d_event *event, unused_window_userdata_t *) { static int view_idx = 0; int key = 0; @@ -2142,7 +2141,7 @@ static int gamebitmaps_viewer_handler(window *wind, d_event *event, unused_windo { case KEY_ESC: window_close(wind); - break; + return window_event_result::close; case KEY_SPACEBAR: view_idx ++; if (view_idx >= Num_bitmap_files) view_idx = 0; @@ -2154,7 +2153,7 @@ static int gamebitmaps_viewer_handler(window *wind, d_event *event, unused_windo default: break; } - return 1; + return window_event_result::handled; case EVENT_WINDOW_DRAW: bi.index = view_idx; bm = &GameBitmaps[view_idx]; @@ -2178,8 +2177,7 @@ static int gamebitmaps_viewer_handler(window *wind, d_event *event, unused_windo default: break; } - - return 0; + return window_event_result::ignored; } static void gamebitmaps_viewer() diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index 133d2b813..de4d8ab3b 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -1427,7 +1427,7 @@ static void multi_define_macro_end() game_flush_inputs(); } -int multi_message_input_sub(int key) +window_event_result multi_message_input_sub(int key) { switch( key ) { @@ -1438,21 +1438,21 @@ int multi_message_input_sub(int key) multi_defining_message = 0; key_toggle_repeat(0); game_flush_inputs(); - return 1; + return window_event_result::handled; case KEY_LEFT: case KEY_BACKSP: case KEY_PAD4: if (multi_message_index > 0) multi_message_index--; Network_message[multi_message_index] = 0; - return 1; + return window_event_result::handled; case KEY_ENTER: if ( multi_sending_message[Player_num] ) multi_send_message_end(); else if ( multi_defining_message ) multi_define_macro_end(); game_flush_inputs(); - return 1; + return window_event_result::handled; default: { int ascii = key_ascii(); @@ -1488,8 +1488,7 @@ int multi_message_input_sub(int key) } } } - - return 0; + return window_event_result::ignored; } void diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index 2831fedbc..9a82e9f43 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -5128,7 +5128,7 @@ void net_udp_send_extras () Player_joining_extras=-1; } -static int show_game_rules_handler(window *wind, d_event *event, netgame_info *netgame) +static window_event_result show_game_rules_handler(window *wind, d_event *event, netgame_info *netgame) { int k; #if defined(DXX_BUILD_DESCENT_I) @@ -5151,7 +5151,7 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n case KEY_SPACEBAR: case KEY_ESC: window_close(wind); - return 1; + return window_event_result::close; } break; @@ -5300,8 +5300,7 @@ static int show_game_rules_handler(window *wind, d_event *event, netgame_info *n default: break; } - - return 0; + return window_event_result::ignored; } static void net_udp_show_game_rules(netgame_info *netgame) diff --git a/similar/main/newmenu.cpp b/similar/main/newmenu.cpp index 10460261f..0cb377230 100644 --- a/similar/main/newmenu.cpp +++ b/similar/main/newmenu.cpp @@ -595,7 +595,7 @@ static void newmenu_scroll(newmenu *menu, int amount) } } -static int newmenu_mouse(window *wind, d_event *event, newmenu *menu, int button) +static window_event_result newmenu_mouse(window *wind, d_event *event, newmenu *menu, int button) { int old_choice, i, mx=0, my=0, mz=0, x1 = 0, x2, y1, y2, changed = 0; grs_canvas *menu_canvas = window_get_canvas(wind), *save_canvas = grd_curcanv; @@ -768,13 +768,13 @@ static int newmenu_mouse(window *wind, d_event *event, newmenu *menu, int button // Tell callback, allow staying in menu event->type = EVENT_NEWMENU_SELECTED; if (menu->subfunction && (*menu->subfunction)(menu, event, menu->userdata)) - return 1; + return window_event_result::handled; if (menu->rval) *menu->rval = menu->citem; window_close(menu->wind); gr_set_current_canvas(save_canvas); - return 1; + return window_event_result::close; } else menu->dblclick_flag = 1; } @@ -783,13 +783,13 @@ static int newmenu_mouse(window *wind, d_event *event, newmenu *menu, int button // Tell callback, allow staying in menu event->type = EVENT_NEWMENU_SELECTED; if (menu->subfunction && (*menu->subfunction)(menu, event, menu->userdata)) - return 1; + return window_event_result::handled; if (menu->rval) *menu->rval = menu->citem; window_close(menu->wind); gr_set_current_canvas(save_canvas); - return 1; + return window_event_result::close; } } } @@ -824,7 +824,7 @@ static int newmenu_mouse(window *wind, d_event *event, newmenu *menu, int button menu->items[menu->citem].value = -1; } else { window_close(menu->wind); - return 1; + return window_event_result::close; } } break; @@ -838,17 +838,17 @@ static int newmenu_mouse(window *wind, d_event *event, newmenu *menu, int button break; } - return 0; + return window_event_result::ignored; } -static int newmenu_key_command(window *wind, d_event *event, newmenu *menu) +static window_event_result newmenu_key_command(window *wind, d_event *event, newmenu *menu) { newmenu_item *item = &menu->items[menu->citem]; int k = event_key_get(event); int old_choice, i; char *Temp,TempVal; int changed = 0; - int rval = 1; + window_event_result rval = window_event_result::handled; if (keyd_pressed[KEY_NUMLOCK]) { @@ -994,12 +994,12 @@ static int newmenu_key_command(window *wind, d_event *event, newmenu *menu) // Tell callback, allow staying in menu event->type = EVENT_NEWMENU_SELECTED; if (menu->subfunction && (*menu->subfunction)(menu, event, menu->userdata)) - return 1; + return window_event_result::handled; if (menu->rval) *menu->rval = menu->citem; window_close(menu->wind); - return 1; + return window_event_result::close; } break; @@ -1010,7 +1010,7 @@ static int newmenu_key_command(window *wind, d_event *event, newmenu *menu) item->value = -1; } else { window_close(menu->wind); - return 1; + return window_event_result::close; } break; @@ -1022,7 +1022,7 @@ static int newmenu_key_command(window *wind, d_event *event, newmenu *menu) #endif default: - rval = 0; + rval = window_event_result::ignored; break; } @@ -1039,7 +1039,7 @@ static int newmenu_key_command(window *wind, d_event *event, newmenu *menu) if (item->type==NM_TYPE_INPUT) changed = 1; - rval = 1; + rval = window_event_result::handled; } else { ascii = key_ascii(); if ((ascii < 255 ) && (item->value < item->text_len )) @@ -1108,23 +1108,23 @@ static int newmenu_key_command(window *wind, d_event *event, newmenu *menu) case KEY_PAD4: item->value -= 1; changed = 1; - rval = 1; + rval = window_event_result::handled; break; case KEY_RIGHT: case KEY_PAD6: item->value++; changed = 1; - rval = 1; + rval = window_event_result::handled; break; case KEY_SPACEBAR: item->value += 10; changed = 1; - rval = 1; + rval = window_event_result::handled; break; case KEY_BACKSP: item->value -= 10; changed = 1; - rval = 1; + rval = window_event_result::handled; break; } @@ -1364,7 +1364,7 @@ static void newmenu_create_structure( newmenu *menu ) gr_set_current_canvas(save_canvas); } -static int newmenu_draw(window *wind, newmenu *menu) +static window_event_result newmenu_draw(window *wind, newmenu *menu) { grs_canvas *menu_canvas = window_get_canvas(wind), *save_canvas = grd_curcanv; int th = 0, ty, sx, sy; @@ -1446,20 +1446,20 @@ static int newmenu_draw(window *wind, newmenu *menu) gr_set_current_canvas(save_canvas); - return 1; + return window_event_result::handled; } -static int newmenu_handler(window *wind, d_event *event, newmenu *menu) +static window_event_result newmenu_handler(window *wind, d_event *event, newmenu *menu) { if (event->type == EVENT_WINDOW_CLOSED) - return 0; + return window_event_result::ignored; if (menu->subfunction) { int rval = (*menu->subfunction)(menu, event, menu->userdata); if (!window_exists(wind)) - return 1; // some subfunction closed the window: bail! + return window_event_result::handled; // some subfunction closed the window: bail! if (rval) { @@ -1468,9 +1468,10 @@ static int newmenu_handler(window *wind, d_event *event, newmenu *menu) if (menu->rval) *menu->rval = rval; window_close(wind); + return window_event_result::close; } - return 1; // event handled + return window_event_result::handled; // event handled } } @@ -1503,18 +1504,11 @@ static int newmenu_handler(window *wind, d_event *event, newmenu *menu) case EVENT_KEY_COMMAND: return newmenu_key_command(wind, event, menu); - break; - case EVENT_IDLE: timer_delay2(50); - return newmenu_mouse(wind, event, menu, -1); - break; - case EVENT_WINDOW_DRAW: return newmenu_draw(wind, menu); - break; - case EVENT_WINDOW_CLOSE: d_free(menu); break; @@ -1522,8 +1516,7 @@ static int newmenu_handler(window *wind, d_event *event, newmenu *menu) default: break; } - - return 0; + return window_event_result::ignored; } newmenu *newmenu_do4( const char * title, const char * subtitle, int nitems, newmenu_item * item, newmenu_subfunction subfunction, void *userdata, int citem, const char * filename, int TinyMode, int TabsFlag ) @@ -1703,7 +1696,7 @@ static void update_scroll_position(listbox *lb) if (lb->first_item < 0 ) lb->first_item = 0; } -static int listbox_mouse(window *wind, d_event *event, listbox *lb, int button) +static window_event_result listbox_mouse(window *wind, d_event *event, listbox *lb, int button) { int i, mx, my, mz, x1, x2, y1, y2; @@ -1726,7 +1719,7 @@ static int listbox_mouse(window *wind, d_event *event, listbox *lb, int button) y2 = y1+h; if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) { lb->citem = i; - return 1; + return window_event_result::handled; } } } @@ -1735,7 +1728,7 @@ static int listbox_mouse(window *wind, d_event *event, listbox *lb, int button) int w, h, aw; if (lb->citem < 0) - return 0; + return window_event_result::ignored; mouse_get_pos(&mx, &my, &mz); gr_get_string_size(lb->item[lb->citem], &w, &h, &aw ); @@ -1748,10 +1741,9 @@ static int listbox_mouse(window *wind, d_event *event, listbox *lb, int button) // Tell callback, allow staying in menu event->type = EVENT_NEWMENU_SELECTED; if (lb->listbox_callback && (*lb->listbox_callback)(lb, event, lb->userdata)) - return 1; - + return window_event_result::handled; window_close(wind); - return 1; + return window_event_result::close; } } break; @@ -1761,7 +1753,7 @@ static int listbox_mouse(window *wind, d_event *event, listbox *lb, int button) if (lb->allow_abort_flag && lb->mouse_state) { lb->citem = -1; window_close(wind); - return 1; + return window_event_result::close; } break; } @@ -1787,13 +1779,13 @@ static int listbox_mouse(window *wind, d_event *event, listbox *lb, int button) break; } - return 0; + return window_event_result::ignored; } -static int listbox_key_command(window *wind, d_event *event, listbox *lb) +static window_event_result listbox_key_command(window *wind, d_event *event, listbox *lb) { int key = event_key_get(event); - int rval = 1; + window_event_result rval = window_event_result::handled; switch(key) { case KEY_HOME: @@ -1824,7 +1816,7 @@ static int listbox_key_command(window *wind, d_event *event, listbox *lb) if (lb->allow_abort_flag) { lb->citem = -1; window_close(wind); - return 1; + return window_event_result::close; } break; case KEY_ENTER: @@ -1832,12 +1824,9 @@ static int listbox_key_command(window *wind, d_event *event, listbox *lb) // Tell callback, allow staying in menu event->type = EVENT_NEWMENU_SELECTED; if (lb->listbox_callback && (*lb->listbox_callback)(lb, event, lb->userdata)) - return 1; - + return window_event_result::handled; window_close(wind); - return 1; - break; - + return window_event_result::close; default: { int ascii = key_ascii(); @@ -1858,12 +1847,10 @@ static int listbox_key_command(window *wind, d_event *event, listbox *lb) cc++; } } - rval = 0; + rval = window_event_result::ignored; } } - update_scroll_position(lb); - return rval; } @@ -1922,7 +1909,7 @@ static void listbox_create_structure( listbox *lb) lb->fntscaley = FNTScaleY; } -static int listbox_draw(window *wind, listbox *lb) +static window_event_result listbox_draw(window *wind, listbox *lb) { int i; @@ -2005,20 +1992,19 @@ static int listbox_draw(window *wind, listbox *lb) if ( lb->listbox_callback ) (*lb->listbox_callback)(lb, &event, lb->userdata); } - - return 1; + return window_event_result::handled; } -static int listbox_handler(window *wind, d_event *event, listbox *lb) +static window_event_result listbox_handler(window *wind, d_event *event, listbox *lb) { if (event->type == EVENT_WINDOW_CLOSED) - return 0; + return window_event_result::ignored; if (lb->listbox_callback) { int rval = (*lb->listbox_callback)(lb, event, lb->userdata); if (rval) - return 1; // event handled + return window_event_result::handled; // event handled } switch (event->type) @@ -2038,30 +2024,20 @@ static int listbox_handler(window *wind, d_event *event, listbox *lb) case EVENT_MOUSE_BUTTON_UP: lb->mouse_state = event->type == EVENT_MOUSE_BUTTON_DOWN; return listbox_mouse(wind, event, lb, event_mouse_get_button(event)); - case EVENT_KEY_COMMAND: return listbox_key_command(wind, event, lb); - break; - case EVENT_IDLE: timer_delay2(50); - return listbox_mouse(wind, event, lb, -1); - break; - case EVENT_WINDOW_DRAW: return listbox_draw(wind, lb); - break; - case EVENT_WINDOW_CLOSE: d_free(lb); break; - default: break; } - - return 0; + return window_event_result::ignored; } listbox *newmenu_listbox1( const char * title, int nitems, const char *items[], int allow_abort_flag, int default_item, listbox_subfunction_t::type listbox_callback, void *userdata ) diff --git a/similar/main/scores.cpp b/similar/main/scores.cpp index 78c6b5313..f2b9ba6a7 100644 --- a/similar/main/scores.cpp +++ b/similar/main/scores.cpp @@ -361,7 +361,7 @@ struct scores_menu stats_info last_game; }; -static int scores_handler(window *wind, d_event *event, scores_menu *menu) +static window_event_result scores_handler(window *wind, d_event *event, scores_menu *menu) { int i; int k; @@ -384,15 +384,15 @@ static int scores_handler(window *wind, d_event *event, scores_menu *menu) PHYSFS_delete(SCORES_FILENAME); scores_view(&menu->last_game, menu->citem); // create new scores window window_close(wind); // then remove the old one + return window_event_result::close; } } - return 1; - + return window_event_result::handled; case KEY_ENTER: case KEY_SPACEBAR: case KEY_ESC: window_close(wind); - return 1; + return window_event_result::close; } break; @@ -401,7 +401,7 @@ static int scores_handler(window *wind, d_event *event, scores_menu *menu) if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT) { window_close(wind); - return 1; + return window_event_result::close; } break; @@ -462,8 +462,7 @@ static int scores_handler(window *wind, d_event *event, scores_menu *menu) default: break; } - - return 0; + return window_event_result::ignored; } void scores_view(stats_info *last_game, int citem) diff --git a/similar/main/titles.cpp b/similar/main/titles.cpp index 342970a84..a29734a2f 100644 --- a/similar/main/titles.cpp +++ b/similar/main/titles.cpp @@ -102,25 +102,28 @@ struct title_screen int allow_keys; }; -static int title_handler(window *wind, d_event *event, title_screen *ts) +static window_event_result title_handler(window *wind, d_event *event, title_screen *ts) { switch (event->type) { case EVENT_MOUSE_BUTTON_DOWN: if (event_mouse_get_button(event) != 0) - return 0; + return window_event_result::ignored; else if (ts->allow_keys) { window_close(wind); - return 1; + return window_event_result::close; } break; case EVENT_KEY_COMMAND: if (!call_default_handler(event)) if (ts->allow_keys) + { window_close(wind); - return 1; + return window_event_result::close; + } + return window_event_result::handled; case EVENT_IDLE: timer_delay2(50); @@ -128,7 +131,7 @@ static int title_handler(window *wind, d_event *event, title_screen *ts) if (timer_query() > ts->timer) { window_close(wind); - return 1; + return window_event_result::close; } break; @@ -145,8 +148,7 @@ static int title_handler(window *wind, d_event *event, title_screen *ts) default: break; } - - return 0; + return window_event_result::ignored; } static int show_title_screen(const char * filename, int allow_keys, int from_hog_only ) @@ -1457,7 +1459,7 @@ static int new_briefing_screen(briefing *br, int first) //----------------------------------------------------------------------------- -static int briefing_handler(window *wind, d_event *event, briefing *br) +static window_event_result briefing_handler(window *wind, d_event *event, briefing *br) { switch (event->type) { @@ -1474,15 +1476,14 @@ static int briefing_handler(window *wind, d_event *event, briefing *br) if (!new_briefing_screen(br, 0)) { window_close(wind); - return 1; + return window_event_result::close; } } else if (br->new_page) init_new_page(br); else br->delay_count = 0; - - return 1; + return window_event_result::handled; } break; @@ -1499,8 +1500,7 @@ static int briefing_handler(window *wind, d_event *event, briefing *br) #endif case KEY_ESC: window_close(wind); - return 1; - + return window_event_result::close; case KEY_SPACEBAR: case KEY_ENTER: br->delay_count = 0; @@ -1508,13 +1508,13 @@ static int briefing_handler(window *wind, d_event *event, briefing *br) default: if (call_default_handler(event)) - return 1; + return window_event_result::handled; else if (br->new_screen) { if (!new_briefing_screen(br, 0)) { window_close(wind); - return 1; + return window_event_result::close; } } else if (br->new_page) @@ -1577,8 +1577,7 @@ static int briefing_handler(window *wind, d_event *event, briefing *br) default: break; } - - return 0; + return window_event_result::ignored; } void do_briefing_screens(const d_fname &filename, int level_num)