예제 #1
0
파일: ui_data.c 프로젝트: chrisglass/ufoai
/**
 * @brief Init an option iterator at an index
 * @note invis option are skipped, and child are counted
 * @param[in] index Requested index (0 is the first option)
 * @param[in] option First element of options (it can be a tree)
 * @param[out] iterator Initialised iterator
 * @return the first option element found (current position of the iterator)
 * @code
 * uiOptionIterator_t iterator;
 * UI_InitOptionIteratorAtIndex(index, firstOption, &iterator);	// also return the option
 * while (iterator.option) {
 *     ...
 *     UI_OptionIteratorNextOption(&iterator);	// also return the option
 * }
 * @endcode
 * @todo Rework that code, we should split "Init" and "AtIndex"
 */
uiNode_t* UI_InitOptionIteratorAtIndex (int index, uiNode_t* option, uiOptionIterator_t* iterator)
{
	assert(option == NULL || option->behaviour == ui_optionBehaviour);
	OBJZERO(*iterator);
	iterator->skipCollapsed = qtrue;
	iterator->skipInvisible = qtrue;
	return UI_FindOptionAtIndex(index, option, iterator);
}
예제 #2
0
파일: ui_data.cpp 프로젝트: chagara/ufoai
/**
 * @brief Init an option iterator at an index
 * @note invis option are skipped, and child are counted
 * @param[in] index Requested index (0 is the first option)
 * @param[in] option First element of options (it can be a tree)
 * @param[in] skipCollapsed Set to true to skip collapsed nodes in the iteration.
 * @param[in] skipInvisible Set to true to skip invisible nodes in the iteration.
 * @param[out] iterator Initialised iterator
 * @return the first option element found (current position of the iterator)
 * @code
 * uiOptionIterator_t iterator;
 * UI_InitOptionIteratorAtIndex(index, firstOption, &iterator);	// also return the option
 * while (iterator.option) {
 *     ...
 *     UI_OptionIteratorNextOption(&iterator);	// also return the option
 * }
 * @endcode
 * @todo Rework that code, we should split "Init" and "AtIndex"
 */
uiNode_t* UI_InitOptionIteratorAtIndex (int index, uiNode_t* option, uiOptionIterator_t* iterator, bool skipCollapsed, bool skipInvisible)
{
	assert(option == nullptr || option->behaviour == ui_optionBehaviour);
	OBJZERO(*iterator);
	iterator->skipCollapsed = skipCollapsed;
	iterator->skipInvisible = skipInvisible;
	return UI_FindOptionAtIndex(index, option, iterator);
}
예제 #3
0
파일: ui_data.c 프로젝트: chrisglass/ufoai
/**
 * @brief find an option why index (0 is the first option)
 * @param[in] index Requested index (0 is the first option)
 * @param[in] option First element of options (it can be a tree)
 * @param[in,out] iterator need an initialised iterator, and update it into the write index
 */
static uiNode_t* UI_FindOptionAtIndex (int index, uiNode_t* option, uiOptionIterator_t* iterator)
{
	while (option) {
		assert(option->behaviour == ui_optionBehaviour);
		if (option->invis) {
			option = option->next;
			continue;
		}

		/* we are on the right element */
		if (index == 0) {
			iterator->option = option;
			return option;
		}

		/* not the parent */
		index--;

		if (OPTIONEXTRADATA(option).collapsed) {
			option = option->next;
			continue;
		}

		/* its a child */
		if (index < OPTIONEXTRADATA(option).childCount) {
			if (iterator->depthPos >= MAX_DEPTH_OPTIONITERATORCACHE)
				assert(qfalse);
			iterator->depthCache[iterator->depthPos] = option;
			iterator->depthPos++;
			return UI_FindOptionAtIndex(index, option->firstChild, iterator);
		}
		index -= OPTIONEXTRADATA(option).childCount;
		option = option->next;
	}

	iterator->option = NULL;
	return NULL;
}