changeset 32761:3ceeb62a1125

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.
author ib
date Thu, 03 Feb 2011 14:44:46 +0000
parents 6b394b24f81c
children 5d1ad5720b32
files gui/app.c gui/app.h gui/mplayer/gui_common.c gui/mplayer/gui_common.h
diffstat 4 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
--- 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;
 // ---
--- 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;
--- 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 );