Ejemplo n.º 1
0
LRESULT GEN::GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
	// Route Windows messages to game engine member functions
	switch (msg)
	{
	case WM_SETFOCUS:
		// Activate the game and update the Sleep status
		GameActivate(hWindow);
		SetSleep(FALSE);
		return 0;
	case WM_KILLFOCUS:
		// Deactivate the game and update the Sleep status
		GameDeactivate(hWindow);
		SetSleep(TRUE);
		return 0;
	case WM_PAINT:
		HDC         hDC;
		PAINTSTRUCT ps;
		hDC = BeginPaint(hWindow, &ps);

		// Paint the game
		GamePaint(hDC);

		EndPaint(hWindow, &ps);
		return 0;
	case MM_MCINOTIFY:
		if (LOWORD(wParam) == MCI_NOTIFY_SUCCESSFUL)
		{
			if (GetMIDIPlayer() != nullptr)
				GetMIDIPlayer()->Restart(hWindow);
		}
		return 0;
		// Mouse Input Cases
	case WM_LBUTTONDOWN:
		// handle mouse button 
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;
	case WM_LBUTTONUP:
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;
	case WM_RBUTTONDOWN:
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;
	case WM_RBUTTONUP:
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;
	case WM_MOUSEMOVE:
		MouseMove(LOWORD(lParam), HIWORD(lParam));
		return 0;
	}
	return DefWindowProc(hWindow, msg, wParam, lParam);
}
Ejemplo n.º 2
0
void BaseScene::ProcessEvents() {
	SDL_Event event;
	while(SDL_PollEvent(&event)) {
		switch(event.type) {
			case SDL_QUIT:
				QuitEvent();
			break;

			case SDL_MOUSEMOTION:
				MouseMotion(event.motion);
			break;

			case SDL_MOUSEBUTTONDOWN:
				MouseButtonDown(event.button);
			break;

			case SDL_MOUSEBUTTONUP:
				MouseButtonUp(event.button);
			break;

			case SDL_KEYDOWN:
				KeyDown(event.key);
			break;

			case SDL_KEYUP:
				KeyUp(event.key);
			break;

			//TODO: joystick and controller events
		}
	}
}
Ejemplo n.º 3
0
bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev)
{
	// !m_target is for future proofing when gsrender isn't automatically initialized on load to ensure events still occur
	// !m_target->isVisible() is a hack since currently a guiless application will STILL inititialize a gsrender (providing a valid target)
	if (!m_target || !m_target->isVisible() || target == m_target)
	{
		switch (ev->type())
		{
		case QEvent::MouseButtonPress:
			MouseButtonDown(static_cast<QMouseEvent*>(ev));
			break;
		case QEvent::MouseButtonRelease:
			MouseButtonUp(static_cast<QMouseEvent*>(ev));
			break;
		case QEvent::MouseMove:
			MouseMove(static_cast<QMouseEvent*>(ev));
			break;
		case QEvent::Wheel:
			MouseScroll(static_cast<QWheelEvent*>(ev));
			break;
		default:
			return false;
		}
	}
	return false;
}
Ejemplo n.º 4
0
bool InputEventHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor*) 
{ 
	osgViewer::View* const view = dynamic_cast<osgViewer::View*>(&aa);
	if (view && view->getViewerBase()) {
		osgGA::GUIEventAdapter::EventType eventType = ea.getEventType();
		switch (eventType) 
		{
			case osgGA::GUIEventAdapter::KEYDOWN:
			{
				KeyDown(ea, aa);
				break;
			}
			case osgGA::GUIEventAdapter::KEYUP:
			{
				KeyUp(ea, aa);
				break;
			}

			case osgGA::GUIEventAdapter::DRAG:
			case osgGA::GUIEventAdapter::MOVE:
			{
				MouseMove(ea, aa);
				break;
			}

			case osgGA::GUIEventAdapter::PUSH:
			{
				MouseButtonDown(ea, aa);
				break;
			}

			case osgGA::GUIEventAdapter::RELEASE:
			{
				MouseButtonRelease(ea, aa);
				break;
			}

			case osgGA::GUIEventAdapter::FRAME:
			{
				m_frameCount ++;
				break;
			}

			case osgGA::GUIEventAdapter::CLOSE_WINDOW:
			case osgGA::GUIEventAdapter::QUIT_APPLICATION:
			{
				m_applicationTerminated = true;
				break;
			}

			default:
				break;
		}
	}

	return false;
}
Ejemplo n.º 5
0
//------------------------------------------------------------------------
// Purpose  : Let the POLLing begin...
//------------------------------------------------------------------------
void InputDevice::Poll()
{
	HRESULT Hr;

	// Poll Keyboard
	if (m_pKeyboard)
	{
		Hr = m_pKeyboard->GetDeviceState(sizeof(m_KeyboardState), (void**)&m_KeyboardState);
		
		if (FAILED(Hr))
		{
			// Keyboard lost ...
			ZeroMemory(m_KeyboardState, sizeof(m_KeyboardState));

			// try to acquire next time we poll
			Hr = m_pKeyboard->Acquire();
		}
		else
		{
			std::map<char, InputState>::iterator iter = m_keyMap.begin();
			
			for ( ; iter != m_keyMap.end() ; iter++)
			{
				if(KeyDown(iter->first))
					notifyObserver(iter->second);
			}
		}
	}
	
	// Poll Mouse...
	if (m_pMouse)
	{
		Hr = m_pMouse->GetDeviceState(sizeof(DIMOUSESTATE2), (void**)&m_MouseState);

		if (FAILED(Hr))
		{
			// Mouse Lost...
			ZeroMemory(&m_MouseState, sizeof(m_MouseState));

			// try to acquire next time we poll
			Hr = m_pMouse->Acquire();
		}
		else
		{
			// We look for first three entries in the InputState enum
			// which holds Mouse Buttons
			for (int i = 0 ; i < 3 ; i++)
			{
				if (MouseButtonDown(i))
					notifyObserver(InputState(i));
			}
		}
	}
}
Ejemplo n.º 6
0
void BaseScene::HandleEvents() {
	SDL_Event event;

	while(SDL_PollEvent(&event)) {
		switch(event.type) {
			case SDL_QUIT:
				QuitEvent();
			break;

			case SDL_VIDEORESIZE:
				SetScreen(event.resize.w, event.resize.h, 0, screen->flags);
			break;

			case SDL_MOUSEMOTION:
				MouseMotion(event.motion);
			break;

			case SDL_MOUSEBUTTONDOWN:
				MouseButtonDown(event.button);
			break;

			case SDL_MOUSEBUTTONUP:
				MouseButtonUp(event.button);
			break;

			case SDL_KEYDOWN:
				KeyDown(event.key);
			break;

			case SDL_KEYUP:
				KeyUp(event.key);
			break;

#ifdef USE_EVENT_JOYSTICK
			//TODO: joystick/gamepad support
#endif

#ifdef USE_EVENT_UNKNOWN
			default:
				UnknownEvent(event);
			break;
#endif
		}//switch
	}//while
}
Ejemplo n.º 7
0
LRESULT GameEngine::HandleEvent(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
	//Route Windows messages to game engine member fucntions
	switch (msg)
	{
	case WM_CREATE:
		//Set the game window and start the game
		SetWindow(hWindow);
		GameStart(hWindow);
		return 0;

	case WM_ACTIVATE:
		//Activate and deactivate the game and update the Sleep status
		if (wParam != WA_INACTIVE)
		{
			GameActivate(hWindow);
			SetSleep(FALSE);
		}
		else
		{
			GameDeactivate(hWindow);
			SetSleep(TRUE);
		}
		return 0;

	case WM_PAINT:
		HDC			hDC;
		PAINTSTRUCT	ps;
		hDC = BeginPaint(hWindow, &ps);

		//Paint the game
		GamePaint(hDC);

		EndPaint(hWindow, &ps);
		return 0;

	case WM_LBUTTONDOWN:
		//Handle left mouse button press
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;

	case WM_LBUTTONUP:
		//Handle left mouse button release
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE);
		return 0;

	case WM_RBUTTONDOWN:
		//Handle right mouse button press
		MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;

	case WM_RBUTTONUP:
		//Handle right mouse button release
		MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE);
		return 0;

	case WM_MOUSEMOVE:
		//Handle mouse movement
		MouseMove(LOWORD(lParam), HIWORD(lParam));
		return 0;

	case WM_DESTROY:
		//End the game and exit the application
		GameEnd();
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hWindow, msg, wParam, lParam);
}
Ejemplo n.º 8
0
/** Handles all controller inputs.
	@remark This function is called once per frame.
**/
void CEngine::HandleInput()
{
	// Poll for events, and handle the ones we care about.
	SDL_Event event;
	while ( SDL_PollEvent( &event ) )
	{
		switch ( event.type )
		{
		case SDL_KEYDOWN:
			// If escape is pressed set the Quit-flag
			if (event.key.keysym.sym == SDLK_ESCAPE)
			{
				m_bQuit = true;
				break;
			}

			KeyDown( event.key.keysym.sym );
			break;

		case SDL_KEYUP:
			KeyUp( event.key.keysym.sym );
			break;

		case SDL_QUIT:
			m_bQuit = true;
			break;

		case SDL_MOUSEMOTION:
			MouseMoved(
				event.button.button,
				event.motion.x,
				event.motion.y,
				event.motion.xrel,
				event.motion.yrel);
			break;

		case SDL_MOUSEBUTTONUP:
			MouseButtonUp(
				event.button.button,
				event.motion.x,
				event.motion.y,
				event.motion.xrel,
				event.motion.yrel);
			break;

		case SDL_MOUSEBUTTONDOWN:
			MouseButtonDown(
				event.button.button,
				event.motion.x,
				event.motion.y,
				event.motion.xrel,
				event.motion.yrel);
			break;

		case SDL_ACTIVEEVENT:
			if ( event.active.state & SDL_APPACTIVE ) {
				if ( event.active.gain ) {
					m_bMinimized = false;
					WindowActive();
				} else {
					m_bMinimized = true;
					WindowInactive();
				}
			}
			break;
		} // switch
	} // while (handling input)
}
Ejemplo n.º 9
0
void AllegroEngine::Run()
  {
  ALLEGRO_EVENT ev;

  while (!quit) {
    al_wait_for_event(event_queue, &ev);
    switch (ev.type) 
      {
      /* ALLEGRO_EVENT_KEY_DOWN - a keyboard key was pressed.
      * The three keyboard event fields we use here are:
      *
      * keycode -- an integer constant representing the key, e.g.
        *             AL_KEY_ESCAPE;
        *
        * unichar -- the Unicode character being typed, if any.  This can
        *             depend on the modifier keys and previous keys that were
        *             pressed, e.g. for accents.
          *
          * modifiers -- a bitmask containing the state of Shift/Ctrl/Alt, etc.
          *             keys.
          */
    case ALLEGRO_EVENT_KEY_DOWN:
      if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
        quit = true;
      KeyDown(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers);
      break;

        /* ALLEGRO_EVENT_KEY_REPEAT - a keyboard key was held down long enough to
          * 'repeat'.  This is a useful event if you are working on something
          * that requires typed input.  The repeat rate should be determined
          * by the operating environment the program is running in.
          */
      case ALLEGRO_EVENT_KEY_CHAR:
        KeyDown(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers, ev.keyboard.repeat);
        break;

        /* ALLEGRO_EVENT_KEY_UP - a keyboard key was released.
        * Note that the unichar field is unused for this event.
          */
      case ALLEGRO_EVENT_KEY_UP:
        KeyUp(ev.keyboard.keycode, ev.keyboard.unichar, ev.keyboard.modifiers);
        break;

        /* ALLEGRO_EVENT_MOUSE_AXES - at least one mouse axis changed value.
        * The 'z' axis is for the scroll wheel.  We also have a fourth 'w'
        * axis for mice with two scroll wheels.
          */
         case ALLEGRO_EVENT_MOUSE_AXES:
            MouseMoved(ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz);
            break;
 
         /* ALLEGRO_EVENT_MOUSE_BUTTON_UP - a mouse button was pressed. 
          * The axis fields are also valid for this event.
          */
         case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
            MouseButtonDown(ev.mouse.button, ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz);
            break;
 
         /* ALLEGRO_EVENT_MOUSE_BUTTON_UP - a mouse button was released.
          * The axis fields are also valid for this event.
          */
         case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
            MouseButtonUp(ev.mouse.button, ev.mouse.x, ev.mouse.y, ev.mouse.z, ev.mouse.dx, ev.mouse.dy, ev.mouse.dz);
            break;
 
         /* ALLEGRO_EVENT_TIMER - a timer 'ticked'.
          * The `source' field in the event structure tells us which timer
          * went off, and the `count' field tells us the timer's counter
          * value at the time that the event was generated.  It's not
          * redundant, because although you can query the timer for its
          * counter value, that value might have changed by the time you got
          * around to processing this event.
          */
         case ALLEGRO_EVENT_TIMER:
            HandleTimers(ev.timer.source, ev.timer.count);
            break;

         /* ALLEGRO_EVENT_DISPLAY_CLOSE - the window close button was pressed.
          */
         case ALLEGRO_EVENT_DISPLAY_CLOSE:
           quit = true;
            return;
 
         /*case ALLEGRO_EVENT_DISPLAY_SWITCH_IN:
            log_general("Switch In");
            break;
 
         case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
            log_general("Switch Out");
            break;*/
 
         /* We received an event of some type we don't know about.
          * Just ignore it.
          */
         default:
            break;
      }
   }
  }