Fixed mouse input in event handlers. Added RequireMouse field in event handler to signify that native mouse should be turned on for certain handlers.

This commit is contained in:
ZZYZX 2017-02-03 20:34:34 +02:00
parent 08f1731ded
commit 03f7c39ea7
6 changed files with 25 additions and 9 deletions

View file

@ -310,8 +310,7 @@ void D_PostEvent (const event_t *ev)
return;
}
events[eventhead] = *ev;
if (ev->type == EV_Mouse && !paused && menuactive == MENU_Off && ConsoleState != c_down && ConsoleState != c_falling
)
if (ev->type == EV_Mouse && !paused && menuactive == MENU_Off && ConsoleState != c_down && ConsoleState != c_falling && !E_CheckUiProcessors())
{
if (Button_Mlook.bDown || freelook)
{

View file

@ -386,7 +386,7 @@ bool E_Responder(event_t* ev)
// not sure if we want to handle device changes, but whatevs.
for (DStaticEventHandler* handler = E_LastEventHandler; handler; handler = handler->prev)
{
if (!handler->IsUiProcessor && handler->InputProcess(ev))
if (handler->InputProcess(ev))
return true; // event was processed
}
}
@ -397,15 +397,18 @@ bool E_Responder(event_t* ev)
bool E_CheckUiProcessors()
{
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
{
if (handler->IsUiProcessor)
{
//Printf("E_CheckUiProcessors = true\n");
return true;
}
}
//Printf("E_CheckUiProcessors = false\n");
return false;
}
bool E_CheckRequireMouse()
{
for (DStaticEventHandler* handler = E_FirstEventHandler; handler; handler = handler->next)
if (handler->IsUiProcessor && handler->RequireMouse)
return true;
return false;
}
@ -427,6 +430,7 @@ IMPLEMENT_CLASS(DInputEvent, false, false)
DEFINE_FIELD_X(StaticEventHandler, DStaticEventHandler, Order);
DEFINE_FIELD_X(StaticEventHandler, DStaticEventHandler, IsUiProcessor);
DEFINE_FIELD_X(StaticEventHandler, DStaticEventHandler, RequireMouse);
DEFINE_FIELD_X(RenderEvent, DRenderEvent, ViewPos);
DEFINE_FIELD_X(RenderEvent, DRenderEvent, ViewAngle);

View file

@ -60,6 +60,8 @@ bool E_Responder(event_t* ev); // splits events into InputProcess and UiProcess
// check if there is anything that should receive GUI events
bool E_CheckUiProcessors();
// check if we need native mouse due to UiProcessors
bool E_CheckRequireMouse();
// serialization stuff
void E_SerializeEvents(FSerializer& arc);
@ -89,6 +91,7 @@ public:
//
int Order;
bool IsUiProcessor;
bool RequireMouse;
// serialization handler. let's keep it here so that I don't get lost in serialized/not serialized fields
void Serialize(FSerializer& arc) override
@ -105,6 +108,7 @@ public:
arc("Order", Order);
arc("IsUiProcessor", IsUiProcessor);
arc("RequireMouse", RequireMouse);
}
// destroy handler. this unlinks EventHandler from the list automatically.

View file

@ -186,6 +186,9 @@ void CheckNativeMouse()
&& (MENU_On == menuactive || MENU_OnNoPause == menuactive);
}
if (!wantNative && E_CheckRequireMouse())
wantNative = true;
I_SetNativeMouse(wantNative);
}

View file

@ -18,6 +18,7 @@
#include "win32iface.h"
#include "rawinput.h"
#include "menu/menu.h"
#include "events.h"
// MACROS ------------------------------------------------------------------
@ -282,6 +283,9 @@ void I_CheckNativeMouse(bool preferNative)
}
}
if (!want_native && E_CheckRequireMouse())
want_native = true;
//Printf ("%d %d %d\n", wantNative, preferNative, NativeMouse);
if (want_native != NativeMouse)

View file

@ -317,6 +317,8 @@ class StaticEventHandler : Object native
native int Order;
// this value will be queried on user input to decide whether to send UiProcess to this handler.
native bool IsUiProcessor;
// this value determines whether mouse input is required.
native bool RequireMouse;
}
class EventHandler : StaticEventHandler native