diff --git a/client/eventsSDL/InputHandler.h b/client/eventsSDL/InputHandler.h index 2b91aea13..94c532054 100644 --- a/client/eventsSDL/InputHandler.h +++ b/client/eventsSDL/InputHandler.h @@ -44,7 +44,9 @@ public: InputHandler(); ~InputHandler(); + /// Fetches events from SDL input system and prepares them for processing void fetchEvents(); + /// Performs actual processing and dispatching of previously fetched events void processEvents(); /// drops all incoming events without processing them @@ -52,11 +54,20 @@ public: bool ignoreEventsUntilInput(); void fakeMoveCursor(float dx, float dy); + + /// Initiates text input in selected area, potentially creating IME popup (mobile systems only at the moment) void startTextInput(const Rect & where); + + /// Ends any existing text input state void stopTextInput(); + + /// Returns true if selected mouse button is pressed at the moment bool isMouseButtonPressed(MouseButton button) const; + + /// Generates new user event that will be processed on next frame void pushUserEvent(EUserEvent usercode, void * userdata); + /// Returns current position of cursor, in VCMI logical screen coordinates const Point & getCursorPosition() const; /// returns true if chosen keyboard key is currently pressed down diff --git a/client/eventsSDL/InputSourceKeyboard.h b/client/eventsSDL/InputSourceKeyboard.h index dc238295c..9e4fdb80a 100644 --- a/client/eventsSDL/InputSourceKeyboard.h +++ b/client/eventsSDL/InputSourceKeyboard.h @@ -12,6 +12,7 @@ struct SDL_KeyboardEvent; +/// Class that handles keyboard input from SDL events class InputSourceKeyboard { public: diff --git a/client/eventsSDL/InputSourceMouse.h b/client/eventsSDL/InputSourceMouse.h index f30609aa1..4331c1688 100644 --- a/client/eventsSDL/InputSourceMouse.h +++ b/client/eventsSDL/InputSourceMouse.h @@ -14,6 +14,7 @@ struct SDL_MouseWheelEvent; struct SDL_MouseMotionEvent; struct SDL_MouseButtonEvent; +/// Class that handles mouse input from SDL events class InputSourceMouse { public: diff --git a/client/eventsSDL/InputSourceText.h b/client/eventsSDL/InputSourceText.h index 02473b3ec..e23e990c8 100644 --- a/client/eventsSDL/InputSourceText.h +++ b/client/eventsSDL/InputSourceText.h @@ -17,6 +17,7 @@ VCMI_LIB_NAMESPACE_END struct SDL_TextEditingEvent; struct SDL_TextInputEvent; +/// Class that handles text input (e.g. IME or direct input from physical keyboard) from SDL events class InputSourceText { public: diff --git a/client/eventsSDL/InputSourceTouch.h b/client/eventsSDL/InputSourceTouch.h index 07017ef70..c8faa05de 100644 --- a/client/eventsSDL/InputSourceTouch.h +++ b/client/eventsSDL/InputSourceTouch.h @@ -16,6 +16,7 @@ VCMI_LIB_NAMESPACE_END struct SDL_TouchFingerEvent; +/// Class that handles touchscreen input from SDL events class InputSourceTouch { bool multifinger; diff --git a/client/eventsSDL/UserEventHandler.h b/client/eventsSDL/UserEventHandler.h index 3fdd0a2ee..837e0a6e3 100644 --- a/client/eventsSDL/UserEventHandler.h +++ b/client/eventsSDL/UserEventHandler.h @@ -12,6 +12,7 @@ struct SDL_UserEvent; +/// Class for handling events of type SDL_UserEvent class UserEventHandler { public: diff --git a/client/gui/EventDispatcher.cpp b/client/gui/EventDispatcher.cpp index 995f66c13..db1d9ab32 100644 --- a/client/gui/EventDispatcher.cpp +++ b/client/gui/EventDispatcher.cpp @@ -17,47 +17,48 @@ #include "../../lib/Point.h" -void EventDispatcher::processList(const ui16 mask, const ui16 flag, CIntObjectList *lst, std::function cb) +template +void EventDispatcher::processLists(ui16 activityFlag, const Functor & cb) { - if (mask & flag) - cb(lst); + auto processList = [&](ui16 mask, EventReceiversList & lst) + { + if(mask & activityFlag) + cb(lst); + }; + + processList(AEventsReceiver::LCLICK, lclickable); + processList(AEventsReceiver::RCLICK, rclickable); + processList(AEventsReceiver::MCLICK, mclickable); + processList(AEventsReceiver::HOVER, hoverable); + processList(AEventsReceiver::MOVE, motioninterested); + processList(AEventsReceiver::KEYBOARD, keyinterested); + processList(AEventsReceiver::TIME, timeinterested); + processList(AEventsReceiver::WHEEL, wheelInterested); + processList(AEventsReceiver::DOUBLECLICK, doubleClickInterested); + processList(AEventsReceiver::TEXTINPUT, textInterested); } -void EventDispatcher::processLists(ui16 activityFlag, std::function cb) +void EventDispatcher::activateElement(AEventsReceiver * elem, ui16 activityFlag) { - processList(AEventsReceiver::LCLICK,activityFlag,&lclickable,cb); - processList(AEventsReceiver::RCLICK,activityFlag,&rclickable,cb); - processList(AEventsReceiver::MCLICK,activityFlag,&mclickable,cb); - processList(AEventsReceiver::HOVER,activityFlag,&hoverable,cb); - processList(AEventsReceiver::MOVE,activityFlag,&motioninterested,cb); - processList(AEventsReceiver::KEYBOARD,activityFlag,&keyinterested,cb); - processList(AEventsReceiver::TIME,activityFlag,&timeinterested,cb); - processList(AEventsReceiver::WHEEL,activityFlag,&wheelInterested,cb); - processList(AEventsReceiver::DOUBLECLICK,activityFlag,&doubleClickInterested,cb); - processList(AEventsReceiver::TEXTINPUT,activityFlag,&textInterested,cb); -} - -void EventDispatcher::handleElementActivate(AEventsReceiver * elem, ui16 activityFlag) -{ - processLists(activityFlag,[&](CIntObjectList * lst){ - lst->push_front(elem); + processLists(activityFlag,[&](EventReceiversList & lst){ + lst.push_front(elem); }); elem->activeState |= activityFlag; } -void EventDispatcher::handleElementDeActivate(AEventsReceiver * elem, ui16 activityFlag) +void EventDispatcher::deactivateElement(AEventsReceiver * elem, ui16 activityFlag) { - processLists(activityFlag,[&](CIntObjectList * lst){ - auto hlp = std::find(lst->begin(),lst->end(),elem); - assert(hlp != lst->end()); - lst->erase(hlp); + processLists(activityFlag,[&](EventReceiversList & lst){ + auto hlp = std::find(lst.begin(),lst.end(),elem); + assert(hlp != lst.end()); + lst.erase(hlp); }); elem->activeState &= ~activityFlag; } void EventDispatcher::dispatchTimer(uint32_t msPassed) { - CIntObjectList hlp = timeinterested; + EventReceiversList hlp = timeinterested; for (auto & elem : hlp) { if(!vstd::contains(timeinterested,elem)) continue; @@ -74,7 +75,7 @@ void EventDispatcher::dispatchShortcutPressed(const std::vector & sho if(i->captureThisKey(shortcut)) keysCaptured = true; - CIntObjectList miCopy = keyinterested; + EventReceiversList miCopy = keyinterested; for(auto & i : miCopy) { @@ -97,7 +98,7 @@ void EventDispatcher::dispatchShortcutReleased(const std::vector & sh if(i->captureThisKey(shortcut)) keysCaptured = true; - CIntObjectList miCopy = keyinterested; + EventReceiversList miCopy = keyinterested; for(auto & i : miCopy) { @@ -111,7 +112,7 @@ void EventDispatcher::dispatchShortcutReleased(const std::vector & sh } } -EventDispatcher::CIntObjectList & EventDispatcher::getListForMouseButton(MouseButton button) +EventDispatcher::EventReceiversList & EventDispatcher::getListForMouseButton(MouseButton button) { switch (button) { @@ -156,7 +157,7 @@ void EventDispatcher::dispatchMouseButtonReleased(const MouseButton & button, co handleMouseButtonClick(getListForMouseButton(button), button, false); } -void EventDispatcher::handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed) +void EventDispatcher::handleMouseButtonClick(EventReceiversList & interestedObjs, MouseButton btn, bool isPressed) { auto hlp = interestedObjs; for(auto & i : hlp) @@ -180,7 +181,7 @@ void EventDispatcher::handleMouseButtonClick(CIntObjectList & interestedObjs, Mo void EventDispatcher::dispatchMouseScrolled(const Point & distance, const Point & position) { - CIntObjectList hlp = wheelInterested; + EventReceiversList hlp = wheelInterested; for(auto & i : hlp) { if(!vstd::contains(wheelInterested,i)) @@ -208,7 +209,7 @@ void EventDispatcher::dispatchTextEditing(const std::string & text) void EventDispatcher::dispatchMouseMoved(const Point & position) { //sending active, hovered hoverable objects hover() call - CIntObjectList hlp; + EventReceiversList hlp; auto hoverableCopy = hoverable; for(auto & elem : hoverableCopy) @@ -232,7 +233,7 @@ void EventDispatcher::dispatchMouseMoved(const Point & position) } //sending active, MotionInterested objects mouseMoved() call - CIntObjectList miCopy = motioninterested; + EventReceiversList miCopy = motioninterested; for(auto & elem : miCopy) { if(elem->strongInterestState || elem->isInside(position)) //checking bounds including border fixes bug #2476 diff --git a/client/gui/EventDispatcher.h b/client/gui/EventDispatcher.h index a9fd59f34..3f5712000 100644 --- a/client/gui/EventDispatcher.h +++ b/client/gui/EventDispatcher.h @@ -20,33 +20,33 @@ enum class EShortcut; /// Class that receives events from event producers and dispatches it to UI elements that are interested in this event class EventDispatcher { - using CIntObjectList = std::list; + using EventReceiversList = std::list; /// list of UI elements that are interested in particular event - CIntObjectList lclickable; - CIntObjectList rclickable; - CIntObjectList mclickable; - CIntObjectList hoverable; - CIntObjectList keyinterested; - CIntObjectList motioninterested; - CIntObjectList timeinterested; - CIntObjectList wheelInterested; - CIntObjectList doubleClickInterested; - CIntObjectList textInterested; + EventReceiversList lclickable; + EventReceiversList rclickable; + EventReceiversList mclickable; + EventReceiversList hoverable; + EventReceiversList keyinterested; + EventReceiversList motioninterested; + EventReceiversList timeinterested; + EventReceiversList wheelInterested; + EventReceiversList doubleClickInterested; + EventReceiversList textInterested; - CIntObjectList & getListForMouseButton(MouseButton button); + EventReceiversList & getListForMouseButton(MouseButton button); - void handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed); + void handleMouseButtonClick(EventReceiversList & interestedObjs, MouseButton btn, bool isPressed); - void processList(const ui16 mask, const ui16 flag, CIntObjectList * lst, std::function cb); - void processLists(ui16 activityFlag, std::function cb); + template + void processLists(ui16 activityFlag, const Functor & cb); public: /// add specified UI element as interested. Uses unnamed enum from AEventsReceiver for activity flags - void handleElementActivate(AEventsReceiver * elem, ui16 activityFlag); + void activateElement(AEventsReceiver * elem, ui16 activityFlag); /// removes specified UI element as interested for specified activities - void handleElementDeActivate(AEventsReceiver * elem, ui16 activityFlag); + void deactivateElement(AEventsReceiver * elem, ui16 activityFlag); /// Regular timer event void dispatchTimer(uint32_t msPassed); diff --git a/client/gui/EventsReceiver.cpp b/client/gui/EventsReceiver.cpp index a6e2924fa..69db18857 100644 --- a/client/gui/EventsReceiver.cpp +++ b/client/gui/EventsReceiver.cpp @@ -46,14 +46,14 @@ void AEventsReceiver::activateEvents(ui16 what) assert((what & GENERAL) || (activeState & GENERAL)); activeState |= GENERAL; - GH.events().handleElementActivate(this, what); + GH.events().activateElement(this, what); } void AEventsReceiver::deactivateEvents(ui16 what) { if (what & GENERAL) activeState &= ~GENERAL; - GH.events().handleElementDeActivate(this, what & activeState); + GH.events().deactivateElement(this, what & activeState); } void AEventsReceiver::click(MouseButton btn, tribool down, bool previousState)