Prechádzať zdrojové kódy

Better documentation & cleanup

Ivan Savenko 2 rokov pred
rodič
commit
6981848288

+ 11 - 0
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

+ 1 - 0
client/eventsSDL/InputSourceKeyboard.h

@@ -12,6 +12,7 @@
 
 struct SDL_KeyboardEvent;
 
+/// Class that handles keyboard input from SDL events
 class InputSourceKeyboard
 {
 public:

+ 1 - 0
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:

+ 1 - 0
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:

+ 1 - 0
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;

+ 1 - 0
client/eventsSDL/UserEventHandler.h

@@ -12,6 +12,7 @@
 
 struct SDL_UserEvent;
 
+/// Class for handling events of type SDL_UserEvent
 class UserEventHandler
 {
 public:

+ 37 - 36
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<void (CIntObjectList *)> cb)
+template<typename Functor>
+void EventDispatcher::processLists(ui16 activityFlag, const Functor & cb)
 {
-	if (mask & flag)
-		cb(lst);
-}
-
-void EventDispatcher::processLists(ui16 activityFlag, std::function<void (CIntObjectList *)> cb)
-{
-	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);
+	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::activateElement(AEventsReceiver * elem, ui16 activityFlag)
+{
+	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<EShortcut> & 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<EShortcut> & 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<EShortcut> & 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

+ 17 - 17
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<AEventsReceiver *>;
+	using EventReceiversList = std::list<AEventsReceiver *>;
 
 	/// 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<void(CIntObjectList *)> cb);
-	void processLists(ui16 activityFlag, std::function<void(CIntObjectList *)> cb);
+	template<typename Functor>
+	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);

+ 2 - 2
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)