예제 #1
0
// Returns whether a hotkey was deleted.
bool remove_wml_hotkey(const std::string& id)
{
	const hotkey::hotkey_command& command = get_hotkey_command(id);
	if(command.id == hotkey::HOTKEY_NULL)
	{
		LOG_G << "remove_wml_hotkey: command with id=" + id + " doesn't exist\n";
		return false;
	}
	else if (command.id != hotkey::HOTKEY_WML)
	{
		LOG_G << "remove_wml_hotkey: command with id=" + id + " cannot be removed because it is no wml menu hotkey\n";
		return false;
	}
	else
	{
		LOG_G << "removing wml hotkey with id=" + id + "\n";
		for(boost::ptr_vector<hotkey_command>::iterator itor = known_hotkeys.begin(); itor != known_hotkeys.end(); itor ++)
		{
			if(itor->command == id)
			{
				known_hotkeys.erase(itor);
				break;
			}
		}
		//command_map_ might be all wrong now, so we need to rebuild.
		command_map_.clear();
		for(size_t index = 0; index < known_hotkeys.size(); index++)
		{
			command_map_[known_hotkeys[index].command] = index;
		}
		return true;
	}
}
void jhat_event_execute(display& disp, const SDL_JoyHatEvent& event, command_executor* executor)
{
	const hotkey_item* hk = &get_hotkey(event);
	if (!hk->active()) {
		return;
	}

	execute_command(disp, get_hotkey_command(hk->get_command()), executor);
	executor->set_button_state(disp);
}
void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor)
{
	const hotkey_item* hk = &get_hotkey(event);

#if 0
	// This is not generally possible without knowing keyboard layout.
	if (hk->null()) {
		//no matching hotkey was found, but try an in-exact match.
		hk = &get_hotkey(event, true);
	}
#endif

	if (!hk->active()) {
		return;
	}

	execute_command(disp, get_hotkey_command(hk->get_command()), executor);
	executor->set_button_state(disp);
}
예제 #4
0
bool has_hotkey_command(const std::string& id)
{
	return get_hotkey_command(id).id != hotkey::HOTKEY_NULL;
}