Ejemplo n.º 1
0
void Engine::processEvents()
{
	sf::Event event;
	
	while (app->GetEvent(event))
	{
		// Close window: exit
		if (event.Type == sf::Event::Closed)
			running = false;
			
		// Resize event: adjust viewport
		else if (event.Type == sf::Event::Resized) {
			glViewport(0, 0, event.Size.Width, event.Size.Height);
		}

		else if (event.Type == sf::Event::KeyPressed)
			processKeyPressed(event);
			
		else if (event.Type == sf::Event::MouseButtonPressed)
			processMouseButtonPressed(event);
			
		else if (event.Type == sf::Event::MouseButtonReleased)
			processMouseButtonReleased(event);
					
		else if (event.Type == sf::Event::MouseMoved)
			processMouseMoved(event);
			
		else if (event.Type == sf::Event::MouseWheelMoved)
			processMouseWheelMoved(event);
	}
}
Ejemplo n.º 2
0
UIEventResult UICanvas::pushEvent(const Event& event)
{
	Event processedEvent = event;
	
	UIEventResult eventUsage;

	// -- Raw event delivery system
	m_surfaceContainerLock++;
	for(std::vector<UIWindow*>::reverse_iterator it = m_surfaces.rbegin(); it != m_surfaces.rend(); it++)
	{
		if((*it)->getChildCount() > 0)
		{
			// deliver the event
			(*it)->dispatchEvent(processedEvent);

			if((*it)->isModal())
			{
				eventUsage.clickPassedThrough = false;
				break;
			}
		}
	}
	m_surfaceContainerLock--;

	// -- Built-in event handling
	switch(event.type)
	{
		case Event::MouseMoved:
			{
				processMouseMove(processedEvent.mouseMove.x, processedEvent.mouseMove.y);
			}
		break;

		case Event::TouchMoved:
			{
				processTouchMove(processedEvent.touch.x, processedEvent.touch.y);
			}
			break;

		case Event::MouseButtonPressed:
			{
				bool result = processMouseButtonPressed(processedEvent.mouseButton.x, processedEvent.mouseButton.y, processedEvent.mouseButton.button);
				eventUsage.hitControls = false;
			}
		break;

		case Event::TouchPressed:
			{
				bool result = processMouseButtonPressed(processedEvent.touch.x, processedEvent.touch.y, Mouse::Left);
				eventUsage.hitControls = false;
			}
			break;

		case Event::MouseButtonReleased:
			{				
				processMouseButtonReleased(processedEvent.mouseButton.x, processedEvent.mouseButton.y, processedEvent.mouseButton.button, eventUsage);
			}
			break;
		case Event::TouchReleased:
			{				
				processMouseButtonReleased(processedEvent.touch.x, processedEvent.touch.y, Mouse::Left, eventUsage);
			}
			break;

		case Event::TextEntered:
			{
				// Deliver input to the focused control
				if(m_state.m_focusControl)
				{
					UxKeyEvent keyEvent;
					keyEvent.type = UxKeyEvent::KeyPress;
					keyEvent.unicode = processedEvent.text.unicode;
					if (keyEvent.unicode >= 32)
						m_state.m_focusControl->keyPressEvent(&keyEvent);

					//m_state.m_focusControl->onTextEvent(processedEvent.text.unicode);
				}
			}
			break;

		case Event::KeyPressed:
		{
				// Deliver input to the focused control
				if (m_state.m_focusControl)
				{
					   UxKeyEvent keyEvent;
					   keyEvent.type = UxKeyEvent::KeyPress;
					   keyEvent.key = processedEvent.key.code;
					   m_state.m_focusControl->keyPressEvent(&keyEvent);
				}
		}break;
	}

	// now that surfaces were processed, apply changes to surfaces container
	// the updates in the container are only considered in the next event, so it is not wrongly consumed
	applyPendingChanges();

	return eventUsage;
};