コード例 #1
0
ファイル: ButtonMonitor.cpp プロジェクト: ikawaljeet/ardurct
/**
 * Returns true if the button has been released
 * once this function has been called, it will return false
 */
bool NIButtonMonitor::isReleased(uint8_t buttonId) {
	uint8_t i = getButtonIndex(buttonId);
	if (i == 0xFF) return false;
	if (_button[i].state != BUTTON_MONITOR_STATE_NOT_READ) return false;
	_button[i].state = BUTTON_MONITOR_NOT_PRESSED;
	return true;
}
コード例 #2
0
ファイル: ButtonMonitor.cpp プロジェクト: ikawaljeet/ardurct
/**
 * Returns true if the button has been depressed
 * once this function has been called, it will return false
 */
bool NIButtonMonitor::isDepressed(uint8_t buttonId) {
	uint8_t i = getButtonIndex(buttonId);
	if (i == 0xFF) return false;
	if (_button[i].state <= BUTTON_MONITOR_STATE_NOT_READ) return false;
	_button[i].state &= ~BUTTON_MONITOR_STATE_NOT_READ;
	return true;
}
コード例 #3
0
bool InputDeviceAdapterMouse::keyReleased(int keyCode)
{
    bool stateChanged=false;

    if(!keyboardMode)
    {
        /* Check if the key is a button key: */
        int buttonIndex=getButtonIndex(keyCode);
        if(buttonIndex>=0)
        {
            /* Set button state: */
            int stateIndex=(numButtons+numButtonKeys)*modifierKeyMask+numButtons+buttonIndex;
            stateChanged=changeButtonState(stateIndex,false);
        }

        /* Check if the key is a modifier key: */
        int modifierIndex=getModifierIndex(keyCode);
        if(modifierIndex>=0)
        {
            /* Change current modifier mask: */
            changeModifierKeyMask(modifierKeyMask&~(0x1<<modifierIndex));
            stateChanged=true;
        }

        // requestUpdate();
    }

    return stateChanged;
}
コード例 #4
0
void InputDeviceAdapterMouse::resetKeys(const XKeymapEvent& event)
{
    /* Calculate the new modifier key mask: */
    int newModifierKeyMask=0x0;
    for(int i=0; i<256; ++i)
        if(event.key_vector[i>>3]&(0x1<<(i&0x7)))
        {
            /* Convert the keycode to a keysym: */
            XKeyEvent keyEvent;
            keyEvent.type=KeyPress;
            keyEvent.serial=event.serial;
            keyEvent.send_event=event.send_event;
            keyEvent.display=event.display;
            keyEvent.window=event.window;
            keyEvent.state=0x0;
            keyEvent.keycode=i;
            KeySym keyCode=XLookupKeysym(&keyEvent,0);

            int modifierIndex=getModifierIndex(keyCode);
            if(modifierIndex>=0)
                newModifierKeyMask|=0x1<<modifierIndex;
        }

    /* Set the new modifier key mask: */
    changeModifierKeyMask(newModifierKeyMask);

    /* Set the states of all button keys: */
    for(int i=0; i<numButtonKeys; ++i)
    {
        int stateIndex=(numButtons+numButtonKeys)*modifierKeyMask+numButtons+i;
        changeButtonState(stateIndex,false);
    }
    for(int i=0; i<256; ++i)
        if(event.key_vector[i>>3]&(0x1<<(i&0x7)))
        {
            /* Convert the keycode to a keysym: */
            XKeyEvent keyEvent;
            keyEvent.type=KeyPress;
            keyEvent.serial=event.serial;
            keyEvent.send_event=event.send_event;
            keyEvent.display=event.display;
            keyEvent.window=event.window;
            keyEvent.state=0x0;
            keyEvent.keycode=i;
            KeySym keyCode=XLookupKeysym(&keyEvent,0);

            int buttonIndex=getButtonIndex(keyCode);
            if(buttonIndex>=0)
            {
                int stateIndex=(numButtons+numButtonKeys)*modifierKeyMask+numButtons+buttonIndex;
                changeButtonState(stateIndex,true);
            }
        }

    // requestUpdate();
}
コード例 #5
0
ファイル: ButtonMonitor.cpp プロジェクト: ikawaljeet/ardurct
void NIButtonMonitor::remove(uint8_t buttonId) {
	uint8_t i = getButtonIndex(buttonId);
	if (i == 0xFF) return;
	for (;i<_numberOfButtons-1; i++) {
		_button[i].id = _button[i+1].id;
		_button[i].pin = _button[i+1].pin;
		_button[i].state = _button[i+1].state;
	}
	_numberOfButtons --;
}
コード例 #6
0
ファイル: NoteSequencer.cpp プロジェクト: daniel-bytes/squar
void NoteSequencer::resized()
{
	const int width = getWidth() / numSteps;
	const int height = getHeight() / numNotes;
	
	for (int step = 0; step < numSteps; step++) {
		for (int note = 0; note < numNotes; note++) {
			int index = getButtonIndex(step, note);
			auto button = buttons[index];

			int x = step * width;
			int y = note * height;

			button->setBounds(x, y, width, height);
		}
	}
}
コード例 #7
0
ファイル: ButtonMonitor.cpp プロジェクト: ikawaljeet/ardurct
/**
 * Returns true as long as the button is pressed
 */
bool NIButtonMonitor::isPressed(uint8_t buttonId) {
	uint8_t i = getButtonIndex(buttonId);
	if (i == 0xFF) return false;
	return (_button[i].state & ~BUTTON_MONITOR_STATE_NOT_READ > 2);
}
コード例 #8
0
ファイル: ButtonMonitor.cpp プロジェクト: ikawaljeet/ardurct
/**
 * Returns true if the button has been pressed more than BUTTON_MONITOR_FAST_REPEATING_TRIGGER
 */
bool NIButtonMonitor::isFastRepeating(uint8_t buttonId) {
	uint8_t i = getButtonIndex(buttonId);
	if (i == 0xFF) return false;
	return (_button[i].state & ~BUTTON_MONITOR_STATE_NOT_READ > BUTTON_MONITOR_FAST_REPEATING_TRIGGER/BUTTON_MONITOR_DEBOUNCE_DELAY_MS);
}
コード例 #9
0
bool InputDeviceAdapterMouse::keyPressed(int keyCode,int modifierMask,const char* string)
{
    bool stateChanged=false;

    if(keyCode==keyboardModeToggleKeyCode)
    {
        keyboardMode=!keyboardMode;
        if(fakeMouseCursor)
        {
            /* Change the glyph renderer's cursor type to a text cursor: */
        }
        else if(keyboardMode)
        {
            /* Change the cursor in all windows to a text cursor: */
            for(int i=0; i<getNumWindows(); ++i)
            {
                VRWindow* win=Vrui::getWindow(i);
                if(win!=0)
                {
                    Cursor cursor=XCreateFontCursor(win->getContext().getDisplay(),XC_xterm);
                    XDefineCursor(win->getContext().getDisplay(),win->getWindow(),cursor);
                    XFreeCursor(win->getContext().getDisplay(),cursor);
                }
            }
        }
        else
        {
            /* Change the cursor in all windows back to the regular: */
            for(int i=0; i<getNumWindows(); ++i)
            {
                VRWindow* win=Vrui::getWindow(i);
                if(win!=0)
                    XUndefineCursor(win->getContext().getDisplay(),win->getWindow());
            }
        }
    }
    else if(keyboardMode)
    {
        /* Process the key event: */
        ControlKeyMap::Iterator ckmIt=controlKeyMap.findEntry(ControlKey(keyCode,modifierMask&(ShiftMask|ControlMask)));
        if(!ckmIt.isFinished())
        {
            /* Store a text control event: */
            textControlEvents.push_back(std::pair<int,GLMotif::TextControlEvent>(nextEventOrdinal,ckmIt->getDest()));
            ++nextEventOrdinal;
        }
        else if(string!=0&&string[0]!='\0')
        {
            /* Store a text event: */
            textEvents.push_back(std::pair<int,GLMotif::TextEvent>(nextEventOrdinal,GLMotif::TextEvent(string)));
            ++nextEventOrdinal;
        }

        stateChanged=true;
    }
    else
    {
        /* Check if the key is a button key: */
        int buttonIndex=getButtonIndex(keyCode);
        if(buttonIndex>=0)
        {
            /* Set button state: */
            int stateIndex=(numButtons+numButtonKeys)*modifierKeyMask+numButtons+buttonIndex;
            stateChanged=changeButtonState(stateIndex,true);
        }

        /* Check if the key is a modifier key: */
        int modifierIndex=getModifierIndex(keyCode);
        if(modifierIndex>=0)
        {
            /* Change current modifier mask: */
            changeModifierKeyMask(modifierKeyMask|(0x1<<modifierIndex));
            stateChanged=true;
        }
    }

    // requestUpdate();

    return stateChanged;
}