1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
23 #include "display_text.h"
25 #ifdef HAVE_LCD_CHARCELLS
31 bool display_text(short words
, char** text
, struct style_text
* style
,
32 struct viewport
* vp_text
)
34 #ifdef HAVE_LCD_BITMAP
40 int space_w
, width
, height
;
42 unsigned short vp_width
= LCD_WIDTH
;
43 unsigned short vp_height
= LCD_HEIGHT
;
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
);
56 standard_fgcolor
= rb
->lcd_get_foreground();
58 rb
->screens
[SCREEN_MAIN
]->clear_viewport();
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) {
70 /* .. or if the current one can't fit the word */
71 } else if (x
+ width
> vp_width
- MARGIN
) {
75 /* display the remaining text by button click or exit */
76 if (y
+ height
> vp_height
- MARGIN
) {
78 rb
->screens
[SCREEN_MAIN
]->update_viewport();
80 button
= rb
->button_get(true);
81 if ( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
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
]);
92 if (style
[style_index
].flags
&TEXT_CENTER
) {
93 x
= (vp_width
-width
)/2;
97 switch (style
[style_index
].flags
&TEXT_COLOR_MASK
) {
99 rb
->lcd_set_foreground(LCD_RGBPACK(255,0,0));
102 rb
->lcd_set_foreground(LCD_RGBPACK(255,255,0));
105 rb
->lcd_set_foreground(LCD_RGBPACK(0,192,0));
108 rb
->lcd_set_foreground(LCD_RGBPACK(0,0,255));
111 rb
->lcd_set_foreground(LCD_RGBPACK(255,192,0));
115 rb
->lcd_set_foreground(standard_fgcolor
);
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);
126 #ifdef HAVE_LCD_COLOR
127 rb
->lcd_set_foreground(standard_fgcolor
);
131 x
+= width
+ space_w
;
133 rb
->screens
[SCREEN_MAIN
]->update_viewport();
134 #ifdef HAVE_LCD_BITMAP
135 rb
->lcd_set_drawmode(prev_drawmode
);