static void I_ReadMouse(void)
{
    int x, y;
    event_t ev;

#if SDL_VERSION_ATLEAST(1, 3, 0)
    SDL_GetRelativeMouseState(0, &x, &y);
#else
    SDL_GetRelativeMouseState(&x, &y);
#endif

    if (x != 0 || y != 0) 
    {
        ev.type = ev_mouse;
        ev.data1 = MouseButtonState();
        ev.data2 = AccelerateMouse(x);
        ev.data3 = -AccelerateMouse(y);
        
        D_PostEvent(&ev);
    }

    if (MouseShouldBeGrabbed())
    {
        CenterMouse();
    }
}
示例#2
0
文件: descent.cpp 项目: paud/d2x-xl
void ShowOrderForm (void)
{
	int 	pcx_error;
	char	exit_screen[16];

	CCanvas::SetCurrent (NULL);
	paletteManager.ClearEffect ();

	KeyFlush ();

	strcpy (exit_screen, gameStates.menus.bHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
	if (! CFile::Exist (exit_screen, gameFolders.szDataDir, 0))
		strcpy (exit_screen, gameStates.menus.bHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
	if (! CFile::Exist (exit_screen, gameFolders.szDataDir, 0))
		strcpy (exit_screen, gameStates.menus.bHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
	if (! CFile::Exist (exit_screen, gameFolders.szDataDir, 0))
		strcpy (exit_screen, gameStates.menus.bHires?"warningb.pcx":"warning.pcx"); // D1
	if (! CFile::Exist (exit_screen, gameFolders.szDataDir, 0))
		return; // D2 registered

	if ((pcx_error=PcxReadFullScrImage (exit_screen, 0))==PCX_ERROR_NONE) {
		paletteManager.EnableEffect ();
		GrUpdate (0);
		while (!(KeyInKey () || MouseButtonState (0)))
			;
		paletteManager.DisableEffect ();
	}
	else
		Int3 ();		//can't load order screen

	KeyFlush ();
}
示例#3
0
inline int ZoomKeyPressed (void)
{
#if 1
	int	v;

return gameStates.input.keys.pressed [kcKeyboard [52].value] || gameStates.input.keys.pressed [kcKeyboard [53].value] ||
		 (((v = kcMouse [30].value) < 255) && MouseButtonState (v));
#else
return (Controls [0].zoomDownCount > 0);
#endif
}
//================================================================================
ATHKeyList ATHInputManager::CheckMouseButtons()
{
	std::list< unsigned int > liButtonsDown;
	
	for( unsigned int i = 0; i < ATH_MAX_MOUSE_BUTTONS; ++i )
	{
		if( MouseButtonState( (unsigned char)(i) ) )
		{
			liButtonsDown.push_back( i );
		}
	}

	return liButtonsDown;
}
示例#5
0
	bool UiElement::checkMouseMoveEvent( const UiInputState& state )
	{
		const bool isInElement = m_layoutRectangle.contains( state.mousePosition );
		if( isInElement || m_mouseMoveState )
		{
			UiEvent eventData;
			eventData.data.mouseMove.position	= state.mousePosition;
			eventData.data.mouseMove.buttons	= state.mouseButtonState;

			if( isInElement && m_mouseMoveState )
			{
				eventData.type = UiEventType_MouseOver;
			}
			else if( isInElement && !m_mouseMoveState )
			{
				eventData.type = UiEventType_MouseIn;
				m_mouseMoveState = true;
			}
			else if( !isInElement && m_mouseMoveState )
			{
				eventData.type = UiEventType_MouseOut;
				m_mouseMoveState = false;
				m_mouseClickState = MouseButtonState();
			}

			raiseEvent( eventData );

			for( UiElement& child : m_children )
			{
				child.checkMouseMoveEvent( state );
			}

			return true;
		}

		return false;
	}
示例#6
0
void ShowOrderForm (void)
{
	char	szExitScreen [16];

CCanvas::SetCurrent (NULL);
KeyFlush ();
strcpy (szExitScreen, gameStates.menus.bHires ? "ordrd2ob.pcx" : "ordrd2o.pcx"); // OEM
if (! CFile::Exist (szExitScreen, gameFolders.szDataDir, 0))
	strcpy (szExitScreen, gameStates.menus.bHires ? "orderd2b.pcx" : "orderd2.pcx"); // SHAREWARE, prefer mac if hires
if (! CFile::Exist (szExitScreen, gameFolders.szDataDir, 0))
	strcpy (szExitScreen, gameStates.menus.bHires ? "orderd2.pcx" : "orderd2b.pcx"); // SHAREWARE, have to rescale
if (! CFile::Exist (szExitScreen, gameFolders.szDataDir, 0))
	strcpy (szExitScreen, gameStates.menus.bHires ? "warningb.pcx" : "warning.pcx"); // D1
if (! CFile::Exist (szExitScreen, gameFolders.szDataDir, 0))
	return; // D2 registered

int pcxResult = PcxReadFullScrImage (szExitScreen, 0);
if (pcxResult == PCX_ERROR_NONE) {
	GrUpdate (0);
	while (!(KeyInKey () || MouseButtonState (0)))
		;
	}
KeyFlush ();
}
示例#7
0
文件: input.cpp 项目: paud/d2x-xl
void ControlsDoMouse (int *mouseAxis, int nMouseButtons, 
							 int *bSlideOn, int *bBankOn, fix *pitchTimeP, fix *headingTimeP, int *nCruiseSpeed, 
							 int bGetSlideBank)
{
	int	v, nMouseSensMod = 8;

if (bGetSlideBank == 0) {
	if ((v = kcMouse [5].value) < 255) 
		*bSlideOn |= nMouseButtons & (1 << v);
	if ((v = kcMouse [10].value) < 255) 
		*bBankOn |= nMouseButtons & (1 << v);
	return;
	}
// Buttons
if (bGetSlideBank == 2) {
	if ((v = kcMouse [0].value) < 255) {
		Controls [0].firePrimaryState |= MouseButtonState (v);
		Controls [0].firePrimaryDownCount += MouseButtonDownCount (v);
		}
	if ((v = kcMouse [1].value) < 255) {
		Controls [0].fireSecondaryState |= MouseButtonState (v);
		Controls [0].fireSecondaryDownCount += MouseButtonDownCount (v);
		}
	if ((v = kcMouse [2].value) < 255) 
		Controls [0].forwardThrustTime += MouseButtonDownTime (v);
	if ((v = kcMouse [3].value) < 255) 
		Controls [0].forwardThrustTime -= MouseButtonDownTime (v);
	if ((v = kcMouse [4].value) < 255) 
		Controls [0].fireFlareDownCount += MouseButtonDownCount (v);
	if ((v = kcMouse [6].value) < 255) 
		Controls [0].sidewaysThrustTime -= MouseButtonDownTime (v);
	if ((v = kcMouse [7].value) < 255) 
		Controls [0].sidewaysThrustTime += MouseButtonDownTime (v);
	if ((v = kcMouse [8].value) < 255) 
		Controls [0].verticalThrustTime += MouseButtonDownTime (v);
	if ((v = kcMouse [9].value) < 255) 
		Controls [0].verticalThrustTime -= MouseButtonDownTime (v);
	if ((v = kcMouse [11].value) < 255) 
		Controls [3].bankTime += MouseButtonDownTime (v);
	if ((v = kcMouse [12].value) < 255) 
		Controls [3].bankTime -= MouseButtonDownTime (v);
	if ((v = kcMouse [25].value) < 255) {
		Controls [0].rearViewDownCount += MouseButtonDownCount (v);
		Controls [0].rearViewDownState |= MouseButtonState (v);
		}
	if ((v = kcMouse [26].value) < 255) 
		Controls [0].dropBombDownCount += MouseButtonDownCount (v);
	if ((v = kcMouse [27].value) < 255) 
		Controls [0].afterburnerState |= MouseButtonState (v);
	if (((v = kcMouse [28].value) < 255) && MouseButtonState (v))
		Controls [0].cyclePrimaryCount += MouseButtonDownCount (v);
	if (((v = kcMouse [29].value) < 255) && MouseButtonState (v))
		Controls [0].cycleSecondaryCount += MouseButtonDownCount (v);
	if (((v = kcMouse [30].value) < 255) && MouseButtonState (v))
		Controls [0].zoomDownCount += MouseButtonDownCount (v);
	// Axis movements
	if ((v = kcMouse [17].value) < 255) {
		if (kcMouse [18].value)		// If inverted...
			Controls [0].sidewaysThrustTime -= mouseAxis [v];
		else
			Controls [0].sidewaysThrustTime += mouseAxis [v];
		}
	if ((v = kcMouse [19].value) < 255) {
		if (kcMouse [20].value)		// If inverted...
			Controls [0].verticalThrustTime -= mouseAxis [v];
		else
			Controls [0].verticalThrustTime += mouseAxis [v];
		}
	if (((v = kcMouse [21].value) < 255) && mouseAxis [v]) {
		if (kcMouse [22].value)		// If inverted...
			Controls [3].bankTime -= mouseAxis [v];
		else
			Controls [3].bankTime += mouseAxis [v];
		}
	if ((v = kcMouse [23].value) < 255) {
		if (kcMouse [24].value)		// If inverted...
			Controls [0].forwardThrustTime += mouseAxis [v];
		else
			Controls [0].forwardThrustTime -= mouseAxis [v];
		}
	// special continuous slide & bank handling
	if (*bSlideOn) {
		if ((v = kcMouse [13].value) < 255) {
			if (kcMouse [14].value)		// If inverted...
				Controls [0].verticalThrustTime += mouseAxis [v];
			else
				Controls [0].verticalThrustTime -= mouseAxis [v];
			}
		if ((v = kcMouse [15].value) < 255)	{
			if (kcMouse [16].value)		// If inverted...
				Controls [0].sidewaysThrustTime -= mouseAxis [v];
			else
				Controls [0].sidewaysThrustTime += mouseAxis [v];
			}
		}
	else {
		SDL_GetMouseState (&mouseData.x, &mouseData.y);
		if (!gameStates.app.bNostalgia && gameOpts->input.mouse.bJoystick) {
			int dx = mouseData.x - SWIDTH / 2;
			int dz = CalcDeadzone (mouseData.y - SHEIGHT / 2, gameOpts->input.mouse.nDeadzone);
			if (dx < 0) {
				if (dx > -dz)
					dx = 0;
				else
					dx += dz;
				}
			else {
				//dz = dz * grdCurScreen->scWidth / grdCurScreen->scHeight;
				if (dx < dz)
					dx = 0;
				else
					dx -= dz;
				}
			dx = 640 * dx / (SWIDTH / gameOpts->input.mouse.sensitivity [0]);
			Controls [3].headingTime += dx; // * gameOpts->input.mouse.sensitivity [0]); // nMouseSensMod;
			}
		else {
			if (((v = kcMouse [13].value) < 255) && mouseAxis [v]) {
				if (kcMouse [14].value)		// If inverted...
					Controls [3].pitchTime += (mouseAxis [v] * gameOpts->input.mouse.sensitivity [1]) / nMouseSensMod;
				else
					Controls [3].pitchTime -= (mouseAxis [v] * gameOpts->input.mouse.sensitivity [1]) / nMouseSensMod;
				}
			}
		if (*bBankOn) {
			if (((v = kcMouse [15].value) < 255) && mouseAxis [v]) {
				if (kcMouse [16].value)		// If inverted...
					Controls [3].bankTime -= (mouseAxis [v] * gameOpts->input.mouse.sensitivity [2]) / nMouseSensMod;
				else
					Controls [3].bankTime += (mouseAxis [v] * gameOpts->input.mouse.sensitivity [2]) / nMouseSensMod;
				}
			}
		else {
			if (!gameStates.app.bNostalgia && gameOpts->input.mouse.bJoystick) {
				int	dy = mouseData.y - SHEIGHT / 2;
				int	dz = CalcDeadzone (mouseData.x - SWIDTH / 2, gameOpts->input.mouse.nDeadzone);
				if (kcMouse [14].value)
					dy = -dy;
				if (dy < 0) {
					if (dy > -dz)
						dy = 0;
					else
						dy += dz;
				}
				else {
					if (dy < dz)
						dy = 0;
					else
						dy -= dz;
					}
				dy = 480 * dy / (SHEIGHT / gameOpts->input.mouse.sensitivity [1]);
				Controls [3].pitchTime += dy; // * gameOpts->input.mouse.sensitivity [1]); // nMouseSensMod;
				}
			else {
				if (((v = kcMouse [15].value) < 255) && mouseAxis [v]) {
					if (kcMouse [16].value)		// If inverted...
						Controls [3].headingTime -= (mouseAxis [v] * gameOpts->input.mouse.sensitivity [0]) / nMouseSensMod;
					else
						Controls [3].headingTime += (mouseAxis [v] * gameOpts->input.mouse.sensitivity [0]) / nMouseSensMod;
					}
				}
			}
		}
	}

if (gameStates.input.nMouseType == CONTROL_CYBERMAN)	{
	if (bGetSlideBank == 2) {
		Controls [0].verticalThrustTime += MouseButtonDownTime (D2_MB_Z_UP) / 2;
		Controls [0].verticalThrustTime -= MouseButtonDownTime (D2_MB_Z_DOWN) / 2;
		Controls [3].bankTime += MouseButtonDownTime (D2_MB_BANK_LEFT);
		Controls [3].bankTime -= MouseButtonDownTime (D2_MB_BANK_RIGHT);
		}
	if (*bSlideOn) {
		if (bGetSlideBank == 2) {
			Controls [0].verticalThrustTime -= MouseButtonDownTime (D2_MB_PITCH_FORWARD);
			Controls [0].verticalThrustTime += MouseButtonDownTime (D2_MB_PITCH_BACKWARD);
			Controls [0].sidewaysThrustTime -= MouseButtonDownTime (D2_MB_HEAD_LEFT);
			Controls [0].sidewaysThrustTime += MouseButtonDownTime (D2_MB_HEAD_RIGHT);
			}
		}
	else if (bGetSlideBank == 1) {
		*pitchTimeP += MouseButtonDownTime (D2_MB_PITCH_FORWARD) / (PH_SCALE * 2);
		*pitchTimeP -= MouseButtonDownTime (D2_MB_PITCH_BACKWARD) / (PH_SCALE * 2);
		if (!*bBankOn) {
			*headingTimeP -= MouseButtonDownTime (D2_MB_HEAD_LEFT) /PH_SCALE;
			*headingTimeP += MouseButtonDownTime (D2_MB_HEAD_RIGHT) /PH_SCALE;
			}
		}
	if (*bBankOn) {
		if (bGetSlideBank == 2) {
			Controls [3].bankTime -= MouseButtonDownTime (D2_MB_HEAD_LEFT);
			Controls [3].bankTime += MouseButtonDownTime (D2_MB_HEAD_RIGHT);
			}
		}
	}
}
void I_GetEvent(void)
{
    SDL_Event sdlevent;
    event_t event;

    // possibly not needed
    
    SDL_PumpEvents();

    // put event-grabbing stuff in here
    
    while (SDL_PollEvent(&sdlevent))
    {
        // ignore mouse events when the window is not focused

        if (!window_focused 
         && (sdlevent.type == SDL_MOUSEMOTION
          || sdlevent.type == SDL_MOUSEBUTTONDOWN
          || sdlevent.type == SDL_MOUSEBUTTONUP))
        {
            continue;
        }

        if (screensaver_mode && sdlevent.type == SDL_QUIT)
        {
            I_Quit();
        }

        // process event
        
        switch (sdlevent.type)
        {
            case SDL_KEYDOWN:
                event.type = ev_keydown;
                event.data1 = TranslateKey(&sdlevent.key.keysym);

                // If Vanilla keyboard mapping enabled, the keyboard
                // scan code is used to give the character typed.
                // This does not change depending on keyboard layout.
                // If you have a German keyboard, pressing 'z' will
                // give 'y', for example.  It is desirable to be able
                // to fix this so that people with non-standard 
                // keyboard mappings can type properly.  If vanilla
                // mode is disabled, use the properly translated 
                // version.

                if (vanilla_keyboard_mapping)
                {
                    event.data2 = event.data1;
                }
                else
                {
                    event.data2 = sdlevent.key.keysym.unicode;
                }

                if (event.data1 != 0)
                {
                    D_PostEvent(&event);
                }
                break;

            case SDL_KEYUP:
                event.type = ev_keyup;
                event.data1 = TranslateKey(&sdlevent.key.keysym);

                if (event.data1 != 0)
                {
                    D_PostEvent(&event);
                }
                break;

                /*
            case SDL_MOUSEMOTION:
                event.type = ev_mouse;
                event.data1 = MouseButtonState();
                event.data2 = AccelerateMouse(sdlevent.motion.xrel);
                event.data3 = -AccelerateMouse(sdlevent.motion.yrel);
                D_PostEvent(&event);
                break;
                */

            case SDL_MOUSEBUTTONDOWN:
		if (usemouse && !nomouse)
		{
                    event.type = ev_mouse;
                    event.data1 = MouseButtonState();
                    event.data2 = event.data3 = 0;
                    D_PostEvent(&event);
		}
                break;

            case SDL_MOUSEBUTTONUP:
		if (usemouse && !nomouse)
		{
                    event.type = ev_mouse;
                    event.data1 = MouseButtonState();
                    event.data2 = event.data3 = 0;
                    D_PostEvent(&event);
		}
                break;

            case SDL_QUIT:
                // bring up the "quit doom?" prompt
                S_StartSound(NULL,sfx_swtchn);
                M_QuitDOOM(0);
                break;

            case SDL_ACTIVEEVENT:
                // need to update our focus state
                UpdateFocus();
                break;

            case SDL_VIDEOEXPOSE:
                palette_to_set = true;
                break;

            default:
                break;
        }
    }
}