Replace TextGroupWidget_SetUsePlaceHolder with simpler method

This commit is contained in:
UnknownShadow200 2019-08-19 18:22:16 +10:00
parent 467bac486c
commit addeb72d30
4 changed files with 10 additions and 17 deletions

View File

@ -157,8 +157,8 @@ struct TextAtlas {
struct Texture tex; struct Texture tex;
int offset, curX; int offset, curX;
float uScale; float uScale;
int16_t widths[TEXTATLAS_MAX_WIDTHS]; short widths[TEXTATLAS_MAX_WIDTHS];
int16_t offsets[TEXTATLAS_MAX_WIDTHS]; short offsets[TEXTATLAS_MAX_WIDTHS];
}; };
void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const FontDesc* font, const String* prefix); void TextAtlas_Make(struct TextAtlas* atlas, const String* chars, const FontDesc* font, const String* prefix);
void TextAtlas_Free(struct TextAtlas* atlas); void TextAtlas_Free(struct TextAtlas* atlas);

View File

@ -710,8 +710,8 @@ static void HUDScreen_ConstructWidgets(struct HUDScreen* s) {
TextGroupWidget_Create(&s->status, CHAT_MAX_STATUS, &s->chatFont, TextGroupWidget_Create(&s->status, CHAT_MAX_STATUS, &s->chatFont,
s->statusTextures, HUDScreen_GetStatus); s->statusTextures, HUDScreen_GetStatus);
Widget_SetLocation(&s->status, ANCHOR_MAX, ANCHOR_MIN, 0, 0); Widget_SetLocation(&s->status, ANCHOR_MAX, ANCHOR_MIN, 0, 0);
s->status.placeholderHeight[0] = false; /* Texture pack download status */
Elem_Init(&s->status); Elem_Init(&s->status);
TextGroupWidget_SetUsePlaceHolder(&s->status, 0, false);
TextGroupWidget_Create(&s->bottomRight, CHAT_MAX_BOTTOMRIGHT, &s->chatFont, TextGroupWidget_Create(&s->bottomRight, CHAT_MAX_BOTTOMRIGHT, &s->chatFont,
s->bottomRightTextures, HUDScreen_GetBottomRight); s->bottomRightTextures, HUDScreen_GetBottomRight);

View File

@ -2174,14 +2174,6 @@ static void TextGroupWidget_UpdateY(struct TextGroupWidget* w) {
} }
} }
void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, int index, bool placeHolder) {
w->placeholderHeight[index] = placeHolder;
if (w->textures[index].ID) return;
w->textures[index].Height = placeHolder ? w->defaultHeight : 0;
TextGroupWidget_UpdateY(w);
}
int TextGroupWidget_UsedHeight(struct TextGroupWidget* w) { int TextGroupWidget_UsedHeight(struct TextGroupWidget* w) {
struct Texture* textures = w->textures; struct Texture* textures = w->textures;
int i, height = 0; int i, height = 0;
@ -2221,7 +2213,7 @@ static void TextGroupWidget_UpdateDimensions(struct TextGroupWidget* w) {
Widget_Reposition(w); Widget_Reposition(w);
} }
struct Portion { int16_t Beg, Len, LineBeg, LineLen; }; struct Portion { short Beg, Len, LineBeg, LineLen; };
#define TEXTGROUPWIDGET_HTTP_LEN 7 /* length of http:// */ #define TEXTGROUPWIDGET_HTTP_LEN 7 /* length of http:// */
#define TEXTGROUPWIDGET_URL 0x8000 #define TEXTGROUPWIDGET_URL 0x8000
#define TEXTGROUPWIDGET_PACKED_LEN 0x7FFF #define TEXTGROUPWIDGET_PACKED_LEN 0x7FFF
@ -2515,8 +2507,7 @@ static void TextGroupWidget_Init(void* widget) {
w->defaultHeight = height; w->defaultHeight = height;
for (i = 0; i < w->lines; i++) { for (i = 0; i < w->lines; i++) {
w->textures[i].Height = height; w->textures[i].Height = w->placeholderHeight[i] ? height : 0;
w->placeholderHeight[i] = true;
} }
TextGroupWidget_UpdateDimensions(w); TextGroupWidget_UpdateDimensions(w);
} }
@ -2548,8 +2539,12 @@ static struct WidgetVTABLE TextGroupWidget_VTABLE = {
TextGroupWidget_Reposition TextGroupWidget_Reposition
}; };
void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, FontDesc* font, struct Texture* textures, TextGroupWidget_Get getLine) { void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, FontDesc* font, struct Texture* textures, TextGroupWidget_Get getLine) {
int i;
Widget_Reset(w); Widget_Reset(w);
w->VTABLE = &TextGroupWidget_VTABLE; w->VTABLE = &TextGroupWidget_VTABLE;
for (i = 0; i < lines; i++) {
w->placeholderHeight[i] = true;
}
w->lines = lines; w->lines = lines;
w->font = font; w->font = font;

View File

@ -203,6 +203,7 @@ struct TextGroupWidget {
Widget_Layout Widget_Layout
int lines, defaultHeight; int lines, defaultHeight;
FontDesc* font; FontDesc* font;
/* Whether a line has non-zero height when that line has no text in it. */
bool placeholderHeight[TEXTGROUPWIDGET_MAX_LINES]; bool placeholderHeight[TEXTGROUPWIDGET_MAX_LINES];
bool underlineUrls; bool underlineUrls;
struct Texture* textures; struct Texture* textures;
@ -211,9 +212,6 @@ struct TextGroupWidget {
}; };
CC_NOINLINE void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, FontDesc* font, struct Texture* textures, TextGroupWidget_Get getLine); CC_NOINLINE void TextGroupWidget_Create(struct TextGroupWidget* w, int lines, FontDesc* font, struct Texture* textures, TextGroupWidget_Get getLine);
/* Sets whether the given line has non-zero height when that line has no text in it. */
/* By default, all lines are placeholder lines. */
CC_NOINLINE void TextGroupWidget_SetUsePlaceHolder(struct TextGroupWidget* w, int index, bool placeHolder);
/* Deletes first line, then moves all other lines upwards, then redraws last line. */ /* Deletes first line, then moves all other lines upwards, then redraws last line. */
/* NOTE: GetLine must also adjust the lines it returns for this to behave properly. */ /* NOTE: GetLine must also adjust the lines it returns for this to behave properly. */
CC_NOINLINE void TextGroupWidget_ShiftUp(struct TextGroupWidget* w); CC_NOINLINE void TextGroupWidget_ShiftUp(struct TextGroupWidget* w);