Пример #1
0
void Keyboard::Update(void)
{
	Device::Update();

	//poll
	HRESULT hr = m_pDevice->GetDeviceState(N_KEYS*sizeof(unsigned char), (void*) currentState());
	
	switch(hr){
		case DI_OK:
			break; //everything is fine
		case DIERR_INPUTLOST:  
		case DIERR_NOTACQUIRED:
			m_pDevice->Acquire(); //get the device back 
			return;
		case E_PENDING: //not ready yet, maybe next frame
			return;
		default:
			assert(hr != DIERR_NOTINITIALIZED);
			assert(hr != DIERR_INVALIDPARAM);
	}

	/* emit events */
	for (unsigned int i=0; i<N_KEYS; i++)
	{
		if (Up(currentState(), i) && Down(oldState(), i))
			EVENT(KeyReleasedEvent(i));
		else if (Down(currentState(), i) && Up(oldState(), i))
			EVENT(KeyPressedEvent(i));
	}

	flipBuffers();
}
Пример #2
0
void CViewTester::NextState()
	{
	TState oldState(iState);

	iState = static_cast<TState>( static_cast<TInt>(iState) + 1 );

	// moving from an event with timeout?
	if(oldState == EWait_RemoteView || oldState == EWait_FilteredView || oldState == EWait_SortViewEvents)
		{
		// Cancel view wait timer, causes RunL to run
		iTimer.Cancel();
		}
	}
Пример #3
0
bool MultiContainerWidget::updateSelection(bool parentSelected)
{
    bool changed = false;
    bool isSel = _isSelected;
    QVector<bool> oldState(_children.count());
    QVector<bool> newState(_children.count());

    for (int i = 0; i< (int)_children.count(); i++) {
        oldState[i] = _children.at(i)->isSelected();
    }

    RegExpWidget::updateSelection( parentSelected );

    int first;
    int last;

    // scan for the first selected item.
    for (first = 1; first < (int) _children.count(); first+= 2 ) {
        RegExpWidget* child = _children.at(first);
        changed = child->updateSelection( _isSelected ) || changed;
        newState[first] = child->isSelected();
        if ( child->isSelected() ) {
            break;
        }
    }

    // scan for the last selected item
    for (last = _children.count()-2; last>first; last -= 2) {
        RegExpWidget* child = _children.at(last);
        changed = child->updateSelection( _isSelected ) || changed;
        newState[last] = child->isSelected();
        if ( child->isSelected() ) {
            break;
        }
    }

    // everything between first and last must be selected.
    for (int j = first+2; j<last; j+=2) {
        RegExpWidget* child = _children.at(j);

        changed = child->updateSelection( true ) || changed;
        newState[j] = true;
    }

    // update drag accepters.
    for (int k = 0; k< (int) _children.count(); k+=2) {
        RegExpWidget* child = _children.at(k);
        bool select;
        if ( k == 0 || k == (int)_children.count()-1) {
            // The elements at the border is only selected if the parent is selected.
            select = _isSelected;
        } else {
            // Drag accepters in the middle is selected if the elements at both
            // sides are selected.
            select = newState[k-1] && newState[k+1];
        }

        bool isChildSel = child->isSelected();
        DragAccepter *accepter = dynamic_cast<DragAccepter*>(child);
        if (accepter) {
            accepter->_isSelected = select;
        }

        if ( select != isChildSel ) {
            child->repaint();
        }
    }

    changed = changed || isSel != _isSelected;
    if ( changed ) {
        repaint();
    }

    return changed;
}
Пример #4
0
bool Keyboard::isKeyDown(int key)
{
	//old states, because buffers have been swapped already
	return Down(oldState(), key);
}
Пример #5
0
void IN_UpdateGamepad(int port)
{
	// Lookup table to convert the digital buttons to fakeAscii_t, in mask order
	const fakeAscii_t digitalXlat[IN_NUM_DIGITAL_BUTTONS] = {
		A_JOY5, // DPAD_UP
		A_JOY7, // DPAD_DOWN
		A_JOY8, // DPAD_LEFT
		A_JOY6, // DPAD_LEFT
		A_JOY4, // Start
		A_JOY1, // Back
		A_JOY2, // Left stick
		A_JOY3  // Right stick
	};

	// Lookup table to convet the analog buttons to fakeAscii_t, in DX order
	const fakeAscii_t analogXlat[IN_NUM_ANALOG_BUTTONS] = {
		A_JOY15, // A
		A_JOY14, // B
		A_JOY16, // X
		A_JOY13, // Y
		A_JOY10, // Black
		A_JOY9,  // White
		A_JOY11, // Left trigger
		A_JOY12  // Right trigger
	};

	// Get new state
	XINPUT_STATE newState;
	XInputGetState( in_state->controllers[port].handle, &newState );

	// Get old state
	XINPUT_STATE &oldState(in_state->controllers[port].state);

	int buttonIdx;
	bool oldPressed, newPressed;

	// Check all digital buttons first
	for (buttonIdx = 0; buttonIdx < IN_NUM_DIGITAL_BUTTONS; ++buttonIdx)
	{
		oldPressed = oldState.Gamepad.wButtons & (1 << buttonIdx);
		newPressed = newState.Gamepad.wButtons & (1 << buttonIdx);

		if (oldPressed != newPressed)
			IN_CommonJoyPress(port, digitalXlat[buttonIdx], newPressed);
	}

	// Now check all analog buttons
	for (buttonIdx = 0; buttonIdx < IN_NUM_ANALOG_BUTTONS; ++buttonIdx)
	{
		oldPressed = oldState.Gamepad.bAnalogButtons[buttonIdx] > IN_ANALOG_BUTTON_THRESHOLD;
		newPressed = newState.Gamepad.bAnalogButtons[buttonIdx] > IN_ANALOG_BUTTON_THRESHOLD;

		if (oldPressed != newPressed)
			IN_CommonJoyPress(port, analogXlat[buttonIdx], newPressed);
	}

	// Update joysticks
	_padInfo.joyInfo[0].x = _joyAxisConvert(newState.Gamepad.sThumbLX);
	_padInfo.joyInfo[0].y = _joyAxisConvert(newState.Gamepad.sThumbLY);
	_padInfo.joyInfo[1].x = _joyAxisConvert(newState.Gamepad.sThumbRX);
	_padInfo.joyInfo[1].y = _joyAxisConvert(newState.Gamepad.sThumbRY);
	_padInfo.joyInfo[0].valid = _padInfo.joyInfo[1].valid = true;
	_padInfo.padId = port;

	// Copy state back
	oldState = newState;

	// Update game
	IN_CommonUpdate();
}