From 03f7c39ea7209e06eb1779e79fffa01602bf6449 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Fri, 3 Feb 2017 20:34:34 +0200 Subject: [PATCH] Fixed mouse input in event handlers. Added RequireMouse field in event handler to signify that native mouse should be turned on for certain handlers. --- src/d_main.cpp | 3 +-- src/events.cpp | 18 +++++++++++------- src/events.h | 4 ++++ src/posix/cocoa/i_input.mm | 3 +++ src/win32/i_mouse.cpp | 4 ++++ wadsrc/static/zscript/events.txt | 2 ++ 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 2a4b44dec..2ed553d0b 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -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) { diff --git a/src/events.cpp b/src/events.cpp index b169cee01..fe081f6c2 100755 --- a/src/events.cpp +++ b/src/events.cpp @@ -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); diff --git a/src/events.h b/src/events.h index a116782c2..1ec6d068a 100755 --- a/src/events.h +++ b/src/events.h @@ -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. diff --git a/src/posix/cocoa/i_input.mm b/src/posix/cocoa/i_input.mm index 7b5faa80e..dae6b8072 100644 --- a/src/posix/cocoa/i_input.mm +++ b/src/posix/cocoa/i_input.mm @@ -186,6 +186,9 @@ void CheckNativeMouse() && (MENU_On == menuactive || MENU_OnNoPause == menuactive); } + if (!wantNative && E_CheckRequireMouse()) + wantNative = true; + I_SetNativeMouse(wantNative); } diff --git a/src/win32/i_mouse.cpp b/src/win32/i_mouse.cpp index b4f82fdb3..d13ef2445 100644 --- a/src/win32/i_mouse.cpp +++ b/src/win32/i_mouse.cpp @@ -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) diff --git a/wadsrc/static/zscript/events.txt b/wadsrc/static/zscript/events.txt index 3d8b61984..690b1a6da 100755 --- a/wadsrc/static/zscript/events.txt +++ b/wadsrc/static/zscript/events.txt @@ -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