dxx-rebirth/common/include/mouse.h

111 lines
2.4 KiB
C
Raw Normal View History

2014-06-01 17:55:23 +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
/*
*
* 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
#include "pstypes.h"
2012-07-01 02:54:33 +00:00
#include "maths.h"
2006-04-03 17:36:27 +00:00
#ifdef __cplusplus
#include <SDL_version.h>
2015-05-14 02:23:13 +00:00
#include <cassert>
#include "event.h"
2012-11-11 00:14:30 +00:00
struct SDL_MouseButtonEvent;
struct SDL_MouseMotionEvent;
2015-12-13 18:00:49 +00:00
namespace dcx {
2022-02-27 14:23:53 +00:00
#define MOUSE_MAX_BUTTONS 17
#define Z_SENSITIVITY 100
2022-02-27 14:23:53 +00:00
enum class mbtn : uint8_t
{
left = 0,
right = 1,
middle = 2,
z_up = 3,
z_down = 4,
pitch_backward = 5,
pitch_forward = 6,
bank_left = 7,
bank_right = 8,
head_left = 9,
head_right = 10,
_11 = 11,
_12 = 12,
_13 = 13,
_14 = 14,
_15 = 15,
_16 = 16,
};
#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...
extern void mouse_init(void);
extern void mouse_close(void);
extern void mouse_get_pos( int *x, int *y, int *z );
window_event_result mouse_in_window(class window *wind);
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();
window_event_result mouse_button_handler(const SDL_MouseButtonEvent *mbe);
window_event_result mouse_motion_handler(const 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:
2022-02-27 14:23:53 +00:00
d_event_mousebutton(event_type type, mbtn b);
const mbtn 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:
#if SDL_MAJOR_VERSION == 1
Enable building with SDL2 This commit enables Rebirth to build with SDL2, but the result is not perfect. - SDL2 removed some sticky key support. Rebirth may behave differently now in this area. - SDL2 removed some key-repeat related support. Rebirth may behave differently now in this area. - SDL2 gained the ability to make a window fullscreen by sizing it to the desktop instead of by changing the desktop resolution. Rebirth uses this, and it mostly works. - Resizing while in the automap does not notify the automap code, so the view is wrong until the player switches out of automap mode and back in. - SDL2 changed how to enumerate available resolutions. Since fitting the window to the desktop is generally more useful than fitting the desktop to the window, I chose to drop support for enumerating resolutions instead of porting to the new API. Users can now enter an arbitrary window dimension and Rebirth will make an attempt to use it. - It might be useful to cap the window dimension at the desktop dimension, but that is not done yet. - Entering fullscreen mode through the Controls->Graphics submenu failed to notify the relevant subsystems, causing the rendered content not to rescale. For now, compile out the option to toggle full screen through that menu. Toggling through Alt+Enter works properly. Despite these quirks, this is a substantial improvement over the prior commit, where SDL2 cannot be used at all. The remaining issues can be resolved in future work. References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/82>
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
#endif
Enable building with SDL2 This commit enables Rebirth to build with SDL2, but the result is not perfect. - SDL2 removed some sticky key support. Rebirth may behave differently now in this area. - SDL2 removed some key-repeat related support. Rebirth may behave differently now in this area. - SDL2 gained the ability to make a window fullscreen by sizing it to the desktop instead of by changing the desktop resolution. Rebirth uses this, and it mostly works. - Resizing while in the automap does not notify the automap code, so the view is wrong until the player switches out of automap mode and back in. - SDL2 changed how to enumerate available resolutions. Since fitting the window to the desktop is generally more useful than fitting the desktop to the window, I chose to drop support for enumerating resolutions instead of porting to the new API. Users can now enter an arbitrary window dimension and Rebirth will make an attempt to use it. - It might be useful to cap the window dimension at the desktop dimension, but that is not done yet. - Entering fullscreen mode through the Controls->Graphics submenu failed to notify the relevant subsystems, causing the rendered content not to rescale. For now, compile out the option to toggle full screen through that menu. Toggling through Alt+Enter works properly. Despite these quirks, this is a substantial improvement over the prior commit, where SDL2 cannot be used at all. The remaining issues can be resolved in future work. References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/82>
2018-07-28 23:22:58 +00:00
const SDL_MOUSE_MOVE_INT_TYPE dx, dy;
const int16_t dz;
Enable building with SDL2 This commit enables Rebirth to build with SDL2, but the result is not perfect. - SDL2 removed some sticky key support. Rebirth may behave differently now in this area. - SDL2 removed some key-repeat related support. Rebirth may behave differently now in this area. - SDL2 gained the ability to make a window fullscreen by sizing it to the desktop instead of by changing the desktop resolution. Rebirth uses this, and it mostly works. - Resizing while in the automap does not notify the automap code, so the view is wrong until the player switches out of automap mode and back in. - SDL2 changed how to enumerate available resolutions. Since fitting the window to the desktop is generally more useful than fitting the desktop to the window, I chose to drop support for enumerating resolutions instead of porting to the new API. Users can now enter an arbitrary window dimension and Rebirth will make an attempt to use it. - It might be useful to cap the window dimension at the desktop dimension, but that is not done yet. - Entering fullscreen mode through the Controls->Graphics submenu failed to notify the relevant subsystems, causing the rendered content not to rescale. For now, compile out the option to toggle full screen through that menu. Toggling through Alt+Enter works properly. Despite these quirks, this is a substantial improvement over the prior commit, where SDL2 cannot be used at all. The remaining issues can be resolved in future work. References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/82>
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)
{
}
Enable building with SDL2 This commit enables Rebirth to build with SDL2, but the result is not perfect. - SDL2 removed some sticky key support. Rebirth may behave differently now in this area. - SDL2 removed some key-repeat related support. Rebirth may behave differently now in this area. - SDL2 gained the ability to make a window fullscreen by sizing it to the desktop instead of by changing the desktop resolution. Rebirth uses this, and it mostly works. - Resizing while in the automap does not notify the automap code, so the view is wrong until the player switches out of automap mode and back in. - SDL2 changed how to enumerate available resolutions. Since fitting the window to the desktop is generally more useful than fitting the desktop to the window, I chose to drop support for enumerating resolutions instead of porting to the new API. Users can now enter an arbitrary window dimension and Rebirth will make an attempt to use it. - It might be useful to cap the window dimension at the desktop dimension, but that is not done yet. - Entering fullscreen mode through the Controls->Graphics submenu failed to notify the relevant subsystems, causing the rendered content not to rescale. For now, compile out the option to toggle full screen through that menu. Toggling through Alt+Enter works properly. Despite these quirks, this is a substantial improvement over the prior commit, where SDL2 cannot be used at all. The remaining issues can be resolved in future work. References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/82>
2018-07-28 23:22:58 +00:00
#undef SDL_MOUSE_MOVE_INT_TYPE
2015-05-14 02:23:13 +00:00
};
2022-02-27 14:23:53 +00:00
static inline mbtn event_mouse_get_button(const d_event &event)
2015-05-14 02:23:13 +00:00
{
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;
}
}
#endif