- 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:
Christoph Oelckers 2019-11-04 01:01:54 +01:00
parent b4f91de7d3
commit 29b7e1cf79
14 changed files with 194 additions and 211 deletions

View file

@ -172,7 +172,7 @@ void D_PostEvent (const event_t *ev)
return;
}
events[eventhead] = *ev;
#if 0
#if 0 // No idea if this can be made to work ever... For now, pass on the mouse movement event so that the input code can deal with them itself.
if (ev->type == EV_Mouse && menuactive == MENU_Off && ConsoleState != c_down && ConsoleState != c_falling && !primaryLevel->localEventManager->Responder(ev) && !paused)
{
if (Button_Mlook.bDown || freelook)

View file

@ -23,7 +23,6 @@ enum
{
NUMKEYS = 256,
MAXMOUSEBUTTONS = 10,
};
extern int32_t CONTROL_ButtonFlags[NUMKEYS];
@ -120,6 +119,26 @@ enum GameFunction_t
};
enum EMouseBits
{
LEFT_MOUSE = 1,
RIGHT_MOUSE = 2,
MIDDLE_MOUSE = 4,
THUMB_MOUSE = 8,
WHEELUP_MOUSE = 16,
WHEELDOWN_MOUSE= 32,
THUMB2_MOUSE = 64,
};
enum
{
MOUSE_IDLE = 0,
MOUSE_PRESSED,
MOUSE_HELD,
MOUSE_RELEASED,
};
class InputState
{
enum
@ -146,7 +165,9 @@ class InputState
uint8_t g_keyAsciiEnd;
kb_scancode KB_LastScan;
int g_mouseBits;
uint8_t g_mouseClickState;
public:
bool BUTTON(int x)
@ -333,12 +354,67 @@ public:
ClearAllKeyStatus();
}
void mouseSetBit(int val, int state)
{
if (state) g_mouseBits |= val;
else g_mouseBits &=~val;
}
void handleevents_updatemousestate(uint8_t state)
{
g_mouseClickState = state == EV_KeyUp ? MOUSE_RELEASED : MOUSE_PRESSED;
}
void AddEvent(const event_t *ev)
{
// Set the old mouseBits. Yet another piece of cruft that needs to go away.
if (ev->type == EV_KeyDown || ev->type == EV_KeyUp)
{
switch (ev->data1)
{
case KEY_MOUSE1 : mouseSetBit(LEFT_MOUSE, ev->type == EV_KeyDown); handleevents_updatemousestate(ev->type); break;
case KEY_MOUSE2 : mouseSetBit(RIGHT_MOUSE, ev->type == EV_KeyDown); break;
case KEY_MOUSE3 : mouseSetBit(MIDDLE_MOUSE, ev->type == EV_KeyDown); break;
case KEY_MOUSE4 : mouseSetBit(THUMB_MOUSE, ev->type == EV_KeyDown); break;
case KEY_MWHEELUP: mouseSetBit(WHEELUP_MOUSE, ev->type == EV_KeyDown); break;
case KEY_MWHEELDOWN: mouseSetBit(WHEELDOWN_MOUSE, ev->type == EV_KeyDown); break;
case KEY_MOUSE5: mouseSetBit(THUMB2_MOUSE, ev->type == EV_KeyDown); break;
default: break;
}
}
keySetState(ev->data1, ev->type == EV_KeyDown);
if (ev->data2) keySetChar(ev->data2);
}
int32_t mouseReadButtons(void)
{
return (!g_mouseEnabled || !appactive || !g_mouseInsideWindow || (osd && osd->flags & OSD_CAPTURE)) ? 0 : g_mouseBits;
}
int mouseClickState()
{
return g_mouseClickState;
}
void clearMouseClickState()
{
g_mouseClickState = MOUSE_IDLE;
}
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;
}
static inline int32_t MouseGetButtons(void) { return mouseReadButtons(); }
static inline void MouseClearButton(int32_t b) { g_mouseBits &= ~b; }
static inline void MouseClearAllButtonss(void) { g_mouseBits = 0; }
};