Changeset 849

Show
Ignore:
Timestamp:
01/28/08 18:03:27 (10 months ago)
Author:
michux
Message:

added pingpong scrolling

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/widget_text.c

    r845 r849  
    66 * Copyright (C) 2003, 2004 Michael Reinelt <michael@reinelt.co.at> 
    77 * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> 
     8 * Copyright (C) 2008 Michael Vogt <michu@neophob.com>  
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    9697  if (T->scroll >= width + len) 
    9798      T->scroll = 0; 
     99  break;   
     100    case ALIGN_PINGPONG: 
     101#define PINGPONGWAIT 2 
     102 
     103  /* scrolling is not necessary - center the string */ 
     104  if (len <= width) { 
     105      pad = (width - len) / 2; 
     106  } 
     107  else { 
     108      if (T->direction == 1) 
     109    T->scroll++;    /* scroll right */ 
     110      else 
     111    T->scroll--;    /* scroll left */ 
     112     
     113      /*pad = if positive, add leading space characters, else offset of string begin */  
     114      pad = 0-T->scroll; 
     115       
     116      if (pad < 0-(len-width)) { 
     117    if (T->delay-- < 1) { /* wait before switch direction */ 
     118        T->direction = 0; /* change scroll direction */ 
     119        T->delay = PINGPONGWAIT; 
     120        T->scroll -= PINGPONGWAIT; 
     121    } /* else debug("wait1"); */ 
     122    pad = 0-(len-width); 
     123      }  
     124      else 
     125      if (pad > 0) { 
     126    if (T->delay-- < 1) { 
     127        T->direction = 1; 
     128        T->delay = PINGPONGWAIT; 
     129        T->scroll += PINGPONGWAIT; 
     130    } /* else debug("wait2"); */ 
     131    pad = 0; 
     132      } 
     133       
     134  } 
    98135  break; 
    99136    default:      /* not reached  */ 
     
    220257    /* something has changed and should be updated */ 
    221258    if (update) { 
    222   /* reset marquee counter if content has changed */ 
     259  /* reset marquee counter if content has changed */   
    223260  T->scroll = 0; 
     261   
     262  /* Init pingpong scroller. start scrolling left (wrong way) to get a delay */ 
     263  if (T->align == ALIGN_PINGPONG) { 
     264      T->direction = 0;  
     265      T->delay = PINGPONGWAIT; 
     266  } 
    224267  /* if there's a marquee scroller active, it has its own */ 
    225268  /* update callback timer, so we do nothing here; otherwise */ 
    226269  /* we simply call this scroll callback directly */ 
    227   if (T->align != ALIGN_MARQUEE || T->align != ALIGN_AUTOMATIC) { 
     270  if (T->align != ALIGN_MARQUEE || T->align != ALIGN_AUTOMATIC || T->align != ALIGN_PINGPONG) { 
    228271      widget_text_scroll(Self); 
    229272  } 
     
    288331  Text->align = ALIGN_AUTOMATIC; 
    289332  break; 
     333    case 'P': 
     334  Text->align = ALIGN_PINGPONG; 
     335  break;               
    290336    default: 
    291337  error("widget %s has unknown alignment '%s', using 'Left'", section, c); 
     
    301347 
    302348    /* marquee scroller speed: interval (msec), default 500msec */ 
    303     if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC) { 
     349    if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC || Text->align == ALIGN_PINGPONG) { 
    304350  cfg_number(section, "speed", 500, 10, -1, &(Text->speed)); 
    305351    } 
     
    315361 
    316362    /* a marquee scroller has its own timer and callback */ 
    317     if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC) { 
     363    if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC || Text->align == ALIGN_PINGPONG) { 
    318364  timer_add(widget_text_scroll, Self, Text->speed, 0); 
    319365    } 
  • trunk/widget_text.h

    r845 r849  
    3131#include "property.h" 
    3232 
    33 typedef enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_MARQUEE, ALIGN_AUTOMATIC } TEXT_ALIGN; 
     33typedef enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_MARQUEE, ALIGN_AUTOMATIC, ALIGN_PINGPONG } TEXT_ALIGN; 
    3434 
    3535typedef struct WIDGET_TEXT { 
     
    4646    int scroll;     /* marquee starting point */ 
    4747    int speed;      /* marquee scrolling speed */ 
     48    int direction;    /* pingpong direction, 0=right, 1=left */ 
     49    int delay;      /* pingpong scrolling, wait before switch direction */ 
    4850} WIDGET_TEXT; 
    4951