Ver Fonte

device: fix touch events ordering

Previously:

	AXIS_CHANGED
	BUTTON_PRESSED
	..
	AXIS_CHANGED
	BUTTON_RELEASED

Now:

	BUTTON_PRESSED
	AXIS_CHANGED
	..
	AXIS_CHANGED
	BUTTON_RELEASED
Daniele Bartolini há 9 meses atrás
pai
commit
460ac91fa0
2 ficheiros alterados com 33 adições e 33 exclusões
  1. 9 32
      src/device/main_android.cpp
  2. 24 1
      src/device/main_html5.cpp

+ 9 - 32
src/device/main_android.cpp

@@ -131,36 +131,19 @@ struct AndroidDevice
 			switch (action) {
 			case AMOTION_EVENT_ACTION_DOWN:
 			case AMOTION_EVENT_ACTION_POINTER_DOWN:
-			case AMOTION_EVENT_ACTION_UP:
-			case AMOTION_EVENT_ACTION_POINTER_UP: {
-				_queue.push_axis_event(InputDeviceType::TOUCHSCREEN
-					, 0
-					, pointer_id
-					, x
-					, y
-					, 0
-					);
-
-				bool pointer_down = false;
-				if (action == AMOTION_EVENT_ACTION_DOWN
-					|| action == AMOTION_EVENT_ACTION_POINTER_DOWN)
-					pointer_down = true;
+				_queue.push_button_event(InputDeviceType::TOUCHSCREEN, 0, pointer_id, true);
+				_queue.push_axis_event(InputDeviceType::TOUCHSCREEN, 0, pointer_id, x, y, 0);
+				break;
 
-				_queue.push_button_event(InputDeviceType::TOUCHSCREEN
-					, 0
-					, pointer_id
-					, pointer_down
-					);
+			case AMOTION_EVENT_ACTION_UP:
+			case AMOTION_EVENT_ACTION_POINTER_UP:
+				_queue.push_axis_event(InputDeviceType::TOUCHSCREEN, 0, pointer_id, x, y, 0);
+				_queue.push_button_event(InputDeviceType::TOUCHSCREEN, 0, pointer_id, false);
 				break;
-			}
 
 			case AMOTION_EVENT_ACTION_OUTSIDE:
 			case AMOTION_EVENT_ACTION_CANCEL:
-				_queue.push_button_event(InputDeviceType::TOUCHSCREEN
-					, 0
-					, pointer_id
-					, false
-					);
+				_queue.push_button_event(InputDeviceType::TOUCHSCREEN, 0, pointer_id, false);
 				break;
 
 			case AMOTION_EVENT_ACTION_MOVE:
@@ -168,13 +151,7 @@ struct AndroidDevice
 					const f32 xx = AMotionEvent_getX(event, index);
 					const f32 yy = AMotionEvent_getY(event, index);
 					const s32 id = AMotionEvent_getPointerId(event, index);
-					_queue.push_axis_event(InputDeviceType::TOUCHSCREEN
-						, 0
-						, id
-						, xx
-						, yy
-						, 0
-						);
+					_queue.push_axis_event(InputDeviceType::TOUCHSCREEN, 0, id, xx, yy, 0);
 				}
 				break;
 			}

+ 24 - 1
src/device/main_html5.cpp

@@ -398,6 +398,29 @@ struct EmscriptenDevice
 
 		switch (event_type) {
 		case EMSCRIPTEN_EVENT_TOUCHSTART:
+			for (int i = 0; i < event->numTouches; ++i) {
+				const EmscriptenTouchPoint *touch = &event->touches[i];
+
+				if (touch->identifier < TouchButton::COUNT) {
+					ed->_queue.push_button_event(InputDeviceType::TOUCHSCREEN
+						, 0
+						, touch->identifier
+						, true
+						);
+				}
+
+				if (touch->identifier < TouchAxis::COUNT) {
+					ed->_queue.push_axis_event(InputDeviceType::TOUCHSCREEN
+						, 0
+						, touch->identifier
+						, touch->targetX
+						, touch->targetY
+						, 0
+						);
+				}
+			}
+			return EM_EVENT_STOP;
+
 		case EMSCRIPTEN_EVENT_TOUCHEND:
 			for (int i = 0; i < event->numTouches; ++i) {
 				const EmscriptenTouchPoint *touch = &event->touches[i];
@@ -416,7 +439,7 @@ struct EmscriptenDevice
 					ed->_queue.push_button_event(InputDeviceType::TOUCHSCREEN
 						, 0
 						, touch->identifier
-						, event_type == EMSCRIPTEN_EVENT_TOUCHSTART
+						, false
 						);
 				}
 			}