Browse Source

Merge pull request #840 from Nodrev/bugfix-mouse-click-position

Bugfix mouse click position
Branimir Karadžić 9 years ago
parent
commit
33ad3c0072
2 changed files with 27 additions and 43 deletions
  1. 6 12
      examples/common/entry/entry.cpp
  2. 21 31
      examples/common/entry/entry_android.cpp

+ 6 - 12
examples/common/entry/entry.cpp

@@ -473,11 +473,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 						const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
 						handle = mouse->m_handle;
 
-						if (mouse->m_move)
-						{
-							inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
-						}
-						else
+						inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
+						if (!mouse->m_move)
 						{
 							inputSetMouseButtonState(mouse->m_button, mouse->m_down);
 						}
@@ -485,13 +482,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 						if (NULL != _mouse
 						&&  !mouseLock)
 						{
-							if (mouse->m_move)
-							{
-								_mouse->m_mx = mouse->m_mx;
-								_mouse->m_my = mouse->m_my;
-								_mouse->m_mz = mouse->m_mz;
-							}
-							else
+							_mouse->m_mx = mouse->m_mx;
+							_mouse->m_my = mouse->m_my;
+							_mouse->m_mz = mouse->m_mz;
+							if (!mouse->m_move) 
 							{
 								_mouse->m_buttons[mouse->m_button] = mouse->m_down;
 							}

+ 21 - 31
examples/common/entry/entry_android.cpp

@@ -82,7 +82,6 @@ namespace entry
 	{
 		Context()
 			: m_window(NULL)
-			, m_count(0)
 		{
 			memset(m_value, 0, sizeof(m_value) );
 
@@ -297,43 +296,35 @@ namespace entry
 						int32_t action = (actionBits & AMOTION_EVENT_ACTION_MASK);
 						int32_t index  = (actionBits & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
 
-						count = m_count;
-
-						switch (action)
-						{
-						case AMOTION_EVENT_ACTION_DOWN:
-						case AMOTION_EVENT_ACTION_POINTER_DOWN:
-							m_count++;
-							break;
-
-						case AMOTION_EVENT_ACTION_UP:
-						case AMOTION_EVENT_ACTION_POINTER_UP:
-							m_count--;
-							break;
-
-						default:
-							break;
-						}
-
-						if (count != m_count)
+						// Simulate left mouse click with 1st touch and right mouse click with 2nd touch. ignore other touchs
+						if (count < 2)
 						{
-							m_eventQueue.postMouseEvent(defaultWindow
-								, (int32_t)mx
-								, (int32_t)my
-								, 0
-								, 1 == count ? MouseButton::Left : MouseButton::Right
-								, false
-								);
-
-							if (0 != m_count)
+							switch (action)
 							{
+							case AMOTION_EVENT_ACTION_DOWN:
+							case AMOTION_EVENT_ACTION_POINTER_DOWN:
 								m_eventQueue.postMouseEvent(defaultWindow
 									, (int32_t)mx
 									, (int32_t)my
 									, 0
-									, 1 == m_count ? MouseButton::Left : MouseButton::Right
+									, action == AMOTION_EVENT_ACTION_DOWN ? MouseButton::Left : MouseButton::Right
 									, true
 									);
+								break;
+
+							case AMOTION_EVENT_ACTION_UP:
+							case AMOTION_EVENT_ACTION_POINTER_UP:
+								m_eventQueue.postMouseEvent(defaultWindow
+									, (int32_t)mx
+									, (int32_t)my
+									, 0
+									, action == AMOTION_EVENT_ACTION_UP ? MouseButton::Left : MouseButton::Right
+									, false
+									);
+								break;
+
+							default:
+								break;
 							}
 						}
 
@@ -405,7 +396,6 @@ namespace entry
 		ANativeWindow* m_window;
 		android_app* m_app;
 
-		int32_t m_count;
 		int32_t m_value[GamepadAxis::Count];
 		int32_t m_deadzone[GamepadAxis::Count];
 	};