Exemple #1
0
TEST( Input, KeyInput )
{
    Input newInput = {};
    Input oldInput = {};

    newInput.keys[KEY_SPACE] = true;

    EXPECT_TRUE( KeyDown( &newInput, KEY_SPACE ) );
    EXPECT_FALSE( KeyDown( &oldInput, KEY_SPACE ) );
    EXPECT_TRUE( KeyPressed( &newInput, &oldInput, KEY_SPACE ) );
    EXPECT_FALSE( KeyReleased( &newInput, &oldInput, KEY_SPACE ) );

    oldInput.keys[KEY_SPACE] = true;

    EXPECT_TRUE( KeyDown( &newInput, KEY_SPACE ) );
    EXPECT_TRUE( KeyDown( &oldInput, KEY_SPACE ) );
    EXPECT_FALSE( KeyPressed( &newInput, &oldInput, KEY_SPACE ) );
    EXPECT_FALSE( KeyReleased( &newInput, &oldInput, KEY_SPACE ) );

    newInput.keys[KEY_SPACE] = false;

    EXPECT_FALSE( KeyDown( &newInput, KEY_SPACE ) );
    EXPECT_TRUE( KeyDown( &oldInput, KEY_SPACE ) );
    EXPECT_FALSE( KeyPressed( &newInput, &oldInput, KEY_SPACE ) );
    EXPECT_TRUE( KeyReleased( &newInput, &oldInput, KEY_SPACE ) );

    newInput.keys[KEY_ENTER] = true;

    EXPECT_TRUE( KeyDown( &newInput, KEY_ENTER ) );
    EXPECT_FALSE( KeyDown( &oldInput, KEY_ENTER ) );
    EXPECT_TRUE( KeyPressed( &newInput, &oldInput, KEY_ENTER ) );
    EXPECT_FALSE( KeyReleased( &newInput, &oldInput, KEY_ENTER ) );
}
void Application::UpdateCamera(float dt)
{
    // don't make movement too sickening in VR
    static const float movementSpeed = VREnabled() ? 1.f : 8.f;

    if (KeyPressed(KEY_A))
        g_cameraDirector.GetActiveCamera()->Strafe(-movementSpeed * dt);

    if (KeyPressed(KEY_D))
        g_cameraDirector.GetActiveCamera()->Strafe(movementSpeed * dt);

    if (KeyPressed(KEY_W))
        g_cameraDirector.GetActiveCamera()->MoveForward(-movementSpeed * dt);

    if (KeyPressed(KEY_S))
        g_cameraDirector.GetActiveCamera()->MoveForward(movementSpeed * dt);

    // do the barrel roll!
    if (KeyPressed(KEY_Q))
        g_cameraDirector.GetActiveCamera()->rotateZ(2.f * dt);

    if (KeyPressed(KEY_E))
        g_cameraDirector.GetActiveCamera()->rotateZ(-2.f * dt);

    // move straight up/down
    if (KeyPressed(KEY_R))
        g_cameraDirector.GetActiveCamera()->MoveUpward(movementSpeed * dt);

    if (KeyPressed(KEY_F))
        g_cameraDirector.GetActiveCamera()->MoveUpward(-movementSpeed * dt);
}
Exemple #3
0
STATIC int _QuerySaveState(void)
{
     _UpdateInterfaceState();
     
     while (KeyPressed())
     {
        if (ReadKey() == STOPKEY)
        {
           UnLockMouse();
           DrawFunctionKey(1, "help");
           if (QueryUserStop())
           {
              StopDefragmentationProcess(); /* Just sets a variable in
                                               main\actions.c           */
              LockMouse(1, 1, 80, 25);
              DrawFunctionKey(3, "stop");
              return TRUE;
           }
           else
           {
              LockMouse(1, 1, 80, 25);
              DrawFunctionKey(3, "stop");
              return FALSE;
           }
        }
     }

     return FALSE;
}
Exemple #4
0
void CUICustomEdit::Update()
{
	if(m_bInputFocus)
	{	
		static u32 last_time; 

		u32 cur_time = Device.TimerAsync();

		if(m_iKeyPressAndHold)
		{
			if(m_bHoldWaitMode)
			{
				if(cur_time - last_time>HOLD_WAIT_TIME)
				{
					m_bHoldWaitMode = false;
					last_time = cur_time;
				}
			}
			else
			{
				if(cur_time - last_time>HOLD_REPEAT_TIME)
				{
					last_time = cur_time;
					KeyPressed(m_iKeyPressAndHold);
				}
			}
		}
		else
			last_time = cur_time;
	}

	m_lines.SetTextColor(m_textColor[IsEnabled()?0:1]);

	CUIWindow::Update();
}
static void
xf86ReleaseKeys(DeviceIntPtr pDev)
{
    KeyClassPtr keyc;
    int i, j, nevents, sigstate;

    if (!pDev || !pDev->key)
        return;

    keyc = pDev->key;

    /*
     * Hmm... here is the biggest hack of every time !
     * It may be possible that a switch-vt procedure has finished BEFORE
     * you released all keys neccessary to do this. That peculiar behavior
     * can fool the X-server pretty much, cause it assumes that some keys
     * were not released. TWM may stuck alsmost completly....
     * OK, what we are doing here is after returning from the vt-switch
     * exeplicitely unrelease all keyboard keys before the input-devices
     * are reenabled.
     */

    for (i = keyc->xkbInfo->desc->min_key_code;
         i < keyc->xkbInfo->desc->max_key_code;
         i++) {
        if (KeyPressed(i)) {
            sigstate = xf86BlockSIGIO ();
            nevents = GetKeyboardEvents(xf86Events, pDev, KeyRelease, i);
            for (j = 0; j < nevents; j++)
                mieqEnqueue(pDev, (InternalEvent*)(xf86Events + j)->event);
            xf86UnblockSIGIO(sigstate);
        }
    }
}
Exemple #6
0
LRESULT FileViewNotifyHandler( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, short win )
{
	LV_DISPINFO *pLvdi = (LV_DISPINFO *)lParam;
	NM_LISTVIEW *pNm = (NM_LISTVIEW *)lParam;
	int				itemSel = pNm->iItem;
	
	if (LOWORD(wParam) != IDC_FILEVIEW)
		return 0L;

	switch(pLvdi->hdr.code)	{
		case LVN_GETDISPINFO:
			itemSel = pLvdi->item.iItem;
			break;
		case NM_RCLICK:
			{
				POINT	pnt;
				GetCursorPos( &pnt );
				if (hMenu[win]) {
					TrackPopupMenu (GetSubMenu (hMenu[win], 0), 0, pnt.x, pnt.y, 0, hWnd, NULL);
				} 
			}
			break;
		case -155: // Dunno why this is -155, but it catches keys pressed, trying to catch messages like WM_KEYDOWN
			//OutDebugs( "Key: %d", pLvdi->item.cchTextMax );
			return KeyPressed( hWnd, pLvdi->item.cchTextMax, win );
		default:
			break;
	}
	return 0L;
}
Exemple #7
0
//-------------------------------------------------------------------
void AppWindow :: MessageLoop()
//-------------------------------------------------------------------
{
	for ( ; ; ) {
		XEvent event;
		XNextEvent (dpy, &event);

		switch (event.type) {
		case ConfigureNotify:
			canvas = RectAngle( 0, 0, event.xconfigure.width, event.xconfigure.height );
			break;
		case Expose:
			{
				XClearWindow(dpy, win);
				ExposeEvent evt( &event.xexpose );
				ExposeAll( &evt );
			}
			break;
		case KeyPress:
			{
				KeyEvent evt( &event.xkey );
				KeyPressed( &evt );
			}
			break;
	    }
      }
}
bool	KeyboardFilter::eventFilter (QObject *dist, QEvent *event) {
	if (event -> type () == QEvent::KeyPress) {
	   QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
	   emit KeyPressed (keyEvent -> key ());
	   return true;
	}
	return false;
}
 PyObject* LMF_KeyPressed (PyObject *self, PyObject *args){
	int iKeyCode;
	if (!PyArg_ParseTuple(args, "i", &iKeyCode)) {
		ParsePyTupleError( __func__, __LINE__ );
		return nullptr;
	}
	int iKeyUp = KeyPressed(iKeyCode);
	return Py_BuildValue("i", iKeyUp);
}
Exemple #10
0
/// Called by GLFW when a key event occurs
void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) {
    auto emu_window = GetEmuWindow(win);
    int keyboard_id = emu_window->keyboard_id;

    if (action == GLFW_PRESS) {
        emu_window->KeyPressed({key, keyboard_id});
    } else if (action == GLFW_RELEASE) {
        emu_window->KeyReleased({key, keyboard_id});
    }
}
Exemple #11
0
int AltKeyPressed (void)
{
    if (!AltKeyDown()) return 0;

    while (AltKeyDown())
          if (KeyPressed()) 
             return 0;

    return 1;
}
Exemple #12
0
bool List::HandleEventSelf(const SDL_Event& ev)
{
	switch (ev.type) {
		case SDL_MOUSEBUTTONDOWN: {
			if (gui->MouseOverElement(GetRoot(), ev.motion.x, ev.motion.y))
			{
				if(!hasFocus) {
					hasFocus = true;
					MouseMove(ev.motion.x, ev.motion.y, ev.motion.xrel, ev.motion.yrel, ev.motion.state);
				}
			}
			else {
				hasFocus = false;
			}
			if(MouseOver(ev.button.x, ev.button.y)) {
				if(hasFocus) {
					MousePress(ev.button.x, ev.button.y, ev.button.button);
					return true;
				}
			}
			break;
		}
		case SDL_MOUSEBUTTONUP: {
			if (!hasFocus)
				break;
			if (MouseOver(ev.button.x, ev.button.y) || activeScrollbar)
			{
				MouseRelease(ev.button.x, ev.button.y, ev.button.button);
				return true;
			}
			break;
		}
		case SDL_MOUSEMOTION: {
			if (!hasFocus)
				break;
			if (MouseOver(ev.button.x, ev.button.y) || activeScrollbar)
			{
				MouseMove(ev.motion.x, ev.motion.y, ev.motion.xrel, ev.motion.yrel, ev.motion.state);
				return true;
			}
			break;
		}
		case SDL_KEYDOWN: {
			if (!hasFocus)
				break;
			if(ev.key.keysym.sym == SDLK_ESCAPE)
			{
				hasFocus = false;
				break;
			}
			return KeyPressed(ev.key.keysym.sym, false);
		}
	}
	return false;
}
Exemple #13
0
// Function name	: CMain::Update
// Description	    : this function will be called every xx milliseconds
//					  update your variables through milliseconds
// Return type		: void 
// Argument         : DWORD milliseconds
void CMain::Update(DWORD milliseconds)
{	
	if (KeyPressed(VK_ESCAPE) == TRUE)						// Is ESC Being Pressed?
	{
		theApp.TerminateApplication ();						// Terminate The Program
	}

	if (KeyPressed(VK_F1) == TRUE)							// Is F1 Being Pressed?
	{		
		theApp.ToggleFullScreen ();							// Toggle Fullscreen Mode
	}

	if (KeyPressed(VK_SPACE ) == TRUE)							// Is F1 Being Pressed?
	{		
		theApp.ToggleFullScreen ();							// Toggle Fullscreen Mode
	}


	angle += (float)(milliseconds) / 5.0f;					// Update angle Based On The Clock
}
D3DXVECTOR3 FirstPersonPlayer::Input(float deltaTime)
{
	D3DXVECTOR3 moveDir = D3DXVECTOR3(0,0,0);
	int speed = 20;
	if(KeyPressed(DIK_LSHIFT))
	{
		speed = 40;
	}
	else
	{
		speed = 20;
	}
	
	if(KeyPressed(DIK_R) == 2)
	{
		checkCollision = true;
		isGrounded= false;
	}
	return moveDir;
}
Exemple #15
0
void Player::onKey()
{
    keyActions();
    emit KeyPressed();

    if (alive == true && (mf == true || mb == true || rl == true || rr == true || hl == true || hr == true || fr == true ||
                          fireReady == false || tankhrotate->state() == QMediaPlayer::PlayingState || out == true))
    {
        timer->start(keyDelay);
    }
}
	void Game::Update() {
		// Update the game Manager
		Manager.Update();

		if (KeyPressed('`')){
			bDebugOpen = !bDebugOpen;
		}

		if (bDebugOpen){
			GlobalContainer.Update();
		}
	}
Exemple #17
0
bool InputLayer::AnyPressed() const
{
	for (int32_t i = 0; i < InputLayer::KEYCOUNT; ++i)
	{
		if (KeyPressed(i))
		{
			return true;
		}
	}

	return false;
}
Exemple #18
0
// Function name	: CMain::Update
// Description	    : this function will be called every xx milliseconds
//					  update your variables through milliseconds
// Return type		: void 
// Argument         : DWORD milliseconds
void CMain::Update(DWORD milliseconds)
{	
	if (KeyPressed(VK_ESCAPE) == TRUE)						// Is ESC Being Pressed?
	{
		theApp.TerminateApplication ();						// Terminate The Program
	}

	if (KeyPressed(VK_F1) == TRUE)							// Is F1 Being Pressed?
	{		
		theApp.ToggleFullScreen ();							// Toggle Fullscreen Mode
	}

	if( KeyPressed( VK_UP ) == TRUE ) {
		yAngle += 1.0;
	}
	if( KeyPressed( VK_DOWN ) == TRUE ){
		yAngle -= 1.0;
	}
	if( KeyPressed( VK_LEFT ) == TRUE ) {
		xAngle += 1.0;
	}
	if( KeyPressed( VK_RIGHT ) == TRUE )  {
		xAngle -= 1.0;
	}
	//angle += (float)(milliseconds) / 5.0f;					// Update angle Based On The Clock
}
Exemple #19
0
void SugoiGame::PollEvents() {
	sr::Event event;
	while (m_window->PollEvent(event)) {
		switch (event.type) {

		case sr::Event::WINDOW_CLOSED:
			m_window->Close();
			break;

		case sr::Event::KEY_PRESSED:
			KeyPressed(event.key.keyCode, event.key.alt, event.key.control, event.key.shift, event.key.system);
			break;

		case sr::Event::KEY_RELEASED:
			KeyReleased(event.key.keyCode, event.key.alt, event.key.control, event.key.shift, event.key.system);
			break;

		case sr::Event::MOUSE_PRESSED:
			if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_1) {
				MouseLeftPressed();
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_2) {
				MouseRightPressed();
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_3) {
				MouseMiddlePressed();
			}
			break;

		case sr::Event::MOUSE_RELEASED:
			if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_1) {
				MouseLeftReleased(event.mouseClicked.x, event.mouseClicked.y);
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_2) {
				MouseRightReleased();
			}
			else if (event.mouseClicked.mouseCode == GLFW_MOUSE_BUTTON_3) {
				MouseMiddleReleased();
			}
			break;

		case sr::Event::MOUSE_MOVED:
			MouseMoved(event.mouseMoved.x, event.mouseMoved.y);
			break;

		case sr::Event::MOUSE_SCROLLED:
			MouseScroll(event.mouseScrolled.xoffset, event.mouseScrolled.yoffset);
			break;
		}
	}
}
Exemple #20
0
void InputContext::TriggerKeyEvent(KeyEvent &key)
{
    KeyEventSignalMap::iterator keySignal = registeredKeyEventSignals.find(key.keyCode);
    switch(key.eventType)
    {
    case KeyEvent::KeyPressed:
        // 1. First emit the generic KeyEventReceived signal that receives all event types for all key codes.
        emit KeyEventReceived(&key);
        // 2. Emit the event type -specific signal for all key codes.
        emit KeyPressed(&key);
        // 3. Emit the key code -specific signal for specific event.
        if (keySignal != registeredKeyEventSignals.end())
            keySignal->second->OnKeyPressed(key);
        break;
    case KeyEvent::KeyDown:
        if (!IsKeyDownImmediate(key.keyCode))
            break; // If we've received a keydown for a key we haven't gotten a corresponding press for before, ignore this event.

        emit KeyEventReceived(&key); // 1.
        emit KeyDown(&key); // 2.
//        if (keySignal != registeredKeyEventSignals.end())
 //           keySignal->second->OnKeyDown(key); // 3.
        break;
    case KeyEvent::KeyReleased:
        if (!IsKeyDownImmediate(key.keyCode))
            break; // If we've received a keydown for a key we haven't gotten a corresponding press for before, ignore this event.

        emit KeyEventReceived(&key); // 1.
        emit KeyReleased(&key); // 2.
        if (keySignal != registeredKeyEventSignals.end())
            keySignal->second->OnKeyReleased(key); // 3.
        break;
    default:
        assert(false);
        break;
    }

    // Update the buffered API.
    KeyPressInformation info;
    info.keyState = key.eventType;
    info.keyPressCount = key.keyPressCount;
//    info.firstPressTime = key.firstPressTime;
    newKeyEvents[key.keyCode] = info;

    // Now if this layer is registered to suppress this keypress from being processed further,
    // mark it handled.
    if (suppressedKeys.find(key.keyCode) != suppressedKeys.end())
        key.handled = true;
}
Exemple #21
0
void
ChronTextEdit::keyPressEvent ( QKeyEvent * event)
{
  int key (0);
  QTextEdit::keyPressEvent (event);
  if (listening && event) {
    key = event->key();
    if (firstKey) {
      emit KeyPressed (key);
      firstKey = false;
    }
    if (key == Qt::Key_Return || key == Qt::Key_Enter) {
      emit ReturnPressed ();
    }
  }
}
BOOL CConfigShortcuts::PreTranslateMessage(MSG* pMsg)
{
	if (GetFocus() == GetDlgItem(IDC_KEY)) {
		switch (pMsg->message) {
			case WM_KEYDOWN:
			case WM_SYSKEYDOWN:
				KeyPressed(pMsg->wParam);
				return TRUE;
			case WM_KEYUP:
			case WM_SYSKEYUP:
				KeyReleased(pMsg->wParam);
				return TRUE;
		}
	}

	return CPropertyPage::PreTranslateMessage(pMsg);
}
Exemple #23
0
int main(void)
{
	Init();

	usart_init_intr(9600);
	// Timer 0 konfigurieren
	TCCR0 = (1<<CS01); //Prescaler 8 | (1<<CS00); // Prescaler 64
	
	// Overflow Interrupt erlauben
	TIMSK |= (1<<TOIE0);
	
	// Global Interrupts aktivieren
	sei();

	
	
	
    while(1)
    {
//-----------------------------------------------------------------Einlesen
		readData(); 
//-----------------------------------------------------------------WASD Steuerung
		checkData(); 
//-----------------------------------------------------------------Regelung
		
		
		usart_putc('E');
		usart_puti(curr_error, 3);
		usart_puts("\r\n");
	
//-----------------------------------------------------------------Minimal/Maximalwerte
		setMotor(DirLeft, DirRight, IstSpeedLeft, IstSpeedRight);
		
		if (KeyPressed() != 0){
			usart_puts("Taster"); 			
		}
		
	
	}
	//------------------------------------------------------------------------------------------------Ende while
}
Exemple #24
0
void BaseApp::Run()
{
	CStopwatch timer;
	int sum = 0;
	int counter = 0;

	int deltaTime = 0;
	while (1)
	{
		timer.Start();
		if (kbhit())
		{
			KeyPressed (getch());
			if (!FlushConsoleInputBuffer(mConsoleIn))
				cout<<"FlushConsoleInputBuffer failed with error "<<GetLastError();
		}

		UpdateF((float)deltaTime / 1000.0f);
		Render();
		Sleep(1);

		while (1)
		{
			deltaTime = timer.Now();
			if (deltaTime > 20)
				break;
		}

		sum += deltaTime;
		counter++;
		if (sum >= 1000)
		{
			TCHAR  szbuff[255];
			StringCchPrintf(szbuff, 255, TEXT("FPS: %d"), counter);
			SetConsoleTitle(szbuff);

			counter = 0;
			sum = 0;
		}
	}
}
Exemple #25
0
void XWindow::HandleInput()
{
  XEvent event;
  KeySym key;
  char text[255];
  if (XCheckMaskEvent(m_pDisplay, ExposureMask | ButtonPressMask | KeyPressMask, &event)) {
    if (event.type == Expose && event.xexpose.count == 0) {
      Clear();
    }
    if (event.type == KeyPress && XLookupString(&event.xkey, text, sizeof(text), &key, 0) == 1) {
      std::cout << "KeyPressed: " << text[0] << std::endl;
      KeyPressed(text[0]);
    }
    if (event.type == ButtonPress) {
      int x = event.xbutton.x;
      int y = event.xbutton.y;
      std::cout << "ButtonPressed: " << x << " " << y << std::endl;
      ButtonPressed(x, y);
    }
  }
}
Exemple #26
0
bool CUICustomEdit::OnKeyboard(int dik, EUIMessages keyboard_action)
{	
	if(!m_bInputFocus) 
		return false;
	if(keyboard_action == WINDOW_KEY_PRESSED)	
	{
		m_iKeyPressAndHold = dik;
		m_bHoldWaitMode = true;

		if(KeyPressed(dik))	return true;
	}
	else if(keyboard_action == WINDOW_KEY_RELEASED)	
	{
		if(m_iKeyPressAndHold == dik)
		{
			m_iKeyPressAndHold = 0;
			m_bHoldWaitMode = false;
		}
		if(KeyReleased(dik)) return true;
	}
	return false;
}
//================================================================================
void ATHInputManager::SendKeyboardEvent()
{
	ATHKeyList m_liKeysDown = CheckKeys();

	ATHKeyList::iterator itrCurr = m_liKeysDown.begin();
	ATHKeyList::iterator itrEnd = m_liKeysDown.end();

	ATHEvent keyEvent( AET_KEYBOARD );
	unsigned int unKeyDownIndex = 0;
	unsigned int unKeyUpIndex = 0;
	while( itrCurr != itrEnd )
	{
		unsigned int szDIKKey = (*itrCurr);
		if (KeyPressed( szDIKKey ) && unKeyDownIndex < 8)
		{
			BYTE chAsciiKeys[ATH_NUM_KEYS] = {};
			if (GetKeyboardState(chAsciiKeys))  
			{
				unsigned short szAsciiKey = 0;
				// Why do I have to do both opposite conversions????
				int nCharCount = ToAsciiEx(MapVirtualKeyEx(szDIKKey, MAPVK_VSC_TO_VK, NULL), MapVirtualKeyEx(szDIKKey, MAPVK_VK_TO_VSC, NULL), chAsciiKeys, &szAsciiKey, 0, NULL);
				
				if (nCharCount > 0)
				{
					keyEvent.KEY_szKeysPressed[unKeyDownIndex] = (char)szAsciiKey;
					unKeyDownIndex++;
				}
			}
		}
	
		itrCurr++;
	}

	if( unKeyDownIndex > 0|| unKeyUpIndex > 0 )
	{
		keyEvent.m_EventID = AEI_KEYDOWN;
		m_pEventManager->SendEvent( keyEvent, AEP_IMMEDIATE );
	}
}
Exemple #28
0
static int OnKeyPressed(void *wnd, int key)
{
  GEM_WINDOW    *gwnd = (GEM_WINDOW *) wnd ;
  HEX_DUMP      *hex_dump = (HEX_DUMP *) gwnd->Extension ;
  long          old_xcursor, old_ycursor, old_ystart, offset ;
  int           htline, code = GW_EVTCONTINUEROUTING ;
  unsigned char new_val, input_valid = 0, plus = 0 ;

  old_xcursor = hex_dump->xcursor ;
  old_ycursor = hex_dump->ycursor ;
  old_ystart  = hex_dump->ystart ;
  ShowCursor( gwnd, 0 ) ;
  switch( key )
  {
	case FERMER      : gwnd->OnClose( gwnd ) ;
                       code = GW_EVTSTOPROUTING ;
				  	   break ;

	case SAUVE       : SaveFile( gwnd, 0 ) ;
                       code = GW_EVTSTOPROUTING ;
					   break ;

	case SAUVES      : SaveFile( gwnd, 1 ) ;
                       code = GW_EVTSTOPROUTING ;
  					   break ;

    case CURSOR_RT :   hex_dump->xcursor++ ;
                       if ( hex_dump->xcursor >= hex_dump->sizeof_raw_offset_array ) hex_dump->xcursor = hex_dump->sizeof_raw_offset_array - 1 ;
                       plus = 1 ;
                       code = GW_EVTSTOPROUTING ;
                       break ;

    case CURSOR_SLT :  hex_dump->xcursor = SearchNextBlock( hex_dump, hex_dump->xcursor, -1L ) ;
                       code = GW_EVTSTOPROUTING ;
                       break ;

    case CURSOR_LT :   hex_dump->xcursor-- ;
                       if ( hex_dump->xcursor < 0 ) hex_dump->xcursor = 0 ;
                       code = GW_EVTSTOPROUTING ;
                       break ;

    case CURSOR_SRT :  hex_dump->xcursor = SearchNextBlock( hex_dump, hex_dump->xcursor, 1L ) ;
                       code = GW_EVTSTOPROUTING ;
                       break ;

    case CURSOR_UP :   hex_dump->ycursor-- ;
                       if ( hex_dump->ycursor < 0 ) hex_dump->ycursor = 0 ;
                       code = GW_EVTSTOPROUTING ;
                       break ;

    case CURSOR_SUP :  hex_dump->ystart  -= hex_dump->nb_lines_on_window ;
                       hex_dump->ycursor -= hex_dump->nb_lines_on_window ;
                       code = GW_EVTSTOPROUTING ;
                       break ; 

    case CURSOR_DN :   hex_dump->ycursor++ ;
                       if ( hex_dump->ycursor > hex_dump->total_nb_lines ) hex_dump->ycursor = hex_dump->total_nb_lines ;
                       code = GW_EVTSTOPROUTING ;
                       break ;

    case CURSOR_SDN :  hex_dump->ystart  += hex_dump->nb_lines_on_window ;
                       hex_dump->ycursor += hex_dump->nb_lines_on_window ;
                       code = GW_EVTSTOPROUTING ;
                       break ; 

    default         :  offset = GetOffset( hex_dump, GetRawOffsetForXCursor( hex_dump, hex_dump->xcursor ), hex_dump->ycursor ) ;
                       key   &= 0xFF ;
                       input_valid = KeyPressed( hex_dump, offset, key, &new_val ) ;
                       if ( input_valid )
                       {
                         int xy[4] ;

                         hex_dump->raw_data[offset] = new_val ;
                         FormatLine( hex_dump, hex_dump->ycursor ) ;
                         hex_dump->xcursor++ ;
                         if ( hex_dump->xcursor >= hex_dump->sizeof_raw_offset_array ) hex_dump->xcursor = hex_dump->sizeof_raw_offset_array - 1 ;
                         htline = hex_dump->h_char + hex_dump->interline ;
                         GWGetWorkXYWH( gwnd, &xy[0], &xy[1], &xy[2], &xy[3] ) ;
                         xy[1] += (int)( hex_dump->ycursor - hex_dump->ystart ) * htline ;
                         xy[3]  = htline ;
                         v_hide_c( handle ) ;
                         OnDraw( gwnd, xy ) ;
                         v_show_c( handle, 1 ) ;
                         plus = 1 ;
                         SetModif( gwnd, 1 ) ;
                         code = GW_EVTSTOPROUTING ;
                       }
                       break ;
  }

  CheckYCursorValid( hex_dump ) ;
  CheckXCursorValid( hex_dump, plus ) ;
  CheckValid( hex_dump ) ;

  if ( ( old_xcursor != hex_dump->xcursor ) || ( old_ycursor != hex_dump->ycursor ) ) SmartInfos( gwnd ) ;
  if ( old_ystart != hex_dump->ystart ) SmartRePaint( gwnd, old_ystart ) ;

  return( code ) ;
}
Exemple #29
0
void CEffectsGame::DoPicking()
{
	bool hit = false;
	Vector3 tileHitPos;
	SMapTile *tileHit;
	Vector3 start = pCamera->GetWorldPosition();
	Vector3 end = start + pCamera->forward * 1000.0f;
	Vector3 pos;

	pLevel->UnHighlightTile();

	// find tile we are pointing at
	if (hit = pLevel->CastRay(start, end, OUT tileHitPos, OUT &tileHit, OUT &pos))
	{
		pLevel->HighlightTile(tileHitPos.x, tileHitPos.y, tileHitPos.z);		
	}

	static float force = 10;
	if (gInput.WasKeyPressed(K_PGUP)) force += 5.0f;
	if (gInput.WasKeyPressed(K_PGDN)) force -= 5.0f;
	//gVGUI.AddTextMessage(300,200,WHITE,"Force: %f",force);

	//car->pBarrel->DrawAxis();

	// shooting - delete tile
	if (gInput.IsKeydown(K_MOUSE1))
	{
		static float delay = 0;
		delay += frametime;
		if (delay > 0.05f)
		{
			
			// shoot a bullet
			CreateBullet(car->pBarrel->GetWorldPosition(), car->pBarrel->up);

			float puffSpeed = 0.35;

			// add puff effect
			for (int i = 0; i<3; i++)
			{					
				static CTexture *puffTex = new CTexture("particles/explosion4.dds");
				CParticle *p = new CParticle(puffTex);
				p->size = Vector2(0.15, 0.15);
				p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2;
				p->velocity = Vector3( frand(-puffSpeed,puffSpeed), frand(-puffSpeed,puffSpeed)+1, frand(-puffSpeed,puffSpeed) );
				//p->gravity = -10;
				p->lifetime = 0.25;
				p->color = SRGBA(255,255,255,50);
				p->sizeVel = Vector2(1,1);
				p->colorChange = SRGBA(255,255,255,0);
				particles->Add(p);
			}

			// add muzzle flash
			static CTexture *muzzleTex[] = {
				new CTexture("particles/flame1.dds"),
				new CTexture("particles/explosion1.dds")				
			};
		
			{
				CParticle *p = new CParticle(muzzleTex[rand()%2]);
				p->size = Vector2(0.7, 0.7);
				p->position = car->pBarrel->GetWorldPosition() + car->pBarrel->up/2;								
				p->lifetime = 0.01;
				p->additive = true;
				//p->color = SRGBA(255,255,255,50);
				//p->sizeVel = Vector2(1,1);
				//p->colorChange = SRGBA(255,255,255,0);
				particles->Add(p);
			}

			
			delay = 0;

			// if hit a tile, destroy it
	/*		if (hit)
			{
				EnterCriticalSection(&renderCS);
				tileHit->type = 0;
				LeaveCriticalSection(&renderCS);

				SMapChunk *chunk = pLevel->GetChunk(
					floor(tileHitPos.x/SMapChunk::Size),
					floor(tileHitPos.y/SMapChunk::Size),
					floor(tileHitPos.z/SMapChunk::Size) );

				chunk->dirtyBody = true;
				chunk->dirty = true;

				//pLevel->UpdateTile(tileHitPos.x, tileHitPos.y, tileHitPos.z);

				SSpawnTile s;
				s.pos = tileHitPos;
				s.vel = pCamera->forward * force;
				boxesToSpawn.push(s);
			
				// create a physical entity in this place
				/*NewtonBody *box = AddBox(pScene, pWorld, tileHitPos+Vector3(0.5, 0.5, 0.5), Vector3(0.95f,0.95f,0.95f), Vector3(), 100);

				// add some velocity
				Vector3 vel = pCamera->forward * force;
				Vector3 pos;
				NewtonBodySetVelocity(box, &vel[0]);*/				
		//	}
		}
	}

	static float lastRocketFire = -100;

	if (gInput.WasKeyPressed(K_MOUSE2) )
	{
		float r = 3;
		int x = tileHitPos.x;
		int y = tileHitPos.y;
		int z = tileHitPos.z;

		if (lastRocketFire + 0 < realtime)
		{
			Debug("Create rocket!");
			lastRocketFire = realtime;

			if (!hit)
			{
				CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, car->pBarrel->up);
			}
			else
			{
				Vector3 dir = (p os-(car->pBarrel->GetWorldPosition() + Vector3(0,10,0))).Normalize();
				if (dir.y < -0.25) 
				{
					dir.y = -0.25;
					dir.Normalize();
				}
				CreateRocket(car->pBarrel->GetWorldPosition() + car->pBarrel->up/2, dir );
			}
			
		}
	
	}


	// show car meshes
	if (car)
	{
		CArray<CObject3D*> meshes;
		GetMeshesList(car, meshes);

		float minT = 99999.0f;

		static int current = 0;
		if (KeyPressed(']')) { meshes[current]->color = WHITE; current++; if (current == meshes.Size()) current = 0; meshes[current]->color = RED;  }
		if (KeyPressed('[')) { meshes[current]->color = WHITE; current--; if (current < 0) current = meshes.Size()-1; meshes[current]->color = RED; }
		//gVGUI.AddTextMessage(200,90,YELLOW,"%d",current);

		car->aimTarget = end;
	}
}
Exemple #30
0
void cDialog :: Get_Focus( void )
{
	bool focus = 1;
	string text_old = text;

	int minwidth_old = min_width;

	pDialogManager->Update();
	
	boxRGBA( screen, 0, 0, screen->w, screen->h , 0, 0, 0, 32 );

	SDL_EnableUNICODE( 1 );
	SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, 50 );

	while( focus )
	{
		Update();

		if( rect.w < min_width ) 
		{
			rect.w = min_width;
		}
		else if( rect.w > min_width ) 
		{
			min_width = rect.w;
		}	

		SDL_Flip( screen );

		while( SDL_PollEvent( &event ) )
		{
			keys = SDL_GetKeyState( NULL );

			if( KeyPressed( KEY_ESC) && event.key.keysym.sym != SDLK_BACKSPACE )
			{
				text = text_old;

				focus = 0;
			}
			else if ( KeyPressed( KEY_ENTER ) )
			{
				focus = 0;
			}
			else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_BACKSPACE )
			{
				if( text.length() && type != DIALOG_ONLY_NUMBERS )
				{
					text.erase( text.length() - 1, 1 );
					
					Update_Text();
				}
			}
			else if( event.type == SDL_KEYDOWN && event.key.keysym.sym != SDLK_ESCAPE )
			{
				if( type != DIALOG_ONLY_NUMBERS ) 
				{
					if( event.key.keysym.unicode && text.length() < max_length )
					{
						if( type == DIALOG_ONLY_LETTERS )
						{
							string s;
							s.insert( (string::size_type)0, (string::size_type)1, (char)event.key.keysym.unicode );

							if( !is_valid_number( s ) )
							{
								text.insert( text.length(), s );
							}
						}
						else
						{
							text.insert( text.length(), 1, (char)event.key.keysym.unicode );
						}

						Update_Text();
					}
				}
				else
				{
					 if( KeyPressed( KEY_UP ) )
					 {
						text_number += 1;
					 }
					 else if( KeyPressed( KEY_DOWN ) )
					 {
						text_number -= 1;
					 }
					 else if( KeyPressed( KEY_LEFT ) )
					 {
						text_number -= 10;
					 }
					 else if( KeyPressed( KEY_RIGHT ) )
					 {
						text_number += 10;
					 }
					 else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_PLUS )
					 {
						text_number += 1;
					 }
					 else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_MINUS )
					 {
						text_number -= 1;
					 }
					 else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_PAGEUP )
					 {
						text_number += 10;
					 }
					 else if( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_PAGEDOWN )
					 {
						text_number -= 10;
					 }

					 if( text_number > max_length )
					 {
						text_number = max_length;
					 }
					 else if( text_number < 0 )
					 {
						text_number = 0;
					 }

					 Update_Text();
				}
			}
		}
		
		Framerate.Update();
	}

	SDL_EnableUNICODE( 0 );
	SDL_EnableKeyRepeat( 0, 0 );

	if( text.compare( text_old ) != 0 ) 
	{
		changed = 1;
	}

	min_width = minwidth_old;
	
	Update_Text();

	Framerate.Reset();
}