2014-06-01 17:55:23 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2014-06-01 17:55:23 +00:00
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
2006-04-03 17:36:27 +00:00
|
|
|
// Event header file
|
|
|
|
|
2015-10-09 02:46:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-18 20:37:29 +00:00
|
|
|
#include <SDL_version.h>
|
2015-10-09 02:46:10 +00:00
|
|
|
#include "fwd-event.h"
|
2012-03-30 14:29:03 +00:00
|
|
|
#include "maths.h"
|
2006-04-03 17:36:27 +00:00
|
|
|
|
2019-08-18 20:37:29 +00:00
|
|
|
#if SDL_MAJOR_VERSION == 2
|
|
|
|
#include <SDL_video.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2012-11-11 22:12:51 +00:00
|
|
|
|
2015-10-09 02:46:10 +00:00
|
|
|
enum event_type : unsigned
|
2009-05-21 12:16:39 +00:00
|
|
|
{
|
2010-01-07 14:49:07 +00:00
|
|
|
EVENT_IDLE = 0,
|
2010-05-03 08:44:46 +00:00
|
|
|
EVENT_QUIT,
|
|
|
|
|
2020-09-11 03:08:02 +00:00
|
|
|
#if DXX_MAX_BUTTONS_PER_JOYSTICK
|
2011-02-02 00:36:43 +00:00
|
|
|
EVENT_JOYSTICK_BUTTON_DOWN,
|
|
|
|
EVENT_JOYSTICK_BUTTON_UP,
|
2020-09-11 03:08:02 +00:00
|
|
|
#endif
|
|
|
|
#if DXX_MAX_AXES_PER_JOYSTICK
|
2011-02-02 00:36:43 +00:00
|
|
|
EVENT_JOYSTICK_MOVED,
|
2020-09-11 03:08:02 +00:00
|
|
|
#endif
|
2011-02-02 00:36:43 +00:00
|
|
|
|
2010-03-24 07:26:52 +00:00
|
|
|
EVENT_MOUSE_BUTTON_DOWN,
|
|
|
|
EVENT_MOUSE_BUTTON_UP,
|
2011-10-09 10:31:44 +00:00
|
|
|
EVENT_MOUSE_DOUBLE_CLICKED,
|
2011-01-13 04:36:19 +00:00
|
|
|
EVENT_MOUSE_MOVED,
|
2010-05-03 08:44:46 +00:00
|
|
|
|
2010-01-07 14:49:07 +00:00
|
|
|
EVENT_KEY_COMMAND,
|
2011-02-02 00:36:43 +00:00
|
|
|
EVENT_KEY_RELEASE,
|
2010-05-03 08:44:46 +00:00
|
|
|
|
2013-12-13 22:39:01 +00:00
|
|
|
EVENT_WINDOW_CREATED,
|
2019-08-18 20:37:29 +00:00
|
|
|
#if SDL_MAJOR_VERSION == 2
|
|
|
|
EVENT_WINDOW_RESIZE,
|
|
|
|
#endif
|
2010-01-20 05:10:32 +00:00
|
|
|
EVENT_WINDOW_ACTIVATED,
|
2010-02-02 03:38:29 +00:00
|
|
|
EVENT_WINDOW_DEACTIVATED,
|
2010-01-20 05:10:32 +00:00
|
|
|
EVENT_WINDOW_DRAW,
|
|
|
|
EVENT_WINDOW_CLOSE,
|
2010-05-03 08:44:46 +00:00
|
|
|
|
|
|
|
EVENT_NEWMENU_DRAW, // draw after the newmenu stuff is drawn (e.g. savegame previews)
|
|
|
|
EVENT_NEWMENU_CHANGED, // an item had its value/text changed
|
2012-03-03 12:12:25 +00:00
|
|
|
EVENT_NEWMENU_SELECTED, // user chose something - pressed enter/clicked on it
|
2020-05-27 03:07:17 +00:00
|
|
|
|
|
|
|
EVENT_LOOP_BEGIN_LOOP,
|
2022-02-27 14:23:53 +00:00
|
|
|
EVENT_LOOP_END_LOOP,
|
2020-05-27 03:07:17 +00:00
|
|
|
|
2012-03-24 09:18:03 +00:00
|
|
|
EVENT_UI_DIALOG_DRAW, // draw after the dialog stuff is drawn (e.g. spinning robots)
|
2012-03-03 12:12:25 +00:00
|
|
|
EVENT_UI_GADGET_PRESSED, // user 'pressed' a gadget
|
|
|
|
EVENT_UI_LISTBOX_MOVED,
|
|
|
|
EVENT_UI_LISTBOX_SELECTED,
|
|
|
|
EVENT_UI_USERBOX_DRAGGED
|
2015-10-09 02:46:10 +00:00
|
|
|
};
|
2009-05-21 12:16:39 +00:00
|
|
|
|
2016-10-31 02:17:54 +00:00
|
|
|
enum class window_event_result : uint8_t
|
2016-10-28 05:32:24 +00:00
|
|
|
{
|
|
|
|
// Window ignored event. Bubble up.
|
|
|
|
ignored,
|
|
|
|
// Window handled event.
|
|
|
|
handled,
|
|
|
|
close,
|
|
|
|
// Window handler already deleted window (most likely because it was subclassed), don't attempt to re-delete
|
|
|
|
deleted,
|
|
|
|
};
|
|
|
|
|
2009-05-21 12:16:39 +00:00
|
|
|
// A vanilla event. Cast to the correct type of event according to 'type'.
|
2013-12-22 22:03:07 +00:00
|
|
|
struct d_event
|
2009-05-21 12:16:39 +00:00
|
|
|
{
|
2018-05-12 18:24:19 +00:00
|
|
|
const event_type type;
|
|
|
|
constexpr d_event(const event_type t) :
|
|
|
|
type(t)
|
|
|
|
{
|
|
|
|
}
|
2013-12-22 22:03:07 +00:00
|
|
|
};
|
2009-05-21 12:16:39 +00:00
|
|
|
|
2014-12-20 04:36:09 +00:00
|
|
|
struct d_create_event : d_event
|
|
|
|
{
|
2020-10-22 02:26:16 +00:00
|
|
|
constexpr d_create_event() :
|
|
|
|
d_event{EVENT_WINDOW_CREATED}
|
2018-05-12 18:24:19 +00:00
|
|
|
{
|
|
|
|
}
|
2014-12-20 04:36:09 +00:00
|
|
|
};
|
|
|
|
|
2015-02-28 22:34:07 +00:00
|
|
|
struct d_change_event : d_event
|
|
|
|
{
|
2018-05-12 18:24:19 +00:00
|
|
|
const int citem;
|
|
|
|
constexpr d_change_event(const int c) :
|
2015-10-09 02:46:10 +00:00
|
|
|
d_event{EVENT_NEWMENU_CHANGED}, citem(c)
|
2015-02-28 22:34:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-28 22:34:07 +00:00
|
|
|
struct d_select_event : d_event
|
|
|
|
{
|
|
|
|
int citem;
|
|
|
|
d_select_event(const int c) :
|
2015-10-09 02:46:10 +00:00
|
|
|
d_event{EVENT_NEWMENU_SELECTED}, citem(c)
|
2015-02-28 22:34:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-18 20:37:29 +00:00
|
|
|
#if SDL_MAJOR_VERSION == 2
|
|
|
|
struct d_window_size_event : d_event
|
|
|
|
{
|
|
|
|
Sint32 width;
|
|
|
|
Sint32 height;
|
|
|
|
d_window_size_event(const Sint32 w, const Sint32 h) :
|
|
|
|
d_event{EVENT_WINDOW_RESIZE}, width(w), height(h)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-05-27 03:07:17 +00:00
|
|
|
struct d_event_begin_loop : d_event
|
|
|
|
{
|
|
|
|
d_event_begin_loop() :
|
|
|
|
d_event{EVENT_LOOP_BEGIN_LOOP}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-27 14:23:53 +00:00
|
|
|
struct d_event_end_loop : d_event
|
|
|
|
{
|
|
|
|
d_event_end_loop() :
|
|
|
|
d_event{EVENT_LOOP_END_LOOP}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-10 22:23:36 +00:00
|
|
|
#if DXX_USE_EDITOR
|
2012-03-30 14:29:03 +00:00
|
|
|
fix event_get_idle_seconds();
|
2018-02-10 22:23:36 +00:00
|
|
|
#endif
|
2012-03-18 10:04:16 +00:00
|
|
|
|
2016-10-29 12:06:01 +00:00
|
|
|
// Process all events until the front window is deleted
|
|
|
|
// Won't work if there's the possibility of another window on top
|
|
|
|
// without its own event loop
|
|
|
|
static inline void event_process_all(void)
|
|
|
|
{
|
|
|
|
while (event_process() != window_event_result::deleted) {}
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:57:24 +00:00
|
|
|
}
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|