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
|
|
|
/*
|
|
|
|
*
|
2008-01-29 14:49:54 +00:00
|
|
|
* SDL mouse driver header
|
2006-04-03 17:36:27 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-05-09 17:39:03 +00:00
|
|
|
#pragma once
|
2006-04-03 17:36:27 +00:00
|
|
|
|
2008-01-02 03:37:13 +00:00
|
|
|
#include "pstypes.h"
|
2012-07-01 02:54:33 +00:00
|
|
|
#include "maths.h"
|
2006-04-03 17:36:27 +00:00
|
|
|
|
2012-11-17 06:14:09 +00:00
|
|
|
#ifdef __cplusplus
|
2018-06-27 03:34:34 +00:00
|
|
|
#include <SDL_version.h>
|
2015-05-14 02:23:13 +00:00
|
|
|
#include <cassert>
|
2015-10-09 02:46:10 +00:00
|
|
|
#include "fwd-window.h"
|
2015-10-09 02:46:10 +00:00
|
|
|
#include "event.h"
|
2012-11-17 06:14:09 +00:00
|
|
|
|
2012-11-11 00:14:30 +00:00
|
|
|
struct SDL_MouseButtonEvent;
|
|
|
|
struct SDL_MouseMotionEvent;
|
2010-03-24 07:26:52 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:24 +00:00
|
|
|
|
2008-09-30 00:07:07 +00:00
|
|
|
#define MOUSE_MAX_BUTTONS 16
|
2006-10-06 11:23:43 +00:00
|
|
|
#define Z_SENSITIVITY 100
|
2008-01-29 14:49:54 +00:00
|
|
|
#define MBTN_LEFT 0
|
2007-06-11 15:54:09 +00:00
|
|
|
#define MBTN_RIGHT 1
|
|
|
|
#define MBTN_MIDDLE 2
|
2008-01-29 14:49:54 +00:00
|
|
|
#define MBTN_Z_UP 3
|
2007-06-11 15:54:09 +00:00
|
|
|
#define MBTN_Z_DOWN 4
|
|
|
|
#define MBTN_PITCH_BACKWARD 5
|
2008-01-29 14:49:54 +00:00
|
|
|
#define MBTN_PITCH_FORWARD 6
|
2007-06-11 15:54:09 +00:00
|
|
|
#define MBTN_BANK_LEFT 7
|
2008-01-29 14:49:54 +00:00
|
|
|
#define MBTN_BANK_RIGHT 8
|
2007-06-11 15:54:09 +00:00
|
|
|
#define MBTN_HEAD_LEFT 9
|
2008-01-29 14:49:54 +00:00
|
|
|
#define MBTN_HEAD_RIGHT 10
|
2008-09-30 00:07:07 +00:00
|
|
|
#define MBTN_11 11
|
|
|
|
#define MBTN_12 12
|
|
|
|
#define MBTN_13 13
|
|
|
|
#define MBTN_14 14
|
|
|
|
#define MBTN_15 15
|
|
|
|
#define MBTN_16 16
|
2008-01-29 14:49:54 +00:00
|
|
|
#define MOUSE_LBTN 1
|
|
|
|
#define MOUSE_RBTN 2
|
|
|
|
#define MOUSE_MBTN 4
|
2006-04-03 17:36:27 +00:00
|
|
|
|
|
|
|
extern void mouse_flush(); // clears all mice events...
|
2010-07-16 11:07:42 +00:00
|
|
|
extern void mouse_init(void);
|
2010-07-28 17:27:35 +00:00
|
|
|
extern void mouse_close(void);
|
2008-01-29 14:49:54 +00:00
|
|
|
extern void mouse_get_pos( int *x, int *y, int *z );
|
2016-10-03 03:15:22 +00:00
|
|
|
window_event_result mouse_in_window(class window *wind);
|
2007-05-14 13:38:44 +00:00
|
|
|
extern void mouse_get_delta( int *dx, int *dy, int *dz );
|
2015-05-28 03:08:38 +00:00
|
|
|
void mouse_enable_cursor();
|
|
|
|
void mouse_disable_cursor();
|
2016-10-28 06:43:20 +00:00
|
|
|
window_event_result mouse_button_handler(struct SDL_MouseButtonEvent *mbe);
|
|
|
|
window_event_result mouse_motion_handler(struct SDL_MouseMotionEvent *mme);
|
2012-11-11 00:14:30 +00:00
|
|
|
void mouse_cursor_autohide();
|
2006-04-03 17:36:27 +00:00
|
|
|
|
2015-05-14 02:23:13 +00:00
|
|
|
class d_event_mousebutton : public d_event
|
|
|
|
{
|
|
|
|
public:
|
2015-05-28 03:08:39 +00:00
|
|
|
d_event_mousebutton(event_type type, unsigned b);
|
|
|
|
const unsigned button;
|
2015-05-14 02:23:13 +00:00
|
|
|
};
|
|
|
|
|
2015-05-14 02:23:13 +00:00
|
|
|
class d_event_mouse_moved : public d_event
|
|
|
|
{
|
|
|
|
public:
|
2018-06-27 03:34:34 +00:00
|
|
|
#if SDL_MAJOR_VERSION == 1
|
2018-07-28 23:22:58 +00:00
|
|
|
#define SDL_MOUSE_MOVE_INT_TYPE Sint16
|
|
|
|
#elif SDL_MAJOR_VERSION == 2
|
|
|
|
#define SDL_MOUSE_MOVE_INT_TYPE Sint32
|
2018-06-27 03:34:34 +00:00
|
|
|
#endif
|
2018-07-28 23:22:58 +00:00
|
|
|
const SDL_MOUSE_MOVE_INT_TYPE dx, dy;
|
2018-06-27 03:34:34 +00:00
|
|
|
const int16_t dz;
|
2018-07-28 23:22:58 +00:00
|
|
|
constexpr d_event_mouse_moved(const event_type t, const SDL_MOUSE_MOVE_INT_TYPE x, const SDL_MOUSE_MOVE_INT_TYPE y, const int16_t z) :
|
2018-05-12 18:24:19 +00:00
|
|
|
d_event(t), dx(x), dy(y), dz(z)
|
|
|
|
{
|
|
|
|
}
|
2018-07-28 23:22:58 +00:00
|
|
|
#undef SDL_MOUSE_MOVE_INT_TYPE
|
2015-05-14 02:23:13 +00:00
|
|
|
};
|
|
|
|
|
2015-05-14 02:23:13 +00:00
|
|
|
static inline int event_mouse_get_button(const d_event &event)
|
|
|
|
{
|
|
|
|
auto &e = static_cast<const d_event_mousebutton &>(event);
|
|
|
|
assert(e.type == EVENT_MOUSE_BUTTON_DOWN || e.type == EVENT_MOUSE_BUTTON_UP);
|
|
|
|
return e.button;
|
|
|
|
}
|
|
|
|
|
2015-05-14 02:23:13 +00:00
|
|
|
static inline void event_mouse_get_delta(const d_event &event, int *dx, int *dy, int *dz)
|
|
|
|
{
|
|
|
|
auto &e = static_cast<const d_event_mouse_moved &>(event);
|
|
|
|
assert(e.type == EVENT_MOUSE_MOVED);
|
|
|
|
*dx = e.dx;
|
|
|
|
*dy = e.dy;
|
|
|
|
*dz = e.dz;
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:57:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-17 06:14:09 +00:00
|
|
|
#endif
|