Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 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 event_type : unsigned |
||
| 23 | { |
||
| 24 | EVENT_IDLE = 0, |
||
| 25 | EVENT_QUIT, |
||
| 26 | |||
| 27 | EVENT_JOYSTICK_BUTTON_DOWN, |
||
| 28 | EVENT_JOYSTICK_BUTTON_UP, |
||
| 29 | EVENT_JOYSTICK_MOVED, |
||
| 30 | |||
| 31 | EVENT_MOUSE_BUTTON_DOWN, |
||
| 32 | EVENT_MOUSE_BUTTON_UP, |
||
| 33 | EVENT_MOUSE_DOUBLE_CLICKED, |
||
| 34 | EVENT_MOUSE_MOVED, |
||
| 35 | |||
| 36 | EVENT_KEY_COMMAND, |
||
| 37 | EVENT_KEY_RELEASE, |
||
| 38 | |||
| 39 | EVENT_WINDOW_CREATED, |
||
| 40 | #if SDL_MAJOR_VERSION == 2 |
||
| 41 | EVENT_WINDOW_RESIZE, |
||
| 42 | #endif |
||
| 43 | EVENT_WINDOW_ACTIVATED, |
||
| 44 | EVENT_WINDOW_DEACTIVATED, |
||
| 45 | EVENT_WINDOW_DRAW, |
||
| 46 | EVENT_WINDOW_CLOSE, |
||
| 47 | |||
| 48 | EVENT_NEWMENU_DRAW, // draw after the newmenu stuff is drawn (e.g. savegame previews) |
||
| 49 | EVENT_NEWMENU_CHANGED, // an item had its value/text changed |
||
| 50 | EVENT_NEWMENU_SELECTED, // user chose something - pressed enter/clicked on it |
||
| 51 | |||
| 52 | EVENT_LOOP_BEGIN_LOOP, |
||
| 53 | |||
| 54 | EVENT_UI_DIALOG_DRAW, // draw after the dialog stuff is drawn (e.g. spinning robots) |
||
| 55 | EVENT_UI_GADGET_PRESSED, // user 'pressed' a gadget |
||
| 56 | EVENT_UI_LISTBOX_MOVED, |
||
| 57 | EVENT_UI_LISTBOX_SELECTED, |
||
| 58 | EVENT_UI_USERBOX_DRAGGED |
||
| 59 | }; |
||
| 60 | |||
| 61 | enum class window_event_result : uint8_t |
||
| 62 | { |
||
| 63 | // Window ignored event. Bubble up. |
||
| 64 | ignored, |
||
| 65 | // Window handled event. |
||
| 66 | handled, |
||
| 67 | close, |
||
| 68 | // Window handler already deleted window (most likely because it was subclassed), don't attempt to re-delete |
||
| 69 | deleted, |
||
| 70 | }; |
||
| 71 | |||
| 72 | // A vanilla event. Cast to the correct type of event according to 'type'. |
||
| 73 | struct d_event |
||
| 74 | { |
||
| 75 | const event_type type; |
||
| 76 | constexpr d_event(const event_type t) : |
||
| 77 | type(t) |
||
| 78 | { |
||
| 79 | } |
||
| 80 | }; |
||
| 81 | |||
| 82 | struct d_create_event : d_event |
||
| 83 | { |
||
| 84 | const void *const createdata; |
||
| 85 | constexpr d_create_event(const event_type t, const void *const c) : |
||
| 86 | d_event(t), createdata(c) |
||
| 87 | { |
||
| 88 | } |
||
| 89 | }; |
||
| 90 | |||
| 91 | struct d_change_event : d_event |
||
| 92 | { |
||
| 93 | const int citem; |
||
| 94 | constexpr d_change_event(const int c) : |
||
| 95 | d_event{EVENT_NEWMENU_CHANGED}, citem(c) |
||
| 96 | { |
||
| 97 | } |
||
| 98 | }; |
||
| 99 | |||
| 100 | struct d_select_event : d_event |
||
| 101 | { |
||
| 102 | int citem; |
||
| 103 | d_select_event(const int c) : |
||
| 104 | d_event{EVENT_NEWMENU_SELECTED}, citem(c) |
||
| 105 | { |
||
| 106 | } |
||
| 107 | }; |
||
| 108 | |||
| 109 | #if SDL_MAJOR_VERSION == 2 |
||
| 110 | struct d_window_size_event : d_event |
||
| 111 | { |
||
| 112 | Sint32 width; |
||
| 113 | Sint32 height; |
||
| 114 | d_window_size_event(const Sint32 w, const Sint32 h) : |
||
| 115 | d_event{EVENT_WINDOW_RESIZE}, width(w), height(h) |
||
| 116 | { |
||
| 117 | } |
||
| 118 | }; |
||
| 119 | #endif |
||
| 120 | |||
| 121 | struct d_event_begin_loop : d_event |
||
| 122 | { |
||
| 123 | d_event_begin_loop() : |
||
| 124 | d_event{EVENT_LOOP_BEGIN_LOOP} |
||
| 125 | { |
||
| 126 | } |
||
| 127 | }; |
||
| 128 | |||
| 129 | #if DXX_USE_EDITOR |
||
| 130 | fix event_get_idle_seconds(); |
||
| 131 | #endif |
||
| 132 | |||
| 133 | // Process all events until the front window is deleted |
||
| 134 | // Won't work if there's the possibility of another window on top |
||
| 135 | // without its own event loop |
||
| 136 | static inline void event_process_all(void) |
||
| 137 | { |
||
| 138 | while (event_process() != window_event_result::deleted) {} |
||
| 139 | } |
||
| 140 | |||
| 141 | } |
||
| 142 | #endif |