mirror of
https://github.com/ZDoom/Raze.git
synced 2025-05-31 01:11:15 +00:00
- moved all mouse button handling to the input state
Yet again an unbelievable piece of code working around how input works on modern systems to keep the old 90's code alive.
This commit is contained in:
parent
b4f91de7d3
commit
29b7e1cf79
14 changed files with 194 additions and 211 deletions
|
@ -111,21 +111,12 @@ char CONSTEXPR const g_keyAsciiTableShift[128] = {
|
|||
extern vec2_t g_mousePos;
|
||||
extern vec2_t g_mouseAbs;
|
||||
extern int32_t g_mouseBits;
|
||||
extern uint8_t g_mouseClickState;
|
||||
extern uint8_t inputState.mouseClickState();
|
||||
extern bool g_mouseGrabbed;
|
||||
extern bool g_mouseEnabled;
|
||||
extern bool g_mouseInsideWindow;
|
||||
extern bool g_mouseLockedToWindow;
|
||||
|
||||
enum
|
||||
{
|
||||
MOUSE_IDLE = 0,
|
||||
MOUSE_PRESSED,
|
||||
MOUSE_HELD,
|
||||
MOUSE_RELEASED,
|
||||
};
|
||||
extern int32_t mouseAdvanceClickState(void);
|
||||
|
||||
// joystick
|
||||
|
||||
typedef struct
|
||||
|
@ -160,13 +151,8 @@ void debugprintf(const char *,...) ATTRIBUTE((format(printf,1,2)));
|
|||
int32_t handleevents(void);
|
||||
int32_t handleevents_peekkeys(void);
|
||||
|
||||
extern void (*keypresscallback)(int32_t,int32_t);
|
||||
extern void (*g_mouseCallback)(int32_t,int32_t);
|
||||
|
||||
int32_t initinput(void);
|
||||
void uninitinput(void);
|
||||
void keySetCallback(void (*callback)(int32_t,int32_t));
|
||||
void mouseSetCallback(void (*callback)(int32_t,int32_t));
|
||||
void joySetCallback(void (*callback)(int32_t,int32_t));
|
||||
const char *joyGetName(int32_t what, int32_t num); // what: 0=axis, 1=button, 2=hat
|
||||
void joyScanDevices(void);
|
||||
|
@ -177,8 +163,6 @@ int32_t mouseReadAbs(vec2_t *pResult, vec2_t const *pInput);
|
|||
void mouseGrabInput(bool grab);
|
||||
void mouseLockToWindow(char a);
|
||||
void mouseMoveToCenter(void);
|
||||
int32_t mouseReadButtons(void);
|
||||
void mouseReadPos(int32_t *x, int32_t *y);
|
||||
|
||||
void joyReadButtons(int32_t *pResult);
|
||||
void joySetDeadZone(int32_t axis, uint16_t dead, uint16_t satur);
|
||||
|
|
|
@ -899,8 +899,6 @@ int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out = n
|
|||
extern const int16_t *chsecptr_onextwall;
|
||||
int32_t checksectorpointer(int16_t i, int16_t sectnum);
|
||||
|
||||
void mouseGetValues(int32_t *mousx, int32_t *mousy, int32_t *bstatus) ATTRIBUTE((nonnull(1,2,3)));
|
||||
|
||||
#if !KRANDDEBUG && !defined LUNATIC
|
||||
static FORCE_INLINE int32_t krand(void)
|
||||
{
|
||||
|
|
|
@ -28,27 +28,13 @@ char inputdevices = 0;
|
|||
|
||||
vec2_t g_mousePos;
|
||||
vec2_t g_mouseAbs;
|
||||
int32_t g_mouseBits;
|
||||
uint8_t g_mouseClickState;
|
||||
|
||||
|
||||
bool g_mouseEnabled;
|
||||
bool g_mouseGrabbed;
|
||||
bool g_mouseInsideWindow = 1;
|
||||
bool g_mouseLockedToWindow = 1;
|
||||
|
||||
void (*g_mouseCallback)(int32_t, int32_t);
|
||||
void mouseSetCallback(void(*callback)(int32_t, int32_t)) { g_mouseCallback = callback; }
|
||||
|
||||
int32_t mouseAdvanceClickState(void)
|
||||
{
|
||||
switch (g_mouseClickState)
|
||||
{
|
||||
case MOUSE_PRESSED: g_mouseClickState = MOUSE_HELD; return 1;
|
||||
case MOUSE_RELEASED: g_mouseClickState = MOUSE_IDLE; return 1;
|
||||
case MOUSE_HELD: return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mouseReadPos(int32_t *x, int32_t *y)
|
||||
{
|
||||
|
@ -78,11 +64,6 @@ int32_t mouseReadAbs(vec2_t * const pResult, vec2_t const * const pInput)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int32_t mouseReadButtons(void)
|
||||
{
|
||||
return (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE)) ? 0 : g_mouseBits;
|
||||
}
|
||||
|
||||
controllerinput_t joystick;
|
||||
|
||||
void joySetCallback(void (*callback)(int32_t, int32_t)) { joystick.pCallback = callback; }
|
||||
|
|
|
@ -11656,16 +11656,6 @@ void rotatepoint(vec2_t const pivot, vec2_t p, int16_t const daang, vec2_t * con
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// getmousevalues
|
||||
//
|
||||
|
||||
void mouseGetValues(int32_t *mousx, int32_t *mousy, int32_t *bstatus)
|
||||
{
|
||||
mouseReadPos(mousx, mousy);
|
||||
*bstatus = mouseReadButtons();
|
||||
}
|
||||
|
||||
|
||||
#if KRANDDEBUG
|
||||
# include <execinfo.h>
|
||||
|
|
|
@ -1733,10 +1733,6 @@ int32_t handleevents_peekkeys(void)
|
|||
return SDL_PeepEvents(NULL, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYDOWN);
|
||||
}
|
||||
|
||||
void handleevents_updatemousestate(uint8_t state)
|
||||
{
|
||||
g_mouseClickState = state == SDL_RELEASED ? MOUSE_RELEASED : MOUSE_PRESSED;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
@ -1773,27 +1769,22 @@ int32_t handleevents_sdlcommon(SDL_Event *ev)
|
|||
switch (ev->button.button)
|
||||
{
|
||||
default: j = -1; break;
|
||||
case SDL_BUTTON_LEFT: j = 0; handleevents_updatemousestate(ev->button.state); break;
|
||||
case SDL_BUTTON_RIGHT: j = 1; break;
|
||||
case SDL_BUTTON_MIDDLE: j = 2; break;
|
||||
case SDL_BUTTON_LEFT: j = KEY_MOUSE1; break;
|
||||
case SDL_BUTTON_RIGHT: j = KEY_MOUSE2; break;
|
||||
case SDL_BUTTON_MIDDLE: j = KEY_MOUSE3; break;
|
||||
|
||||
/* Thumb buttons. */
|
||||
// On SDL2/Windows and SDL >= 2.0.?/Linux, everything is as it should be.
|
||||
// If anyone cares about old versions of SDL2 on Linux, patches welcome.
|
||||
case SDL_BUTTON_X1: j = 3; break;
|
||||
case SDL_BUTTON_X2: j = 6; break;
|
||||
case SDL_BUTTON_X1: j = KEY_MOUSE4; break;
|
||||
case SDL_BUTTON_X2: j = KEY_MOUSE5; break;
|
||||
}
|
||||
|
||||
if (j < 0)
|
||||
break;
|
||||
|
||||
if (ev->button.state == SDL_PRESSED)
|
||||
g_mouseBits |= (1 << j);
|
||||
else
|
||||
g_mouseBits &= ~(1 << j);
|
||||
|
||||
if (g_mouseCallback)
|
||||
g_mouseCallback(j+1, ev->button.state == SDL_PRESSED);
|
||||
event_t ev = { (ev->button.state == SDL_PRESSED)? EV_KeyDown : EV_KeyUp, 0, j};
|
||||
D_PostEvent(ev);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2013,17 +2004,17 @@ int32_t handleevents_pollsdl(void)
|
|||
|
||||
case SDL_MOUSEWHEEL:
|
||||
// initprintf("wheel y %d\n",ev.wheel.y);
|
||||
|
||||
// This never sends keyup events. For the current code that should suffice
|
||||
if (ev.wheel.y > 0)
|
||||
{
|
||||
g_mouseBits |= 16;
|
||||
if (g_mouseCallback)
|
||||
g_mouseCallback(5, 1);
|
||||
event_t ev = { EV_KeyDown, 0, (int16_t)KEY_MWHEELUP };
|
||||
D_PostEvent(&ev);
|
||||
}
|
||||
if (ev.wheel.y < 0)
|
||||
{
|
||||
g_mouseBits |= 32;
|
||||
if (g_mouseCallback)
|
||||
g_mouseCallback(6, 1);
|
||||
event_t ev = { EV_KeyDown, 0, (int16_t)KEY_MWHEELDOWN };
|
||||
D_PostEvent(&ev);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -2076,13 +2067,6 @@ int32_t handleevents(void)
|
|||
|
||||
if (inputchecked && g_mouseEnabled)
|
||||
{
|
||||
if (g_mouseCallback)
|
||||
{
|
||||
if (g_mouseBits & 16)
|
||||
g_mouseCallback(5, 0);
|
||||
if (g_mouseBits & 32)
|
||||
g_mouseCallback(6, 0);
|
||||
}
|
||||
g_mouseBits &= ~(16 | 32);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue