/** * @brief Custom tooltip of tab node * @param[in] node Node we request to draw tooltip * @param[in] x Position x of the mouse * @param[in] y Position y of the mouse */ void uiTabNode::drawTooltip (uiNode_t *node, int x, int y) { uiNode_t *option; const int tooltipWidth = 250; option = UI_TabNodeTabAtPosition(node, x, y); if (option == NULL) return; if (!OPTIONEXTRADATA(option).truncated) return; const char *label = CL_Translate(OPTIONEXTRADATA(option).label); UI_DrawTooltip(label, x, y, tooltipWidth); }
/** * @brief Handles tab clicks */ static void UI_TabNodeClick (uiNode_t * node, int x, int y) { uiNode_t* option; if (UI_AbstractOptionGetCurrentValue(node) == NULL) return; option = UI_TabNodeTabAtPosition(node, x, y); if (option == NULL) return; if (option->disabled) return; /* only execute the click stuff if the selectbox is active */ if (node->state) UI_AbstractOptionSetCurrentValue(node, OPTIONEXTRADATA(option).value); }
/** * @brief Custom tooltip of tab node * @param[in] node Node we request to draw tooltip * @param[in] x Position x of the mouse * @param[in] y Position y of the mouse */ static void UI_TabNodeDrawTooltip (uiNode_t *node, int x, int y) { uiNode_t *option; const int tooltipWidth = 250; const char *label; option = UI_TabNodeTabAtPosition(node, x, y); if (option == NULL) return; if (!OPTIONEXTRADATA(option).truncated) return; label = OPTIONEXTRADATA(option).label; if (label[0] == '_') label = _(label + 1); UI_DrawTooltip(label, x, y, tooltipWidth); }
/** * @brief Handles tab clicks */ void uiTabNode::onLeftClick (uiNode_t* node, int x, int y) { uiNode_t* option; if (UI_AbstractOption_GetCurrentValue(node) == nullptr) return; option = UI_TabNodeTabAtPosition(node, x, y); if (option == nullptr) return; if (option->disabled) return; /* only execute the click stuff if the selectbox is active */ if (node->state) UI_AbstractOption_SetCurrentValue(node, OPTIONEXTRADATA(option).value); UI_PlaySound("click1"); }
void uiTabNode::draw (uiNode_t *node) { ui_tabStatus_t lastStatus = UI_TAB_NOTHING; uiNode_t* option; uiNode_t* overMouseOption = NULL; const char *ref; const char *font; int currentX; int allowedWidth; vec2_t pos; const char* image = UI_GetReferenceString(node, node->image); if (!image) image = "ui/tab"; ref = UI_AbstractOptionGetCurrentValue(node); if (ref == NULL) return; font = UI_GetFontFromNode(node); if (node->state) { overMouseOption = UI_TabNodeTabAtPosition(node, mousePosX, mousePosY); } UI_GetNodeAbsPos(node, pos); currentX = pos[0]; option = node->firstChild; assert(option->behaviour == ui_optionBehaviour); /** @todo this dont work when an option is hidden */ allowedWidth = node->box.size[0] - TILE_WIDTH * (EXTRADATA(node).count + 1); while (option) { int fontHeight; int fontWidth; int tabWidth; int textPos; bool drawIcon = false; ui_tabStatus_t status = UI_TAB_NORMAL; assert(option->behaviour == ui_optionBehaviour); /* skip hidden options */ if (option->invis) { option = option->next; continue; } /* Check the status of the current tab */ if (Q_streq(OPTIONEXTRADATA(option).value, ref)) { status = UI_TAB_SELECTED; } else if (option->disabled || node->disabled) { status = UI_TAB_DISABLED; } else if (option == overMouseOption) { status = UI_TAB_HIGHLIGHTED; } /* Display */ UI_TabNodeDrawJunction(image, currentX, pos[1], lastStatus, status); currentX += TILE_WIDTH; const char *label = CL_Translate(OPTIONEXTRADATA(option).label); R_FontTextSize(font, label, 0, LONGLINES_PRETTYCHOP, &fontWidth, &fontHeight, NULL, NULL); tabWidth = fontWidth; if (OPTIONEXTRADATA(option).icon && OPTIONEXTRADATA(option).icon->size[0] < allowedWidth) { tabWidth += OPTIONEXTRADATA(option).icon->size[0]; drawIcon = true; } if (tabWidth > allowedWidth) { if (allowedWidth > 0) tabWidth = allowedWidth; else tabWidth = 0; } if (tabWidth > 0) { UI_TabNodeDrawPlain(image, currentX, pos[1], tabWidth, status); } textPos = currentX; if (drawIcon) { uiSpriteStatus_t iconStatus = SPRITE_STATUS_NORMAL; if (status == UI_TAB_DISABLED) { iconStatus = SPRITE_STATUS_DISABLED; } UI_DrawSpriteInBox(OPTIONEXTRADATA(option).flipIcon, OPTIONEXTRADATA(option).icon, iconStatus, currentX, pos[1], OPTIONEXTRADATA(option).icon->size[0], TILE_HEIGHT); textPos += OPTIONEXTRADATA(option).icon->size[0]; } /** @todo fontWidth can be =0, maybe a bug from the font cache */ OPTIONEXTRADATA(option).truncated = tabWidth < fontWidth || tabWidth == 0; UI_DrawString(font, ALIGN_UL, textPos, pos[1] + ((node->box.size[1] - fontHeight) / 2), textPos, tabWidth + 1, 0, label, 0, 0, NULL, false, LONGLINES_PRETTYCHOP); currentX += tabWidth; allowedWidth -= tabWidth; /* Next */ lastStatus = status; option = option->next; } /* Display last junction and end of header */ UI_TabNodeDrawJunction(image, currentX, pos[1], lastStatus, UI_TAB_NOTHING); currentX += TILE_WIDTH; if (currentX < pos[0] + node->box.size[0]) UI_TabNodeDrawPlain(image, currentX, pos[1], pos[0] + node->box.size[0] - currentX, UI_TAB_NOTHING); }