/** * @brief Search a file name inside pics/ according to the sprite name * If it exists, generate a "single" sprite using the size of the image * @param name Name of the sprite * @return A sprite, else nullptr */ static uiSprite_t* UI_AutoGenerateSprite (const char* name) { uiSprite_t* sprite = nullptr; const char* suffix[SPRITE_STATUS_MAX] = {"", "_hovered", "_disabled", "_clicked"}; char basePicNameBuf[MAX_QPATH]; const image_t* pic; int i; Q_strncpyz(basePicNameBuf, name, sizeof(basePicNameBuf)); pic = UI_LoadImage(basePicNameBuf); if (pic == nullptr) return nullptr; sprite = UI_AllocStaticSprite(basePicNameBuf); sprite->image[SPRITE_STATUS_NORMAL] = UI_AllocStaticString(basePicNameBuf, 0); sprite->size[0] = pic->width; sprite->size[1] = pic->height; for (i = 1; i < SPRITE_STATUS_MAX; i++) { char picNameBuf[MAX_QPATH]; Com_sprintf(picNameBuf, sizeof(picNameBuf), "%s%s", basePicNameBuf, suffix[i]); pic = UI_LoadImage(picNameBuf); if (pic != nullptr) sprite->image[i] = UI_AllocStaticString(picNameBuf, 0); } return sprite; }
bool UI_ParseSprite (const char* name, const char** text) { uiSprite_t* icon; const char* token; /* search for icons with same name */ icon = UI_AllocStaticSprite(name); /* get it's body */ token = Com_Parse(text); assert(token[0] == '{'); /* read properties */ while (true) { const value_t* property; token = Com_Parse(text); if (*text == nullptr) return false; if (token[0] == '}') break; property = UI_FindPropertyByName(ui_spriteProperties, token); if (!property) { Com_Printf("UI_ParseIcon: unknown options property: '%s' - ignore it\n", token); return false; } /* get parameter values */ const bool result = UI_ParseProperty(icon, property, icon->name, text, &token); if (!result) { Com_Printf("UI_ParseIcon: Parsing for sprite '%s'. See upper\n", icon->name); return false; } } return true; }
/** * @brief Search a file name inside pics/ according to the sprite name * If it exists, generate a "single" sprite using the size of the image * @param name Name of the sprite * @return A sprite, else NULL */ static uiSprite_t* UI_AutoGenerateSprite (const char* name) { uiSprite_t* sprite = NULL; const char* suffix[SPRITE_STATUS_MAX] = {"", "_hovered", "_disabled", "_clicked"}; int i; const char *picName = name; const image_t *pic = UI_LoadImage(picName); if (pic == NULL) return NULL; sprite = UI_AllocStaticSprite(name); sprite->image[SPRITE_STATUS_NORMAL] = UI_AllocStaticString(picName, 0); sprite->size[0] = pic->width; sprite->size[1] = pic->height; for (i = 1; i < SPRITE_STATUS_MAX; i++) { picName = va("%s%s", name, suffix[i]); pic = UI_LoadImage(picName); if (pic != NULL) sprite->image[i] = UI_AllocStaticString(picName, 0); } return sprite; }