aboutsummaryrefslogtreecommitdiffstats
path: root/widget_text.c
diff options
context:
space:
mode:
Diffstat (limited to 'widget_text.c')
-rw-r--r--widget_text.c119
1 files changed, 108 insertions, 11 deletions
diff --git a/widget_text.c b/widget_text.c
index ffe1863..1199e40 100644
--- a/widget_text.c
+++ b/widget_text.c
@@ -1,10 +1,11 @@
-/* $Id: widget_text.c 773 2007-02-25 12:39:09Z michael $
- * $URL: https://ssl.bulix.org/svn/lcd4linux/branches/0.10.1/widget_text.c $
+/* $Id: widget_text.c 1106 2010-02-07 14:03:46Z mzuther $
+ * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/widget_text.c $
*
* simple text widget handling
*
- * Copyright (C) 2003, 2004 Michael Reinelt <reinelt@eunet.at>
+ * Copyright (C) 2003, 2004 Michael Reinelt <michael@reinelt.co.at>
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
+ * Copyright (C) 2008 Michael Vogt <michu@neophob.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,11 +23,11 @@
*
*/
-/*
+/*
* exported functions:
*
* WIDGET_CLASS Widget_Text
- * a simple text widget which
+ * a simple text widget which
* must be supported by all displays
*
*/
@@ -44,9 +45,11 @@
#include "evaluator.h"
#include "property.h"
#include "timer.h"
+#include "timer_group.h"
+#include "event.h"
#include "widget.h"
#include "widget_text.h"
-#
+
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif
@@ -85,12 +88,66 @@ void widget_text_scroll(void *Self)
if (pad < 0)
pad = 0;
break;
+ case ALIGN_AUTOMATIC:
+ if (len <= width) {
+ pad = 0;
+ break;
+ }
case ALIGN_MARQUEE:
pad = width - T->scroll;
T->scroll++;
if (T->scroll >= width + len)
T->scroll = 0;
break;
+ case ALIGN_PINGPONG_LEFT:
+ case ALIGN_PINGPONG_CENTER:
+ case ALIGN_PINGPONG_RIGHT:
+#define PINGPONGWAIT 2
+
+ /* scrolling is not necessary - align the string */
+ if (len <= width) {
+ switch (T->align) {
+ case ALIGN_PINGPONG_LEFT:
+ pad = 0;
+ break;
+ case ALIGN_PINGPONG_RIGHT:
+ pad = width - len;
+ if (pad < 0)
+ pad = 0;
+ break;
+ default:
+ pad = (width - len) / 2;
+ if (pad < 0)
+ pad = 0;
+ break;
+ }
+ } else {
+ if (T->direction == 1)
+ T->scroll++; /* scroll right */
+ else
+ T->scroll--; /* scroll left */
+
+ /*pad = if positive, add leading space characters, else offset of string begin */
+ pad = 0 - T->scroll;
+
+ if (pad < 0 - (len - width)) {
+ if (T->delay-- < 1) { /* wait before switch direction */
+ T->direction = 0; /* change scroll direction */
+ T->delay = PINGPONGWAIT;
+ T->scroll -= PINGPONGWAIT;
+ } /* else debug("wait1"); */
+ pad = 0 - (len - width);
+ } else if (pad > 0) {
+ if (T->delay-- < 1) {
+ T->direction = 1;
+ T->delay = PINGPONGWAIT;
+ T->scroll += PINGPONGWAIT;
+ } /* else debug("wait2"); */
+ pad = 0;
+ }
+
+ }
+ break;
default: /* not reached */
pad = 0;
}
@@ -216,10 +273,17 @@ void widget_text_update(void *Self)
if (update) {
/* reset marquee counter if content has changed */
T->scroll = 0;
+
+ /* Init pingpong scroller. start scrolling left (wrong way) to get a delay */
+ if (T->align == ALIGN_PINGPONG_LEFT || T->align == ALIGN_PINGPONG_CENTER || T->align == ALIGN_PINGPONG_RIGHT) {
+ T->direction = 0;
+ T->delay = PINGPONGWAIT;
+ }
/* if there's a marquee scroller active, it has its own */
/* update callback timer, so we do nothing here; otherwise */
/* we simply call this scroll callback directly */
- if (T->align != ALIGN_MARQUEE) {
+ if (T->align != ALIGN_MARQUEE || T->align != ALIGN_AUTOMATIC || T->align != ALIGN_PINGPONG_LEFT
+ || T->align != ALIGN_PINGPONG_CENTER || T->align != ALIGN_PINGPONG_RIGHT) {
widget_text_scroll(Self);
}
}
@@ -266,7 +330,7 @@ int widget_text_init(WIDGET * Self)
/* field alignment: Left (default), Center, Right or Marquee */
c = cfg_get(section, "align", "L");
- switch (toupper(*c)) {
+ switch (toupper(c[0])) {
case 'L':
Text->align = ALIGN_LEFT;
break;
@@ -279,6 +343,25 @@ int widget_text_init(WIDGET * Self)
case 'M':
Text->align = ALIGN_MARQUEE;
break;
+ case 'A':
+ Text->align = ALIGN_AUTOMATIC;
+ break;
+ case 'P':
+ switch (toupper(c[1])) {
+ case 'C':
+ Text->align = ALIGN_PINGPONG_CENTER;
+ break;
+ case 'L':
+ Text->align = ALIGN_PINGPONG_LEFT;
+ break;
+ case 'R':
+ Text->align = ALIGN_PINGPONG_RIGHT;
+ break;
+ default:
+ Text->align = ALIGN_PINGPONG_CENTER;
+ error("widget %s has unknown alignment '%s', using 'Centered Pingpong'", section, c);
+ }
+ break;
default:
error("widget %s has unknown alignment '%s', using 'Left'", section, c);
Text->align = ALIGN_LEFT;
@@ -292,21 +375,35 @@ int widget_text_init(WIDGET * Self)
Text->update = 10;
/* marquee scroller speed: interval (msec), default 500msec */
- if (Text->align == ALIGN_MARQUEE) {
+ if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC || Text->align == ALIGN_PINGPONG_LEFT
+ || Text->align == ALIGN_PINGPONG_CENTER || Text->align == ALIGN_PINGPONG_RIGHT) {
cfg_number(section, "speed", 500, 10, -1, &(Text->speed));
}
+ //update on this event
+ char *event_name = cfg_get(section, "event", "");
+ if (*event_name != '\0') {
+ named_event_add(event_name, widget_text_update, Self);
+ if (Text->update == 1000) {
+ Text->update = 0;
+ }
+ }
+ free(event_name);
+
/* buffer */
Text->buffer = malloc(Text->width + 1);
free(section);
Self->data = Text;
+ Self->x2 = Self->col + Text->width;
+ Self->y2 = Self->row;
/* add update timer, use one-shot if 'update' is zero */
- timer_add(widget_text_update, Self, Text->update, Text->update == 0);
+ timer_add_widget(widget_text_update, Self, Text->update, Text->update == 0);
/* a marquee scroller has its own timer and callback */
- if (Text->align == ALIGN_MARQUEE) {
+ if (Text->align == ALIGN_MARQUEE || Text->align == ALIGN_AUTOMATIC || Text->align == ALIGN_PINGPONG_LEFT
+ || Text->align == ALIGN_PINGPONG_CENTER || Text->align == ALIGN_PINGPONG_RIGHT) {
timer_add(widget_text_scroll, Self, Text->speed, 0);
}