| 1 |
/* |
| 2 |
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
| 3 |
* It is copyright by its individual contributors, as recorded in the |
| 4 |
* project's Git history. See COPYING.txt at the top level for license |
| 5 |
* terms and a link to the Git history. |
| 6 |
*/ |
| 7 |
// Event header file |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include <SDL_version.h> |
| 12 |
#include "fwd-event.h" |
| 13 |
#include "maths.h" |
| 14 |
|
| 15 |
#if SDL_MAJOR_VERSION == 2 |
| 16 |
#include <SDL_video.h> |
| 17 |
#endif |
| 18 |
|
| 19 |
#ifdef __cplusplus |
| 20 |
namespace dcx { |
| 21 |
|
| 22 |
enum class event_type : uint8_t |
| 23 |
{ |
| 24 |
idle = 0, |
| 25 |
quit, |
| 26 |
|
| 27 |
#if DXX_MAX_BUTTONS_PER_JOYSTICK |
| 28 |
joystick_button_down, |
| 29 |
joystick_button_up, |
| 30 |
#endif |
| 31 |
#if DXX_MAX_AXES_PER_JOYSTICK |
| 32 |
joystick_moved, |
| 33 |
#endif |
| 34 |
|
| 35 |
mouse_button_down, |
| 36 |
mouse_button_up, |
| 37 |
mouse_double_clicked, |
| 38 |
mouse_moved, |
| 39 |
|
| 40 |
key_command, |
| 41 |
key_release, |
| 42 |
|
| 43 |
window_created, |
| 44 |
#if SDL_MAJOR_VERSION == 2 |
| 45 |
window_resize, |
| 46 |
#endif |
| 47 |
window_activated, |
| 48 |
window_deactivated, |
| 49 |
window_draw, |
| 50 |
window_close, |
| 51 |
|
| 52 |
newmenu_draw, // draw after the newmenu stuff is drawn (e.g. savegame previews) |
| 53 |
newmenu_changed, // an item had its value/text changed |
| 54 |
newmenu_selected, // user chose something - pressed enter/clicked on it |
| 55 |
|
| 56 |
loop_begin_loop, |
| 57 |
loop_end_loop, |
| 58 |
|
| 59 |
ui_dialog_draw, // draw after the dialog stuff is drawn (e.g. spinning robots) |
| 60 |
ui_gadget_pressed, // user 'pressed' a gadget |
| 61 |
ui_listbox_moved, |
| 62 |
ui_listbox_selected, |
| 63 |
ui_userbox_dragged |
| 64 |
}; |
| 65 |
|
| 66 |
enum class window_event_result : uint8_t |
| 67 |
{ |
| 68 |
// Window ignored event. Bubble up. |
| 69 |
ignored, |
| 70 |
// Window handled event. |
| 71 |
handled, |
| 72 |
close, |
| 73 |
// Window handler already deleted window (most likely because it was subclassed), don't attempt to re-delete |
| 74 |
deleted, |
| 75 |
}; |
| 76 |
|
| 77 |
// A vanilla event. Cast to the correct type of event according to 'type'. |
| 78 |
struct d_event |
| 79 |
{ |
| 80 |
const event_type type; |
| 81 |
constexpr d_event(const event_type t) : |
| 82 |
type{t} |
| 83 |
{ |
| 84 |
} |
| 85 |
}; |
| 86 |
|
| 87 |
struct d_create_event : d_event |
| 88 |
{ |
| 89 |
constexpr d_create_event() : |
| 90 |
d_event{event_type::window_created} |
| 91 |
{ |
| 92 |
} |
| 93 |
}; |
| 94 |
|
| 95 |
struct d_change_event : d_event |
| 96 |
{ |
| 97 |
const int citem; |
| 98 |
constexpr d_change_event(const int c) : |
| 99 |
d_event{event_type::newmenu_changed}, citem{c} |
| 100 |
{ |
| 101 |
} |
| 102 |
}; |
| 103 |
|
| 104 |
struct d_select_event : d_event |
| 105 |
{ |
| 106 |
int citem; |
| 107 |
d_select_event(const int c) : |
| 108 |
d_event{event_type::newmenu_selected}, citem{c} |
| 109 |
{ |
| 110 |
} |
| 111 |
}; |
| 112 |
|
| 113 |
#if SDL_MAJOR_VERSION == 2 |
| 114 |
struct d_window_size_event : d_event |
| 115 |
{ |
| 116 |
Sint32 width; |
| 117 |
Sint32 height; |
| 118 |
d_window_size_event(const Sint32 w, const Sint32 h) : |
| 119 |
d_event{event_type::window_resize}, width{w}, height{h} |
| 120 |
{ |
| 121 |
} |
| 122 |
}; |
| 123 |
#endif |
| 124 |
|
| 125 |
struct d_event_begin_loop : d_event |
| 126 |
{ |
| 127 |
d_event_begin_loop() : |
| 128 |
d_event{event_type::loop_begin_loop} |
| 129 |
{ |
| 130 |
} |
| 131 |
}; |
| 132 |
|
| 133 |
struct d_event_end_loop : d_event |
| 134 |
{ |
| 135 |
d_event_end_loop() : |
| 136 |
d_event{event_type::loop_end_loop} |
| 137 |
{ |
| 138 |
} |
| 139 |
}; |
| 140 |
|
| 141 |
#if DXX_USE_EDITOR |
| 142 |
fix event_get_idle_seconds(); |
| 143 |
#endif |
| 144 |
|
| 145 |
// Process all events until the front window is deleted |
| 146 |
// Won't work if there's the possibility of another window on top |
| 147 |
// without its own event loop |
| 148 |
static inline void event_process_all(void) |
| 149 |
{ |
| 150 |
while (event_process() != window_event_result::deleted) {} |
| 151 |
} |
| 152 |
|
| 153 |
} |
| 154 |
#endif |