summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schwarz <ubuntuxer@rockbox.org>2009-06-28 09:48:12 +0000
committerJohannes Schwarz <ubuntuxer@rockbox.org>2009-06-28 09:48:12 +0000
commit8a21372e5bcfddabac0aa05b9dd9e3dc5e85da9b (patch)
tree9e5e3c67cbafd8b4b6806f0b5e777500e6b0135b
parent41baca7de673d8b3935fa21fb6d6b10722b10b7e (diff)
downloadrockbox-8a21372e5bcfddabac0aa05b9dd9e3dc5e85da9b.tar.gz
rockbox-8a21372e5bcfddabac0aa05b9dd9e3dc5e85da9b.zip
FS#10099: new lib, which displays formatted text on every target; also supports viewport
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21537 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/lib/SOURCES1
-rw-r--r--apps/plugins/lib/display_text.c139
-rw-r--r--apps/plugins/lib/display_text.h47
3 files changed, 187 insertions, 0 deletions
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index 2ed38c4f8b..02adb7089c 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -5,6 +5,7 @@ fixedpoint.c
5playback_control.c 5playback_control.c
6rgb_hsv.c 6rgb_hsv.c
7buflib.c 7buflib.c
8display_text.c
8#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) 9#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
9grey_core.c 10grey_core.c
10grey_draw.c 11grey_draw.c
diff --git a/apps/plugins/lib/display_text.c b/apps/plugins/lib/display_text.c
new file mode 100644
index 0000000000..8ba31e2ff3
--- /dev/null
+++ b/apps/plugins/lib/display_text.c
@@ -0,0 +1,139 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Johannes Schwarz
11 * based on Will Robertson code in superdom
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "plugin.h"
23#include "display_text.h"
24
25#ifdef HAVE_LCD_CHARCELLS
26#define MARGIN 0
27#else
28#define MARGIN 5
29#endif
30
31bool display_text(short words, char** text, struct style_text* style,
32 struct viewport* vp_text)
33{
34#ifdef HAVE_LCD_BITMAP
35 int prev_drawmode;
36#endif
37#ifdef HAVE_LCD_COLOR
38 unsigned standard_fgcolor;
39#endif
40 int space_w, width, height;
41 unsigned short x , y;
42 unsigned short vp_width = LCD_WIDTH;
43 unsigned short vp_height = LCD_HEIGHT;
44 int button;
45 short i=0;
46 if (vp_text != NULL) {
47 vp_width = vp_text->width;
48 vp_height = vp_text->height;
49 }
50 rb->screens[SCREEN_MAIN]->set_viewport(vp_text);
51#ifdef HAVE_LCD_BITMAP
52 prev_drawmode = rb->lcd_get_drawmode();
53 rb->lcd_set_drawmode(DRMODE_SOLID);
54#endif
55#ifdef HAVE_LCD_COLOR
56 standard_fgcolor = rb->lcd_get_foreground();
57#endif
58 rb->screens[SCREEN_MAIN]->clear_viewport();
59 x = MARGIN;
60 y = MARGIN;
61 rb->button_clear_queue();
62 rb->lcd_getstringsize(" ", &space_w, &height);
63 for (i = 0; i < words; i++) {
64 rb->lcd_getstringsize(text[i], &width, NULL);
65 /* skip to next line if the current one can't fit the word */
66 if (x + width > vp_width - MARGIN) {
67 x = MARGIN;
68 y = y + height;
69 }
70 /* .. or if the word is the empty string */
71 if (rb->strcmp(text[i], "")==0) {
72 x = MARGIN;
73 y = y + height;
74 continue;
75 }
76 /* display the remaining text by button click or exit */
77 if (y + height > vp_height - MARGIN) {
78 y = MARGIN;
79 rb->screens[SCREEN_MAIN]->update_viewport();
80 do {
81 button = rb->button_get(true);
82 if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
83 return true;
84 } while( ( button == BUTTON_NONE )
85 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
86 rb->screens[SCREEN_MAIN]->clear_viewport();
87 }
88 /* no text formations available */
89 if (style==NULL) {
90 rb->lcd_putsxy(x, y, text[i]);
91 } else {
92 /* set align */
93 if (style[i].flags&TEXT_CENTER) {
94 x = (vp_width-width)/2;
95 }
96 /* set font color */
97#ifdef HAVE_LCD_COLOR
98 switch (style[i].flags&TEXT_COLOR_MASK) {
99 case C_RED:
100 rb->lcd_set_foreground(LCD_RGBPACK(255,0,0));
101 break;
102 case C_YELLOW:
103 rb->lcd_set_foreground(LCD_RGBPACK(255,255,0));
104 break;
105 case C_GREEN:
106 rb->lcd_set_foreground(LCD_RGBPACK(0,192,0));
107 break;
108 case C_BLUE:
109 rb->lcd_set_foreground(LCD_RGBPACK(0,0,255));
110 break;
111 case C_ORANGE:
112 rb->lcd_set_foreground(LCD_RGBPACK(255,192,0));
113 break;
114 case STANDARD:
115 default:
116 rb->lcd_set_foreground(standard_fgcolor);
117 break;
118 }
119#endif
120 rb->lcd_putsxy(x, y, text[i]);
121#ifdef HAVE_LCD_BITMAP
122 if (style[i].flags&TEXT_UNDERLINE) {
123 rb->lcd_hline(x, x+width, y+height-1);
124 }
125#endif
126 }
127 x += width + space_w;
128 }
129 rb->screens[SCREEN_MAIN]->update_viewport();
130#ifdef HAVE_LCD_BITMAP
131 rb->lcd_set_drawmode(prev_drawmode);
132#endif
133#ifdef HAVE_LCD_COLOR
134 if (style!=NULL) {
135 rb->lcd_set_foreground(standard_fgcolor);
136 }
137#endif
138 return false;
139}
diff --git a/apps/plugins/lib/display_text.h b/apps/plugins/lib/display_text.h
new file mode 100644
index 0000000000..9f21d236ea
--- /dev/null
+++ b/apps/plugins/lib/display_text.h
@@ -0,0 +1,47 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Johannes Schwarz
11 * based on Will Robertson code in superdom
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "plugin.h"
23/*
24 * basic usage:
25 * #define WORDS (sizeof text / sizeof (char*))
26 * char *text[] = {"normal", "centering", "red,underline"};
27 * struct style_text formation[WORDS]={
28 * [1] = { TEXT_CENTER },
29 * [2] = { C_RED|TEXT_UNDERLINE },
30 * };
31 * if (display_text(WORDS, text, formation, NULL))
32 * return PLUGIN_USB_CONNECTED;
33 */
34
35enum ecolor { STANDARD, C_YELLOW, C_RED, C_BLUE, C_GREEN , C_ORANGE };
36#define TEXT_COLOR_MASK 0x00ff
37#define TEXT_CENTER 0x0100
38#define TEXT_UNDERLINE 0x0200
39
40struct style_text {
41 unsigned short flags;
42};
43
44/* style and vp_text is optional.
45 * return true if usb is connected. */
46bool display_text(short words, char** text, struct style_text* style,
47 struct viewport* vp_text);