Пример #1
0
void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent)
{
    if (keyEvent.isConsumed() || !isFocused())
        return;

    if (keyEvent.getKey().getValue() == Key::LEFT)
    {
        int index = getSelectedTabIndex();
        index--;

        if (index < 0)
            setSelectedTab(mTabs[mTabs.size() - 1].first);
        else
            setSelectedTab(mTabs[index].first);

        keyEvent.consume();
    }
    else if (keyEvent.getKey().getValue() == Key::RIGHT)
    {
        int index = getSelectedTabIndex();
        index++;

        if (index >= (int) mTabs.size())
            setSelectedTab(mTabs[0].first);
        else
            setSelectedTab(mTabs[index].first);

        keyEvent.consume();
    }
}
Пример #2
0
void Slider::keyPressed(gcn::KeyEvent &keyEvent)
{
    gcn::Key key = keyEvent.getKey();

    if (getOrientation() == HORIZONTAL)
    {
        if (key.getValue() == Key::RIGHT)
        {
            setValue(getValue() + getStepLength());
            distributeActionEvent();
            keyEvent.consume();
        }
        else if (key.getValue() == Key::LEFT)
        {
            setValue(getValue() - getStepLength());
            distributeActionEvent();
            keyEvent.consume();
        }            
    }
    else
    {
        if (key.getValue() == Key::UP)
        {
            setValue(getValue() + getStepLength());
            distributeActionEvent();
            keyEvent.consume();
        }
        else if (key.getValue() == Key::DOWN)
        {
            setValue(getValue() - getStepLength());
            distributeActionEvent();
            keyEvent.consume();
        }
    }
}
Пример #3
0
void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent)
{
    if (keyEvent.isConsumed() || !isFocused())
        return;

    if (keyEvent.getKey().getValue() == Key::LEFT)
    {
        TabContainer::iterator index = getTabIterator(mSelectedTab);

        if (index != mTabs.begin())
            setSelectedTab((--index)->first);
        else
            setSelectedTab((--mTabs.end())->first);

        keyEvent.consume();
    }
    else if (keyEvent.getKey().getValue() == Key::RIGHT)
    {
        TabContainer::iterator index = getTabIterator(mSelectedTab);

        if (index != (--mTabs.end()))
            setSelectedTab((++index)->first);
        else
            setSelectedTab(mTabs.begin()->first);

        keyEvent.consume();
    }
}
Пример #4
0
    void Menu::keyPressed(gcn::KeyEvent& keyEvent) {
        std::cout << "Menu::keyPressed" << std::endl;
        hikari::Input::Button button =
            InputHelper::getMappedButtonForKey(keyEvent.getKey());

        if(button == Input::BUTTON_UP) {
            selectPreviousItem();
            keyEvent.consume();
        } else if(button == Input::BUTTON_DOWN) {
            selectNextItem();
            keyEvent.consume();
        } else if(button == Input::BUTTON_START || button == Input::BUTTON_SHOOT) {
            distributeActionEvent();
        }
    }
Пример #5
0
void IntTextField::keyPressed(gcn::KeyEvent &event)
{
    int action = static_cast<KeyEvent*>(&event)->getActionId();

    if (action == Input::KEY_GUI_DELETE || action == Input::KEY_GUI_BACKSPACE)
    {
        setText(std::string());
        if (mSendAlwaysEvents)
            distributeActionEvent();

        event.consume();
    }

    if (!event.getKey().isNumber())
        return;

    TextField::keyPressed(event);

    std::istringstream s(getText());
    int i;
    s >> i;
    setValue(i);
    if (mSendAlwaysEvents)
        distributeActionEvent();
}
Пример #6
0
void PlayControllerZone::keyPressed( gcn::KeyEvent& keyEvent )
{

  switch ( keyEvent.getKey().getValue() )
  {

    case gcn::Key::LEFT:
      view().Scroll( 1,
                     IMap::WEST );
      break;

    case gcn::Key::RIGHT:
      view().Scroll( 1,
                     IMap::EAST );
      break;

    case gcn::Key::UP:
      view().Scroll( 1,
                     IMap::NORTH );
      break;

    case gcn::Key::DOWN:
      view().Scroll( 1,
                     IMap::SOUTH );
      break;

    default:
      ;

  }
  keyEvent.consume();
}
Пример #7
0
// -- KeyListener notifications
void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
{
    gcn::Key key = keyEvent.getKey();

    if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
    {
        if (keyEvent.isShiftPressed())
        {
            const std::string actionEventId = getActionEventId();
            setActionEventId("default");
            distributeActionEvent();
            setActionEventId(actionEventId);
        }
        else
            distributeActionEvent();
    }
    else if (key.getValue() == Key::UP)
        decrementSelected();
    else if (key.getValue() == Key::DOWN)
        incrementSelected();
    else if (key.getValue() == Key::HOME)
        setSelected(0);
    else if (key.getValue() == Key::END)
        setSelected(getListModel()->getNumberOfElements() - 1);
    else
        return;

    keyEvent.consume();
}
Пример #8
0
void IntroController::keyPressed( gcn::KeyEvent& keyEvent )
{

  if ( keyEvent.getKey().getValue() == gcn::Key::ESCAPE ) {

    model().final(); //! Paramos el bucle asi?.......
    keyEvent.consume();

  }
Пример #9
0
void CharCreateDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
    int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
    switch (actionId)
    {
        case Input::KEY_GUI_CANCEL:
            keyEvent.consume();
            action(gcn::ActionEvent(mCancelButton,
                mCancelButton->getActionEventId()));
            break;

        default:
            break;
    }
}
Пример #10
0
void IntTextField::keyPressed(gcn::KeyEvent &event)
{
    const gcn::Key &key = event.getKey();

    if (key.getValue() == Key::BACKSPACE ||
        key.getValue() == Key::DELETE)
    {
        setText(std::string());
        event.consume();
    }

    if (!key.isNumber())
        return;

    TextField::keyPressed(event);

    std::istringstream s(getText());
    int i;
    s >> i;
    setValue(i);
}
Пример #11
0
// -- KeyListener notifications
void DropDown::keyPressed(gcn::KeyEvent& keyEvent)
{
    if (keyEvent.isConsumed())
        return;

    int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();

    switch (actionId)
    {
        case Input::KEY_GUI_SELECT:
        case Input::KEY_GUI_SELECT2:
            dropDown();
            break;

        case Input::KEY_GUI_UP:
            setSelected(getSelected() - 1);
            break;

        case Input::KEY_GUI_DOWN:
            setSelected(getSelected() + 1);
            break;

        case Input::KEY_GUI_HOME:
            setSelected(0);
            break;

        case Input::KEY_GUI_END:
            if (mListBox->getListModel())
            {
                setSelected(mListBox->getListModel()->
                    getNumberOfElements() - 1);
            }
            break;

        default:
            return;
    }

    keyEvent.consume();
}
Пример #12
0
// -- KeyListener notifications
void GuiTable::keyPressed(gcn::KeyEvent& keyEvent)
{
    gcn::Key key = keyEvent.getKey();

    if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
    {
        distributeActionEvent();
        keyEvent.consume();
    }
    else if (key.getValue() == Key::UP)
    {
        setSelectedRow(mSelectedRow - 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::DOWN)
    {
        setSelectedRow(mSelectedRow + 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::LEFT)
    {
        setSelectedColumn(mSelectedColumn - 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::RIGHT)
    {
        setSelectedColumn(mSelectedColumn + 1);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::HOME)
    {
        setSelectedRow(0);
        setSelectedColumn(0);
        keyEvent.consume();
    }
    else if (key.getValue() == Key::END)
    {
        setSelectedRow(mModel->getRows() - 1);
        setSelectedColumn(mModel->getColumns() - 1);
        keyEvent.consume();
    }
}
Пример #13
0
// -- KeyListener notifications
void DropDown::keyPressed(gcn::KeyEvent& keyEvent)
{
    if (keyEvent.isConsumed())
        return;

    gcn::Key key = keyEvent.getKey();

    if (key.getValue() == Key::ENTER || key.getValue() == Key::SPACE)
        dropDown();
    else if (key.getValue() == Key::UP)
        setSelected(getSelected() - 1);
    else if (key.getValue() == Key::DOWN)
        setSelected(getSelected() + 1);
    else if (key.getValue() == Key::HOME)
        setSelected(0);
    else if (key.getValue() == Key::END)
        setSelected(mListBox->getListModel()->getNumberOfElements() - 1);
    else
        return;

    keyEvent.consume();
}
Пример #14
0
void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
{
    gcn::Key key = keyEvent.getKey();
    int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();

    switch (action)
    {
        case Input::KEY_GUI_LEFT:
        {
            --mCaretColumn;
            if (mCaretColumn < 0)
            {
                --mCaretRow;

                if (mCaretRow < 0)
                {
                    mCaretRow = 0;
                    mCaretColumn = 0;
                }
                else
                {
                    mCaretColumn = mTextRows[mCaretRow].size();
                }
            }
            break;
        }

        case Input::KEY_GUI_RIGHT:
        {
            ++mCaretColumn;
            if (mCaretColumn > static_cast<int>(mTextRows[mCaretRow].size()))
            {
                ++ mCaretRow;

                if (mCaretRow >= static_cast<int>(mTextRows.size()))
                {
                    mCaretRow = mTextRows.size() - 1;
                    if (mCaretRow < 0)
                        mCaretRow = 0;

                    mCaretColumn = mTextRows[mCaretRow].size();
                }
                else
                {
                    mCaretColumn = 0;
                }
            }
            break;
        }

        case Input::KEY_GUI_DOWN:
        {
            setCaretRow(mCaretRow + 1);
            break;
        }
        case Input::KEY_GUI_UP:
        {
            setCaretRow(mCaretRow - 1);
            break;
        }
        case Input::KEY_GUI_HOME:
        {
            mCaretColumn = 0;
            break;
        }
        case Input::KEY_GUI_END:
        {
            mCaretColumn = mTextRows[mCaretRow].size();
            break;
        }

        case Input::KEY_GUI_SELECT2:
        {
            if (mEditable)
            {
                mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
                    mTextRows[mCaretRow].substr(mCaretColumn,
                    mTextRows[mCaretRow].size() - mCaretColumn));
                mTextRows[mCaretRow].resize(mCaretColumn);
                ++mCaretRow;
                mCaretColumn = 0;
            }
            break;
        }

        case Input::KEY_GUI_BACKSPACE:
        {
            if (mCaretColumn != 0 && mEditable)
            {
                mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
                --mCaretColumn;
            }
            else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable)
            {
                mCaretColumn = mTextRows[mCaretRow - 1].size();
                mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
                mTextRows.erase(mTextRows.begin() + mCaretRow);
                --mCaretRow;
            }
            break;
        }

        case Input::KEY_GUI_DELETE:
        {
            if (mCaretColumn < static_cast<int>(
                mTextRows[mCaretRow].size()) && mEditable)
            {
                mTextRows[mCaretRow].erase(mCaretColumn, 1);
            }
            else if (mCaretColumn == static_cast<int>(
                     mTextRows[mCaretRow].size()) &&
                     mCaretRow < (static_cast<int>(mTextRows.size()) - 1) &&
                     mEditable)
            {
                mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
                mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
            }
            break;
        }

        case Input::KEY_GUI_PAGE_UP:
        {
            gcn::Widget* par = getParent();

            if (par)
            {
                int rowsPerPage = par->getChildrenArea().height
                    / getFont()->getHeight();
                mCaretRow -= rowsPerPage;

                if (mCaretRow < 0)
                    mCaretRow = 0;
            }
            break;
        }

        case Input::KEY_GUI_PAGE_DOWN:
        {
            gcn::Widget* par = getParent();

            if (par)
            {
                int rowsPerPage = par->getChildrenArea().height
                    / getFont()->getHeight();
                mCaretRow += rowsPerPage;

                if (mCaretRow >= static_cast<int>(mTextRows.size()))
                    mCaretRow = mTextRows.size() - 1;
            }
            break;
        }

        case Input::KEY_GUI_TAB:
        {
            if (mEditable)
            {
                mTextRows[mCaretRow].insert(mCaretColumn, std::string("    "));
                mCaretColumn += 4;
            }
            break;
        }

        default:
        {
            if (key.isCharacter() && mEditable)
            {
                mTextRows[mCaretRow].insert(mCaretColumn,
                    std::string(1, static_cast<char>(key.getValue())));
                ++ mCaretColumn;
            }
            break;
        }
    }

    adjustSize();
    scrollToCaret();

    keyEvent.consume();
}
Пример #15
0
void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
    int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
    switch (actionId)
    {
        case Input::KEY_GUI_CANCEL:
            keyEvent.consume();
            action(gcn::ActionEvent(mSwitchLoginButton,
                mSwitchLoginButton->getActionEventId()));
            break;

        case Input::KEY_GUI_RIGHT:
        {
            keyEvent.consume();
            int idx;
            int idx2;
            if (getFocusedContainer(idx, idx2))
            {
                idx ++;
                if (idx == SLOTS_PER_ROW)
                    break;
                setFocusedContainer(idx, idx2);
            }
            break;
        }

        case Input::KEY_GUI_LEFT:
        {
            keyEvent.consume();
            int idx;
            int idx2;
            if (getFocusedContainer(idx, idx2))
            {
                if (!idx || idx == SLOTS_PER_ROW)
                    break;
                idx --;
                setFocusedContainer(idx, idx2);
            }
            break;
        }

        case Input::KEY_GUI_UP:
        {
            keyEvent.consume();
            int idx;
            int idx2;
            if (getFocusedContainer(idx, idx2))
            {
                if (idx < SLOTS_PER_ROW && !idx2)
                    break;
                if (idx2 > 0)
                {
                    idx2 = 0;
                }
                else
                {
                    idx -= SLOTS_PER_ROW;
                    if (mCharacterEntries[idx]->getCharacter())
                        idx2 = 1;
                    else
                        idx2 = 0;
                }
                setFocusedContainer(idx, idx2);
            }
            break;
        }

        case Input::KEY_GUI_DOWN:
        {
            keyEvent.consume();
            int idx;
            int idx2;
            if (getFocusedContainer(idx, idx2))
            {
                if (idx >= SLOTS_PER_ROW && idx2)
                    break;
                if (idx2 > 0)
                {
                    idx += SLOTS_PER_ROW;
                    idx2 = 0;
                }
                else
                {
                    if (mCharacterEntries[idx]->getCharacter())
                        idx2 = 1;
                    else
                        idx += SLOTS_PER_ROW;
                }
                setFocusedContainer(idx, idx2);
            }
            break;
        }

        case Input::KEY_GUI_DELETE:
        {
            keyEvent.consume();
            int idx;
            int idx2;
            if (getFocusedContainer(idx, idx2)
                && mCharacterEntries[idx]->getCharacter())
            {
                new CharDeleteConfirm(this, idx);
            }
            break;
        }

        default:
            break;
    }
}
Пример #16
0
void ItemContainer::keyPressed(gcn::KeyEvent &event)
{
    const int columns = std::max(1, getWidth() / gridWidth);
    const int gridSlot = getVisibleSlot(getSelectedItem());
    int itemX = gridSlot % columns;
    int itemY = gridSlot / columns;

    // Handling direction keys: all of these set selectNewItem, and change
    // itemX or itemY checking only that the selection doesn't go off the top,
    // left or right of the grid.  The block below the switch statement then
    // checks that there's an item in that slot (implictly bounds-checking that
    // the selection didn't go off the bottom of the grid).
    bool selectNewItem = false;
    switch (event.getKey().getValue())
    {
        case Key::LEFT:
            if (itemX != 0)
                itemX--;

            selectNewItem = true;
            event.consume();
            break;
        case Key::RIGHT:
            if (itemX < (columns - 1))
                itemX++;

            selectNewItem = true;
            event.consume();
            break;
        case Key::UP:
            if (itemY != 0)
                itemY--;

            selectNewItem = true;
            event.consume();
            break;
        case Key::DOWN:
            itemY++;
            selectNewItem = true;
            event.consume();
            break;
        case Key::ENTER:
        case Key::SPACE:
            if (event.isShiftPressed())
            {
                const std::string actionEventId = getActionEventId();
                setActionEventId("default");
                distributeActionEvent();
                setActionEventId(actionEventId);
            }
            else
                distributeActionEvent();

            event.consume();
            break;
    }

    if (selectNewItem)
    {
        Item* selection = getItemInVisibleSlot(itemX + columns * itemY);

        if (selection)
            setSelectedItemIndex(selection->getInvIndex());
    }
}