Example #1
0
/**
 * @brief Find an option (and all his parents) by is value.
 * @param[in,out] iterator If it found an option, the iterator contain all option parent
 * @param[in] value The value we search
 * @return The right option, else NULL
 */
uiNode_t* UI_FindOptionByValue (uiOptionIterator_t* iterator, const char* value)
{
	while (iterator->option) {
		assert(iterator->option->behaviour == ui_optionBehaviour);
		if (Q_streq(OPTIONEXTRADATA(iterator->option).value, value))
			return iterator->option;
		UI_OptionIteratorNextOption(iterator);
	}
	return NULL;
}
Example #2
0
/**
 * @brief Find an option position from an option iterator
 * @param[in,out] iterator Context of the iteration. If it found an option, the iterator contain all option parent
 * @param[in] option The value we search
 * @return The option index, else -1
 */
int UI_FindOptionPosition (uiOptionIterator_t* iterator, const uiNode_t* option)
{
	int i = 0;
	while (iterator->option) {
		if (iterator->option == option)
			return i;
		i++;
		UI_OptionIteratorNextOption(iterator);
	}
	return -1;
}
/**
 * @brief Executes confuncs to update visible message options lines.
 * @sa MSO_Init_f
 * @todo move this into scripts
 */
static void MSO_UpdateVisibleButtons (void)
{
	int visible;/* current line */
	uiOptionIterator_t iterator;
	uiNode_t* messageSetting = cgi->UI_GetOption(TEXT_MESSAGEOPTIONS);

	UI_InitOptionIteratorAtIndex(messageList_scroll, messageSetting, &iterator);

	/* update visible button lines based on current displayed values */
	for (visible = 0; visible < messageList_size; visible++) {
		const uiNode_t* option = iterator.option;
		int idx;
		msgCategoryEntry_t* entry;

		if (!option)
			break;
		idx = atoi(OPTIONEXTRADATACONST(option).value);

		entry = &ccs.msgCategoryEntries[idx];
		if (!entry)
			break;
		if (entry->isCategory) {
			/* category is visible anyway*/
			cgi->UI_ExecuteConfunc("ms_disable %i", visible);

		} else {
			assert(entry->category);
			cgi->UI_ExecuteConfunc("ms_enable %i", visible);
			cgi->UI_ExecuteConfunc("ms_btnstate %i %i %i %i", visible, entry->settings->doPause,
				entry->settings->doNotify, entry->settings->doSound);
		}

		UI_OptionIteratorNextOption(&iterator);
	}

	for (; visible < messageList_size; visible++)
		cgi->UI_ExecuteConfunc("ms_disable %i", visible);
}
Example #4
0
static void UI_OptionTreeNodeDraw (uiNode_t *node)
{
	static const int panelTemplate[] = {
		CORNER_SIZE, MID_SIZE, CORNER_SIZE,
		CORNER_SIZE, MID_SIZE, CORNER_SIZE,
		MARGE
	};
	uiNode_t* option;
	const char *ref;
	const char *font;
	vec2_t pos;
	const char* image;
	int fontHeight;
	int currentY;
	int currentDecY = 0;
	const float *textColor;
	vec4_t disabledColor = {0.5, 0.5, 0.5, 1.0};
	int count = 0;
	uiOptionIterator_t iterator;

	if (!systemExpand)
		systemExpand = UI_GetSpriteByName("icons/system_expand");
	if (!systemCollapse)
		systemCollapse = UI_GetSpriteByName("icons/system_collapse");

	ref = UI_AbstractOptionGetCurrentValue(node);
	if (ref == NULL)
		return;

	UI_GetNodeAbsPos(node, pos);

	image = UI_GetReferenceString(node, node->image);
	if (image)
		UI_DrawPanel(pos, node->size, image, 0, 0, panelTemplate);

	font = UI_GetFontFromNode(node);
	fontHeight = EXTRADATA(node).lineHeight;
	currentY = pos[1] + node->padding;
	if (fontHeight == 0)
		fontHeight = UI_FontGetHeight(font);
	else {
		const int height = UI_FontGetHeight(font);
		currentDecY = (fontHeight - height) / 2;
	}

	/* skip option over current position */
	option = UI_OptionTreeNodeGetFirstOption(node);
	UI_OptionTreeNodeUpdateScroll(node);
	option = UI_InitOptionIteratorAtIndex(EXTRADATA(node).scrollY.viewPos, option, &iterator);

	/* draw all available options for this selectbox */
	for (; option; option = UI_OptionIteratorNextOption(&iterator)) {
		int decX;
		const char *label;

		/* outside the node */
		if (currentY + fontHeight > pos[1] + node->size[1] - node->padding) {
			count++;
			break;
		}

		/* draw the hover effect */
		if (OPTIONEXTRADATA(option).hovered)
			UI_DrawFill(pos[0] + node->padding, currentY, node->size[0] - node->padding - node->padding, fontHeight, node->color);

		/* text color */
		if (Q_streq(OPTIONEXTRADATA(option).value, ref)) {
			textColor = node->selectedColor;
		} else if (node->disabled || option->disabled) {
			textColor = disabledColor;
		} else if (option->color[3] == 0.0f) {
			textColor = node->color;
		} else {
			textColor = option->color;
		}

		/* print the option label */
		decX = pos[0] + node->padding + iterator.depthPos * DEPTH_WIDTH;

		R_Color(NULL);
		if (option->firstChild) {
			uiSprite_t *icon = OPTIONEXTRADATA(option).collapsed ? systemExpand : systemCollapse;
			UI_DrawSpriteInBox(OPTIONEXTRADATA(option).flipIcon, icon, SPRITE_STATUS_NORMAL, decX, currentY, icon->size[0], fontHeight);
		}

		decX += COLLAPSEBUTTON_WIDTH;

		if (OPTIONEXTRADATA(option).icon) {
			uiSpriteStatus_t iconStatus = SPRITE_STATUS_NORMAL;
			if (option->disabled)
				iconStatus = SPRITE_STATUS_DISABLED;
			UI_DrawSpriteInBox(OPTIONEXTRADATA(option).flipIcon, OPTIONEXTRADATA(option).icon, iconStatus, decX, currentY,
					OPTIONEXTRADATA(option).icon->size[0], fontHeight);
			decX += OPTIONEXTRADATA(option).icon->size[0] + fontHeight / 4;
		}

		label = OPTIONEXTRADATA(option).label;
		if (label[0] == '_')
			label = _(label + 1);

		R_Color(textColor);
		UI_DrawString(font, ALIGN_UL, decX, currentY + currentDecY,
			pos[0], node->size[0] - node->padding - node->padding,
			0, label, 0, 0, NULL, qfalse, LONGLINES_PRETTYCHOP);

		/* next entries' position */
		currentY += fontHeight;
		count++;
	}
	R_Color(NULL);
}