void uiOptionListNode::draw (uiNode_t* node) { uiNode_t* option; const char* ref; const char* font; int lineHeight; vec2_t pos; int currentY; const float* textColor; int count = 0; ref = UI_AbstractOptionGetCurrentValue(node); if (ref == nullptr) return; UI_GetNodeAbsPos(node, pos); if (EXTRADATA(node).background) { UI_DrawSpriteInBox(false, EXTRADATA(node).background, SPRITE_STATUS_NORMAL, pos[0], pos[1], node->box.size[0], node->box.size[1]); } 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) { int decX = pos[0] + node->padding; /* outside the node */ if (currentY + lineHeight > pos[1] + node->box.size[1] - node->padding) { count++; break; } /* draw the hover effect */ if (OPTIONEXTRADATA(option).hovered) UI_DrawFill(pos[0] + node->padding, currentY, node->box.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 = node->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(nullptr); 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 */ const char* label = CL_Translate(OPTIONEXTRADATA(option).label); R_Color(textColor); UI_DrawString(font, ALIGN_UL, decX, currentY, pos[0], node->box.size[0] - node->padding - node->padding, 0, label, 0, 0, nullptr, false, LONGLINES_PRETTYCHOP); /* next entries' position */ currentY += lineHeight; count++; } R_Color(nullptr); /* 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); }
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); }