Example #1
0
void OSystem_IPHONE::suspendLoop() {
	bool done = false;
	uint32 startTime = getMillis();

	stopSoundsystem();

	InternalEvent event;
	while (!done) {
		if (iPhone_fetchEvent(&event))
			if (event.type == kInputApplicationResumed)
				done = true;
		usleep(100000);
	}

	startSoundsystem();

	_timeSuspended += getMillis() - startTime;
}
Example #2
0
unsigned long gp2x_joystick_read(void)
{
	static u32 gp2x_keys = 0;
	int eventType;
	float xUnit, yUnit;

	if (iPhone_fetchEvent(&eventType, &xUnit, &yUnit)) {
		int x = (int)((1.0 - yUnit) * _screenWidth);
		int y = (int)(xUnit * _screenHeight);

		long curTime = gp2x_getMillis();

		switch ((InputEvent)eventType) {
			case kInputMouseDown:
				//printf("Mouse down at (%u, %u)\n", x, y);
				_lastMouseDown = curTime;
				_mouseX = x;
				_mouseY = y;

				gp2x_keys |= gp2x_get_mouse(x, y);
				return gp2x_keys;

				break;
			case kInputMouseUp:
				//printf("Mouse up at (%u, %u)\n", x, y);

				if (curTime - _lastMouseDown < 250) {

					gp2x_keys &= ~(gp2x_get_mouse(_mouseX, _mouseY));
					_lastMouseTap = curTime;
					
					// if (curTime - _lastMouseTap < 250 && !_overlayVisible) {
					// 	event.type = Common::EVENT_KEYDOWN;
					// 	_queuedInputEvent.type = Common::EVENT_KEYUP;
					// 
					// 	event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
					// 	event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_ESCAPE;
					// 	event.kbd.ascii = _queuedInputEvent.kbd.ascii = 27;		
					// 							
					// 	_lastMouseTap = 0;
					// } else {
					// 
					// }
				} else {
					return gp2x_keys;
				}

				break;
			case kInputMouseDragged:
				//printf("Mouse dragged at (%u, %u)\n", x, y);
				if (_secondaryTapped) {
					int vecX = (x - _gestureStartX);
					int vecY = (y - _gestureStartY);
					int lengthSq =  vecX * vecX + vecY * vecY;
					//printf("Lengthsq: %u\n", lengthSq);

					if (lengthSq > 5000) { // Long enough gesture to react upon.
						_gestureStartX = x;
						_gestureStartY = y;
						
						float vecLength = sqrt(lengthSq);
						float vecXNorm = vecX / vecLength;
						float vecYNorm = vecY / vecLength;

						//printf("Swipe vector: (%.2f, %.2f)\n", vecXNorm, vecYNorm);

						if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm > 0.75) {
							// Swipe down
							
							gp2x_keys |= GP2X_VOL_DOWN;
						} else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) {
							// Swipe up
							gp2x_keys |= GP2X_VOL_UP;
						} else if (vecXNorm > 0.75 && vecYNorm >  -0.5 && vecYNorm < 0.5) {
							// Swipe right
							gp2x_keys |= GP2X_VOL_UP | GP2X_VOL_DOWN;
						} else if (vecXNorm < -0.75 && vecYNorm >  -0.5 && vecYNorm < 0.5) {
							// Swipe left
							return gp2x_keys;
						} else {
							return gp2x_keys;
						}				
					} else {
						return gp2x_keys;						
					}
				} else {
					event.type = Common::EVENT_MOUSEMOVE;
					event.mouse.x = x;
					event.mouse.y = y;
					_mouseX = x;
					_mouseY = y;					
				}
				break;
			case kInputMouseSecondToggled:
				_secondaryTapped = !_secondaryTapped;
				//printf("Mouse second at (%u, %u). State now %s.\n", x, y, _secondaryTapped ? "on" : "off");
				if (_secondaryTapped) {
					_lastSecondaryDown = curTime;
					_gestureStartX = x;
					_gestureStartY = y;
					return gp2x_keys;
				} else if (curTime - _lastSecondaryDown < 250 ) {
					if (curTime - _lastSecondaryTap < 250 && !_overlayVisible) {
						_lastSecondaryTap = 0;
					} else {
						_lastSecondaryTap = curTime;
					}		
				} else {
					return gp2x_keys;
				}
				break;
			default:
				break;
		}

		return gp2x_keys;
	}
	return gp2x_keys;
}
Example #3
0
bool OSystem_IPHONE::pollEvent(Common::Event &event) {
	//printf("pollEvent()\n");

	long curTime = getMillis();

	if (_timerCallback && (curTime >= _timerCallbackNext)) {
		_timerCallback(_timerCallbackTimer);
		_timerCallbackNext = curTime + _timerCallbackTimer;
	}

	if (_queuedInputEvent.type != Common::EVENT_INVALID && curTime >= _queuedEventTime) {
		event = _queuedInputEvent;
		_queuedInputEvent.type = Common::EVENT_INVALID;
		return true;
	}

	int eventType;
	int x, y;

	if (iPhone_fetchEvent(&eventType, &x, &y)) {
		switch ((InputEvent)eventType) {
		case kInputMouseDown:
			if (!handleEvent_mouseDown(event, x, y))
				return false;
			break;

		case kInputMouseUp:
			if (!handleEvent_mouseUp(event, x, y))
				return false;
			break;

		case kInputMouseDragged:
			if (!handleEvent_mouseDragged(event, x, y))
				return false;
			break;
		case kInputMouseSecondDragged:
			if (!handleEvent_mouseSecondDragged(event, x, y))
				return false;
			break;
		case kInputMouseSecondDown:
			_secondaryTapped = true;
			if (!handleEvent_secondMouseDown(event, x, y))
				return false;
			break;
		case kInputMouseSecondUp:
			_secondaryTapped = false;
			if (!handleEvent_secondMouseUp(event, x, y))
				return false;
			break;
		case kInputOrientationChanged:
			handleEvent_orientationChanged(x);
			return false;
			break;

		case kInputApplicationSuspended:
			suspendLoop();
			return false;
			break;

		case kInputKeyPressed:
			handleEvent_keyPressed(event, x);
			break;

		case kInputSwipe:
			if (!handleEvent_swipe(event, x))
				return false;
			break;

		default:
			break;
		}

		return true;
	}
	return false;
}