diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c index 3200d2dd1a..13f6a9e57a 100644 --- a/firmware/drivers/lcd-bitmap-common.c +++ b/firmware/drivers/lcd-bitmap-common.c @@ -684,7 +684,7 @@ static bool LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string, cwidth = font_get(vp->font)->maxwidth; /* get width (pixels) of the string */ - LCDFN(getstringsize)(string, &w, &h); + font_getstringsize(string, &w, &h, vp->font); height = h; y = y * (linebased ? height : 1); @@ -713,6 +713,8 @@ static bool LCDFN(puts_scroll_worker)(int x, int y, const unsigned char *string, /* copy contents to the line buffer */ strmemccpy(s->linebuffer, string, sizeof(s->linebuffer)); + s->line_stringsize = w; + /* scroll bidirectional or forward only depending on the string width */ if ( LCDFN(scroll_info).bidir_limit ) { s->bidir = w < (vp->width) * diff --git a/firmware/drivers/lcd-scroll.c b/firmware/drivers/lcd-scroll.c index 7c5492e983..14789be64a 100644 --- a/firmware/drivers/lcd-scroll.c +++ b/firmware/drivers/lcd-scroll.c @@ -122,7 +122,9 @@ void LCDFN(bidir_scroll)(int percent) * Returns true if the text scrolled to the end */ bool LCDFN(scroll_now)(struct scrollinfo *s) { - int width = LCDFN(getstringsize)(s->linebuffer, NULL, NULL); + int width = s->line_stringsize; /* Calculated by LCDFN puts_scroll_worker() */ + /*int width = font_getstringsize(s->linebuffer, NULL, NULL, s->vp->font);*/ + bool ended = false; /* assume s->scroll_func() don't yield; otherwise this buffer might need * to be mutex'd (the worst case would be minor glitches though) */ @@ -149,7 +151,7 @@ bool LCDFN(scroll_now)(struct scrollinfo *s) snprintf(line_buf, sizeof(line_buf)-1, "%s%s%s", s->linebuffer, " ", s->linebuffer); s->line = line_buf; - width += LCDFN(getstringsize)(" ", NULL, NULL); + width += font_getstringsize(" ", NULL, NULL, s->vp->font) * 3; /* scroll forward the whole time */ if (s->offset >= width) { s->offset = 0; @@ -184,53 +186,53 @@ bool LCDFN(scroll_now)(struct scrollinfo *s) static void LCDFN(scroll_worker)(void) { int index; - bool makedelay; struct scroll_screen_info *si = &LCDFN(scroll_info); - struct scrollinfo *s; struct viewport *oldvp; - int step; + + if (global_settings.disable_mainmenu_scrolling + && get_current_activity() == ACTIVITY_MAINMENU) { + /* No scrolling on the main menu if disabled + (to not break themes with lockscreens) */ + return; + } for ( index = 0; index < si->lines; index++ ) { - s = &si->scroll[index]; + struct scrollinfo *s = &si->scroll[index]; /* check pause */ if (TIME_BEFORE(current_tick, s->start_tick)) { continue; } - if (global_settings.disable_mainmenu_scrolling && get_current_activity() == ACTIVITY_MAINMENU) { - // No scrolling on the main menu if disabled (to not break themes with lockscreens) - continue; - } - s->start_tick = current_tick; + if (s->backward) + s->offset -= si->step; + else + s->offset += si->step; + /* this runs out of the ui thread, thus we need to - * save and restore the current viewport since the ui thread - * is unaware of the swapped viewports. the vp must - * be switched early so that lcd_getstringsize() picks the - * correct font */ + * save and restore the current viewport since the + * ui thread is unaware of the swapped viewports. */ oldvp = LCDFN(set_viewport_ex)(s->vp, 0); /* don't mark the last vp as dirty */ - makedelay = false; - step = si->step; - - if (s->backward) - s->offset -= step; - else - s->offset += step; - /* put the line onto the display now */ - makedelay = LCDFN(scroll_now(s)); + bool makedelay = LCDFN(scroll_now(s)); + if (makedelay) + { +#if 0 /* haven't found a case in which this matters .. yet?? --Bilgus */ + /* re-calculate stringsize in case the font changed */ + s->line_stringsize = font_getstringsize(s->linebuffer, NULL, NULL, s->vp->font); +#endif + s->start_tick += si->delay + si->ticks; + } #ifdef SIMULATOR /* Bugfix sim won't update screen unless called from active thread */ LCDFN(set_viewport)(oldvp); #else LCDFN(set_viewport_ex)(oldvp, 0); /* don't mark the last vp as dirty */ #endif - if (makedelay) - s->start_tick += si->delay + si->ticks; } } #endif /*!BOOTLOADER*/ diff --git a/firmware/export/scroll_engine.h b/firmware/export/scroll_engine.h index ba7cc3c4d5..ed8f93b476 100644 --- a/firmware/export/scroll_engine.h +++ b/firmware/export/scroll_engine.h @@ -124,6 +124,8 @@ struct scrollinfo int width, height; /* pixel to skip from the beginning of the string, increments as the text scrolls */ int offset; + /* getstringsize width of linebuffer */ + unsigned short line_stringsize; /* scroll presently forward or backward? */ bool backward; bool bidir;