void uiSelectBoxNode::draw (uiNode_t* node) { uiNode_t* option; int selBoxX, selBoxY; const char* ref; const char* font; vec2_t nodepos; const char* imageName; const image_t* image; static vec4_t invisColor = {1.0, 1.0, 1.0, 0.7}; ref = UI_AbstractOptionGetCurrentValue(node); if (ref == nullptr) return; UI_GetNodeAbsPos(node, nodepos); imageName = UI_GetReferenceString(node, node->image); if (!imageName) imageName = "ui/selectbox"; image = UI_LoadImage(imageName); font = UI_GetFontFromNode(node); selBoxX = nodepos[0] + SELECTBOX_SIDE_WIDTH; selBoxY = nodepos[1] + SELECTBOX_SPACER; /* left border */ UI_DrawNormImage(false, nodepos[0], nodepos[1], SELECTBOX_SIDE_WIDTH, node->box.size[1], SELECTBOX_SIDE_WIDTH, SELECTBOX_DEFAULT_HEIGHT, 0.0f, 0.0f, image); /* stretched middle bar */ UI_DrawNormImage(false, nodepos[0] + SELECTBOX_SIDE_WIDTH, nodepos[1], node->box.size[0]-SELECTBOX_SIDE_WIDTH-SELECTBOX_RIGHT_WIDTH, node->box.size[1], 12.0f, SELECTBOX_DEFAULT_HEIGHT, 7.0f, 0.0f, image); /* right border (arrow) */ UI_DrawNormImage(false, nodepos[0] + node->box.size[0] - SELECTBOX_RIGHT_WIDTH, nodepos[1], SELECTBOX_DEFAULT_HEIGHT, node->box.size[1], 12.0f + SELECTBOX_RIGHT_WIDTH, SELECTBOX_DEFAULT_HEIGHT, 12.0f, 0.0f, image); /* draw the label for the current selected option */ for (option = UI_AbstractOptionGetFirstOption(node); option; option = option->next) { if (!Q_streq(OPTIONEXTRADATA(option).value, ref)) continue; if (option->invis) R_Color(invisColor); const char* label = CL_Translate(OPTIONEXTRADATA(option).label); UI_DrawString(font, ALIGN_UL, selBoxX, selBoxY, selBoxX, node->box.size[0] - 4, 0, label, 0, 0, nullptr, false, LONGLINES_PRETTYCHOP); R_Color(nullptr); break; } /* must we draw the drop-down list */ if (UI_GetMouseCapture() == node) { UI_CaptureDrawOver(node); } }
/** * @param node The node to draw */ void uiMaterialEditorNode::draw (uiNode_t *node) { int i; vec2_t pos; int cnt = 0; int cntView = 0; const int imagesPerLine = (node->box.size[0] - node->padding) / (IMAGE_WIDTH + node->padding); if (isSizeChange(node)) updateView(node, false); /* width too small to display anything */ if (imagesPerLine <= 0) return; UI_GetNodeAbsPos(node, pos); /* display images */ for (i = 0; i < r_numImages; i++) { image_t *image = R_GetImageAtIndex(i); vec2_t imagepos; #ifndef ANYIMAGES /* filter */ if (image->type != it_world) continue; if (strstr(image->name, "tex_common")) continue; #endif /* skip images before the scroll position */ if (cnt / imagesPerLine < EXTRADATA(node).scrollY.viewPos) { cnt++; continue; } /** @todo do it incremental. Don't need all this math */ imagepos[0] = pos[0] + node->padding + (cntView % imagesPerLine) * (IMAGE_WIDTH + node->padding); imagepos[1] = pos[1] + node->padding + (cntView / imagesPerLine) * (IMAGE_WIDTH + node->padding); /* vertical overflow */ if (imagepos[1] + IMAGE_WIDTH + node->padding >= pos[1] + node->box.size[1]) break; if (i == node->num) { #define MARGIN 3 UI_DrawRect(imagepos[0] - MARGIN, imagepos[1] - MARGIN, IMAGE_WIDTH + MARGIN * 2, IMAGE_WIDTH + MARGIN * 2, node->selectedColor, 2, 0xFFFF); #undef MARGIN } UI_DrawNormImage(false, imagepos[0], imagepos[1], IMAGE_WIDTH, IMAGE_WIDTH, 0, 0, 0, 0, image); cnt++; cntView++; } }
/** * @brief draw a panel from a texture as we can see on the image * @image html http://ufoai.org/wiki/images/Inline_draw_panel.png * @param[in] pos Position of the output panel * @param[in] size Size of the output panel * @param[in] texture Texture contain the template of the panel * @param[in] texX Position x of the panel template into the texture * @param[in] texY Position y of the panel template into the texture * @param[in] panelDef Array of seven elements define the panel template used in the texture. * From the first to the last: left width, mid width, right width, * top height, mid height, bottom height, and margin * @todo can we improve the code? is it need? */ void UI_DrawPanel (const vec2_t pos, const vec2_t size, const char* texture, int texX, int texY, const int panelDef[7]) { const image_t* image = UI_LoadImage(texture); if (!image) return; const int leftWidth = panelDef[0]; const int midWidth = panelDef[1]; const int rightWidth = panelDef[2]; const int topHeight = panelDef[3]; const int midHeight = panelDef[4]; const int bottomHeight = panelDef[5]; const int marge = panelDef[6]; /** @todo merge texX and texY here */ const int firstPos = 0; const int secondPos = firstPos + leftWidth + marge; const int thirdPos = secondPos + midWidth + marge; const int firstPosY = 0; const int secondPosY = firstPosY + topHeight + marge; const int thirdPosY = secondPosY + midHeight + marge; /* draw top (from left to right) */ UI_DrawNormImage(false, pos[0], pos[1], leftWidth, topHeight, texX + firstPos + leftWidth, texY + firstPosY + topHeight, texX + firstPos, texY + firstPosY, image); UI_DrawNormImage(false, pos[0] + leftWidth, pos[1], size[0] - leftWidth - rightWidth, topHeight, texX + secondPos + midWidth, texY + firstPosY + topHeight, texX + secondPos, texY + firstPosY, image); UI_DrawNormImage(false, pos[0] + size[0] - rightWidth, pos[1], rightWidth, topHeight, texX + thirdPos + rightWidth, texY + firstPosY + topHeight, texX + thirdPos, texY + firstPosY, image); /* draw middle (from left to right) */ const int yMiddle = pos[1] + topHeight; const int hMiddle = size[1] - topHeight - bottomHeight; /* height of middle */ UI_DrawNormImage(false, pos[0], yMiddle, leftWidth, hMiddle, texX + firstPos + leftWidth, texY + secondPosY + midHeight, texX + firstPos, texY + secondPosY, image); UI_DrawNormImage(false, pos[0] + leftWidth, yMiddle, size[0] - leftWidth - rightWidth, hMiddle, texX + secondPos + midWidth, texY + secondPosY + midHeight, texX + secondPos, texY + secondPosY, image); UI_DrawNormImage(false, pos[0] + size[0] - rightWidth, yMiddle, rightWidth, hMiddle, texX + thirdPos + rightWidth, texY + secondPosY + midHeight, texX + thirdPos, texY + secondPosY, image); /* draw bottom (from left to right) */ const int yBottom = pos[1] + size[1] - bottomHeight; UI_DrawNormImage(false, pos[0], yBottom, leftWidth, bottomHeight, texX + firstPos + leftWidth, texY + thirdPosY + bottomHeight, texX + firstPos, texY + thirdPosY, image); UI_DrawNormImage(false, pos[0] + leftWidth, yBottom, size[0] - leftWidth - rightWidth, bottomHeight, texX + secondPos + midWidth, texY + thirdPosY + bottomHeight, texX + secondPos, texY + thirdPosY, image); UI_DrawNormImage(false, pos[0] + size[0] - bottomHeight, yBottom, rightWidth, bottomHeight, texX + thirdPos + rightWidth, texY + thirdPosY + bottomHeight, texX + thirdPos, texY + thirdPosY, image); }
/** * @brief draw a panel from a texture as we can see on the image * @image html http://ufoai.org/wiki/images/Inline_draw_panel.png * @param[in] pos Position of the output panel * @param[in] size Size of the output panel * @param[in] texture Texture contain the template of the panel * @param[in] texX,texY Position of the panel template into the texture * @param[in] texW,texH Width/height of the panel template into the texture * @param[in] border Size of unscalable border * From the first to the last: left width, mid width, right width, * top height, mid height, bottom height, and margin * @todo can we improve the code? is it need? */ void UI_DrawBorderedPanel (const vec2_t pos, const vec2_t size, const char* texture, int texX, int texY, int texW, int texH, int border) { const image_t* image = UI_LoadImage(texture); if (!image) return; const int leftWidth = border; const int midWidth = texW - 2 * border; const int rightWidth = border; const int topHeight = border; const int midHeight = texH - 2 * border; const int bottomHeight = border; const int marge = 0; const int firstPos = texX; const int secondPos = firstPos + leftWidth + marge; const int thirdPos = secondPos + midWidth + marge; const int firstPosY = texY; const int secondPosY = firstPosY + topHeight + marge; const int thirdPosY = secondPosY + midHeight + marge; /* draw top (from left to right) */ UI_DrawNormImage(false, pos[0], pos[1], leftWidth, topHeight, firstPos + leftWidth, firstPosY + topHeight, firstPos, firstPosY, image); UI_DrawNormImage(false, pos[0] + leftWidth, pos[1], size[0] - leftWidth - rightWidth, topHeight, secondPos + midWidth, firstPosY + topHeight, secondPos, firstPosY, image); UI_DrawNormImage(false, pos[0] + size[0] - rightWidth, pos[1], rightWidth, topHeight, thirdPos + rightWidth, firstPosY + topHeight, thirdPos, firstPosY, image); /* draw middle (from left to right) */ const int yMiddle = pos[1] + topHeight; const int hMiddle = size[1] - topHeight - bottomHeight; /* height of middle */ UI_DrawNormImage(false, pos[0], yMiddle, leftWidth, hMiddle, firstPos + leftWidth, secondPosY + midHeight, firstPos, secondPosY, image); UI_DrawNormImage(false, pos[0] + leftWidth, yMiddle, size[0] - leftWidth - rightWidth, hMiddle, secondPos + midWidth, secondPosY + midHeight, secondPos, secondPosY, image); UI_DrawNormImage(false, pos[0] + size[0] - rightWidth, yMiddle, rightWidth, hMiddle, thirdPos + rightWidth, secondPosY + midHeight, thirdPos, secondPosY, image); /* draw bottom (from left to right) */ const int yBottom = pos[1] + size[1] - bottomHeight; UI_DrawNormImage(false, pos[0], yBottom, leftWidth, bottomHeight, firstPos + leftWidth, thirdPosY + bottomHeight, firstPos, thirdPosY, image); UI_DrawNormImage(false, pos[0] + leftWidth, yBottom, size[0] - leftWidth - rightWidth, bottomHeight, secondPos + midWidth, thirdPosY + bottomHeight, secondPos, thirdPosY, image); UI_DrawNormImage(false, pos[0] + size[0] - bottomHeight, yBottom, rightWidth, bottomHeight, thirdPos + rightWidth, thirdPosY + bottomHeight, thirdPos, thirdPosY, image); }
/** * @brief Draws an image or parts of it * @param[in] flip Flip the icon rendering (horizontal) * @param[in] x,y position to draw the image to * @param[in] w Width of the image * @param[in] h Height of the image * @param[in] sh Right x corner coord of the square to draw * @param[in] th Lower y corner coord of the square to draw * @param[in] sl Left x corner coord of the square to draw * @param[in] tl Upper y corner coord of the square to draw * @param[in] name The name of the image - relative to base/pics * @sa R_RegisterImage * @note All these parameter are normalized to VID_NORM_WIDTH and VID_NORM_HEIGHT * they are adjusted in this function */ const image_t* UI_DrawNormImageByName (bool flip, float x, float y, float w, float h, float sh, float th, float sl, float tl, const char* name) { const struct image_s* image; image = UI_LoadImage(name); if (!image) { Com_Printf("Can't find pic: %s\n", name); return nullptr; } UI_DrawNormImage(flip, x, y, w, h, sh, th, sl, tl, image); return image; }
/** * @brief Draws the texture node * @param[in] node The UI node to draw */ void uiTextureNode::draw (uiNode_t* node) { vec2_t nodepos; const image_t* image; const char* imageName = UI_GetReferenceString(node, node->image); if (Q_strnull(imageName)) return; image = UI_LoadWrappedImage(imageName); if (!image) return; /* avoid potential infinit loop */ if (image->height == 0 || image->width == 0) return; UI_GetNodeAbsPos(node, nodepos); UI_DrawNormImage(false, nodepos[0], nodepos[1], node->box.size[0], node->box.size[1], node->box.size[0], node->box.size[1], 0, 0, image); }
/** * @brief Call to draw the node */ static void UI_VScrollbarNodeDraw (uiNode_t *node) { vec2_t pos; int y = 0; int texX = 0; int texY = 0; const char *texture; const image_t *image; UI_GetNodeAbsPos(node, pos); y = pos[1]; texture = UI_GetReferenceString(node, node->image); if (!texture) return; image = UI_LoadImage(texture); if (EXTRADATA(node).fullsize == 0 || EXTRADATA(node).fullsize <= EXTRADATA(node).viewsize) { /* hide the scrollbar */ if (EXTRADATA(node).hideWhenUnused) return; texX = TILE_WIDTH * 3; /* top */ UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, ELEMENT_HEIGHT, texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); texY += TILE_HEIGHT; y += ELEMENT_HEIGHT; /* top to bottom */ UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, node->size[1] - (ELEMENT_HEIGHT * 2), texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); texY += TILE_HEIGHT * 5; y += node->size[1] - (ELEMENT_HEIGHT * 2); assert(y == pos[1] + node->size[1] - ELEMENT_HEIGHT); /* bottom */ UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, ELEMENT_HEIGHT, texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); } else { int houveredElement = -1; int description[5]; UI_VScrollbarNodeGetElementSize(node, description); if (UI_GetMouseCapture() == node) houveredElement = capturedElement; else if (node->state) houveredElement = UI_VScrollbarNodeGetElement(node, description, mousePosX, mousePosY); /* top */ texX = (houveredElement == 0)?TILE_WIDTH:0; UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, ELEMENT_HEIGHT, texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); texY += TILE_HEIGHT; y += ELEMENT_HEIGHT; /* top to slider */ if (description[1]) { texX = (houveredElement == 1)?TILE_WIDTH:0; UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, description[1], texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); y += description[1]; } texY += TILE_HEIGHT; /* slider */ texX = (houveredElement == 2)?TILE_WIDTH:0; /* top slider */ UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, ELEMENT_HEIGHT, texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); texY += TILE_HEIGHT; y += ELEMENT_HEIGHT; /* middle slider */ if (description[2]) { UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, description[2]-ELEMENT_HEIGHT-ELEMENT_HEIGHT, texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); y += description[2]-ELEMENT_HEIGHT-ELEMENT_HEIGHT; } texY += TILE_HEIGHT; /* bottom slider */ UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, ELEMENT_HEIGHT, texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); texY += TILE_HEIGHT; y += ELEMENT_HEIGHT; /* slider to bottom */ if (description[3]) { texX = (houveredElement == 3)?TILE_WIDTH:0; UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, description[3], texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); y += description[3]; } texY += TILE_HEIGHT; assert(y == pos[1] + node->size[1] - ELEMENT_HEIGHT); /* bottom */ texX = (houveredElement == 4)?TILE_WIDTH:0; UI_DrawNormImage(qfalse, pos[0], y, ELEMENT_WIDTH, ELEMENT_HEIGHT, texX + ELEMENT_WIDTH, texY + ELEMENT_HEIGHT, texX, texY, image); } }
void uiEkgNode::draw (uiNode_t *node) { vec2_t size; vec2_t nodepos; const image_t *image; const char* imageName = UI_GetReferenceString(node, EXTRADATA(node).super.source); if (Q_strnull(imageName)) return; UI_GetNodeAbsPos(node, nodepos); image = UI_LoadWrappedImage(imageName); if (image) { const int ekgHeight = node->box.size[1]; const int ekgWidth = image->width; /* we have different ekg parts in each ekg image... */ const int ekgImageParts = image->height / node->box.size[1]; const int ekgMaxIndex = ekgImageParts - 1; /* we change the index of the image part in 20s steps */ /** @todo this magic number should be replaced with a sane calculation of the value */ const int ekgDivide = 20; /* If we are in the range of (ekgMaxValue + ekgDivide, ekgMaxValue) we are using the first image */ const int ekgMaxValue = ekgDivide * ekgMaxIndex; int ekgValue; float current; /** @todo these cvars should come from the script */ /* ekg_morale and ekg_hp are the node names */ if (node->name[0] == 'm') current = Cvar_GetValue("mn_morale") / EXTRADATA(node).scaleCvarValue; else current = Cvar_GetValue("mn_hp") / EXTRADATA(node).scaleCvarValue; ekgValue = std::min((int)current, ekgMaxValue); EXTRADATA(node).super.texl[1] = (ekgMaxIndex - (int)(ekgValue / ekgDivide)) * ekgHeight; EXTRADATA(node).super.texh[1] = EXTRADATA(node).super.texl[1] + ekgHeight; EXTRADATA(node).super.texl[0] = -(int) (EXTRADATA(node).scrollSpeed * CL_Milliseconds()) % ekgWidth; EXTRADATA(node).super.texh[0] = EXTRADATA(node).super.texl[0] + node->box.size[0]; /** @todo code is duplicated in the image node code */ if (node->box.size[0] && !node->box.size[1]) { const float scale = image->width / node->box.size[0]; Vector2Set(size, node->box.size[0], image->height / scale); } else if (node->box.size[1] && !node->box.size[0]) { const float scale = image->height / node->box.size[1]; Vector2Set(size, image->width / scale, node->box.size[1]); } else { if (EXTRADATA(node).super.preventRatio) { /* maximize the image into the bounding box */ const float ratio = (float) image->width / (float) image->height; if (node->box.size[1] * ratio > node->box.size[0]) { Vector2Set(size, node->box.size[0], node->box.size[0] / ratio); } else { Vector2Set(size, node->box.size[1] * ratio, node->box.size[1]); } } else { Vector2Copy(node->box.size, size); } } UI_DrawNormImage(false, nodepos[0], nodepos[1], size[0], size[1], EXTRADATA(node).super.texh[0], EXTRADATA(node).super.texh[1], EXTRADATA(node).super.texl[0], EXTRADATA(node).super.texl[1], image); } }
void uiSelectBoxNode::drawOverWindow (uiNode_t* node) { const char* ref = UI_AbstractOptionGetCurrentValue(node); if (ref == nullptr) return; vec2_t nodepos; UI_GetNodeAbsPos(node, nodepos); const char* imageName = UI_GetReferenceString(node, node->image); if (!imageName) imageName = "ui/selectbox"; const image_t* image = UI_LoadImage(imageName); const char* font = UI_GetFontFromNode(node); int selBoxX = nodepos[0] + SELECTBOX_SIDE_WIDTH; int selBoxY = nodepos[1] + SELECTBOX_SPACER; selBoxY += node->box.size[1]; /* drop down list */ /* left side */ UI_DrawNormImage(false, nodepos[0], nodepos[1] + node->box.size[1], SELECTBOX_SIDE_WIDTH, node->box.size[1] * EXTRADATA(node).count, 7.0f, 28.0f, 0.0f, 21.0f, image); /* stretched middle bar */ UI_DrawNormImage(false, nodepos[0] + SELECTBOX_SIDE_WIDTH, nodepos[1] + node->box.size[1], node->box.size[0] -SELECTBOX_SIDE_WIDTH-SELECTBOX_RIGHT_WIDTH, node->box.size[1] * EXTRADATA(node).count, 16.0f, 28.0f, 7.0f, 21.0f, image); /* right side */ UI_DrawNormImage(false, nodepos[0] + node->box.size[0] -SELECTBOX_SIDE_WIDTH-SELECTBOX_RIGHT_WIDTH, nodepos[1] + node->box.size[1], SELECTBOX_SIDE_WIDTH, node->box.size[1] * EXTRADATA(node).count, 23.0f, 28.0f, 16.0f, 21.0f, image); /* now draw all available options for this selectbox */ int check = 0; for (uiNode_t* option = UI_AbstractOptionGetFirstOption(node); option; option = option->next) { if (option->invis) continue; /* draw the hover effect */ if (OPTIONEXTRADATA(option).hovered) UI_DrawFill(selBoxX, selBoxY, node->box.size[0] -SELECTBOX_SIDE_WIDTH - SELECTBOX_SIDE_WIDTH - SELECTBOX_RIGHT_WIDTH, SELECTBOX_DEFAULT_HEIGHT, node->color); /* print the option label */ const char* label = CL_Translate(OPTIONEXTRADATA(option).label); UI_DrawString(font, ALIGN_UL, selBoxX, selBoxY, selBoxX, node->box.size[0] - 4, 0, label, 0, 0, nullptr, false, LONGLINES_PRETTYCHOP); /* next entries' position */ selBoxY += node->box.size[1]; check++; } /** detect inconsistency */ if (check != EXTRADATA(node).count) { /** force clean up cache */ Com_Printf("uiSelectBoxNode::drawOverWindow: Node '%s' contains unsynchronized option list. Fixed.\n", UI_GetPath(node)); EXTRADATA(node).versionId = 0; } /* left side */ UI_DrawNormImage(false, nodepos[0], selBoxY - SELECTBOX_SPACER, SELECTBOX_SIDE_WIDTH, SELECTBOX_BOTTOM_HEIGHT, 7.0f, 32.0f, 0.0f, 28.0f, image); /* stretched middle bar */ UI_DrawNormImage(false, nodepos[0] + SELECTBOX_SIDE_WIDTH, selBoxY - SELECTBOX_SPACER, node->box.size[0] - SELECTBOX_SIDE_WIDTH - SELECTBOX_RIGHT_WIDTH, SELECTBOX_BOTTOM_HEIGHT, 16.0f, 32.0f, 7.0f, 28.0f, image); /* right bottom side */ UI_DrawNormImage(false, nodepos[0] + node->box.size[0] - SELECTBOX_SIDE_WIDTH - SELECTBOX_RIGHT_WIDTH, selBoxY - SELECTBOX_SPACER, SELECTBOX_SIDE_WIDTH, SELECTBOX_BOTTOM_HEIGHT, 23.0f, 32.0f, 16.0f, 28.0f, image); }
static void UI_SelectBoxNodeDrawOverWindow (uiNode_t *node) { uiNode_t* option; int selBoxX, selBoxY; const char *ref; const char *font; vec2_t nodepos; const char* imageName; const image_t *image; ref = UI_AbstractOptionGetCurrentValue(node); if (ref == NULL) return; UI_GetNodeAbsPos(node, nodepos); imageName = UI_GetReferenceString(node, node->image); if (!imageName) imageName = "ui/selectbox"; image = UI_LoadImage(imageName); font = UI_GetFontFromNode(node); selBoxX = nodepos[0] + SELECTBOX_SIDE_WIDTH; selBoxY = nodepos[1] + SELECTBOX_SPACER; selBoxY += node->size[1]; /* drop down list */ /* left side */ UI_DrawNormImage(nodepos[0], nodepos[1] + node->size[1], SELECTBOX_SIDE_WIDTH, node->size[1] * EXTRADATA(node).count, 7.0f, 28.0f, 0.0f, 21.0f, image); /* stretched middle bar */ UI_DrawNormImage(nodepos[0] + SELECTBOX_SIDE_WIDTH, nodepos[1] + node->size[1], node->size[0] -SELECTBOX_SIDE_WIDTH-SELECTBOX_RIGHT_WIDTH, node->size[1] * EXTRADATA(node).count, 16.0f, 28.0f, 7.0f, 21.0f, image); /* right side */ UI_DrawNormImage(nodepos[0] + node->size[0] -SELECTBOX_SIDE_WIDTH-SELECTBOX_RIGHT_WIDTH, nodepos[1] + node->size[1], SELECTBOX_SIDE_WIDTH, node->size[1] * EXTRADATA(node).count, 23.0f, 28.0f, 16.0f, 21.0f, image); /* now draw all available options for this selectbox */ for (option = UI_AbstractOptionGetFirstOption(node); option; option = option->next) { const char *label; if (option->invis) continue; /* draw the hover effect */ if (OPTIONEXTRADATA(option).hovered) UI_DrawFill(selBoxX, selBoxY, node->size[0] -SELECTBOX_SIDE_WIDTH - SELECTBOX_SIDE_WIDTH - SELECTBOX_RIGHT_WIDTH, SELECTBOX_DEFAULT_HEIGHT, node->color); /* print the option label */ label = OPTIONEXTRADATA(option).label; if (label[0] == '_') label = _(label + 1); UI_DrawString(font, ALIGN_UL, selBoxX, selBoxY, selBoxX, node->size[0] - 4, 0, label, 0, 0, NULL, qfalse, LONGLINES_PRETTYCHOP); /* next entries' position */ selBoxY += node->size[1]; } /* left side */ UI_DrawNormImage(nodepos[0], selBoxY - SELECTBOX_SPACER, SELECTBOX_SIDE_WIDTH, SELECTBOX_BOTTOM_HEIGHT, 7.0f, 32.0f, 0.0f, 28.0f, image); /* stretched middle bar */ UI_DrawNormImage(nodepos[0] + SELECTBOX_SIDE_WIDTH, selBoxY - SELECTBOX_SPACER, node->size[0] - SELECTBOX_SIDE_WIDTH - SELECTBOX_RIGHT_WIDTH, SELECTBOX_BOTTOM_HEIGHT, 16.0f, 32.0f, 7.0f, 28.0f, image); /* right bottom side */ UI_DrawNormImage(nodepos[0] + node->size[0] - SELECTBOX_SIDE_WIDTH - SELECTBOX_RIGHT_WIDTH, selBoxY - SELECTBOX_SPACER, SELECTBOX_SIDE_WIDTH, SELECTBOX_BOTTOM_HEIGHT, 23.0f, 32.0f, 16.0f, 28.0f, image); }
/** * @brief Draws the image node * @param[in] node The UI node to draw */ void uiImageNode::draw (uiNode_t* node) { vec2_t size; vec2_t nodepos; const image_t* image; vec2_t imagepos; vec2_t nodesize; const char* imageName = UI_GetReferenceString(node, node->image); if (Q_strnull(imageName)) return; image = UI_LoadImage(imageName); if (!image) return; /* mouse darken effect */ /** @todo convert all pic using mousefx into button. * @todo delete mousefx */ #if 0 if (node->mousefx && node->state) { vec4_t color; VectorScale(node->color, 0.8, color); color[3] = node->color[3]; R_Color(color); } #endif UI_GetNodeAbsPos(node, nodepos); Vector2Copy(node->box.size, nodesize); nodesize[0] -= node->padding + node->padding; if (nodesize[0] < 0) nodesize[0] = 0; nodesize[1] -= node->padding + node->padding; if (nodesize[1] < 0) nodesize[1] = 0; /** @todo code is duplicated in the ekg node code */ if (node->box.size[0] && !node->box.size[1]) { const float scale = image->width / node->box.size[0]; Vector2Set(size, node->box.size[0], image->height / scale); } else if (node->box.size[1] && !node->box.size[0]) { const float scale = image->height / node->box.size[1]; Vector2Set(size, image->width / scale, node->box.size[1]); } else { Vector2Copy(nodesize, size); if (EXTRADATA(node).preventRatio) { /* maximize the image into the bounding box */ const float ratio = (float) image->width / (float) image->height; if (size[1] * ratio > size[0]) { Vector2Set(size, size[0], size[0] / ratio); } else { Vector2Set(size, size[1] * ratio, size[1]); } } } UI_ImageAlignBoxInBox(nodepos, nodesize, size, (align_t) node->contentAlign, imagepos); UI_DrawNormImage(false, imagepos[0] + node->padding, imagepos[1] + node->padding, size[0], size[1], EXTRADATA(node).texh[0], EXTRADATA(node).texh[1], EXTRADATA(node).texl[0], EXTRADATA(node).texl[1], image); /** @todo convert all pic using mousefx into button. * @todo delete mousefx */ #if 0 if (node->mousefx && node->state) { R_Color(nullptr); } #endif }