Exemplo n.º 1
0
void CoreServices::handleEvent(Event *event) {
	if(event->getDispatcher() == core->getInput()) {
		InputEvent *inputEvent = (InputEvent*)event;
		switch(event->getEventCode()) {
			case InputEvent::EVENT_KEYDOWN:
			case InputEvent::EVENT_KEYUP:
				dispatchEvent(new InputEvent(inputEvent->key, inputEvent->charCode, inputEvent->timestamp), inputEvent->getEventCode());			
			break;
			case InputEvent::EVENT_TOUCHES_BEGAN:
			case InputEvent::EVENT_TOUCHES_ENDED:
			case InputEvent::EVENT_TOUCHES_MOVED:						
			{
				InputEvent *event = new InputEvent();
				event->touches = inputEvent->touches;
				event->timestamp = inputEvent->timestamp;
				dispatchEvent(event, inputEvent->getEventCode());
			}
			break;
			default:
				InputEvent *_inputEvent = new InputEvent(inputEvent->mousePosition, inputEvent->timestamp);
				_inputEvent->mouseButton = inputEvent->mouseButton;
				dispatchEvent(_inputEvent, inputEvent->getEventCode());			
			break;
		}
	}
}
Exemplo n.º 2
0
void InputHandler::handleEvent(Event *e)
{
    /* make sure we are getting events from the correct place */
    if (e->getDispatcher() == coreInput)
    {
        InputEvent *ie = (InputEvent*) e;
        switch (ie->getEventCode()) {
            case InputEvent::EVENT_KEYDOWN:
                HandleKeyDown(ie->getKey());
                break;
            case InputEvent::EVENT_KEYUP:
                HandleKeyUp(ie->getKey());
                break;
        }
        
    }
}
Exemplo n.º 3
0
void Scene::handleEvent(Event *event) {
    if(event->getDispatcher() == core) {
        if(sceneType == SCENE_2D_TOPLEFT) {
            rootEntity.setPositionY(-CoreServices::getInstance()->getCore()->getYRes());
        }
    } else if(event->getDispatcher() == core->getInput() && rootEntity.processInputEvents) {
		InputEvent *inputEvent = (InputEvent*) event;
        
        if(constrainPickingToViewport) {
            Polycode::Rectangle v = activeCamera->getViewport();
            if(remapMouse) {
                v.x = sceneMouseRect.x;
                v.y = sceneMouseRect.y;
            }
            
            if(inputEvent->mousePosition.x < v.x || inputEvent->mousePosition.x > v.x+(v.w / renderer->getBackingResolutionScaleX()) || inputEvent->mousePosition.y < v.y || inputEvent->mousePosition.y > v.y + (v.h/renderer->getBackingResolutionScaleY())) {
                    return;
            }
        }
        
		Ray ray = projectRayFromCameraAndViewportCoordinate(activeCamera, inputEvent->mousePosition);
		
		switch(inputEvent->getEventCode()) {
			case InputEvent::EVENT_MOUSEDOWN:
				rootEntity.onMouseDown(ray, inputEvent->mouseButton, inputEvent->timestamp);
			break;
			case InputEvent::EVENT_MOUSEMOVE:
				rootEntity.onMouseMove(ray, inputEvent->timestamp);
			break;
			case InputEvent::EVENT_MOUSEUP:
				rootEntity.onMouseUp(ray, inputEvent->mouseButton, inputEvent->timestamp);
			break;
			case InputEvent::EVENT_MOUSEWHEEL_UP:
				rootEntity.onMouseWheelUp(ray, inputEvent->timestamp);
			break;
			case InputEvent::EVENT_MOUSEWHEEL_DOWN:
				rootEntity.onMouseWheelDown(ray,inputEvent->timestamp);	
			break;	
		}
	}
}