/** * @brief Handles Button draw */ static void UI_PanelNodeDraw (uiNode_t *node) { static const int panelTemplate[] = { CORNER_SIZE, MID_SIZE, CORNER_SIZE, CORNER_SIZE, MID_SIZE, CORNER_SIZE, MARGE }; const char *image; vec2_t pos; UI_GetNodeAbsPos(node, pos); image = UI_GetReferenceString(node, node->image); if (image) UI_DrawPanel(pos, node->size, image, 0, 0, panelTemplate); }
/** * @param[in] flip Flip the icon rendering (horizontal) * @param[in] sprite Context sprite * @param[in] status The state of the sprite node * @param[in] posX,posY Absolute X/Y position of the top-left corner * @param[in] sizeX,sizeY Width/height of the bounding box */ void UI_DrawSpriteInBox (bool flip, const uiSprite_t* sprite, uiSpriteStatus_t status, int posX, int posY, int sizeX, int sizeY) { float texX; float texY; const char* image; /** @todo Add warning */ if (status >= SPRITE_STATUS_MAX) return; /** @todo merge all this cases */ if (sprite->single || sprite->blend) { texX = sprite->pos[SPRITE_STATUS_NORMAL][0]; texY = sprite->pos[SPRITE_STATUS_NORMAL][1]; image = sprite->image[SPRITE_STATUS_NORMAL]; } else if (sprite->pack64) { texX = sprite->pos[SPRITE_STATUS_NORMAL][0]; texY = sprite->pos[SPRITE_STATUS_NORMAL][1] + (64 * status); image = sprite->image[SPRITE_STATUS_NORMAL]; } else { texX = sprite->pos[status][0]; texY = sprite->pos[status][1]; image = sprite->image[status]; if (!image) { if (texX == 0 && texY == 0) { texX = sprite->pos[SPRITE_STATUS_NORMAL][0]; texY = sprite->pos[SPRITE_STATUS_NORMAL][1]; image = sprite->image[SPRITE_STATUS_NORMAL]; } else { image = sprite->image[SPRITE_STATUS_NORMAL]; } } } if (!image) return; if (sprite->blend) { const vec_t* color = sprite->color[status]; R_Color(color); } if (sprite->tiled_17_1_3) { const vec2_t pos = Vector2FromInt(posX, posY); const vec2_t size = Vector2FromInt(sizeX, sizeY); UI_DrawPanel(pos, size, image, texX, texY, tile_template_17_1_3); } else if (sprite->tiled_25_1_3) { const vec2_t pos = Vector2FromInt(posX, posY); const vec2_t size = Vector2FromInt(sizeX, sizeY); UI_DrawPanel(pos, size, image, texX, texY, tile_template_25_1_3); } else if (sprite->tiled_popup) { const vec2_t pos = Vector2FromInt(posX, posY); const vec2_t size = Vector2FromInt(sizeX, sizeY); UI_DrawPanel(pos, size, image, texX, texY, tile_template_popup); } else if (sprite->border != 0) { const vec2_t pos = Vector2FromInt(posX, posY); const vec2_t size = Vector2FromInt(sizeX, sizeY); UI_DrawBorderedPanel(pos, size, image, texX, texY, sprite->size[0], sprite->size[1], sprite->border); } else { posX += (sizeX - sprite->size[0]) / 2; posY += (sizeY - sprite->size[1]) / 2; UI_DrawNormImageByName(flip, posX, posY, sprite->size[0], sprite->size[1], texX + sprite->size[0], texY + sprite->size[1], texX, texY, image); } if (sprite->blend) R_Color(nullptr); }
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); } } }
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); }
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); }
static void UI_OptionListNodeDraw (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; int lineHeight; vec2_t pos; const char* image; int currentY; const float *textColor; static vec4_t disabledColor = {0.5, 0.5, 0.5, 1.0}; int count = 0; 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); lineHeight = EXTRADATA(node).lineHeight; if (lineHeight == 0) lineHeight = UI_FontGetHeight(font); currentY = pos[1] + node->padding; /* skip option over current position */ option = UI_AbstractOptionGetFirstOption(node); while (option && count < EXTRADATA(node).scrollY.viewPos) { option = option->next; count++; } /* draw all available options for this selectbox */ for (; option; option = option->next) { const char *label; int decX = pos[0] + node->padding; /* outside the node */ if (currentY + lineHeight > 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, lineHeight, 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; } if (OPTIONEXTRADATA(option).icon) { uiSpriteStatus_t iconStatus = SPRITE_STATUS_NORMAL; if (option->disabled) iconStatus = SPRITE_STATUS_DISABLED; R_Color(NULL); UI_DrawSpriteInBox(OPTIONEXTRADATA(option).flipIcon, OPTIONEXTRADATA(option).icon, iconStatus, decX, currentY, OPTIONEXTRADATA(option).icon->size[0], lineHeight); decX += OPTIONEXTRADATA(option).icon->size[0] + lineHeight / 4; } /* print the option label */ label = OPTIONEXTRADATA(option).label; if (label[0] == '_') label = _(label + 1); R_Color(textColor); UI_DrawString(font, ALIGN_UL, decX, currentY, pos[0], node->size[0] - node->padding - node->padding, 0, label, 0, 0, NULL, qfalse, LONGLINES_PRETTYCHOP); /* next entries' position */ currentY += lineHeight; count++; } R_Color(NULL); /* count number of options (current architecture doesn't allow to know if the data change) */ for (; option; option = option->next) { count++; } if (EXTRADATA(node).count != count) { EXTRADATA(node).count = count; } UI_OptionListNodeUpdateScroll(node); }
/** * @brief Handles Button draw */ static void UI_ButtonNodeDraw (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}; int iconPadding = 0; uiSpriteStatus_t iconStatus = SPRITE_STATUS_NORMAL; const char *font = UI_GetFontFromNode(node); if (!node->onClick || node->disabled) { /** @todo need custom color when button is disabled */ textColor = disabledColor; texX = TILE_SIZE; texY = TILE_SIZE; iconStatus = SPRITE_STATUS_DISABLED; } else if (node->state) { textColor = node->selectedColor; texX = TILE_SIZE; texY = 0; iconStatus = SPRITE_STATUS_HOVER; } else { textColor = node->color; texX = 0; texY = 0; } UI_GetNodeAbsPos(node, pos); image = UI_GetReferenceString(node, node->image); if (image) UI_DrawPanel(pos, node->size, image, texX, texY, panelTemplate); /* display the icon at the left */ /** @todo should we move it according to the text align? */ if (EXTRADATA(node).icon) { /* use at least a box size equals to button height */ int size = node->size[1] - node->padding - node->padding; if (size < EXTRADATA(node).icon->size[0]) size = EXTRADATA(node).icon->size[0]; UI_DrawSpriteInBox(EXTRADATA(node).flipIcon, EXTRADATA(node).icon, iconStatus, pos[0] + node->padding, pos[1] + node->padding, size, node->size[1] - node->padding - node->padding); iconPadding = size + node->padding; } text = UI_GetReferenceString(node, node->text); if (text != NULL && *text != '\0') { R_Color(textColor); text = _(text); UI_DrawStringInBox(font, node->contentAlign, pos[0] + node->padding + iconPadding, pos[1] + node->padding, node->size[0] - node->padding - node->padding - iconPadding, node->size[1] - node->padding - node->padding, text, LONGLINES_PRETTYCHOP); R_Color(NULL); } }