wxMenu *GetMenu(std::string const& name, agi::Context *c) { CommandMenu *menu = new CommandMenu(c); build_menu(name, c, &menu->cm, menu); menu->Bind(wxEVT_MENU_OPEN, &CommandManager::OnMenuOpen, &menu->cm); menu->Bind(wxEVT_COMMAND_MENU_SELECTED, &CommandManager::OnMenuClick, &menu->cm); return menu; }
Component *CommandTableModel::refreshComponentForCell(int rowNumber, int columnId, bool /*isRowSelected*/, Component *existingComponentToUpdate) { if (columnId == 2) // LR command column { // because Juce recycles these components when scrolling, we need to reset their properties CommandMenu* commandSelect = dynamic_cast<CommandMenu *>(existingComponentToUpdate); // create a new command menu if (commandSelect == nullptr) { commandSelect = new CommandMenu(_commands[rowNumber]); commandSelect->Init(m_commandMap); } else commandSelect->setMsg(_commands[rowNumber]); if (m_commandMap) { // add 1 because 0 is reserved for no selection commandSelect->setSelectedItem(LRCommandList::getIndexOfCommand(m_commandMap->getCommandforMessage(_commands[rowNumber])) + 1); } return commandSelect; } else return nullptr; }
//----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- CSpectatorMenu::CSpectatorMenu( IViewPort *pViewPort ) : Frame( NULL, PANEL_SPECMENU ) { SetScheme("ClientScheme"); m_iDuckKey = BUTTON_CODE_INVALID; m_pViewPort = pViewPort; SetMouseInputEnabled( true ); SetKeyBoardInputEnabled( false ); SetTitleBarVisible( false ); // don't draw a title bar SetMoveable( false ); SetSizeable( false ); SetProportional(false); m_pMainPanel = new Panel(this, ""); m_pTargetList = new ComboBox(m_pMainPanel, "playercombo", 10 , false); m_pTargetList->SetOpenDirection(Menu::UP); CommandMenu *pTargetListMenu = new CommandMenu(m_pTargetList, "playercombo", gViewPortInterface); m_pTargetList->SetMenu(pTargetListMenu); m_pCamModes = new ComboBox(m_pMainPanel, "cammodes", 10 , false ); m_pCamModes->SetOpenDirection(Menu::UP); CommandMenu *pCamModeMenu = new CommandMenu(m_pCamModes, "cammodes", gViewPortInterface); for (int i = 0; i < CAM_MODE_COUNT; i++) { pCamModeMenu->AddMenuItem(g_szCamModeNames[i], VarArgs("cam_mode %d", i), this); } m_pCamModes->SetMenu(pCamModeMenu); m_pCamModes->ActivateItemByRow(0); m_pTVCamModes = new ComboBox(m_pMainPanel, "tvcammodes", 10 , false ); m_pTVCamModes->SetOpenDirection(Menu::UP); CommandMenu *pTVCamModeMenu = new CommandMenu(m_pTVCamModes, "tvcammodes", gViewPortInterface); for (int i = 0; i < TVCAM_MODE_COUNT; i++) { pTVCamModeMenu->AddMenuItem(g_szTVCamModeNames[i], VarArgs("tvcam_mode %d", i), this); } m_pTVCamModes->SetMenu(pTVCamModeMenu); m_pTVCamModes->ActivateItemByRow(0); m_pLeftButton = new Button(m_pMainPanel, "", "<", this, "spec_prev"); m_pRightButton = new Button(m_pMainPanel, "", ">", this, "spec_next"); ListenForGameEvent("spec_target_updated"); ListenForGameEvent("player_team"); ListenForGameEvent("cam_mode_updated"); ListenForGameEvent("tvcam_mode_updated"); }
int main(int argc, char** argv) { Command1 cmd1; Command2 cmd2; CommandMenu menu; menu.RegisterCommand("command1", &cmd1); menu.RegisterCommand("command2", &cmd2); menu.ExecuteCommand("command2"); }
//----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- CSpectatorMenu::CSpectatorMenu( IViewPort *pViewPort ) : BaseClass( NULL, PANEL_SPECMENU ) { m_iDuckKey = BUTTON_CODE_INVALID; m_pViewPort = pViewPort; SetMouseInputEnabled( true ); SetKeyBoardInputEnabled( true ); SetTitleBarVisible( false ); // don't draw a title bar SetMoveable( false ); SetSizeable( false ); SetProportional(true); SetScheme("ClientScheme"); m_pPlayerList = new ComboBox(this, "playercombo", 10 , false); HFont hFallbackFont = scheme()->GetIScheme( GetScheme() )->GetFont( "DefaultVerySmallFallBack", false ); if ( INVALID_FONT != hFallbackFont ) { m_pPlayerList->SetUseFallbackFont( true, hFallbackFont ); } m_pViewOptions = new ComboBox(this, "viewcombo", 10 , false ); m_pConfigSettings = new ComboBox(this, "settingscombo", 10 , false ); m_pLeftButton = new CSpecButton( this, "specprev"); m_pLeftButton->SetText("3"); m_pRightButton = new CSpecButton( this, "specnext"); m_pRightButton->SetText("4"); m_pPlayerList->SetText(""); m_pViewOptions->SetText("#Spec_Modes"); m_pConfigSettings->SetText("#Spec_Options"); m_pPlayerList->SetOpenDirection( Menu::UP ); m_pViewOptions->SetOpenDirection( Menu::UP ); m_pConfigSettings->SetOpenDirection( Menu::UP ); // create view config menu CommandMenu * menu = new CommandMenu(m_pViewOptions, "spectatormenu", GetViewPortInterface()); menu->LoadFromFile( "Resource/spectatormenu.res" ); m_pConfigSettings->SetMenu( menu ); // attach menu to combo box // create view mode menu menu = new CommandMenu(m_pViewOptions, "spectatormodes", GetViewPortInterface()); menu->LoadFromFile("Resource/spectatormodes.res"); m_pViewOptions->SetMenu( menu ); // attach menu to combo box LoadControlSettings("Resource/UI/BottomSpectator.res"); ListenForGameEvent( "spec_target_updated" ); }
//----------------------------------------------------------------------------- // Purpose: Constructor //----------------------------------------------------------------------------- CSpectatorMenu::CSpectatorMenu( IViewPort *pViewPort ) : Frame( NULL, PANEL_SPECMENU ) { m_iDuckKey = -1; m_pViewPort = pViewPort; SetMouseInputEnabled( true ); SetKeyBoardInputEnabled( true ); SetTitleBarVisible( false ); // don't draw a title bar SetMoveable( false ); SetSizeable( false ); SetProportional(true); SetScheme("ClientScheme"); m_pPlayerList = new ComboBox(this, "playercombo", 10 , false); m_pViewOptions = new ComboBox(this, "viewcombo", 10 , false ); m_pConfigSettings = new ComboBox(this, "settingscombo", 10 , false ); m_pLeftButton = new CSpecButton( this, "specprev"); m_pLeftButton->SetText("3"); m_pRightButton = new CSpecButton( this, "specnext"); m_pRightButton->SetText("4"); m_pPlayerList->SetText(""); m_pViewOptions->SetText("#Spec_Modes"); m_pConfigSettings->SetText("#Spec_Options"); m_pPlayerList->SetOpenDirection( Menu::UP ); m_pViewOptions->SetOpenDirection( Menu::UP ); m_pConfigSettings->SetOpenDirection( Menu::UP ); // create view config menu CommandMenu * menu = new CommandMenu(m_pViewOptions, "spectatormenu", gViewPortInterface); menu->LoadFromFile( "Resource/spectatormenu.res" ); m_pConfigSettings->SetMenu( menu ); // attach menu to combo box // create view mode menu menu = new CommandMenu(m_pViewOptions, "spectatormodes", gViewPortInterface); menu->LoadFromFile("Resource/spectatormodes.res"); m_pViewOptions->SetMenu( menu ); // attach menu to combo box LoadControlSettings("Resource/UI/BottomSpectator.res"); }