// *** AdvanceMenus
void UserInput::AdvanceMenus()
{
//	if ( g_keyDeltas[KEY_F1] )
//		DebugKeyBindings::DebugMenu();

	InputManager *im = g_inputManager;
	int mouseX = g_target->X();
	int mouseY = g_target->Y();
	bool lmb = im->controlEvent( ControlEclipseLMousePressed );
	bool rmb = im->controlEvent( ControlEclipseRMousePressed );

    EclUpdateMouse( mouseX, mouseY, lmb, rmb );
    EclUpdate();

	if ( im->controlEvent( ControlEclipseLMouseDown ) )
	{
		EclWindow *winUnderMouse = EclGetWindow( mouseX, mouseY );
		if (winUnderMouse)
		{
			im->suppressEvent( ControlEclipseLMouseDown );
		}
	}
}
Пример #2
0
// Returns 0 if the event is handled here, -1 otherwise
int InputManagerSDL::EventHandler(unsigned int message, long long wParam, int lParam, bool _isAReplayedEvent)
{
	SDL_Event *sdlEvent = (SDL_Event*)wParam;

	switch (message)
	{
		case SDL_MOUSEBUTTONUP:
		{
			if (sdlEvent->button.button == SDL_BUTTON_LEFT)	
			{
				m_lmb = false;
				m_emulatedRmb = false;
			}
			else if (sdlEvent->button.button == SDL_BUTTON_MIDDLE)	
				m_mmb = false;
			else if (sdlEvent->button.button == SDL_BUTTON_RIGHT)
				m_rawRmb = false;
				
			m_rmb = m_shouldEmulateRmb ? (m_rawRmb || m_emulatedRmb) : m_rawRmb;
			break;
		}

		case SDL_MOUSEBUTTONDOWN:
		{
			if (sdlEvent->button.button == SDL_BUTTON_LEFT)
			{
				if (g_keys[KEY_CONTROL])
					m_emulatedRmb = true;
				else
					m_lmb = true;
			}
			else if (sdlEvent->button.button == SDL_BUTTON_MIDDLE)	
				m_mmb = true;
			else if (sdlEvent->button.button == SDL_BUTTON_RIGHT)	
				m_rawRmb = true;
			else if (sdlEvent->button.button == SDL_BUTTON_WHEELUP) 
				m_mouseZ += 3;
			else if (sdlEvent->button.button == SDL_BUTTON_WHEELDOWN) 
				m_mouseZ -= 3;
				
			m_rmb = m_shouldEmulateRmb ? (m_rawRmb || m_emulatedRmb) : m_rawRmb;
			break;
		}

		case SDL_MOUSEMOTION:
		{		
			if (g_windowManager->Captured()) {

				int xrel = sdlEvent->motion.xrel;
				int yrel = sdlEvent->motion.yrel;

// Temporarily disabled until I find where m_renderer is in Defcon. -- Steven
#if defined TARGET_OS_LINUX && 0
				if (m_xineramaOffsetHack) 
					AdjustForBuggyXinerama(xrel, yrel);
#endif // TARGET_OS_LINUX

				m_mouseX += xrel;
				m_mouseY += yrel;

#ifdef VERBOSE_DEBUG				
				AppDebugOut("Mouse captured (%d,%d) - Rel (%d, %d) - Adjusted (%d, %d)\n", 
					        sdlEvent->motion.x, sdlEvent->motion.y,
					        sdlEvent->motion.xrel, sdlEvent->motion.yrel,
					        xrel, yrel);
#endif // VERBOSE_DEBUG
					   
				BoundMouseXY(m_mouseX, m_mouseY);
			}
			else {
#ifdef VERBOSE_DEBUG				
				AppDebugOut("Mouse uncaptured (%d,%d) - Rel (%d, %d)\n", 
					        sdlEvent->motion.x, sdlEvent->motion.y,
					        sdlEvent->motion.xrel, sdlEvent->motion.yrel);
#endif // VERBOSE_DEBUG
				m_mouseX = sdlEvent->motion.x;
				m_mouseY = sdlEvent->motion.y;
			}
			break;
		}

		case SDL_KEYUP:
		{
			int keyCode = ConvertSDLKeyIdToWin32KeyId(sdlEvent->key.keysym.sym);
			AppDebugAssert(keyCode >= 0 && keyCode < KEY_MAX);
			if (g_keys[keyCode] != 0)
			{
				m_numKeysPressed--;
				g_keys[keyCode] = 0;
			}
			
			break;
		}

		case SDL_KEYDOWN:
		{
			int keyCode = ConvertSDLKeyIdToWin32KeyId(sdlEvent->key.keysym.sym);
			AppDebugAssert(keyCode >= 0 && keyCode < KEY_MAX);
			if (g_keys[keyCode] != 1)
			{
				m_keyNewDeltas[keyCode] = 1;
				m_numKeysPressed++;
				g_keys[keyCode] = 1;
				g_keyDownTime[keyCode] = GetHighResTime();
			}
			
			EclUpdateKeyboard( keyCode, false, false, false, sdlEvent->key.keysym.unicode );

			break;
		}
		
		case SDL_ACTIVEEVENT:
		{
			if (sdlEvent->active.state & SDL_APPINPUTFOCUS)
				m_windowHasFocus = sdlEvent->active.gain;
		}
		break;
		
		case SDL_QUIT:
			m_quitRequested = true;
			break;
					
		default:
			return -1;
	}
	
	// Run this for every event we get, to handle the case of multiple mouse events in a
	// single update cycle.
	EclUpdateMouse( g_inputManager->m_mouseX, 
					g_inputManager->m_mouseY, 
					g_inputManager->m_lmb, 
					g_inputManager->m_rmb );
	
	return 0;
}
Пример #3
0
// Returns 0 if the event is handled here, -1 otherwise
int InputManagerWin32::EventHandler(unsigned int message, long long wParam, int lParam, bool _isAReplayedEvent)
{
	bool logEvent = false;

	switch (message) 
	{
		case WM_SIZING:
		case WM_WINDOWPOSCHANGING:
		case WM_WINDOWPOSCHANGED:
		case WM_DESTROY:
		case WM_CREATE:
		case WM_COMMAND:
		case WM_SETCURSOR:		// Cursor move
		case WM_NCHITTEST:		// Mouse move or button
        case WM_CLOSE:
			return -1;
	
		case WM_CANCELMODE:
			return 0;

		case WM_SETFOCUS:
			m_windowHasFocus = true;
			if( m_altTabBound ) BindAltTab();
			return 0;

		case WM_KILLFOCUS:
			m_windowHasFocus = false;
			UnbindAltTab();
			return 0;

        case WM_LBUTTONDOWN:
			m_lmb = true;
			g_windowManager->CaptureMouse();
			logEvent = true;
			break;
		case WM_LBUTTONUP:
			m_lmb = false;
			g_windowManager->UncaptureMouse();
			logEvent = true;
			break;
		case WM_MBUTTONDOWN:
			m_mmb = true;
			g_windowManager->CaptureMouse();
			logEvent = true;
			break;
		case WM_MBUTTONUP:
			m_mmb = false;
			g_windowManager->UncaptureMouse();
			logEvent = true;
			break;
		case WM_RBUTTONDOWN:
			m_rmb = true;
			g_windowManager->CaptureMouse();
			logEvent = true;
			break;
		case WM_RBUTTONUP:
			m_rmb = false;
			g_windowManager->UncaptureMouse();
			logEvent = true;
			break;

		case 0x020A:
//		case WM_MOUSEWHEEL:
		{
			int move = (short)HIWORD(wParam) / 120;
			m_mouseZ += move;
			logEvent = true;
			break;
		}
        
		case WM_MOUSEMOVE:
		{
			short newPosX = lParam & 0xFFFF;
			short newPosY = short(lParam >> 16);
			m_mouseX = newPosX;
			m_mouseY = newPosY;
			logEvent = true;
			break;
		}

		case WM_HOTKEY:
			if (wParam == 0)
			{
				g_keys[KEY_TAB] = 1;
				m_keyNewDeltas[KEY_TAB] = 1;
			}
			break;
			
		case WM_SYSKEYUP:
			if (wParam == KEY_ALT)
			{
				// ALT pressed
				g_keys[wParam] = 0;
			}
			else
			{
				g_keys[wParam] = 0;
			}
			logEvent = true;
			break;
			
		case WM_SYSKEYDOWN:
		{
			int flags = (short)HIWORD(lParam);
			if (wParam == KEY_ALT)
			{
				g_keys[wParam] = 1;
			}
			else if (flags & KF_ALTDOWN)
			{
				m_keyNewDeltas[wParam] = 1;
				g_keys[wParam] = 1;
				if (wParam == KEY_F4)
				{
					exit(0);
				}
			}
			logEvent = true;
			break;
		}

		case WM_KEYUP:
		{
			AppAssert(wParam >= 0 && wParam < KEY_MAX);
			if (g_keys[wParam] != 0)
			{
//				m_keyNewDeltas[wParam] = -1;
				g_keys[wParam] = 0;
			}
			logEvent = true;
			break;
		}

		case WM_KEYDOWN:
		{
			AppAssert(wParam >= 0 && wParam < KEY_MAX);

			if (g_keys[wParam] != 1)
			{
				m_keyNewDeltas[wParam] = 1;
				g_keys[wParam] = 1;
			}

			//unsigned char keys[256];
			//memset( keys, 0, 256*sizeof(unsigned char) );
			//for( int i = 0; i < 256; ++i )
			//	if( g_keys[i] ) keys[i] = 0xff;
			//
			//unsigned short ascii = 0;
			//unsigned int scanCode = ( lParam & 0xff0000 ) >> 16;
			//int retToAscii = ToAscii( wParam, scanCode, keys, &ascii, 0 );
			//if( retToAscii > 0 )
			//{
			//	EclUpdateKeyboard( wParam, false, false, false, ascii & 0xff );
			//}

			logEvent = true;
			break;
		}

		case WM_CHAR:
		{
			EclUpdateKeyboard( wParam, false, false, false, wParam );
			logEvent = true;
			break;
		}

		default:
			return -1;		
	}
	
	// Run this for every event we get, to handle the case of multiple mouse events in a
	// single update cycle.
	EclUpdateMouse( g_inputManager->m_mouseX, 
					g_inputManager->m_mouseY, 
					g_inputManager->m_lmb, 
					g_inputManager->m_rmb );

	return 0;
}