# HG changeset patch # User ib # Date 1296744286 0 # Node ID 3ceeb62a11254187637bcab735a924628cbb42f5 # Parent 6b394b24f81cc1aa9712f6b5002b6bfcd8c1ce16 Improve the readability of dynamic labels which scroll. If the text of a dynamic label to be displayed is wider than the given length, it will be scrolled. Currently such a label starts scrolling immediately after it is placed and - even more unpleasant - the start of the text is randomly somewhere within the specified space of the label. Both makes it hard to track and to read. Now such a dynamic label starts left-aligned and begins scrolling through the specified space only after a short delay (2.5 seconds). Every time the start of the text nears the left margin again during the scrolling process it will stop and everything starts all over again, i.e. scrolling after a short delay. diff -r 6b394b24f81c -r 3ceeb62a1125 gui/app.c --- a/gui/app.c Thu Feb 03 14:26:58 2011 +0000 +++ b/gui/app.c Thu Feb 03 14:44:46 2011 +0000 @@ -114,6 +114,11 @@ item->fontid=0; free(item->label); item->label=NULL; + free(item->text); + item->text=NULL; + item->textwidth=0; + item->starttime=0; + item->last_x=0; item->event=0; } diff -r 6b394b24f81c -r 3ceeb62a1125 gui/app.h --- a/gui/app.h Thu Feb 03 14:26:58 2011 +0000 +++ b/gui/app.h Thu Feb 03 14:44:46 2011 +0000 @@ -148,6 +148,10 @@ int fontid; int align; char * label; + char * text; + int textwidth; + unsigned int starttime; + int last_x; // --- int event; // --- diff -r 6b394b24f81c -r 3ceeb62a1125 gui/mplayer/gui_common.c --- a/gui/mplayer/gui_common.c Thu Feb 03 14:26:58 2011 +0000 +++ b/gui/mplayer/gui_common.c Thu Feb 03 14:44:46 2011 +0000 @@ -298,10 +298,34 @@ if ( image ) PutImage( image,item->x,item->y,1,0 ); case itDLabel: { + int x; + unsigned int d; char * t = Translate( item->label ); - int l = fntTextWidth( item->fontid,t ); - l=(l?l:item->width); - image=fntRender( item,l-(GetTimerMS() / 20)%l,t ); + if ( g_strcmp0( item->text, t ) != 0 ) + { + g_free( item->text ); + item->text = g_strdup( t ); + item->textwidth = fntTextWidth( item->fontid, t ); + item->starttime = GetTimerMS(); + item->last_x = 0; + } + d = GetTimerMS() - item->starttime; + if ( d < DELAYTIME ) x = item->last_x; // don't scroll yet + else + { + int l; + char c[2]; + l = (item->textwidth ? item->textwidth : item->width); + x = l - ((d - DELAYTIME) / 20) % l - 1; + c[0] = *item->text; + c[1] = '\0'; + if ( x < (fntTextWidth( item->fontid, c ) + 1) >> 1) + { + item->starttime = GetTimerMS(); // stop again + item->last_x = x; // at current x pos + } + } + image = fntRender( item, x, t ); } if ( image ) PutImage( image,item->x,item->y,1,0 ); break; diff -r 6b394b24f81c -r 3ceeb62a1125 gui/mplayer/gui_common.h --- a/gui/mplayer/gui_common.h Thu Feb 03 14:26:58 2011 +0000 +++ b/gui/mplayer/gui_common.h Thu Feb 03 14:44:46 2011 +0000 @@ -29,6 +29,8 @@ #include "gui/bitmap.h" #include "gui/wm/ws.h" +#define DELAYTIME 2500 // in milliseconds + char * Translate( char * str ); void PutImage( txSample * bf,int x, int y, int max, int ofs ); void SimplePotmeterPutImage( txSample * bf, int x, int y, float frac );