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-03-20 17:12:09 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Header for joystick functions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-11-01 21:15:40 +00:00
|
|
|
#pragma once
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-11-01 21:15:40 +00:00
|
|
|
#include "dxxsconf.h"
|
2016-03-19 19:08:10 +00:00
|
|
|
#include "dsx-ns.h"
|
2021-02-05 12:54:08 +00:00
|
|
|
#include "fwd-event.h"
|
2015-11-01 21:15:40 +00:00
|
|
|
|
2016-09-25 04:52:48 +00:00
|
|
|
#if DXX_MAX_JOYSTICKS
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "pstypes.h"
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2013-06-30 02:22:56 +00:00
|
|
|
#include <SDL.h>
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2012-11-11 22:12:51 +00:00
|
|
|
|
2017-10-14 17:10:30 +00:00
|
|
|
constexpr std::integral_constant<unsigned, DXX_MAX_AXES_PER_JOYSTICK * DXX_MAX_JOYSTICKS> JOY_MAX_AXES{};
|
2016-09-25 04:52:49 +00:00
|
|
|
#define JOY_MAX_BUTTONS (DXX_MAX_BUTTONS_PER_JOYSTICK * DXX_MAX_JOYSTICKS)
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-09-19 23:04:34 +00:00
|
|
|
struct d_event_joystick_axis_value
|
|
|
|
{
|
|
|
|
unsigned axis;
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
2010-02-14 18:48:02 +00:00
|
|
|
extern void joy_init();
|
2006-03-20 17:12:09 +00:00
|
|
|
extern void joy_close();
|
|
|
|
extern void joy_flush();
|
2019-09-01 14:14:02 +00:00
|
|
|
extern int apply_deadzone(int value, int deadzone);
|
2015-12-05 22:57:24 +00:00
|
|
|
|
|
|
|
}
|
2015-11-01 21:15:40 +00:00
|
|
|
#else
|
2016-11-05 21:22:43 +00:00
|
|
|
#define joy_init() static_cast<void>(0)
|
2015-11-01 21:15:40 +00:00
|
|
|
#define joy_flush()
|
2016-11-05 21:22:43 +00:00
|
|
|
#define joy_close() static_cast<void>(0)
|
2015-11-01 21:15:40 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:24 +00:00
|
|
|
|
2016-09-25 04:52:49 +00:00
|
|
|
#if DXX_MAX_BUTTONS_PER_JOYSTICK
|
2020-09-11 03:08:02 +00:00
|
|
|
bool joy_translate_menu_key(const d_event &event);
|
|
|
|
int event_joystick_get_button(const d_event &event);
|
2020-05-27 03:07:17 +00:00
|
|
|
window_event_result joy_button_handler(const SDL_JoyButtonEvent *jbe);
|
2015-11-01 21:15:40 +00:00
|
|
|
#else
|
2020-05-27 03:07:17 +00:00
|
|
|
#define joy_button_handler(jbe) (static_cast<const SDL_JoyButtonEvent *const &>(jbe), window_event_result::ignored)
|
2015-11-01 21:15:40 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2016-09-25 04:52:49 +00:00
|
|
|
#if DXX_MAX_HATS_PER_JOYSTICK
|
2020-05-27 03:07:17 +00:00
|
|
|
window_event_result joy_hat_handler(const SDL_JoyHatEvent *jhe);
|
2015-11-01 21:15:40 +00:00
|
|
|
#else
|
2020-05-27 03:07:17 +00:00
|
|
|
#define joy_hat_handler(jbe) (static_cast<const SDL_JoyHatEvent *const &>(jbe), window_event_result::ignored)
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-25 04:52:49 +00:00
|
|
|
#if DXX_MAX_AXES_PER_JOYSTICK
|
2020-09-11 03:08:02 +00:00
|
|
|
const d_event_joystick_axis_value &event_joystick_get_axis(const d_event &event);
|
2020-05-27 03:07:17 +00:00
|
|
|
window_event_result joy_axis_handler(const SDL_JoyAxisEvent *jae);
|
2015-11-01 21:15:40 +00:00
|
|
|
#else
|
2020-05-27 03:07:17 +00:00
|
|
|
#define joy_axis_handler(jbe) (static_cast<const SDL_JoyAxisEvent *const &>(jbe), window_event_result::ignored)
|
2020-07-05 23:34:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DXX_MAX_AXES_PER_JOYSTICK && (DXX_MAX_BUTTONS_PER_JOYSTICK || DXX_MAX_HATS_PER_JOYSTICK)
|
|
|
|
window_event_result joy_axisbutton_handler(const SDL_JoyAxisEvent *jae);
|
|
|
|
#else
|
2020-05-27 03:07:17 +00:00
|
|
|
#define joy_axisbutton_handler(jbe) (static_cast<const SDL_JoyAxisEvent *const &>(jbe), window_event_result::ignored)
|
2015-11-01 21:15:40 +00:00
|
|
|
#endif
|
2015-12-05 22:57:24 +00:00
|
|
|
|
|
|
|
}
|