void Menu::keyEvent(Key key, KeyMod mod, bool pressed) { if (key == KEY_ESCAPE) { menu_manager_->changeCurrentMenu(parent_menu_); return; } if (pressed) { std::vector < MenuText * >options_vec; for (std::map < Key, MenuText >::iterator it = options_.begin(); it != options_.end(); it++) options_vec.push_back(&it->second); if (options_vec.size()) { unsigned int curOpt = 0; for (unsigned int i = 0; i < options_vec.size(); i++) if (!options_vec[i]->dark_) { curOpt = i; break; } if (key == VK_UP || key == KEY_UP) { options_vec[curOpt]->dark_ = true; if (curOpt == 0) curOpt = options_vec.size() - 1; else curOpt--; options_vec[curOpt]->dark_ = false; show(false); } if (key == VK_DOWN || key == KEY_DOWN) { if (!options_vec[curOpt]->dark_) { options_vec[curOpt]->dark_ = true; curOpt++; if (curOpt >= options_vec.size()) curOpt = 0; } options_vec[curOpt]->dark_ = false; show(false); } if (key == VK_FB || key == KEY_RETURN || key == KEY_KP_ENTER) { for (std::map < Key, MenuText >::iterator it = options_.begin(); it != options_.end(); it++) if (&it->second == options_vec[curOpt]) key = it->first; } } } if (options_.find(key) == options_.end()) { handleUnknownKey(key, mod, pressed); return; } handleOption(key); if (options_[key].to_) menu_manager_->changeCurrentMenu(options_[key].to_); }
/*! * Handles the key pressed event. * \param key The key that was pressed * \param modKeys State of all modifier keys */ void Menu::keyEvent(Key key, const int modKeys) { // first pass the event to the textfield that has the cursor if (pCaptureInput_ != NULL) { if (pCaptureInput_->handleKey(key, modKeys)) { return; } } if (!paused_) { // Then look for a mapped key to execute an action for (std::list < HotKey >::iterator it = hotKeys_.begin(); it != hotKeys_.end(); it++) { uint16 c = key.unicode; // Hotkey can only be character from 'A' to 'Z' if (c >= 'a' && c <= 'z') { // so uppercase it c -= 32; } if ((*it).key.keyFunc == key.keyFunc && (*it).key.unicode == c) { Option *opt = (*it).pOption; if (opt->isVisible() && opt->isWidgetEnabled()) { opt->executeAction(modKeys); } return; } } } // Finally pass the event to the menu instance if (!handleUnknownKey(key, modKeys)) { // Menu has not consummed key event : // Pressing Escape changes the current menu to its parent(like a back) if (key.keyFunc == KFC_ESCAPE) { menu_manager_->gotoMenu(parentId_); return; } } }