void uiTextEntryNode::draw (uiNode_t* node)
{
	const float* textColor;
	vec2_t pos;
	const char* font = UI_GetFontFromNode(node);
	uiSpriteStatus_t iconStatus = SPRITE_STATUS_NORMAL;

	if (node->disabled) {
		textColor = node->disabledColor;
		iconStatus = SPRITE_STATUS_DISABLED;
	} else if (node->state) {
		textColor = node->color;
		iconStatus = SPRITE_STATUS_HOVER;
	} else {
		textColor = node->color;
	}
	if (UI_HasFocus(node)) {
		textColor = node->selectedColor;
	}

	UI_GetNodeAbsPos(node, pos);

	if (EXTRADATA(node).background) {
		UI_DrawSpriteInBox(false, EXTRADATA(node).background, iconStatus, pos[0], pos[1], node->box.size[0], node->box.size[1]);
	}

	if (char const* const text = UI_GetReferenceString(node, node->text)) {
		char  buf[MAX_VAR];
		if (EXTRADATA(node).isPassword) {
			size_t size = UTF8_strlen(text);

			if (size > MAX_VAR - 2)
				size = MAX_VAR - 2;

			memset(buf, HIDECHAR, size);
			buf[size] = '\0';
		} else {
			/* leave one byte empty for the text-based cursor */
			UTF8_strncpyz(buf, text, sizeof(buf) - 1);
		}

		/** @todo Make the cursor into a real graphical object instead of using a text character. */
		if (UI_HasFocus(node)) {
			if (CL_Milliseconds() % 1000 < 500) {
				UTF8_insert_char_at(buf, sizeof(buf), EXTRADATA(node).cursorPosition, (int)CURSOR_ON);
			} else {
				UTF8_insert_char_at(buf, sizeof(buf), EXTRADATA(node).cursorPosition, (int)CURSOR_OFF);
			}
		}

		if (*buf != '\0') {
			R_Color(textColor);
			UI_DrawStringInBox(font, (align_t)node->contentAlign,
				pos[0] + node->padding, pos[1] + node->padding,
				node->box.size[0] - node->padding - node->padding, node->box.size[1] - node->padding - node->padding,
				buf);
			R_Color(nullptr);
		}
	}
}
Exemple #2
0
/**
 * @brief force edition of a textentry node
 * @note the textentry must be on the active window
 */
static void UI_TextEntryNodeFocus (uiNode_t *node, const uiCallContext_t *context)
{
    /* remove the focus to show changes */
    if (!UI_HasFocus(node)) {
        UI_RequestFocus(node);
    }
}
Exemple #3
0
/**
 * @brief Called when the user click with the right mouse button
 */
static void UI_TextEntryNodeClick (uiNode_t *node, int x, int y)
{
    if (node->disabled)
        return;

    /* no cvar */
    if (!node->text)
        return;
    if (!Q_strstart(node->text, "*cvar"))
        return;

    if (!UI_HasFocus(node)) {
        if (node->onClick) {
            UI_ExecuteEventActions(node, node->onClick);
        }
        UI_RequestFocus(node);
    }
}
Exemple #4
0
/**
 * @brief Called when the user click with the right mouse button
 */
static void UI_KeyBindingNodeClick (uiNode_t *node, int x, int y)
{
	if (node->disabled)
		return;

	/* no binding given */
	if (!node->text)
		return;

	if (!Q_strstart(node->text, "*binding"))
		return;

	if (!UI_HasFocus(node)) {
		if (node->onClick)
			UI_ExecuteEventActions(node, node->onClick);
		UI_RequestFocus(node);
	}
}
Exemple #5
0
/**
 * @brief Called when the user click with the right mouse button
 */
void uiTextEntryNode::onLeftClick (uiNode_t* node, int x, int y)
{
	if (node->disabled)
		return;

	/* no cvar */
	if (!node->text)
		return;
	if (!Q_strstart(node->text, "*cvar:"))
		return;

	if (!UI_HasFocus(node)) {
		if (node->onClick) {
			UI_ExecuteEventActions(node, node->onClick);
		}
		if (node->lua_onClick != LUA_NOREF) {
			UI_ExecuteLuaEventScript_XY(node, node->lua_onClick, x, y);
		}
		UI_RequestFocus(node);
	}
}
Exemple #6
0
static void UI_TextEntryNodeDraw (uiNode_t *node)
{
    static const int panelTemplate[] = {
        CORNER_SIZE, MID_SIZE, CORNER_SIZE,
        CORNER_SIZE, MID_SIZE, CORNER_SIZE,
        MARGE
    };
    const char *text;
    int texX, texY;
    const float *textColor;
    const char *image;
    vec2_t pos;
    static vec4_t disabledColor = {0.5, 0.5, 0.5, 1.0};
    const char *font = UI_GetFontFromNode(node);

    if (node->disabled) {
        /** @todo need custom color when node is disabled */
        textColor = disabledColor;
        texX = TILE_SIZE;
        texY = TILE_SIZE;
    } else if (node->state) {
        textColor = node->color;
        texX = TILE_SIZE;
        texY = 0;
    } else {
        textColor = node->color;
        texX = 0;
        texY = 0;
    }
    if (UI_HasFocus(node))
        textColor = node->selectedColor;

    UI_GetNodeAbsPos(node, pos);

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

    text = UI_GetReferenceString(node, node->text);
    if (text != NULL) {
        /** @todo we don't need to edit the text to draw the cursor */
        if (UI_HasFocus(node)) {
            if (CL_Milliseconds() % 1000 < 500) {
                text = va("%s%c", text, CURSOR);
            }
        }

        if (EXTRADATA(node).isPassword) {
            char *c = va("%s", text);
            int size = UTF8_strlen(c);
            text = c;
            /* hide the text with a special char */
            assert(strlen(c) >= size);	/* trustable, but it can't be false */
            while (size) {
                *c++ = HIDECHAR;
                size--;
            }
            /* readd the cursor */
            if (UI_HasFocus(node)) {
                if (CL_Milliseconds() % 1000 < 500) {
                    c--;
                    *c++ = CURSOR;
                }
            }
            *c = '\0';
        }

        if (*text != '\0') {
            R_Color(textColor);
            UI_DrawStringInBox(font, node->textalign,
                               pos[0] + node->padding, pos[1] + node->padding,
                               node->size[0] - node->padding - node->padding, node->size[1] - node->padding - node->padding,
                               text, LONGLINES_PRETTYCHOP);
            R_Color(NULL);
        }
    }

}
Exemple #7
0
static void UI_KeyBindingNodeDraw (uiNode_t *node)
{
	static const int panelTemplate[] = {
		CORNER_SIZE, MID_SIZE, CORNER_SIZE,
		CORNER_SIZE, MID_SIZE, CORNER_SIZE,
		MARGE
	};
	const char *binding, *description, *command;
	int texX, texY;
	const float *textColor;
	const char *image;
	vec2_t pos;
	const char *font = UI_GetFontFromNode(node);
	const int bindingWidth = EXTRADATA(node).bindingWidth;
	const int descriptionWidth = node->size[0] - bindingWidth;
	vec2_t descriptionPos, descriptionSize;
	vec2_t bindingPos, bindingSize;

	if (node->state) {
		textColor = node->color;
		texX = TILE_SIZE;
		texY = 0;
	} else {
		textColor = node->color;
		texX = 0;
		texY = 0;
	}
	if (UI_HasFocus(node))
		textColor = node->selectedColor;

	UI_GetNodeAbsPos(node, pos);

	Vector2Set(descriptionSize, descriptionWidth, node->size[1]);
	Vector2Set(bindingSize, bindingWidth, node->size[1]);
	Vector2Set(descriptionPos, pos[0], pos[1]);
	Vector2Set(bindingPos, pos[0] + descriptionWidth + node->padding, pos[1]);

	image = UI_GetReferenceString(node, node->image);
	if (image) {
		UI_DrawPanel(descriptionPos, descriptionSize, image, texX, texY, panelTemplate);
		UI_DrawPanel(bindingPos, bindingSize, image, texX, texY, panelTemplate);
	}

	binding = UI_GetReferenceString(node, node->text);
	if (Q_strnull(binding))
		binding = _("NONE");

	/** @todo check that this is a keybinding value (with macro expansion) */
	command = node->text + 9;
	description = Cmd_GetCommandDesc(command);
	if (description[0] == '\0')
		description = command;

	R_Color(textColor);

	UI_DrawStringInBox(font, node->contentAlign,
		descriptionPos[0] + node->padding, descriptionPos[1] + node->padding,
		descriptionSize[0] - node->padding - node->padding, descriptionSize[1] - node->padding - node->padding,
		description, LONGLINES_PRETTYCHOP);

	UI_DrawStringInBox(font, node->contentAlign,
		bindingPos[0] + node->padding, bindingPos[1] + node->padding,
		bindingSize[0] - node->padding - node->padding, bindingSize[1] - node->padding - node->padding,
		binding, LONGLINES_PRETTYCHOP);

	R_Color(NULL);
}