From 6535908acb6d1bd131f870a811ad7659a9bfce13 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Sat, 23 Nov 2024 09:48:07 -0800 Subject: [PATCH] Fixes and cleanups to text_objects --- src/console/console.c | 5 +- src/game/gui/label.c | 2 +- src/game/gui/menu.c | 7 +- src/game/gui/text_render.c | 173 +++++++++++++----------------------- src/game/gui/text_render.h | 16 ++-- src/game/gui/textselector.c | 39 +++++--- src/game/gui/textslider.c | 29 ++++-- src/game/scenes/arena.c | 9 +- src/game/scenes/cutscene.c | 3 +- src/game/scenes/lobby.c | 24 ++--- src/game/scenes/melee.c | 13 +-- src/game/scenes/vs.c | 12 +-- src/video/video.c | 10 +-- src/video/video.h | 2 +- 14 files changed, 165 insertions(+), 179 deletions(-) diff --git a/src/console/console.c b/src/console/console.c index e1bd1c257..d9496670d 100644 --- a/src/console/console.c +++ b/src/console/console.c @@ -307,7 +307,7 @@ void console_event(game_state *gs, SDL_Event *e) { } void console_render(void) { - if (con == NULL) { + if(con == NULL) { return; } @@ -333,7 +333,8 @@ void console_render(void) { // cursor tconf.cforeground = TEXT_BLINKY_GREEN; - text_render(&text_cache[1], &tconf, TEXT_DEFAULT, strlen(con->input) * font_small.w, con->y_pos - 7, 6, 6, CURSOR_STR); + text_render(&text_cache[1], &tconf, TEXT_DEFAULT, strlen(con->input) * font_small.w, con->y_pos - 7, 6, 6, + CURSOR_STR); console_output_render(); } } diff --git a/src/game/gui/label.c b/src/game/gui/label.c index 5e4057e62..366d2c05d 100644 --- a/src/game/gui/label.c +++ b/src/game/gui/label.c @@ -57,7 +57,7 @@ component *label_create_with_width(const text_settings *tconf, const char *text, widget_set_obj(c, local); widget_set_render_cb(c, label_render); widget_set_free_cb(c, label_free); - //local->text_cache[0].dynamic = true; + // local->text_cache[0].dynamic = true; return c; } diff --git a/src/game/gui/menu.c b/src/game/gui/menu.c index d908b7d88..633606631 100644 --- a/src/game/gui/menu.c +++ b/src/game/gui/menu.c @@ -111,9 +111,10 @@ static void menu_render(component *c) { video_draw(m->help_bg2, m->help_x - 8, m->help_y - 8); } // TODO: The text_cache should move into inner component. In this case the one of the s->objs. - // Right now it will get invalidated on every render. For help text it usually doesn't matter because there is - // usually only 1 help text on the screen per time. - text_render(&(m->text_cache[0]), &m->help_text_conf, TEXT_DEFAULT, m->help_x, m->help_y, m->help_w, m->help_h, (*tmp)->help); + // Right now it will get invalidated on every render. For help text it usually doesn't matter because there + // is usually only 1 help text on the screen per time. + text_render(&(m->text_cache[0]), &m->help_text_conf, TEXT_DEFAULT, m->help_x, m->help_y, m->help_w, + m->help_h, (*tmp)->help); } i++; } diff --git a/src/game/gui/text_render.c b/src/game/gui/text_render.c index 9020d3d60..552d8de1f 100644 --- a/src/game/gui/text_render.c +++ b/src/game/gui/text_render.c @@ -2,11 +2,11 @@ #include #include "game/gui/text_render.h" +#include "utils/allocator.h" #include "utils/log.h" #include "utils/miscmath.h" #include "utils/vector.h" #include "video/video.h" -#include "utils/allocator.h" static unsigned char FIRST_PRINTABLE_CHAR = (unsigned char)' '; @@ -55,7 +55,6 @@ static inline surface *get_font_surface(const text_settings *settings, char ch) return (ret == NULL) ? NULL : *ret; } - int text_render_char_uncached(const text_settings *settings, text_mode state, int x, int y, char ch, bool shadow) { surface *sur = get_font_surface(settings, ch); @@ -63,7 +62,7 @@ int text_render_char_uncached(const text_settings *settings, text_mode state, in return 0; } // Handle shadows if necessary - if (shadow != false) { + if(shadow != false) { if(settings->shadow & TEXT_SHADOW_RIGHT) video_draw_offset(sur, x + 1, y, settings->cshadow, 255); if(settings->shadow & TEXT_SHADOW_LEFT) @@ -96,44 +95,7 @@ int text_render_char_uncached(const text_settings *settings, text_mode state, in return sur->w; } -/*static inline void render_char_shadow_surface(const text_settings *settings, const surface *sur, int x, int y) { - if(settings->shadow & TEXT_SHADOW_RIGHT) - video_draw_offset(sur, x + 1, y, settings->cshadow, 255); - if(settings->shadow & TEXT_SHADOW_LEFT) - video_draw_offset(sur, x - 1, y, settings->cshadow, 255); - if(settings->shadow & TEXT_SHADOW_BOTTOM) - video_draw_offset(sur, x, y + 1, settings->cshadow, 255); - if(settings->shadow & TEXT_SHADOW_TOP) - video_draw_offset(sur, x, y - 1, settings->cshadow, 255); -}*/ - -/*static inline void render_char_surface(const text_settings *settings, text_mode state, surface *sur, int x, int y) { - int color; - switch(state) { - case TEXT_SELECTED: - color = settings->cselected; - break; - case TEXT_UNSELECTED: - color = settings->cinactive; - break; - case TEXT_DISABLED: - color = settings->cdisabled; - break; - default: - color = settings->cforeground; - } - video_draw_offset(sur, x, y, color - 1, 255); -}*/ - -/*int text_render_char(const text_settings *settings, text_mode state, int x, int y, char ch) { - surface *sur = get_font_surface(settings, ch); - render_char_shadow_surface(settings, sur, x, y); - render_char_surface(settings, state, sur, x, y); - return sur->w; -}*/ - -void letter_set_parameters(text_object *cached_text, surface *sur, int x, int y, int offset, int limit) -{ +void letter_set_parameters(text_object *cached_text, surface *sur, int x, int y, int offset, int limit) { cached_text->cur_letter->x = x; cached_text->cur_letter->y = y; cached_text->cur_letter->sur = sur; @@ -143,7 +105,8 @@ void letter_set_parameters(text_object *cached_text, surface *sur, int x, int y, cached_text->letter_count++; } -int text_render_char(text_object *cached_text, const text_settings *settings, text_mode state, int x, int y, char ch, bool shadow) { +int text_render_char(text_object *cached_text, const text_settings *settings, text_mode state, int x, int y, char ch, + bool shadow) { // Make sure code is valid int code = ch - 32; surface **sur = NULL; @@ -167,12 +130,12 @@ int text_render_char(text_object *cached_text, const text_settings *settings, te } // Empty character's don't need to be rendered just skip the space. - if (ch == ' ') { + if(ch == ' ') { return (*sur)->w; } - + // Handle shadows if necessary - if (shadow != false) { + if(shadow != false) { if(settings->shadow & TEXT_SHADOW_RIGHT) letter_set_parameters(cached_text, *sur, x + 1, y, settings->cshadow, 255); if(settings->shadow & TEXT_SHADOW_LEFT) @@ -211,7 +174,7 @@ int text_find_max_strlen(const text_settings *settings, int max_chars, const cha // Skip whitespace at the start of the string if(settings->strip_leading_whitespace) { - while ((*ptr != 0) && (*ptr == ' ')) { + while((*ptr != 0) && (*ptr == ' ')) { ptr++; i++; } @@ -240,7 +203,7 @@ int text_find_max_strlen(const text_settings *settings, int max_chars, const cha } // If we detect a newline, this line ends here. - if (*ptr == '\n') { + if(*ptr == '\n') { return i + 1; } @@ -277,7 +240,7 @@ int text_char_width(const text_settings *settings) { } int text_find_line_count(const text_settings *settings, int cols, int rows, const char *text, int *longest) { - const char* ptr = text; + const char *ptr = text; int lines = 0; int space; if(settings->direction == TEXT_HORIZONTAL) { @@ -296,32 +259,14 @@ int text_find_line_count(const text_settings *settings, int cols, int rows, cons return lines; } -/*static void text_render_len(const text_settings *settings, text_mode mode, int x, int y, int w, int h, const char *text, - int len) { - int size = text_char_width(settings); - int x_space = w - settings->padding.left - settings->padding.right; - int y_space = h - settings->padding.top - settings->padding.bottom; - int char_w = size + settings->cspacing; - int char_h = size + settings->lspacing; - int rows = (y_space + settings->lspacing) / char_h; - int cols = (x_space + settings->cspacing) / char_w; - int longest = 0; - int fit_lines = text_find_line_count(settings, cols, rows, text, &longest); - int max_chars = settings->direction == TEXT_HORIZONTAL ? cols : rows; - if(max_chars == 0) { - DEBUG("Warning: Text has zero size! text: '%s'"); - max_chars = 1; - } -}*/ - -void text_object_invalidate_cache(text_object *obj) -{ +void text_object_invalidate_cache(text_object *obj) { obj->dirty = true; } -// This function should not be called outside of the text_render.c because it is heavy and may cause significant performance drops -// on slow systems. -static void setup_letter_locations(text_object *cached_text, const text_settings *settings, text_mode mode, int x, int y, int w, int h, const char *text) { +// This function should not be called outside of the text_render.c because it is heavy and may cause significant +// performance drops on slow systems. +static void setup_letter_locations(text_object *cached_text, const text_settings *settings, text_mode mode, int x, + int y, int w, int h, const char *text) { int size = text_char_width(settings); int x_space = w - settings->padding.left - settings->padding.right; int y_space = h - settings->padding.top - settings->padding.bottom; @@ -366,7 +311,7 @@ static void setup_letter_locations(text_object *cached_text, const text_settings break; } - const char* ptr = text; + const char *ptr = text; int line = 0; int space; if(settings->direction == TEXT_HORIZONTAL) { @@ -381,8 +326,8 @@ static void setup_letter_locations(text_object *cached_text, const text_settings int my = 0; int line_pw; int line_ph; - const char* prevptr = ptr; - const char* line_end; + const char *prevptr = ptr; + const char *line_end; // Find out how many characters for this row/col line_len = text_find_max_strlen(settings, space, ptr); line_end = ptr + line_len; @@ -433,12 +378,12 @@ static void setup_letter_locations(text_object *cached_text, const text_settings int w = 0; int mxstart = mx; int mystart = my; - const char* shadow_ptr = ptr; + const char *shadow_ptr = ptr; // Render shadow characters. while((*shadow_ptr != 0) && (shadow_ptr < line_end)) { // Skip line endings. - if (*shadow_ptr == '\n') { + if(*shadow_ptr == '\n') { shadow_ptr++; continue; } @@ -458,7 +403,7 @@ static void setup_letter_locations(text_object *cached_text, const text_settings // Render regular color characters. mx = mxstart; my = mystart; - while ((*ptr != 0) && (ptr < line_end)) { + while((*ptr != 0) && (ptr < line_end)) { // Skip line endings. if(*ptr == '\n') { ptr++; @@ -482,44 +427,47 @@ static void setup_letter_locations(text_object *cached_text, const text_settings } } -void text_objects_free(text_object *cached_text, size_t count) -{ - for (size_t i = 0; i < count; i += 1) { +void text_objects_free(text_object *cached_text, size_t count) { + for(size_t i = 0; i < count; i += 1) { omf_free(cached_text[i].letters); } } -void text_objects_invalidate(text_object *text_cache, size_t cache_size) -{ - for (size_t i = 0; i < cache_size; i++) { +void text_objects_invalidate(text_object *text_cache, size_t cache_size) { + for(size_t i = 0; i < cache_size; i++) { text_cache[i].dirty = true; } } -void text_render(text_object *cached_text, const text_settings *settings, text_mode mode, int x, int y, int w, int h, const char *text) -{ +void text_render(text_object *cached_text, const text_settings *settings, text_mode mode, int x, int y, int w, int h, + const char *text) { bool dirty = false; dirty |= (cached_text->x != x); dirty |= (cached_text->y != y); - if (w > 0) { + if(w > 0) { dirty |= (cached_text->w != w); } - if (h > 0) { + if(h > 0) { dirty |= (cached_text->h != h); } - dirty |= (cached_text->text != text); + // dirty |= (cached_text->text != text); + if(cached_text->text) { + dirty |= (cached_text->text != text); + // dirty |= strncmp(cached_text->text, text, min2(strlen(cached_text->text), strlen(text))) != 0; + } dirty |= (cached_text->mode != mode); dirty |= (memcmp(&cached_text->settings, settings, sizeof(cached_text->settings)) != 0); - if (cached_text->dirty || dirty) { + if(cached_text->dirty || dirty) { size_t text_len = strlen(text); - if (text_len == 0) { + if(text_len == 0) { return; } - if (cached_text->max_letters < (text_len * 4)) { + if(cached_text->max_letters < (text_len * 4)) { size_t size = (text_len * sizeof(letter) * 4); - //assertf(size < (1024 * 40), "%i %s", size, text); // Allow up to 40KB of cache per text block. Support up to 3 shadows per char. + // assertf(size < (1024 * 40), "%i %s", size, text); // Allow up to 40KB of cache per text block. Support up + // to 3 shadows per char. cached_text->letters = omf_realloc(cached_text->letters, size); cached_text->max_letters = text_len * 4; } @@ -538,39 +486,45 @@ void text_render(text_object *cached_text, const text_settings *settings, text_m memcpy(&cached_text->settings, settings, sizeof(cached_text->settings)); cached_text->dirty = true; // This is kind of annoying.. h and w can be less than zero to specify a "figure it out" value. - if ((h <= 0) || (w <= 0)) { + if((h <= 0) || (w <= 0)) { int height = 0; int width = 0; - for (uint32_t i = 0; i < cached_text->letter_count; i += 1) { - const letter* letterptr = &(cached_text->letters[i]); + for(uint32_t i = 0; i < cached_text->letter_count; i += 1) { + const letter *letterptr = &(cached_text->letters[i]); int calculated_height = (letterptr->y + letterptr->sur->h) - y; - if (calculated_height > height) { + if(calculated_height > height) { height = calculated_height; } int calculated_width = (letterptr->x + letterptr->sur->w) - x; - if (calculated_width > width) { + if(calculated_width > width) { width = calculated_width; } } - cached_text->h = height; - cached_text->w = width; + if(h <= 0) { + cached_text->h = height; + } + + if(w <= 0) { + cached_text->w = width; + } } // Validate all letterptrs are non null - for (unsigned int i = 0; i < cached_text->letter_count; i += 1) { - const letter* letterptr = &(cached_text->letters[i]); - assert(letterptr != NULL);//, "%i", i); + for(unsigned int i = 0; i < cached_text->letter_count; i += 1) { + const letter *letterptr = &(cached_text->letters[i]); + assert(letterptr != NULL); //, "%i", i); } - //assertf((cached_text->max_letters > cached_text->letter_count), "Max:%u < Count:%u TextLen:%i %s", (unsigned int)cached_text->max_letters, (unsigned int)cached_text->letter_count, text_len, text); - //assertf(cached_text->h > 0, "%s", text); - //assertf(cached_text->w > 0, "%s", text); - //assertf(cached_text->x < 320, "%s", text); - //assertf(cached_text->y < 240, "%s", text); - //assertf(cached_text->x > 0, "%i %s", cached_text->x, text); - //assertf(cached_text->y > 0, "%i %s", cached_text->y, text); + // assertf((cached_text->max_letters > cached_text->letter_count), "Max:%u < Count:%u TextLen:%i %s", (unsigned + // int)cached_text->max_letters, (unsigned int)cached_text->letter_count, text_len, text); + // assertf(cached_text->h > 0, "%s", text); + // assertf(cached_text->w > 0, "%s", text); + // assertf(cached_text->x < 320, "%s", text); + // assertf(cached_text->y < 240, "%s", text); + // assertf(cached_text->x > 0, "%i %s", cached_text->x, text); + // assertf(cached_text->y > 0, "%i %s", cached_text->y, text); } video_render_text_block(cached_text); @@ -580,4 +534,3 @@ void text_render(text_object *cached_text, const text_settings *settings, text_m /*void text_render_str(const text_settings *settings, text_mode mode, int x, int y, int w, int h, const str *text) { text_render_len(settings, mode, x, y, w, h, str_c(text), str_size(text)); }*/ - diff --git a/src/game/gui/text_render.h b/src/game/gui/text_render.h index 0a09fd33b..4c87d8241 100644 --- a/src/game/gui/text_render.h +++ b/src/game/gui/text_render.h @@ -83,7 +83,7 @@ typedef struct letter { int y; int offset; int limit; - surface* sur; + surface *sur; } letter; typedef struct text_object { @@ -95,12 +95,12 @@ typedef struct text_object { int y; int w; int h; - letter* letters; - letter* cur_letter; + letter *letters; + letter *cur_letter; text_mode mode; text_settings settings; - const char* text; - void* render_private; + const char *text; + void *render_private; } text_object; // New text rendering functions @@ -110,9 +110,11 @@ int text_find_max_strlen(const text_settings *settings, int max_chars, const cha void text_render_str(const text_settings *settings, text_mode mode, int x, int y, int w, int h, const str *text); int text_find_line_count(const text_settings *settings, int cols, int rows, const char *text, int *longest_line_len); -int text_render_char(text_object *cached_text, const text_settings *settings, text_mode mode, int x, int y, char ch, bool shadow); +int text_render_char(text_object *cached_text, const text_settings *settings, text_mode mode, int x, int y, char ch, + bool shadow); int text_render_char_uncached(const text_settings *settings, text_mode mode, int x, int y, char ch, bool shadow); -void text_render(text_object *cached_text, const text_settings *settings, text_mode mode, int x, int y, int w, int h, const char *text); +void text_render(text_object *cached_text, const text_settings *settings, text_mode mode, int x, int y, int w, int h, + const char *text); int text_char_width(const text_settings *settings); int text_width(const text_settings *settings, const char *text); void text_objects_free(text_object *cached_text, size_t count); diff --git a/src/game/gui/textselector.c b/src/game/gui/textselector.c index 437d1f32c..9bfe1d351 100644 --- a/src/game/gui/textselector.c +++ b/src/game/gui/textselector.c @@ -15,6 +15,7 @@ typedef struct { int pos_; int *pos; vector options; + str buf; void *userdata; textselector_toggle_cb toggle; @@ -53,29 +54,31 @@ const char *textselector_get_current_text(const component *c) { static void textselector_render(component *c) { textselector *tb = widget_get_obj(c); - str buf; + + // Render text + text_mode mode = TEXT_UNSELECTED; + if(component_is_selected(c)) { + mode = TEXT_SELECTED; + } else if(component_is_disabled(c)) { + mode = TEXT_DISABLED; + } + text_render(&(tb->text_cache[0]), &tb->tconf, mode, c->x, c->y, c->w, c->h, str_c(&tb->buf)); +} + +void textselector_refresh(textselector *tb) { if(vector_size(&tb->options) > 0 && tb->text[0] != '\0') { // label & options char **opt = vector_get(&tb->options, *tb->pos); - str_from_format(&buf, "%s %s", tb->text, *opt); + str_format(&tb->buf, "%s %s", tb->text, *opt); } else if(vector_size(&tb->options) > 0) { // no label, just options char **opt = vector_get(&tb->options, *tb->pos); - str_from_format(&buf, "%s", *opt); + str_format(&tb->buf, "%s", *opt); } else { // no options, just label - str_from_format(&buf, "%s -", tb->text); - } - - // Render text - text_mode mode = TEXT_UNSELECTED; - if(component_is_selected(c)) { - mode = TEXT_SELECTED; - } else if(component_is_disabled(c)) { - mode = TEXT_DISABLED; + str_format(&tb->buf, "%s -", tb->text); } - text_render(&(tb->text_cache[0]), &tb->tconf, mode, c->x, c->y, c->w, c->h, str_c(&buf)); - str_free(&buf); + tb->text_cache[0].dirty = true; } static int textselector_action(component *c, int action) { @@ -95,6 +98,7 @@ static int textselector_action(component *c, int action) { // reset ticks so text is bright tb->ticks = 0; tb->dir = 0; + textselector_refresh(tb); return 0; } else if(action == ACT_LEFT) { if(vector_size(&tb->options) == 0) { @@ -111,6 +115,7 @@ static int textselector_action(component *c, int action) { // reset ticks so text is bright tb->ticks = 0; tb->dir = 0; + textselector_refresh(tb); return 0; } return 1; @@ -145,6 +150,7 @@ static void textselector_free(component *c) { textselector *tb = widget_get_obj(c); textselector_clear_options(c); text_objects_free(tb->text_cache, (sizeof(tb->text_cache) / sizeof(tb->text_cache[0]))); + str_free(&tb->buf); vector_free(&tb->options); omf_free(tb->text); omf_free(tb); @@ -163,6 +169,9 @@ component *textselector_create(const text_settings *tconf, const char *text, con tb->toggle = cb; vector_create(&tb->options, sizeof(char *)); widget_set_obj(c, tb); + str_create(&tb->buf); + + textselector_refresh(tb); component_set_size_hints(c, text_width(&tb->tconf, text), 8); @@ -179,6 +188,7 @@ component *textselector_create_bind(const text_settings *tconf, const char *text component *c = textselector_create(tconf, text, help, toggle_cb, userdata); textselector *ts = widget_get_obj(c); ts->pos = (bind) ? bind : &ts->pos_; + textselector_refresh(widget_get_obj(c)); return c; } @@ -189,5 +199,6 @@ component *textselector_create_bind_opts(const text_settings *tconf, const char for(int i = 0; i < opt_size; i++) { textselector_add_option(c, opts[i]); } + textselector_refresh(widget_get_obj(c)); return c; } diff --git a/src/game/gui/textslider.c b/src/game/gui/textslider.c index 769143a95..6d1c2a1d5 100644 --- a/src/game/gui/textslider.c +++ b/src/game/gui/textslider.c @@ -16,36 +16,40 @@ typedef struct { int *pos; int has_off; int positions; + str txt; void *userdata; textslider_slide_cb slide; text_object text_cache[1]; } textslider; -static void textslider_render(component *c) { - textslider *tb = widget_get_obj(c); - str txt; - str_from_format(&txt, "%s ", tb->text); +void textslider_refresh(textslider *tb) { if(tb->has_off && *tb->pos == 0) { - str_append_c(&txt, "OFF"); + str_format(&tb->txt, "%s OFF", tb->text); } else { + str_format(&tb->txt, "%s ", tb->text); + str_truncate(&tb->txt, strlen(tb->text) + 1); for(int i = 0; i < tb->positions; i++) { if(i + 1 > *tb->pos) { - str_append_c(&txt, "|"); + str_append_c(&tb->txt, "|"); } else { - str_append_c(&txt, "\x7f"); + str_append_c(&tb->txt, "\x7f"); } } } + tb->text_cache[0].dirty = true; +} +static void textslider_render(component *c) { + textslider *tb = widget_get_obj(c); text_mode mode = TEXT_UNSELECTED; + if(component_is_selected(c)) { mode = TEXT_SELECTED; } else if(component_is_disabled(c)) { mode = TEXT_DISABLED; } - text_render(&(tb->text_cache[0]), &tb->tconf, mode, c->x, c->y, c->w, c->h, str_c(&txt)); - str_free(&txt); + text_render(&(tb->text_cache[0]), &tb->tconf, mode, c->x, c->y, c->w, c->h, str_c(&tb->txt)); } static int textslider_action(component *c, int action) { @@ -64,6 +68,7 @@ static int textslider_action(component *c, int action) { // reset ticks so text is bright tb->ticks = 0; tb->dir = 0; + textslider_refresh(tb); return 0; } else if(action == ACT_LEFT) { (*tb->pos)--; @@ -79,6 +84,7 @@ static int textslider_action(component *c, int action) { // reset ticks so text is bright tb->ticks = 0; tb->dir = 0; + textslider_refresh(tb); return 0; } return 1; @@ -102,6 +108,7 @@ static void textslider_tick(component *c) { static void textslider_free(component *c) { textslider *tb = widget_get_obj(c); text_objects_free(tb->text_cache, (sizeof(tb->text_cache) / sizeof(tb->text_cache[0]))); + str_free(&tb->txt); omf_free(tb->text); omf_free(tb); } @@ -122,8 +129,11 @@ component *textslider_create(const text_settings *tconf, const char *text, const tb->positions = positions; tb->userdata = userdata; tb->slide = cb; + str_create(&tb->txt); widget_set_obj(c, tb); + textslider_refresh(tb); + component_set_size_hints(c, text_width(&tb->tconf, text), 8); widget_set_render_cb(c, textslider_render); @@ -139,5 +149,6 @@ component *textslider_create_bind(const text_settings *tconf, const char *text, component *c = textslider_create(tconf, text, help, positions, has_off, cb, userdata); textslider *ts = widget_get_obj(c); ts->pos = (bind) ? bind : &ts->pos_; + textslider_refresh(ts); return c; } diff --git a/src/game/scenes/arena.c b/src/game/scenes/arena.c index 9387013eb..85999277e 100644 --- a/src/game/scenes/arena.c +++ b/src/game/scenes/arena.c @@ -94,7 +94,6 @@ void game_menu_return(component *c, void *userdata) { game_state_set_paused(((scene *)userdata)->gs, 0); // invalidate the cache of the menu items. menu_invalidate_help_text_cache(local->game_menu->root_node); - } void arena_music_slide(component *c, void *userdata, int pos) { @@ -1154,7 +1153,8 @@ void arena_render_overlay(scene *scene) { } text_render(&text_cache[2], &tconf_players, TEXT_DEFAULT, 5, 19, 250, 6, player1_name); - text_render(&text_cache[3], &tconf_players, TEXT_DEFAULT, 5, 26, 250, 6, lang_get((player[0]->pilot->har_id) + 31)); + text_render(&text_cache[3], &tconf_players, TEXT_DEFAULT, 5, 26, 250, 6, + lang_get((player[0]->pilot->har_id) + 31)); if(player[1]->pilot) { // when quitting, this can go null @@ -1180,7 +1180,8 @@ void arena_render_overlay(scene *scene) { } if(player[1]->ctrl->type == CTRL_TYPE_NETWORK) { snprintf(buf, 40, "ping %d", player[1]->ctrl->rtt); - text_render(&text_cache[7], &tconf_debug, TEXT_DEFAULT, 315 - (strlen(buf) * font_small.w), 40, 250, 6, buf); + text_render(&text_cache[7], &tconf_debug, TEXT_DEFAULT, 315 - (strlen(buf) * font_small.w), 40, 250, 6, + buf); } } @@ -1231,7 +1232,7 @@ int arena_create(scene *scene) { settings *setting; arena_local *local; memset(text_cache, 0, sizeof(text_cache)); - for (size_t i = 0; i < (sizeof(text_cache)/sizeof(text_cache[0])); i++) { + for(size_t i = 0; i < (sizeof(text_cache) / sizeof(text_cache[0])); i++) { text_cache[i].dynamic = true; } diff --git a/src/game/scenes/cutscene.c b/src/game/scenes/cutscene.c index d03faa46b..4ba129d01 100644 --- a/src/game/scenes/cutscene.c +++ b/src/game/scenes/cutscene.c @@ -78,7 +78,8 @@ static void cutscene_input_tick(scene *scene) { static void cutscene_render_overlay(scene *scene) { cutscene_local *local = scene_get_userdata(scene); - text_render(&local->text_cache[0], &local->text_conf, TEXT_DEFAULT, local->text_x, local->text_y, local->text_width, 200, local->current); + text_render(&local->text_cache[0], &local->text_conf, TEXT_DEFAULT, local->text_x, local->text_y, local->text_width, + 200, local->current); } static void cutscene_free(scene *scene) { diff --git a/src/game/scenes/lobby.c b/src/game/scenes/lobby.c index c2f47e675..e1aab949f 100644 --- a/src/game/scenes/lobby.c +++ b/src/game/scenes/lobby.c @@ -165,19 +165,19 @@ void lobby_render_overlay(scene *scene) { if(local->mode > LOBBY_YELL) { snprintf(buf, sizeof(buf), "Player"); - //text_render(&font_big, TEXT_DEFAULT, 16, 7, 50, 8, buf); + // text_render(&font_big, TEXT_DEFAULT, 16, 7, 50, 8, buf); snprintf(buf, sizeof(buf), "Action"); - //text_render(&font_big, TEXT_DEFAULT, 117, 7, 50, 8, buf); + // text_render(&font_big, TEXT_DEFAULT, 117, 7, 50, 8, buf); snprintf(buf, sizeof(buf), "Wn/Loss"); - //text_render(&font_small, TEXT_DEFAULT, 200, 8, 50, 6, buf); + // text_render(&font_small, TEXT_DEFAULT, 200, 8, 50, 6, buf); snprintf(buf, sizeof(buf), "Version"); - //text_render(&font_small, TEXT_DEFAULT, 240, 8, 50, 6, buf); + // text_render(&font_small, TEXT_DEFAULT, 240, 8, 50, 6, buf); snprintf(buf, sizeof(buf), "%d of %d", local->active_user + 1, list_size(&local->users)); - //text_render(&font_small, TEXT_DEFAULT, 284, 8, 40, 6, buf); + // text_render(&font_small, TEXT_DEFAULT, 284, 8, 40, 6, buf); iterator it; lobby_user *user; @@ -189,15 +189,15 @@ void lobby_render_overlay(scene *scene) { } else { font_big.cforeground = 8; } - //text_render(&font_big, TEXT_DEFAULT, 16, 18 + (10 * i), 90, 8, user->name); - // TODO status + // text_render(&font_big, TEXT_DEFAULT, 16, 18 + (10 * i), 90, 8, user->name); + // TODO status font_small.cforeground = 40; - //text_render(&font_small, TEXT_DEFAULT, 117, 18 + (10 * i), 60, 6, "available"); + // text_render(&font_small, TEXT_DEFAULT, 117, 18 + (10 * i), 60, 6, "available"); char wins[8]; snprintf(wins, sizeof(wins), "%d/%d", user->wins, user->losses); font_small.cforeground = 56; - //text_render(&font_small, TEXT_DEFAULT, 200, 18 + (10 * i), 50, 6, wins); - //text_render(&font_small, TEXT_DEFAULT, 240, 18 + (10 * i), 50, 6, user->version); + // text_render(&font_small, TEXT_DEFAULT, 200, 18 + (10 * i), 50, 6, wins); + // text_render(&font_small, TEXT_DEFAULT, 240, 18 + (10 * i), 50, 6, user->version); i++; } @@ -206,7 +206,7 @@ void lobby_render_overlay(scene *scene) { log_event *logmsg; while((logmsg = list_iter_prev(&it)) && i < 4) { font_big.cforeground = logmsg->color; - //text_render(&font_big, TEXT_DEFAULT, 10, 188 - (8 * i), 300, 8, logmsg->msg); + // text_render(&font_big, TEXT_DEFAULT, 10, 188 - (8 * i), 300, 8, logmsg->msg); i += text_find_line_count(&font_big, 300 / 8, 3, logmsg->msg, &longest); } } else if(local->mode == LOBBY_YELL) { @@ -216,7 +216,7 @@ void lobby_render_overlay(scene *scene) { log_event *logmsg; while((logmsg = list_iter_prev(&it)) && i < 13) { font_big.cforeground = logmsg->color; - //text_render(&font_big, TEXT_DEFAULT, 10, 120 - (8 * i), 300, 8, logmsg->msg); + // text_render(&font_big, TEXT_DEFAULT, 10, 120 - (8 * i), 300, 8, logmsg->msg); i += text_find_line_count(&font_big, 300 / 8, 3, logmsg->msg, &longest); } } diff --git a/src/game/scenes/melee.c b/src/game/scenes/melee.c index e7bfeda27..d617c7c56 100644 --- a/src/game/scenes/melee.c +++ b/src/game/scenes/melee.c @@ -52,8 +52,8 @@ typedef struct { #define CURSORS_DONE(local) (local->cursor[0].done && local->cursor[1].done) #define CURSOR_NOVA_SELECT(local, player) (local->cursor[player].row == 1 && local->cursor[player].column == 2) -static const char* p1_bio_prev = NULL; -static const char* p2_bio_prev = NULL; +static const char *p1_bio_prev = NULL; +static const char *p2_bio_prev = NULL; static text_object text_cache[18]; typedef enum @@ -532,9 +532,12 @@ static void render_pilot_select(melee_local *local, bool player2_is_selectable) lang_get(135 + current_b)); // player stats - text_render(&text_cache[6], &tconf_green, TEXT_DEFAULT, 320 - 66 - local->bg_player_stats.w, 4, 85, 6, lang_get(216)); - text_render(&text_cache[7], &tconf_green, TEXT_DEFAULT, 320 - 66 - local->bg_player_stats.w, 22, 85, 6, lang_get(217)); - text_render(&text_cache[8], &tconf_green, TEXT_DEFAULT, 320 - 66 - local->bg_player_stats.w, 40, 85, 6, lang_get(218)); + text_render(&text_cache[6], &tconf_green, TEXT_DEFAULT, 320 - 66 - local->bg_player_stats.w, 4, 85, 6, + lang_get(216)); + text_render(&text_cache[7], &tconf_green, TEXT_DEFAULT, 320 - 66 - local->bg_player_stats.w, 22, 85, 6, + lang_get(217)); + text_render(&text_cache[8], &tconf_green, TEXT_DEFAULT, 320 - 66 - local->bg_player_stats.w, 40, 85, 6, + lang_get(218)); component_render(local->bar_power[1]); component_render(local->bar_agility[1]); diff --git a/src/game/scenes/vs.c b/src/game/scenes/vs.c index 7446f0b7a..c97053046 100644 --- a/src/game/scenes/vs.c +++ b/src/game/scenes/vs.c @@ -131,7 +131,7 @@ void cb_vs_destroy_object(object *parent, int id, void *userdata) { void vs_free(scene *scene) { vs_local *local = scene_get_userdata(scene); size_t cache_size = sizeof(local->text_cache) / sizeof(local->text_cache[0]); - for (size_t i = 0; i < cache_size; i++) { + for(size_t i = 0; i < cache_size; i++) { local->text_cache[i].dirty = true; } @@ -287,11 +287,13 @@ void vs_render(scene *scene) { video_draw(&local->arena_select_bg, 55, 150); // arena name - text_render(&(local->text_cache[1]), &tconf_green, TEXT_DEFAULT, 56 + 72, 152, (211 - 72), 8, lang_get(56 + local->arena)); + text_render(&(local->text_cache[1]), &tconf_green, TEXT_DEFAULT, 56 + 72, 152, (211 - 72), 8, + lang_get(56 + local->arena)); tconf_green.valign = TEXT_MIDDLE; // arena description - text_render(&(local->text_cache[2]), &tconf_green, TEXT_DEFAULT, 56 + 72, 153, (211 - 72), 50, lang_get(66 + local->arena)); + text_render(&(local->text_cache[2]), &tconf_green, TEXT_DEFAULT, 56 + 72, 153, (211 - 72), 50, + lang_get(66 + local->arena)); } else if(player2->pilot && player2->pilot->pilot_id == PILOT_KREISSACK && settings_get()->gameplay.difficulty < 2) { // kreissack, but not on Veteran or higher @@ -318,10 +320,10 @@ void vs_render(scene *scene) { char money[16]; fight_stats *fight_stats = &scene->gs->fight_stats; static int force_redraw = 1; - if (force_redraw) { + if(force_redraw) { // TODO: Find out why this caching doesn't work. The cache is built before the stats are correct. // Rendering the first time, after a scene switch should fill the cache correctly but it doesn't. - // The text_render cache should never do a strcmp or memcmp on the text. However setting dirty + // The text_render cache should never do a strcmp or memcmp on the text. However setting dirty // here every time would bypass the cache and therefore is not desirable. size_t cache_size = sizeof(local->text_cache) / sizeof(local->text_cache[0]); text_objects_invalidate(local->text_cache, cache_size); diff --git a/src/video/video.c b/src/video/video.c index 75bec0980..cbfc783c9 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -1,9 +1,10 @@ #include +#include "game/gui/text_render.h" +#include "utils/allocator.h" #include "utils/log.h" #include "video/renderers/renderer.h" #include "video/video.h" -#include "game/gui/text_render.h" // If-def the includes here #ifdef ENABLE_OPENGL3_RENDERER @@ -248,10 +249,9 @@ void video_draw_remap(const surface *src_surface, int x, int y, int remap_offset draw_args(src_surface, &dst, remap_offset, remap_rounds, 0, 255, 255, 0, options); } -void video_render_text_block(text_object *text) -{ - for (uint32_t i = 0; i < text->letter_count;i += 1) { - const letter* letterptr = &(text->letters[i]); +void video_render_text_block(text_object *text) { + for(uint32_t i = 0; i < text->letter_count; i += 1) { + const letter *letterptr = &(text->letters[i]); video_draw_offset(letterptr->sur, letterptr->x, letterptr->y, letterptr->offset, letterptr->limit); } } diff --git a/src/video/video.h b/src/video/video.h index 4da2f50f3..32ab434d8 100644 --- a/src/video/video.h +++ b/src/video/video.h @@ -4,11 +4,11 @@ #include #include "formats/palette.h" +#include "game/gui/text_render.h" #include "video/color.h" #include "video/enums.h" #include "video/image.h" #include "video/surface.h" -#include "game/gui/text_render.h" #define NATIVE_W 320 #define NATIVE_H 200