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 static bool wait_key_press(void)
35 button
= rb
->button_get(true);
36 if ( rb
->default_event_handler( button
) == SYS_USB_CONNECTED
)
38 } while( ( button
== BUTTON_NONE
)
39 || ( button
& (BUTTON_REL
|BUTTON_REPEAT
) ) );
43 bool display_text(unsigned short words
, char** text
, struct style_text
* style
,
44 struct viewport
* vp_text
, bool wait_key
)
46 #ifdef HAVE_LCD_BITMAP
52 int space_w
, width
, height
;
54 unsigned short vp_width
= LCD_WIDTH
;
55 unsigned short vp_height
= LCD_HEIGHT
;
56 unsigned short i
= 0, style_index
= 0;
57 if (vp_text
!= NULL
) {
58 vp_width
= vp_text
->width
;
59 vp_height
= vp_text
->height
;
61 rb
->screens
[SCREEN_MAIN
]->set_viewport(vp_text
);
62 #ifdef HAVE_LCD_BITMAP
63 prev_drawmode
= rb
->lcd_get_drawmode();
64 rb
->lcd_set_drawmode(DRMODE_SOLID
);
67 standard_fgcolor
= rb
->lcd_get_foreground();
69 rb
->screens
[SCREEN_MAIN
]->clear_viewport();
72 rb
->button_clear_queue();
73 rb
->lcd_getstringsize(" ", &space_w
, &height
);
74 for (i
= 0; i
< words
; i
++) {
75 rb
->lcd_getstringsize(text
[i
], &width
, NULL
);
76 /* skip to next line if the word is an empty string */
77 if (rb
->strcmp(text
[i
], "")==0) {
81 /* .. or if the current one can't fit the word */
82 } else if (x
+ width
> vp_width
- MARGIN
) {
86 /* display the remaining text by button click or exit */
87 if (y
+ height
> vp_height
- MARGIN
) {
89 rb
->screens
[SCREEN_MAIN
]->update_viewport();
92 rb
->screens
[SCREEN_MAIN
]->clear_viewport();
94 /* no text formatting available */
95 if (style
==NULL
|| style
[style_index
].index
!= i
) {
96 rb
->lcd_putsxy(x
, y
, text
[i
]);
99 if (style
[style_index
].flags
&TEXT_CENTER
) {
100 x
= (vp_width
-width
)/2;
103 #ifdef HAVE_LCD_COLOR
104 switch (style
[style_index
].flags
&TEXT_COLOR_MASK
) {
106 rb
->lcd_set_foreground(LCD_RGBPACK(255,0,0));
109 rb
->lcd_set_foreground(LCD_RGBPACK(255,255,0));
112 rb
->lcd_set_foreground(LCD_RGBPACK(0,192,0));
115 rb
->lcd_set_foreground(LCD_RGBPACK(0,0,255));
118 rb
->lcd_set_foreground(LCD_RGBPACK(255,192,0));
122 rb
->lcd_set_foreground(standard_fgcolor
);
126 rb
->lcd_putsxy(x
, y
, text
[i
]);
127 /* underline the word */
128 #ifdef HAVE_LCD_BITMAP
129 if (style
[style_index
].flags
&TEXT_UNDERLINE
) {
130 rb
->lcd_hline(x
, x
+width
, y
+height
-1);
133 #ifdef HAVE_LCD_COLOR
134 rb
->lcd_set_foreground(standard_fgcolor
);
138 x
+= width
+ space_w
;
140 rb
->screens
[SCREEN_MAIN
]->update_viewport();
141 #ifdef HAVE_LCD_BITMAP
142 rb
->lcd_set_drawmode(prev_drawmode
);
146 if (wait_key_press())