void command_executor::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool /*context_menu*/, display& gui)
{
	std::vector<std::string> items = items_arg;
	if (items.empty()) return;

	std::vector<std::string> menu = get_menu_images(gui, items);
	int res = 0;
	{
		gui::dialog mmenu = gui::dialog(gui,"","",
				gui::MESSAGE, gui::dialog::hotkeys_style);
		mmenu.set_menu(menu);
		res = mmenu.show(xloc, yloc);
	} // This will kill the dialog.
	if (res < 0 || size_t(res) >= items.size()) return;

	const theme::menu* submenu = gui.get_theme().get_menu_item(items[res]);
	if (submenu) {
		int y,x;
		SDL_GetMouseState(&x,&y);
		this->show_menu(submenu->items(), x, y, submenu->is_context(), gui);
	} else {
		const hotkey::hotkey_command& cmd = hotkey::get_hotkey_command(items[res]);
		hotkey::execute_command(gui,cmd,this,res);
		set_button_state(gui);
	}
}
void command_executor::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool /*context_menu*/, display& gui)
{
	std::vector<std::string> items = items_arg;
	if (items.empty()) return;

	std::vector<config> menu = get_menu_images(gui, items);
	int res = -1;
	{
		SDL_Rect pos = {xloc, yloc, 1, 1};
		gui2::tdrop_down_list mmenu(pos, menu, -1, false);
		mmenu.show(gui.video());
		if(mmenu.get_retval() == gui2::twindow::OK) {
			res = mmenu.selected_item();
		}
	} // This will kill the dialog.
	if (res < 0 || size_t(res) >= items.size()) return;

	const theme::menu* submenu = gui.get_theme().get_menu_item(items[res]);
	if (submenu) {
		int y,x;
		SDL_GetMouseState(&x,&y);
		this->show_menu(submenu->items(), x, y, submenu->is_context(), gui);
	} else {
		const hotkey::hotkey_command& cmd = hotkey::get_hotkey_command(items[res]);
		hotkey::execute_command(cmd,this,res);
		set_button_state();
	}
}
Exemple #3
0
void command_executor::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui)
{
	std::vector<std::string> items = items_arg;
	if (items.empty())
		return;
	if (can_execute_command(hotkey::get_hotkey(items.front()).get_id(), 0)){
		//if just one item is passed in, that means we should execute that item
		if(!context_menu && items.size() == 1 && items_arg.size() == 1) {
			hotkey::execute_command(gui,hotkey::get_hotkey(items.front()).get_id(),this);
			return;
		}

		std::vector<std::string> menu = get_menu_images(gui, items);

		int res = 0;
		{
			gui::dialog mmenu = gui::dialog(gui,"","",
			gui::MESSAGE, gui::dialog::hotkeys_style);
#ifdef USE_TINY_GUI
            mmenu.set_menu_bigger(menu);
#else
			mmenu.set_menu(menu);
#endif
			res = mmenu.show(xloc, yloc);
		} // this will kill the dialog
		if (res < 0 || size_t(res) >= items.size())
			return;

		const hotkey::HOTKEY_COMMAND cmd = hotkey::get_hotkey(items[res]).get_id();
		hotkey::execute_command(gui,cmd,this,res);
	}
}