Call the oddly labelled button on the gigabeat remote "Menu" in the
[kugel-rb.git] / apps / plugins / lib / display_text.c
blobc69661030e5f6d093feadedc31a237dabf107a85
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Johannes Schwarz
11 * based on Will Robertson code in superdom
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
22 #include "plugin.h"
23 #include "display_text.h"
25 #ifdef HAVE_LCD_CHARCELLS
26 #define MARGIN 0
27 #else
28 #define MARGIN 5
29 #endif
31 bool display_text(short words, char** text, struct style_text* style,
32 struct viewport* vp_text)
34 #ifdef HAVE_LCD_BITMAP
35 int prev_drawmode;
36 #endif
37 #ifdef HAVE_LCD_COLOR
38 int 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 unsigned short i = 0, style_index = 0;
46 if (vp_text != NULL) {
47 vp_width = vp_text->width;
48 vp_height = vp_text->height;
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 word is an empty string */
66 if (rb->strcmp(text[i], "")==0) {
67 x = MARGIN;
68 y = y + height;
69 continue;
70 /* .. or if the current one can't fit the word */
71 } else if (x + width > vp_width - MARGIN) {
72 x = MARGIN;
73 y = y + height;
75 /* display the remaining text by button click or exit */
76 if (y + height > vp_height - MARGIN) {
77 y = MARGIN;
78 rb->screens[SCREEN_MAIN]->update_viewport();
79 do {
80 button = rb->button_get(true);
81 if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED )
82 return true;
83 } while( ( button == BUTTON_NONE )
84 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
85 rb->screens[SCREEN_MAIN]->clear_viewport();
87 /* no text formatting available */
88 if (style==NULL || style[style_index].index != i) {
89 rb->lcd_putsxy(x, y, text[i]);
90 } else {
91 /* set align */
92 if (style[style_index].flags&TEXT_CENTER) {
93 x = (vp_width-width)/2;
95 /* set font color */
96 #ifdef HAVE_LCD_COLOR
97 switch (style[style_index].flags&TEXT_COLOR_MASK) {
98 case C_RED:
99 rb->lcd_set_foreground(LCD_RGBPACK(255,0,0));
100 break;
101 case C_YELLOW:
102 rb->lcd_set_foreground(LCD_RGBPACK(255,255,0));
103 break;
104 case C_GREEN:
105 rb->lcd_set_foreground(LCD_RGBPACK(0,192,0));
106 break;
107 case C_BLUE:
108 rb->lcd_set_foreground(LCD_RGBPACK(0,0,255));
109 break;
110 case C_ORANGE:
111 rb->lcd_set_foreground(LCD_RGBPACK(255,192,0));
112 break;
113 case STANDARD:
114 default:
115 rb->lcd_set_foreground(standard_fgcolor);
116 break;
118 #endif
119 rb->lcd_putsxy(x, y, text[i]);
120 /* underline the word */
121 #ifdef HAVE_LCD_BITMAP
122 if (style[style_index].flags&TEXT_UNDERLINE) {
123 rb->lcd_hline(x, x+width, y+height-1);
125 #endif
126 #ifdef HAVE_LCD_COLOR
127 rb->lcd_set_foreground(standard_fgcolor);
128 #endif
129 style_index++;
131 x += width + space_w;
133 rb->screens[SCREEN_MAIN]->update_viewport();
134 #ifdef HAVE_LCD_BITMAP
135 rb->lcd_set_drawmode(prev_drawmode);
136 #endif
137 return false;