Ejemplo n.º 1
0
	void SDLApplication::HandleEvent (SDL_Event* event) {
		
		switch (event->type) {
			
			case SDL_USEREVENT:
				
				currentUpdate = SDL_GetTicks ();
				updateEvent.deltaTime = currentUpdate - lastUpdate;
				lastUpdate = currentUpdate;
				
				while (nextUpdate <= currentUpdate) {
					
					nextUpdate += framePeriod;
					
				}
				
				UpdateEvent::Dispatch (&updateEvent);
				RenderEvent::Dispatch (&renderEvent);
				break;
			
			case SDL_APP_WILLENTERBACKGROUND:
				
				windowEvent.type = WINDOW_DEACTIVATE;
				WindowEvent::Dispatch (&windowEvent);
				break;
			
			case SDL_APP_WILLENTERFOREGROUND:
				
				windowEvent.type = WINDOW_ACTIVATE;
				WindowEvent::Dispatch (&windowEvent);
				break;
			
			case SDL_CONTROLLERAXISMOTION:
			case SDL_CONTROLLERBUTTONDOWN:
			case SDL_CONTROLLERBUTTONUP:
			case SDL_CONTROLLERDEVICEADDED:
			case SDL_CONTROLLERDEVICEREMOVED:
				
				ProcessGamepadEvent (event);
				break;
			
			case SDL_FINGERMOTION:
			case SDL_FINGERDOWN:
			case SDL_FINGERUP:
				
				ProcessTouchEvent (event);
				break;
			
			case SDL_JOYAXISMOTION:
			case SDL_JOYBALLMOTION:
			case SDL_JOYBUTTONDOWN:
			case SDL_JOYBUTTONUP:
			case SDL_JOYHATMOTION:
			case SDL_JOYDEVICEADDED:
			case SDL_JOYDEVICEREMOVED:
				
				//joy
				break;
			
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				
				ProcessKeyEvent (event);
				break;
			
			case SDL_MOUSEMOTION:
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEWHEEL:
				
				ProcessMouseEvent (event);
				break;
			
			case SDL_TEXTINPUT:
			case SDL_TEXTEDITING:
				
				ProcessTextEvent (event);
				break;
			
			case SDL_WINDOWEVENT:
				
				switch (event->window.event) {
					
					case SDL_WINDOWEVENT_ENTER:
					case SDL_WINDOWEVENT_LEAVE:
					case SDL_WINDOWEVENT_SHOWN:
					case SDL_WINDOWEVENT_HIDDEN:
					case SDL_WINDOWEVENT_FOCUS_GAINED:
					case SDL_WINDOWEVENT_FOCUS_LOST:
					case SDL_WINDOWEVENT_MINIMIZED:
					case SDL_WINDOWEVENT_MOVED:
					case SDL_WINDOWEVENT_RESTORED:
						
						ProcessWindowEvent (event);
						break;
					
					case SDL_WINDOWEVENT_EXPOSED: 
						
						RenderEvent::Dispatch (&renderEvent);
						break;
					
					case SDL_WINDOWEVENT_SIZE_CHANGED:
						
						ProcessWindowEvent (event);
						RenderEvent::Dispatch (&renderEvent);
						break;
					
					case SDL_WINDOWEVENT_CLOSE:
						
						ProcessWindowEvent (event);
						active = false;
						break;
					
				}
				
				break;
			
			case SDL_QUIT:
				
				//quit
				active = false;
				break;
			
		}
		
	}
Ejemplo n.º 2
0
	void SDLApplication::HandleEvent (SDL_Event* event) {
		
		switch (event->type) {
			
			case SDL_USEREVENT:
				
				currentUpdate = SDL_GetTicks ();
				applicationEvent.type = UPDATE;
				applicationEvent.deltaTime = currentUpdate - lastUpdate;
				lastUpdate = currentUpdate;
				
				nextUpdate += framePeriod;
				
				while (nextUpdate <= currentUpdate) {
					
					nextUpdate += framePeriod;
					
				}
				
				ApplicationEvent::Dispatch (&applicationEvent);
				RenderEvent::Dispatch (&renderEvent);
				break;
			
			case SDL_APP_WILLENTERBACKGROUND:
				
				windowEvent.type = WINDOW_DEACTIVATE;
				WindowEvent::Dispatch (&windowEvent);
				break;
			
			case SDL_APP_WILLENTERFOREGROUND:
				
				windowEvent.type = WINDOW_ACTIVATE;
				WindowEvent::Dispatch (&windowEvent);
				break;
			
			case SDL_CONTROLLERAXISMOTION:
			case SDL_CONTROLLERBUTTONDOWN:
			case SDL_CONTROLLERBUTTONUP:
			case SDL_CONTROLLERDEVICEADDED:
			case SDL_CONTROLLERDEVICEREMOVED:
				
				ProcessGamepadEvent (event);
				break;
			
			case SDL_DROPFILE:
				
				ProcessDropEvent (event);
				break;
			
			case SDL_FINGERMOTION:
			case SDL_FINGERDOWN:
			case SDL_FINGERUP:
				
				#ifndef HX_MACOS
				ProcessTouchEvent (event);
				#endif
				break;
			
			case SDL_JOYAXISMOTION:
				
				if (SDLJoystick::IsAccelerometer (event->jaxis.which)) {
					
					ProcessSensorEvent (event);
					
				} else {
					
					ProcessJoystickEvent (event);
					
				}
				
				break;
			
			case SDL_JOYBALLMOTION:
			case SDL_JOYBUTTONDOWN:
			case SDL_JOYBUTTONUP:
			case SDL_JOYHATMOTION:
			case SDL_JOYDEVICEADDED:
			case SDL_JOYDEVICEREMOVED:
				
				ProcessJoystickEvent (event);
				break;
			
			case SDL_KEYDOWN:
			case SDL_KEYUP:
				
				ProcessKeyEvent (event);
				break;
			
			case SDL_MOUSEMOTION:
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEWHEEL:
				
				ProcessMouseEvent (event);
				break;
			
			case SDL_TEXTINPUT:
			case SDL_TEXTEDITING:
				
				ProcessTextEvent (event);
				break;
			
			case SDL_WINDOWEVENT:
				
				switch (event->window.event) {
					
					case SDL_WINDOWEVENT_ENTER:
					case SDL_WINDOWEVENT_LEAVE:
					case SDL_WINDOWEVENT_SHOWN:
					case SDL_WINDOWEVENT_HIDDEN:
					case SDL_WINDOWEVENT_FOCUS_GAINED:
					case SDL_WINDOWEVENT_FOCUS_LOST:
					case SDL_WINDOWEVENT_MINIMIZED:
					case SDL_WINDOWEVENT_MOVED:
					case SDL_WINDOWEVENT_RESTORED:
						
						ProcessWindowEvent (event);
						break;
					
					case SDL_WINDOWEVENT_EXPOSED: 
						
						RenderEvent::Dispatch (&renderEvent);
						break;
					
					case SDL_WINDOWEVENT_SIZE_CHANGED:
						
						ProcessWindowEvent (event);
						RenderEvent::Dispatch (&renderEvent);
						break;
					
					case SDL_WINDOWEVENT_CLOSE:
						
						ProcessWindowEvent (event);
						break;
					
				}
				
				break;
			
			case SDL_QUIT:
				
				active = false;
				break;
			
		}
		
	}