예제 #1
0
파일: ui_nodes.c 프로젝트: chrisglass/ufoai
/**
 * @brief Return the first visible node at a position
 * @param[in] node Node where we must search
 * @param[in] rx Relative x position to the parent of the node
 * @param[in] ry Relative y position to the parent of the node
 * @return The first visible node at position, else NULL
 */
static uiNode_t *UI_GetNodeInTreeAtPosition (uiNode_t *node, int rx, int ry)
{
	uiNode_t *find;

	if (node->invis || node->behaviour->isVirtual || !UI_CheckVisibility(node))
		return NULL;

	/* relative to the node */
	rx -= node->pos[0];
	ry -= node->pos[1];

	/* check bounding box */
	if (rx < 0 || ry < 0 || rx >= node->size[0] || ry >= node->size[1])
		return NULL;

	/** @todo we should improve the loop (last-to-first) */
	find = NULL;
	if (node->firstChild) {
		uiNode_t *child;
		vec2_t clientPosition = {0, 0};

		if (node->behaviour->getClientPosition)
			node->behaviour->getClientPosition(node, clientPosition);

		rx -= clientPosition[0];
		ry -= clientPosition[1];

		for (child = node->firstChild; child; child = child->next) {
			uiNode_t *tmp;
			tmp = UI_GetNodeInTreeAtPosition(child, rx, ry);
			if (tmp)
				find = tmp;
		}

		rx += clientPosition[0];
		ry += clientPosition[1];
	}
	if (find)
		return find;

	/* disable ghost/excluderect in debug mode 2 */
	if (UI_DebugMode() != 2) {
		int i;
		/* is the node tangible */
		if (node->ghost)
			return NULL;

		/* check excluded box */
		for (i = 0; i < node->excludeRectNum; i++) {
			if (rx >= node->excludeRect[i].pos[0]
			 && rx < node->excludeRect[i].pos[0] + node->excludeRect[i].size[0]
			 && ry >= node->excludeRect[i].pos[1]
			 && ry < node->excludeRect[i].pos[1] + node->excludeRect[i].size[1])
				return NULL;
		}
	}

	/* we are over the node */
	return node;
}
예제 #2
0
/**
 * @brief Return the first visible node at a position
 * @param[in] node Node where we must search
 * @param[in] rx Relative x position to the parent of the node
 * @param[in] ry Relative y position to the parent of the node
 * @return The first visible node at position, else nullptr
 */
static uiNode_t *UI_GetNodeInTreeAtPosition (uiNode_t *node, int rx, int ry)
{
	uiNode_t *find;

	if (node->invis || UI_Node_IsVirtual(node) || !UI_CheckVisibility(node))
		return nullptr;

	/* relative to the node */
	rx -= node->box.pos[0];
	ry -= node->box.pos[1];

	/* check bounding box */
	if (rx < 0 || ry < 0 || rx >= node->box.size[0] || ry >= node->box.size[1])
		return nullptr;

	/** @todo we should improve the loop (last-to-first) */
	find = nullptr;
	if (node->firstChild) {
		uiNode_t *child;
		vec2_t clientPosition = {0, 0};

		if (UI_Node_IsScrollableContainer(node))
			UI_Node_GetClientPosition(node, clientPosition);

		rx -= clientPosition[0];
		ry -= clientPosition[1];

		for (child = node->firstChild; child; child = child->next) {
			uiNode_t *tmp;
			tmp = UI_GetNodeInTreeAtPosition(child, rx, ry);
			if (tmp)
				find = tmp;
		}

		rx += clientPosition[0];
		ry += clientPosition[1];
	}
	if (find)
		return find;

	/* disable ghost/excluderect in debug mode 2 */
	if (UI_DebugMode() != 2) {
		uiExcludeRect_t *excludeRect;
		/* is the node tangible */
		if (node->ghost)
			return nullptr;

		/* check excluded box */
		for (excludeRect = node->firstExcludeRect; excludeRect != nullptr; excludeRect = excludeRect->next) {
			if (rx >= excludeRect->pos[0]
			 && rx < excludeRect->pos[0] + excludeRect->size[0]
			 && ry >= excludeRect->pos[1]
			 && ry < excludeRect->pos[1] + excludeRect->size[1])
				return nullptr;
		}
	}

	/* we are over the node */
	return node;
}