/** * @brief Draw an item node */ void uiItemNode::draw (uiNode_t* node) { const objDef_t* od; const char* ref = UI_GetReferenceString(node, EXTRADATA(node).model); vec2_t pos; if (Q_strnull(ref)) return; UI_GetNodeAbsPos(node, pos); R_CleanupDepthBuffer(pos[0], pos[1], node->box.size[0], node->box.size[1]); od = INVSH_GetItemByIDSilent(ref); if (od) { Item item(od, nullptr, 1); /* 1 so it's not reddish; fake item anyway */ const char* model = GAME_GetModelForItem(item.def(), nullptr); if (EXTRADATA(node).containerLike || Q_strnull(model)) { const vec4_t color = {1, 1, 1, 1}; vec3_t itemNodePos; /* We position the model of the item ourself (in the middle of the item * node). See the "-1, -1" parameter of UI_DrawItem. */ UI_GetNodeAbsPos(node, itemNodePos); itemNodePos[0] += node->box.size[0] / 2.0; itemNodePos[1] += node->box.size[1] / 2.0; itemNodePos[2] = 0; /** @todo we should not use DrawItem but draw the image with render function (remove dependency with container) */ UI_DrawItem(node, itemNodePos, &item, -1, -1, EXTRADATA(node).scale, color); } else { UI_DrawModelNode(node, model); } } else { GAME_DisplayItemInfo(node, ref); } }
static void UI_CheckBoxNodeDraw (uiNode_t* node) { const float value = UI_GetReferenceFloat(node, EXTRADATA(node).value); vec2_t pos; const char *image = UI_GetReferenceString(node, node->image); int texx, texy; /* image set? */ if (Q_strnull(image)) return; /* outer status */ if (node->disabled) { texy = 96; } else if (node->state) { texy = 32; } else { texy = 0; } /* inner status */ if (value == 0) { texx = 0; } else if (value > 0) { texx = 32; } else { /* value < 0 */ texx = 64; } UI_GetNodeAbsPos(node, pos); UI_DrawNormImageByName(qfalse, pos[0], pos[1], node->size[0], node->size[1], texx + node->size[0], texy + node->size[1], texx, texy, image); }
void uiVideoNode::drawOverWindow (uiNode_t *node) { if (EXTRADATA(node).cin.status == CIN_STATUS_INVALID) { /** @todo Maybe draw a black screen? */ return; } if (EXTRADATA(node).cin.status == CIN_STATUS_NONE) { vec2_t pos; bool nosound = UI_VIDEOEXTRADATACONST(node).nosound; CIN_OpenCinematic(&(EXTRADATA(node).cin), va("videos/%s", EXTRADATA(node).source)); if (EXTRADATA(node).cin.status == CIN_STATUS_INVALID) { UI_ExecuteEventActions(node, EXTRADATA(node).onEnd); return; } UI_GetNodeAbsPos(node, pos); CIN_SetParameters(&(EXTRADATA(node).cin), pos[0], pos[1], node->box.size[0], node->box.size[1], CIN_STATUS_PLAYING, nosound); } if (EXTRADATA(node).cin.status == CIN_STATUS_PLAYING || EXTRADATA(node).cin.status == CIN_STATUS_PAUSE) { /* only set replay to true if video was found and is running */ CIN_RunCinematic(&(EXTRADATA(node).cin)); if (EXTRADATA(node).cin.status == CIN_STATUS_NONE) { UI_ExecuteEventActions(node, EXTRADATA(node).onEnd); } } }
void uiBattleScapeNode::draw (uiNode_t* node) { /** Note: hack to fix everytime renderrect (for example when we close hud_nohud) */ vec2_t pos; UI_GetNodeAbsPos(node, pos); UI_SetRenderRect(pos[0], pos[1], node->box.size[0], node->box.size[1]); }
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); } } }
void uiCheckBoxNode::draw (uiNode_t* node) { const float value = getValue(node); vec2_t pos; uiSprite_t *icon = NULL; uiSpriteStatus_t status = SPRITE_STATUS_NORMAL; /* outer status */ if (node->disabled) { status = SPRITE_STATUS_DISABLED; } else if (node->state) { status = SPRITE_STATUS_HOVER; } else { status = SPRITE_STATUS_NORMAL; } /* inner status */ if (value == 0) { icon = EXTRADATA(node).iconUnchecked; } else if (value > 0) { icon = EXTRADATA(node).iconChecked; } else { /* value < 0 */ icon = EXTRADATA(node).iconIndeterminate; } UI_GetNodeAbsPos(node, pos); if (EXTRADATA(node).background) { UI_DrawSpriteInBox(false, EXTRADATA(node).background, status, pos[0], pos[1], node->box.size[0], node->box.size[1]); } if (icon) { UI_DrawSpriteInBox(false, icon, status, pos[0], pos[1], node->box.size[0], node->box.size[1]); } }
/** * @brief Called when the node got the focus */ void uiTextEntryNode::onFocusGained (uiNode_t* node) { assert(editedCvar == nullptr); /* skip '*cvar ' */ const char* cvarRef = "*cvar:"; editedCvar = Cvar_Get(&((const char*)node->text)[strlen(cvarRef)]); assert(editedCvar); Q_strncpyz(cvarValueBackup, editedCvar->string, sizeof(cvarValueBackup)); isAborted = false; EXTRADATA(node).cursorPosition = UTF8_strlen(editedCvar->string); #if SDL_VERSION_ATLEAST(2,0,0) SDL_StartTextInput(); vec2_t pos; UI_GetNodeAbsPos(node, pos); SDL_Rect r = {static_cast<int>(pos[0]), static_cast<int>(pos[1]), static_cast<int>(node->box.size[0]), static_cast<int>(node->box.size[1])}; SDL_SetTextInputRect(&r); #else #ifdef ANDROID char buf[MAX_CVAR_EDITING_LENGTH]; Q_strncpyz(buf, editedCvar->string, sizeof(buf)); SDL_ANDROID_GetScreenKeyboardTextInput(buf, sizeof(buf)); Cvar_ForceSet(editedCvar->name, buf); UI_TextEntryNodeValidateEdition(node); UI_RemoveFocus(); #endif #endif }
static uiNode_t* UI_OptionListNodeGetOptionAtPosition (uiNode_t* node, int x, int y) { uiNode_t* option; vec2_t pos; int lineHeight; int currentY; int count = 0; UI_GetNodeAbsPos(node, pos); currentY = pos[1] + node->padding; lineHeight = EXTRADATA(node).lineHeight; if (lineHeight == 0) { const char* font = UI_GetFontFromNode(node); lineHeight = UI_FontGetHeight(font); } option = UI_AbstractOptionGetFirstOption(node); while (option && count < EXTRADATA(node).scrollY.viewPos) { option = option->next; count++; } /* now draw all available options for this selectbox */ for (; option; option = option->next) { if (y < currentY + lineHeight) return option; if (currentY + lineHeight > pos[1] + node->box.size[1] - node->padding) break; currentY += lineHeight; } return nullptr; }
static void UI_TBarNodeDraw (uiNode_t *node) { /* dataImageOrModel is the texture name */ float shx; vec2_t nodepos; const char* ref = UI_GetReferenceString(node, node->image); float pointWidth; float width; if (Q_strnull(ref)) return; UI_GetNodeAbsPos(node, nodepos); pointWidth = TEXTURE_WIDTH / 100.0; /* relative to the texture */ { float ps; const float min = UI_GetReferenceFloat(node, EXTRADATA(node).super.min); const float max = UI_GetReferenceFloat(node, EXTRADATA(node).super.max); float value = UI_GetReferenceFloat(node, EXTRADATA(node).super.value); /* clamp the value */ if (value > max) value = max; if (value < min) value = min; ps = (value - min) / (max - min) * 100; shx = EXTRADATA(node).texl[0]; /* left gap to the texture */ shx += round(ps * pointWidth); /* add size from 0..TEXTURE_WIDTH */ } width = (shx * node->size[0]) / TEXTURE_WIDTH; UI_DrawNormImageByName(qfalse, nodepos[0], nodepos[1], width, node->size[1], shx, EXTRADATA(node).texh[1], EXTRADATA(node).texl[0], EXTRADATA(node).texl[1], ref); }
/** * @brief Gets location of the item the mouse is over * @param[in] node The container-node. * @param[in] mouseX X location of the mouse. * @param[in] mouseY Y location of the mouse. * @param[out] contX X location in the container (index of item in row). * @param[out] contY Y location in the container (row). * @sa UI_ContainerNodeSearchInScrollableContainer */ static invList_t *UI_ContainerNodeGetItemAtPosition (const uiNode_t* const node, int mouseX, int mouseY, int* contX = NULL, int* contY = NULL) { invList_t *result = NULL; if (!ui_inventory) return NULL; /* Get coordinates inside a scrollable container (if it is one). */ if (UI_IsScrollContainerNode(node)) { Sys_Error("UI_ContainerNodeGetItemAtPosition is not usable for scrollable containers!"); } else { vec2_t nodepos; int fromX, fromY; UI_GetNodeAbsPos(node, nodepos); /* Normalize screen coordinates to container coordinates. */ fromX = (int) (mouseX - nodepos[0]) / C_UNIT; fromY = (int) (mouseY - nodepos[1]) / C_UNIT; if (contX) *contX = fromX; if (contY) *contY = fromY; result = INVSH_SearchInInventory(ui_inventory, EXTRADATACONST(node).container, fromX, fromY); } return result; }
void uiSequenceNode::draw (uiNode_t *node) { if (EXTRADATA(node).context != NULL && EXTRADATA(node).playing) { bool finished = false; vec2_t pos; vec2_t screenPos; UI_GetNodeAbsPos(node, pos); UI_GetNodeScreenPos(node, screenPos); R_PushMatrix(); R_CleanupDepthBuffer(pos[0], pos[1], node->box.size[0], node->box.size[1]); R_PushClipRect(screenPos[0], screenPos[1], node->box.size[0], node->box.size[1]); SEQ_SetView(EXTRADATA(node).context, pos, node->box.size); finished = !SEQ_Render(EXTRADATA(node).context); R_PopClipRect(); R_PopMatrix(); if (finished && EXTRADATA(node).onEnd) { UI_ExecuteEventActions(node, EXTRADATA(node).onEnd); EXTRADATA(node).playing = true; } } }
/** * @brief Return index of the image (r_images[i]) else NULL */ static int UI_MaterialEditorNodeGetImageAtPosition (uiNode_t *node, int x, int y) { int i; vec2_t pos; int cnt = 0; int cntView = 0; const int imagesPerLine = (node->box.size[0] - node->padding) / (IMAGE_WIDTH + node->padding); const int imagesPerColumn = (node->box.size[1] - node->padding) / (IMAGE_WIDTH + node->padding); int columnRequested; int lineRequested; UI_NodeAbsoluteToRelativePos(node, &x, &y); /* have we click between 2 images? */ if (((x % (IMAGE_WIDTH + node->padding)) < node->padding) || ((y % (IMAGE_WIDTH + node->padding)) < node->padding)) return -1; /* get column and line of the image */ columnRequested = x / (IMAGE_WIDTH + node->padding); lineRequested = y / (IMAGE_WIDTH + node->padding); /* have we click outside? */ if (columnRequested >= imagesPerLine || lineRequested >= imagesPerColumn) return -1; UI_GetNodeAbsPos(node, pos); /* check images */ for (i = 0; i < r_numImages; i++) { #ifndef ANYIMAGES /* filter */ image_t *image = R_GetImageAtIndex(i); 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; } if (cntView % imagesPerLine == columnRequested && cntView / imagesPerLine == lineRequested) return i; /* vertical overflow */ if (cntView / imagesPerLine > lineRequested) break; cnt++; cntView++; } return -1; }
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); } }
/** * @brief Draws the rectangle in a 'free' style on position posx/posy (pixel) in the size sizex/sizey (pixel) */ static void UI_DrawDisabled (const uiNode_t* node) { const vec4_t color = { 0.3f, 0.3f, 0.3f, 0.7f }; vec2_t nodepos; UI_GetNodeAbsPos(node, nodepos); UI_DrawFill(nodepos[0], nodepos[1], node->box.size[0], node->box.size[1], color); }
/** * @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 small square with the layout of the given base */ void uiBaseLayoutNode::draw (uiNode_t * node) { const int totalMarge = node->padding * (BASE_SIZE + 1); const int width = (node->box.size[0] - totalMarge) / BASE_SIZE; const int height = (node->box.size[1] - totalMarge) / BASE_SIZE; vec2_t nodepos; UI_GetNodeAbsPos(node, nodepos); GAME_DrawBaseLayout(EXTRADATA(node).baseid, nodepos[0], nodepos[1], totalMarge, width, height, node->padding, node->bgcolor, node->color); }
void uiTodoNode::draw (uiNode_t* node) { static vec4_t red = {1.0, 0.0, 0.0, 1.0}; vec2_t pos; UI_GetNodeAbsPos(node, pos); UI_DrawFill(pos[0], pos[1], node->box.size[0], node->box.size[1], red); if (node->state) UI_CaptureDrawOver(node); }
/** * @brief Handles CustomButton draw */ static void UI_CustomButtonNodeDraw (uiNode_t *node) { const char *text; int texY; const float *textColor; const char *image; vec2_t pos; static vec4_t disabledColor = {0.5, 0.5, 0.5, 1.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; texY = UI_CUSTOMBUTTON_TEX_HEIGHT * 2; iconStatus = SPRITE_STATUS_DISABLED; } else if (node->state) { textColor = node->selectedColor; texY = UI_CUSTOMBUTTON_TEX_HEIGHT; iconStatus = SPRITE_STATUS_HOVER; } else { textColor = node->color; texY = 0; } UI_GetNodeAbsPos(node, pos); image = UI_GetReferenceString(node, node->image); if (image) { const int texX = rint(EXTRADATA(node).texl[0]); texY += EXTRADATA(node).texl[1]; UI_DrawNormImageByName(qfalse, pos[0], pos[1], node->size[0], node->size[1], texX + node->size[0], texY + node->size[1], texX, texY, image); } if (EXTRADATA(node).background) { UI_DrawSpriteInBox(qfalse, EXTRADATA(node).background, iconStatus, pos[0], pos[1], node->size[0], node->size[1]); } if (EXTRADATA(node).super.icon) { UI_DrawSpriteInBox(EXTRADATA(node).super.flipIcon, EXTRADATA(node).super.icon, iconStatus, pos[0], pos[1], node->size[0], node->size[1]); } text = UI_GetReferenceString(node, node->text); if (text != NULL && *text != '\0') { R_Color(textColor); UI_DrawStringInBox(font, node->contentAlign, 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); } }
/** * @brief Draw a preview of the DND item dropped into the node */ static void UI_ContainerNodeDrawDropPreview (uiNode_t *target) { item_t previewItem; int checkedTo; vec3_t origine; /* no preview into scrollable list */ if (UI_IsScrollContainerNode(target)) return; /* copy the DND item to not change the original one */ previewItem = *UI_DNDGetItem(); previewItem.rotated = false; checkedTo = INVSH_CheckToInventory(ui_inventory, previewItem.item, EXTRADATA(target).container, dragInfoToX, dragInfoToY, dragInfoIC); switch (checkedTo) { case INV_DOES_NOT_FIT: return; case INV_FITS: break; case INV_FITS_BOTH: /** @todo enable Shift-rotate for battlescape too when issues are solved */ if (!Key_IsDown(K_SHIFT) || CL_BattlescapeRunning()) break; case INV_FITS_ONLY_ROTATED: previewItem.rotated = true; } /* Hack, no preview for armour, we don't want it out of the armour container (and armour container is not visible) */ if (INV_IsArmour(previewItem.item)) return; UI_GetNodeAbsPos(target, origine); origine[2] = -40; /* Get center of single container for placement of preview item */ if (EXTRADATA(target).container->single) { origine[0] += target->box.size[0] / 2.0; origine[1] += target->box.size[1] / 2.0; /* This is a "grid" container - we need to calculate the item-position * (on the screen) from stored placement in the container and the * calculated rotation info. */ } else { if (previewItem.rotated) { origine[0] += (dragInfoToX + previewItem.item->sy / 2.0) * C_UNIT; origine[1] += (dragInfoToY + previewItem.item->sx / 2.0) * C_UNIT; } else { origine[0] += (dragInfoToX + previewItem.item->sx / 2.0) * C_UNIT; origine[1] += (dragInfoToY + previewItem.item->sy / 2.0) * C_UNIT; } } UI_DrawItem(NULL, origine, &previewItem, -1, -1, scale, colorPreview); }
/** * @brief Handles selectboxes clicks */ static void UI_SelectBoxNodeClick (uiNode_t *node, int x, int y) { uiNode_t* option; int clickedAtOption; vec2_t pos; /* dropdown the node */ if (UI_GetMouseCapture() == NULL) { UI_SetMouseCapture(node); return; } UI_GetNodeAbsPos(node, pos); clickedAtOption = (y - pos[1]); /* we click outside */ if (x < pos[0] || y < pos[1] || x >= pos[0] + node->size[0] || y >= pos[1] + node->size[1] * (EXTRADATA(node).count + 1)) { UI_MouseRelease(); return; } /* we click on the head */ if (clickedAtOption < node->size[1]) { UI_MouseRelease(); return; } clickedAtOption = (clickedAtOption - node->size[1]) / node->size[1]; if (clickedAtOption < 0 || clickedAtOption >= EXTRADATA(node).count) return; if (UI_AbstractOptionGetCurrentValue(node) == NULL) return; /* select the right option */ option = UI_AbstractOptionGetFirstOption(node); for (; option; option = option->next) { if (option->invis) continue; if (clickedAtOption == 0) break; clickedAtOption--; } /* update the status */ if (option) UI_AbstractOptionSetCurrentValue(node, OPTIONEXTRADATA(option).value); /* close the dropdown */ UI_MouseRelease(); }
void uiSpinnerNode::draw (uiNode_t *node) { vec2_t pos; const float delta = getDelta(node); const bool disabled = node->disabled || node->parent->disabled; UI_GetNodeAbsPos(node, pos); uiSpriteStatus_t status; uiSpriteStatus_t topStatus; uiSpriteStatus_t bottomStatus; if (disabled || delta == 0) { status = SPRITE_STATUS_DISABLED; topStatus = SPRITE_STATUS_DISABLED; bottomStatus = SPRITE_STATUS_DISABLED; } else { const float value = getValue(node); const float min = getMin(node); const float max = getMax(node); status = SPRITE_STATUS_NORMAL; bool increaseLocation = isPositionIncrease(node, mousePosX - pos[0], mousePosY - pos[1]); /* top button status */ if (value >= max) { topStatus = SPRITE_STATUS_DISABLED; } else if (node->state && increaseLocation) { topStatus = SPRITE_STATUS_HOVER; } else { topStatus = SPRITE_STATUS_NORMAL; } /* bottom button status */ if (value <= min) { bottomStatus = SPRITE_STATUS_DISABLED; } else if (node->state && !increaseLocation) { bottomStatus = SPRITE_STATUS_HOVER; } else { bottomStatus = SPRITE_STATUS_NORMAL; } } if (EXTRADATA(node).background) UI_DrawSpriteInBox(false, EXTRADATA(node).background, status, pos[0], pos[1], node->box.size[0], node->box.size[1]); if (EXTRADATA(node).topIcon) UI_DrawSpriteInBox(false, EXTRADATA(node).topIcon, topStatus, pos[0], pos[1], node->box.size[0], node->box.size[1]); if (EXTRADATA(node).bottomIcon) UI_DrawSpriteInBox(false, EXTRADATA(node).bottomIcon, bottomStatus, pos[0], pos[1], node->box.size[0], node->box.size[1]); }
static void UI_EditorNodeHighlightNode (uiNode_t* node, const vec4_t color, bool displayAnchor) { vec2_t pos; UI_GetNodeAbsPos(node, pos); UI_DrawRect(pos[0] - 1, pos[1] - 1, node->box.size[0] + 2, node->box.size[1] + 2, color, 1.0, 0x3333); if (displayAnchor) { UI_DrawFill(pos[0] - anchorSize, pos[1] - anchorSize, anchorSize, anchorSize, color); UI_DrawFill(pos[0] - anchorSize, pos[1] + node->box.size[1], anchorSize, anchorSize, color); UI_DrawFill(pos[0] + node->box.size[0], pos[1] + node->box.size[1], anchorSize, anchorSize, color); UI_DrawFill(pos[0] + node->box.size[0], pos[1] - anchorSize, anchorSize, anchorSize, color); } }
/** * @brief Set the Model info view (angle,origin,scale) according to the node definition * @todo the param "model" is not used !? */ static inline void UI_InitModelInfoView (uiNode_t* node, modelInfo_t* mi, uiModel_t* model) { vec3_t nodeorigin; UI_GetNodeAbsPos(node, nodeorigin); nodeorigin[0] += node->box.size[0] / 2 + EXTRADATA(node).origin[0]; nodeorigin[1] += node->box.size[1] / 2 + EXTRADATA(node).origin[1]; nodeorigin[2] = EXTRADATA(node).origin[2]; VectorCopy(EXTRADATA(node).scale, mi->scale); VectorCopy(EXTRADATA(node).angles, mi->angles); VectorCopy(nodeorigin, mi->origin); VectorCopy(nullVector, mi->center); }
/** * @brief Draws a base. */ void uiBaseMapNode::draw (uiNode_t * node) { int col, row; bool hover = node->state; getCellAtPos(node, mousePosX, mousePosY, &col, &row); if (col == -1) hover = false; const int width = node->box.size[0] / BASE_SIZE; const int height = node->box.size[1] / BASE_SIZE + BASE_IMAGE_OVERLAY; vec2_t nodePos; UI_GetNodeAbsPos(node, nodePos); GAME_DrawBase(EXTRADATA(node).baseid, nodePos[0], nodePos[1], width, height, col, row, hover, BASE_IMAGE_OVERLAY); }
/** * @brief Draw a grip container */ static void UI_ContainerNodeDrawGrid (uiNode_t *node, const objDef_t *highlightType) { const invList_t *ic; vec3_t pos; UI_GetNodeAbsPos(node, pos); pos[2] = 0; for (ic = ui_inventory->c[EXTRADATA(node).container->id]; ic; ic = ic->next) { assert(ic->item.item); if (highlightType && INVSH_LoadableInWeapon(highlightType, ic->item.item)) UI_DrawItem(node, pos, &ic->item, ic->x, ic->y, scale, colorLoadable); else UI_DrawItem(node, pos, &ic->item, ic->x, ic->y, scale, colorDefault); } }
/** * @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); }
void uiLineChartNode::draw (uiNode_t *node) { lineStrip_t *lineStrip; const int dataId = EXTRADATA(node).dataId; vec3_t pos; if (dataId == 0) return; if (ui_global.sharedData[dataId].type != UI_SHARED_LINESTRIP) { Com_Printf("UI_LineStripNodeDraw: Node '%s' have use an invalide dataId type. LineStrip expected. dataId invalidated\n", UI_GetPath(node)); EXTRADATA(node).dataId = 0; return; } UI_GetNodeAbsPos(node, pos); pos[2] = 0; UI_Transform(pos, nullptr, nullptr); /* Draw axes */ if (EXTRADATA(node).displayAxes) { int axes[6]; axes[0] = 0; axes[1] = 0; axes[2] = 0; axes[3] = (int) node->box.size[1]; axes[4] = (int) node->box.size[0]; axes[5] = (int) node->box.size[1]; R_Color(EXTRADATA(node).axesColor); R_DrawLineStrip(3, axes); } /* Draw all linestrips. */ lineStrip = ui_global.sharedData[dataId].data.lineStrip; for (; lineStrip; lineStrip = lineStrip->next) { /* Draw this line if it's valid. */ if (lineStrip->pointList && lineStrip->numPoints > 0) { R_Color(lineStrip->color); R_DrawLineStrip(lineStrip->numPoints, lineStrip->pointList); } } R_Color(nullptr); UI_Transform(nullptr, nullptr, nullptr); }
/** * @brief Draws the rectangle in a 'free' style on position posx/posy (pixel) in the size sizex/sizey (pixel) */ static void UI_DrawFree (containerIndex_t container, const uiNode_t *node, int posx, int posy, int sizex, int sizey, bool showTUs) { const vec4_t color = { 0.0f, 1.0f, 0.0f, 0.7f }; invDef_t* inv = INVDEF(container); vec2_t nodepos; UI_GetNodeAbsPos(node, nodepos); UI_DrawFill(posx, posy, sizex, sizey, color); /* if showTUs is true (only the first time in none single containers) * and we are connected to a game */ if (showTUs && CL_BattlescapeRunning()) { UI_DrawString("f_verysmall", ALIGN_UL, nodepos[0] + 3, nodepos[1] + 3, nodepos[0] + 3, node->box.size[0] - 6, 0, va(_("In: %i Out: %i"), inv->in, inv->out)); } }
void uiBarNode::draw (uiNode_t* node) { vec4_t color; float fac; vec2_t nodepos; const float min = getMin(node); const float max = getMax(node); const float value = getValue(node); UI_GetNodeAbsPos(node, nodepos); if (node->state && !EXTRADATA(node).readOnly) { Vector4Copy(node->color, color); } else { const float scale = EXTRADATA(node).noHover ? 1.0 : 0.8; VectorScale(node->color, scale, color); color[3] = node->color[3]; } /* shoud it return an error? */ if (max > min) fac = (value - min) / (max - min); else fac = 1; if (fac <= 0 || fac > 1) return; switch (EXTRADATA(node).orientation) { case ALIGN_UC: UI_DrawFill(nodepos[0] + node->padding, nodepos[1] + node->padding + node->box.size[1] - fac * node->box.size[1], node->box.size[0] - 2 * node->padding, fac * node->box.size[1] - 2 * node->padding , color); break; case ALIGN_LC: UI_DrawFill(nodepos[0] + node->padding, nodepos[1] + node->padding, node->box.size[0] - 2 * node->padding, fac * node->box.size[1] - 2 * node->padding, color); break; case ALIGN_CR: UI_DrawFill(nodepos[0] + node->padding, nodepos[1] + node->padding, fac * node->box.size[0] - 2 * node->padding, node->box.size[1] - 2 * node->padding, color); break; case ALIGN_CL: UI_DrawFill(nodepos[0] + node->padding + node->box.size[0] - fac * node->box.size[0], nodepos[1] + node->padding, fac * node->box.size[0] - 2 * node->padding, node->box.size[1] - 2 * node->padding, color); break; default: Com_Printf("UI_BarNodeDraw: Orientation %d not supported\n", EXTRADATA(node).orientation); break; } }
/** * @brief Draws the free and usable inventory positions when dragging an item. * @note Only call this function in dragging mode */ static void UI_ContainerNodeDrawFreeSpace (uiNode_t *node, inventory_t *inv) { const objDef_t *od = UI_DNDGetItem()->item; /**< Get the 'type' of the dragged item. */ vec2_t nodepos; /* Draw only in dragging-mode and not for the equip-floor */ assert(UI_DNDIsDragging()); assert(inv); UI_GetNodeAbsPos(node, nodepos); /* if single container (hands, extension, headgear) */ if (EXTRADATA(node).container->single) { /* if container is free or the dragged-item is in it */ if (UI_DNDIsSourceNode(node) || INVSH_CheckToInventory(inv, od, EXTRADATA(node).container, 0, 0, dragInfoIC)) UI_DrawFree(EXTRADATA(node).container->id, node, nodepos[0], nodepos[1], node->box.size[0], node->box.size[1], true); } else { /* The shape of the free positions. */ uint32_t free[SHAPE_BIG_MAX_HEIGHT]; bool showTUs = true; int x, y; OBJZERO(free); for (y = 0; y < SHAPE_BIG_MAX_HEIGHT; y++) { for (x = 0; x < SHAPE_BIG_MAX_WIDTH; x++) { /* Check if the current position is usable (topleft of the item). */ /* Add '1's to each position the item is 'blocking'. */ const int checkedTo = INVSH_CheckToInventory(inv, od, EXTRADATA(node).container, x, y, dragInfoIC); if (checkedTo & INV_FITS) /* Item can be placed normally. */ INVSH_MergeShapes(free, (uint32_t)od->shape, x, y); if (checkedTo & INV_FITS_ONLY_ROTATED) /* Item can be placed rotated. */ INVSH_MergeShapes(free, INVSH_ShapeRotate((uint32_t)od->shape), x, y); /* Only draw on existing positions. */ if (INVSH_CheckShape(EXTRADATA(node).container->shape, x, y)) { if (INVSH_CheckShape(free, x, y)) { UI_DrawFree(EXTRADATA(node).container->id, node, nodepos[0] + x * C_UNIT, nodepos[1] + y * C_UNIT, C_UNIT, C_UNIT, showTUs); showTUs = false; } } } } } }