void QuitDialog::keyPressed(KeyEvent &event) { const int actionId = event.getActionId(); int dir = 0; switch (actionId) { case InputAction::GUI_SELECT: case InputAction::GUI_SELECT2: action(ActionEvent(nullptr, mOkButton->getActionEventId())); break; case InputAction::GUI_CANCEL: action(ActionEvent(nullptr, mCancelButton->getActionEventId())); break; case InputAction::GUI_UP: dir = -1; break; case InputAction::GUI_DOWN: dir = 1; break; default: break; } if (dir != 0) { std::vector<RadioButton*>::const_iterator it = mOptions.begin(); const std::vector<RadioButton*>::const_iterator it_end = mOptions.end(); for (; it < it_end; ++it) { if ((*it)->isSelected()) break; } if (it == mOptions.end()) { if (mOptions[0]) mOptions[0]->setSelected(true); return; } else if (it == mOptions.begin() && dir < 0) { it = mOptions.end(); } it += dir; if (it == mOptions.end()) it = mOptions.begin(); (*it)->setSelected(true); } }
void ServerDialog::keyPressed(KeyEvent &event) { switch (event.getActionId()) { case InputAction::GUI_CANCEL: event.consume(); client->setState(STATE_EXIT); return; case InputAction::GUI_SELECT: case InputAction::GUI_SELECT2: event.consume(); action(ActionEvent(nullptr, mConnectButton->getActionEventId())); return; case InputAction::GUI_INSERT: (new EditServerDialog(this, ServerInfo(), -1))->postInit(); return; case InputAction::GUI_DELETE: { const int index = mServersList->getSelected(); if (index >= 0) { mServersList->setSelected(0); mServers.erase(mServers.begin() + index); saveCustomServers(); } return; } case InputAction::GUI_BACKSPACE: { const int index = mServersList->getSelected(); if (index >= 0) { (new EditServerDialog(this, mServers.at(index), index))->postInit(); } return; } default: break; } if (!event.isConsumed()) mServersList->keyPressed(event); }
void CharCreateDialog::keyPressed(KeyEvent &event) { const InputActionT actionId = event.getActionId(); switch (actionId) { case InputAction::GUI_CANCEL: event.consume(); action(ActionEvent(mCancelButton, mCancelButton->getActionEventId())); break; default: break; } }
void WorldSelectDialog::keyPressed(KeyEvent &event) { const int actionId = event.getActionId(); if (actionId == static_cast<int>(InputAction::GUI_CANCEL)) { action(ActionEvent(nullptr, mChangeLoginButton->getActionEventId())); } else if (actionId == static_cast<int>(InputAction::GUI_SELECT) || actionId == static_cast<int>(InputAction::GUI_SELECT2)) { action(ActionEvent(nullptr, mChooseWorld->getActionEventId())); } }
void EditServerDialog::keyPressed(KeyEvent &event) { if (event.isConsumed()) return; const InputActionT actionId = event.getActionId(); if (actionId == InputAction::GUI_CANCEL) { scheduleDelete(); } else if (actionId == InputAction::GUI_SELECT || actionId == InputAction::GUI_SELECT2) { action(ActionEvent(nullptr, mOkButton->getActionEventId())); } }
void IntTextField::keyPressed(KeyEvent &event) { const int action = event.getActionId(); if (action == InputAction::GUI_DELETE || action == InputAction::GUI_BACKSPACE) { setText(std::string()); if (mSendAlwaysEvents) distributeActionEvent(); event.consume(); } #ifdef USE_SDL2 const int val = event.getKey().getValue(); if (val != Key::TEXTINPUT) return; const std::string str = event.getText(); if (str.empty()) return; const size_t sz = str.size(); for (size_t f = 0; f < sz; f ++) { const char chr = str[f]; if (chr < '0' || chr > '9') return; } #else if (!event.getKey().isNumber()) return; #endif TextField::keyPressed(event); std::istringstream s(getText()); int i; s >> i; setValue(i); if (mSendAlwaysEvents) distributeActionEvent(); }
void ListBox::keyPressed(KeyEvent &event) { const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT) { distributeActionEvent(); event.consume(); } else if (action == InputAction::GUI_UP) { if (mSelected > 0) { setSelected(mSelected - 1); } else if (mSelected == 0 && mWrappingEnabled && getListModel() != nullptr) { setSelected(getListModel()->getNumberOfElements() - 1); } event.consume(); } else if (action == InputAction::GUI_DOWN) { const int num = getListModel()->getNumberOfElements() - 1; if (mSelected < num) setSelected(mSelected + 1); else if (mSelected == num && mWrappingEnabled) setSelected(0); event.consume(); } else if (action == InputAction::GUI_HOME) { setSelected(0); event.consume(); } else if (action == InputAction::GUI_END && (getListModel() != nullptr)) { setSelected(getListModel()->getNumberOfElements() - 1); event.consume(); } }
// -- KeyListener notifications void GuiTable::keyPressed(KeyEvent& event) { const InputActionT action = event.getActionId(); if (action == InputAction::GUI_SELECT) { distributeActionEvent(); event.consume(); } else if (action == InputAction::GUI_UP) { setSelectedRow(mSelectedRow - 1); event.consume(); } else if (action == InputAction::GUI_DOWN) { setSelectedRow(mSelectedRow + 1); event.consume(); } else if (action == InputAction::GUI_LEFT) { setSelectedColumn(mSelectedColumn - 1); event.consume(); } else if (action == InputAction::GUI_RIGHT) { setSelectedColumn(mSelectedColumn + 1); event.consume(); } else if (action == InputAction::GUI_HOME) { setSelectedRow(0); setSelectedColumn(0); event.consume(); } else if (action == InputAction::GUI_END && mModel) { setSelectedRow(mModel->getRows() - 1); setSelectedColumn(mModel->getColumns() - 1); event.consume(); } }
void RegisterDialog::keyPressed(KeyEvent &event) { if (event.isConsumed()) { mRegisterButton->setEnabled(canSubmit()); return; } const InputActionT actionId = event.getActionId(); if (actionId == InputAction::GUI_CANCEL) { action(ActionEvent(nullptr, mCancelButton->getActionEventId())); } else if (actionId == InputAction::GUI_SELECT || actionId == InputAction::GUI_SELECT2) { action(ActionEvent(nullptr, mRegisterButton->getActionEventId())); } else { mRegisterButton->setEnabled(canSubmit()); } }
void LoginDialog::keyPressed(KeyEvent &event) { if (event.isConsumed()) { mLoginButton->setEnabled(canSubmit()); return; } const int actionId = event.getActionId(); if (actionId == static_cast<int>(InputAction::GUI_CANCEL)) { action(ActionEvent(nullptr, mServerButton->getActionEventId())); } else if (actionId == static_cast<int>(InputAction::GUI_SELECT) || actionId == static_cast<int>(InputAction::GUI_SELECT2)) { action(ActionEvent(nullptr, mLoginButton->getActionEventId())); } else { mLoginButton->setEnabled(canSubmit()); } }
void TextBox::keyPressed(KeyEvent& event) { const Key &key = event.getKey(); const int action = event.getActionId(); switch (action) { case InputAction::GUI_LEFT: { --mCaretColumn; if (mCaretColumn < 0) { --mCaretRow; if (mCaretRow < 0) { mCaretRow = 0; mCaretColumn = 0; } else { mCaretColumn = static_cast<int>( mTextRows[mCaretRow].size()); } } break; } case InputAction::GUI_RIGHT: { ++mCaretColumn; if (mCaretColumn > static_cast<int>(mTextRows[mCaretRow].size())) { ++ mCaretRow; const int sz = static_cast<int>(mTextRows.size()); if (mCaretRow >= sz) { mCaretRow = sz - 1; if (mCaretRow < 0) mCaretRow = 0; mCaretColumn = static_cast<int>( mTextRows[mCaretRow].size()); } else { mCaretColumn = 0; } } break; } case InputAction::GUI_DOWN: { setCaretRow(mCaretRow + 1); break; } case InputAction::GUI_UP: { setCaretRow(mCaretRow - 1); break; } case InputAction::GUI_HOME: { mCaretColumn = 0; break; } case InputAction::GUI_END: { mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size()); break; } case InputAction::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 InputAction::GUI_BACKSPACE: { if (mCaretColumn != 0 && mEditable) { mTextRows[mCaretRow].erase(mCaretColumn - 1, 1); --mCaretColumn; } else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable) { mCaretColumn = static_cast<int>( mTextRows[mCaretRow - 1].size()); mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; mTextRows.erase(mTextRows.begin() + mCaretRow); --mCaretRow; } break; } case InputAction::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 InputAction::GUI_PAGE_UP: { Widget *const par = getParent(); if (par) { const int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); mCaretRow -= rowsPerPage; if (mCaretRow < 0) mCaretRow = 0; } break; } case InputAction::GUI_PAGE_DOWN: { Widget *const par = getParent(); if (par) { const int rowsPerPage = par->getChildrenArea().height / getFont()->getHeight(); mCaretRow += rowsPerPage; const int sz = static_cast<int>(mTextRows.size()); if (mCaretRow >= sz) mCaretRow = sz - 1; } break; } case InputAction::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<signed char>(key.getValue()))); ++ mCaretColumn; } break; } } adjustSize(); scrollToCaret(); event.consume(); }