Inline event_mouse_get_button

This commit is contained in:
Kp 2015-05-14 02:23:13 +00:00
parent 0ece005dfa
commit 2a8b79f868
2 changed files with 14 additions and 13 deletions

View file

@ -16,6 +16,7 @@
#include "maths.h"
#ifdef __cplusplus
#include <cassert>
#include "window.h"
struct d_event;
@ -48,7 +49,6 @@ struct SDL_MouseMotionEvent;
extern void mouse_flush(); // clears all mice events...
extern void mouse_init(void);
extern void mouse_close(void);
extern int event_mouse_get_button(const d_event &event);
extern void mouse_get_pos( int *x, int *y, int *z );
window_event_result mouse_in_window(struct window *wind);
extern void mouse_get_delta( int *dx, int *dy, int *dz );
@ -58,4 +58,17 @@ void mouse_button_handler(struct SDL_MouseButtonEvent *mbe);
void mouse_motion_handler(struct SDL_MouseMotionEvent *mme);
void mouse_cursor_autohide();
class d_event_mousebutton : public d_event
{
public:
int button;
};
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;
}
#endif

View file

@ -43,11 +43,6 @@ struct mouseinfo : flushable_mouseinfo
static mouseinfo Mouse;
struct d_event_mousebutton : d_event
{
int button;
};
struct d_event_mouse_moved : d_event
{
short dx, dy, dz;
@ -206,13 +201,6 @@ void event_mouse_get_delta(const d_event &event, int *dx, int *dy, int *dz)
*dz = e.dz;
}
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;
}
void mouse_toggle_cursor(int activate)
{
Mouse.cursor_enabled = (activate && !GameArg.CtlNoMouse && !GameArg.CtlNoCursor);