MCPcopy Create free account
hub / github.com/JACoders/OpenJK / Item_SetTextExtents

Function Item_SetTextExtents

code/ui/ui_shared.cpp:6195–6252  ·  view source on GitHub ↗

================= Item_SetTextExtents ================= */

Source from the content-addressed store, hash-verified

6193=================
6194*/
6195void Item_SetTextExtents(itemDef_t *item, int *width, int *height, const char *text)
6196{
6197 const char *textPtr = (text) ? text : item->text;
6198
6199 if (textPtr == NULL )
6200 {
6201 return;
6202 }
6203
6204 *width = item->textRect.w;
6205 *height = item->textRect.h;
6206
6207 // keeps us from computing the widths and heights more than once
6208 if (*width == 0 ||
6209 (item->type == ITEM_TYPE_OWNERDRAW && item->textalignment == ITEM_ALIGN_CENTER) ||
6210 HasStringLanguageChanged (item))
6211 {
6212 int originalWidth;
6213
6214 originalWidth = DC->textWidth(textPtr, item->textscale, item->font);
6215
6216 if (item->type == ITEM_TYPE_OWNERDRAW && (item->textalignment == ITEM_ALIGN_CENTER || item->textalignment == ITEM_ALIGN_RIGHT))
6217 {
6218 originalWidth += DC->ownerDrawWidth(item->window.ownerDraw, item->textscale);
6219 }
6220 else if (item->type == ITEM_TYPE_EDITFIELD && item->textalignment == ITEM_ALIGN_CENTER && item->cvar)
6221 {
6222 char buff[256];
6223 DC->getCVarString(item->cvar, buff, 256);
6224 originalWidth += DC->textWidth(buff, item->textscale, item->font);
6225 }
6226
6227 *width = DC->textWidth(textPtr, item->textscale, item->font);
6228 *height = DC->textHeight(textPtr, item->textscale, item->font);
6229
6230 item->textRect.w = *width;
6231 item->textRect.h = *height;
6232 item->textRect.x = item->textalignx;
6233 item->textRect.y = item->textaligny;
6234 if (item->textalignment == ITEM_ALIGN_RIGHT)
6235 {
6236 item->textRect.x = item->textalignx - originalWidth;
6237 }
6238 else if (item->textalignment == ITEM_ALIGN_CENTER)
6239 {
6240 item->textRect.x = item->textalignx - originalWidth / 2;
6241 }
6242
6243 ToWindowCoords(&item->textRect.x, &item->textRect.y, &item->window);
6244#ifdef JK2_MODE
6245 if(item->text && item->text[0]=='@')
6246 item->asset = sp_language->modificationCount;
6247#else
6248 if (item->text && item->text[0]=='@' )//string package
6249 item->asset = se_language->modificationCount; //mark language
6250#endif
6251 }
6252}

Callers 2

Item_Text_Wrapped_PaintFunction · 0.70
Item_Text_PaintFunction · 0.70

Calls 2

HasStringLanguageChangedFunction · 0.85
ToWindowCoordsFunction · 0.70

Tested by

no test coverage detected