1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Dave Chapman
12 * Copyright (C) 2006 Shachar Liberman
13 * Offset text, scrolling
14 * Copyright (C) 2007 Nicolas Pennequin, Tom Ross, Ken Fazzone, Akio Idehara
15 * Color gradient background
16 * Copyright (C) 2009 Andrew Mahone
17 * Merged common LCD bitmap code
19 * Rockbox common bitmap LCD functions
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation; either version 2
24 * of the License, or (at your option) any later version.
26 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
27 * KIND, either express or implied.
29 ****************************************************************************/
31 #ifndef LCDFN /* Not compiling for remote - define macros for main LCD. */
32 #define LCDFN(fn) lcd_ ## fn
33 #define FBFN(fn) fb_ ## fn
34 #define LCDM(ma) LCD_ ## ma
35 #define LCDNAME "lcd_"
39 #if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
40 /* Fill a rectangle with a gradient */
41 static void lcd_gradient_rect(int x1
, int x2
, int y
, unsigned h
,
42 int num_lines
, int cur_line
)
44 int old_pattern
= current_vp
->fg_pattern
;
50 step_mul
= (1 << 16) / (num_lines
);
51 int h_r
= RGB_UNPACK_RED(current_vp
->lss_pattern
);
52 int h_g
= RGB_UNPACK_GREEN(current_vp
->lss_pattern
);
53 int h_b
= RGB_UNPACK_BLUE(current_vp
->lss_pattern
);
54 int rstep
= (h_r
- RGB_UNPACK_RED(current_vp
->lse_pattern
)) * step_mul
;
55 int gstep
= (h_g
- RGB_UNPACK_GREEN(current_vp
->lse_pattern
)) * step_mul
;
56 int bstep
= (h_b
- RGB_UNPACK_BLUE(current_vp
->lse_pattern
)) * step_mul
;
57 h_r
= (h_r
<< 16) + (1 << 15);
58 h_g
= (h_g
<< 16) + (1 << 15);
59 h_b
= (h_b
<< 16) + (1 << 15);
62 h_r
-= cur_line
* rstep
;
63 h_g
-= cur_line
* gstep
;
64 h_b
-= cur_line
* bstep
;
68 for(count
= 0; count
< h
; count
++) {
69 current_vp
->fg_pattern
= LCD_RGBPACK(h_r
>> 16, h_g
>> 16, h_b
>> 16);
70 lcd_hline(x1
, x2
, y
+ count
);
76 current_vp
->fg_pattern
= old_pattern
;
80 /* put a string at a given pixel position, skipping first ofs pixel columns */
81 static void LCDFN(putsxyofs
)(int x
, int y
, int ofs
, const unsigned char *str
)
85 struct font
* pf
= font_get(current_vp
->font
);
87 ucs
= bidi_l2v(str
, 1);
89 while ((ch
= *ucs
++) != 0 && x
< current_vp
->width
)
92 const unsigned char *bits
;
94 /* get proportional width and glyph bits */
95 width
= font_get_width(pf
, ch
);
103 bits
= font_get_bits(pf
, ch
);
105 #if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
107 lcd_alpha_bitmap_part(bits
, ofs
, 0, width
, x
, y
, width
- ofs
,
111 LCDFN(mono_bitmap_part
)(bits
, ofs
, 0, width
, x
, y
, width
- ofs
,
118 /* put a string at a given pixel position */
119 void LCDFN(putsxy
)(int x
, int y
, const unsigned char *str
)
121 LCDFN(putsxyofs
)(x
, y
, 0, str
);
124 static void LCDFN(putsxyofs_style
)(int xpos
, int ypos
,
125 const unsigned char *str
, int style
,
126 int w
, int h
, int offset
)
128 int lastmode
= current_vp
->drawmode
;
129 int xrect
= xpos
+ MAX(w
- offset
, 0);
130 #if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
131 int oldfgcolor
= current_vp
->fg_pattern
;
132 int oldbgcolor
= current_vp
->bg_pattern
;
133 current_vp
->drawmode
= DRMODE_SOLID
| ((style
& STYLE_INVERT
) ?
134 DRMODE_INVERSEVID
: 0);
135 if (style
& STYLE_COLORED
) {
136 if (current_vp
->drawmode
== DRMODE_SOLID
)
137 current_vp
->fg_pattern
= style
& STYLE_COLOR_MASK
;
139 current_vp
->bg_pattern
= style
& STYLE_COLOR_MASK
;
141 current_vp
->drawmode
^= DRMODE_INVERSEVID
;
142 if (style
& STYLE_GRADIENT
) {
143 current_vp
->drawmode
= DRMODE_FG
;
144 lcd_gradient_rect(xpos
, current_vp
->width
, ypos
, h
,
145 NUMLN_UNPACK(style
), CURLN_UNPACK(style
));
146 current_vp
->fg_pattern
= current_vp
->lst_pattern
;
148 else if (style
& STYLE_COLORBAR
) {
149 current_vp
->drawmode
= DRMODE_FG
;
150 current_vp
->fg_pattern
= current_vp
->lss_pattern
;
151 lcd_fillrect(xpos
, ypos
, current_vp
->width
- xpos
, h
);
152 current_vp
->fg_pattern
= current_vp
->lst_pattern
;
155 lcd_fillrect(xrect
, ypos
, current_vp
->width
- xrect
, h
);
156 current_vp
->drawmode
= (style
& STYLE_INVERT
) ?
157 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
159 lcd_putsxyofs(xpos
, ypos
, offset
, str
);
160 current_vp
->fg_pattern
= oldfgcolor
;
161 current_vp
->bg_pattern
= oldbgcolor
;
163 current_vp
->drawmode
= DRMODE_SOLID
| ((style
& STYLE_INVERT
) ?
164 0 : DRMODE_INVERSEVID
);
165 LCDFN(fillrect
)(xrect
, ypos
, current_vp
->width
- xrect
, h
);
166 current_vp
->drawmode
^= DRMODE_INVERSEVID
;
167 LCDFN(putsxyofs
)(xpos
, ypos
, offset
, str
);
169 current_vp
->drawmode
= lastmode
;
172 /*** Line oriented text output ***/
174 /* put a string at a given char position */
175 void LCDFN(puts_style_offset
)(int x
, int y
, const unsigned char *str
,
176 int style
, int offset
)
178 int xpos
, ypos
, w
, h
;
179 LCDFN(scroll_stop_line
)(current_vp
, y
);
182 LCDFN(getstringsize
)(str
, &w
, &h
);
183 xpos
= x
* w
/ utf8length((char *)str
);
185 LCDFN(putsxyofs_style
)(xpos
, ypos
, str
, style
, w
, h
, offset
);
188 void LCDFN(puts
)(int x
, int y
, const unsigned char *str
)
190 LCDFN(puts_style_offset
)(x
, y
, str
, STYLE_DEFAULT
, 0);
193 void LCDFN(puts_style
)(int x
, int y
, const unsigned char *str
, int style
)
195 LCDFN(puts_style_offset
)(x
, y
, str
, style
, 0);
198 void LCDFN(puts_offset
)(int x
, int y
, const unsigned char *str
, int offset
)
200 LCDFN(puts_style_offset
)(x
, y
, str
, STYLE_DEFAULT
, offset
);
205 void LCDFN(puts_scroll_style_offset
)(int x
, int y
, const unsigned char *string
,
206 int style
, int offset
)
210 if ((unsigned)y
>= (unsigned)current_vp
->height
)
213 /* remove any previously scrolling line at the same location */
214 lcd_scroll_stop_line(current_vp
, y
);
216 if (LCDFN(scroll_info
.lines
) >= LCDM(SCROLLABLE_LINES
)) return;
219 LCDFN(puts_style_offset
)(x
, y
, string
, style
, offset
);
221 LCDFN(getstringsize
)(string
, &w
, &h
);
223 if (current_vp
->width
- x
* 8 < w
) {
224 /* prepare scroll line */
225 struct scrollinfo
* s
;
226 s
= &LCDFN(scroll_info
).scroll
[LCDFN(scroll_info
).lines
];
227 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
;
232 memset(s
->line
, 0, sizeof s
->line
);
233 strcpy(s
->line
, string
);
236 s
->width
= LCDFN(getstringsize
)(s
->line
, &w
, &h
);
238 /* scroll bidirectional or forward only depending on the string
240 if ( LCDFN(scroll_info
).bidir_limit
) {
241 s
->bidir
= s
->width
< (current_vp
->width
) *
242 (100 + LCDFN(scroll_info
).bidir_limit
) / 100;
247 if (!s
->bidir
) { /* add spaces if scrolling in the round */
248 strcat(s
->line
, " ");
249 /* get new width incl. spaces */
250 s
->width
= LCDFN(getstringsize
)(s
->line
, &w
, &h
);
253 end
= strchr(s
->line
, '\0');
254 strlcpy(end
, string
, current_vp
->width
/2);
258 s
->len
= utf8length(string
);
260 s
->startx
= x
* s
->width
/ s
->len
;
263 LCDFN(scroll_info
).lines
++;
267 void LCDFN(puts_scroll
)(int x
, int y
, const unsigned char *string
)
269 LCDFN(puts_scroll_style
)(x
, y
, string
, STYLE_DEFAULT
);
272 void LCDFN(puts_scroll_style
)(int x
, int y
, const unsigned char *string
,
275 LCDFN(puts_scroll_style_offset
)(x
, y
, string
, style
, 0);
278 void LCDFN(puts_scroll_offset
)(int x
, int y
, const unsigned char *string
,
281 LCDFN(puts_scroll_style_offset
)(x
, y
, string
, STYLE_DEFAULT
, offset
);
284 void LCDFN(scroll_fn
)(void)
287 struct scrollinfo
* s
;
290 struct viewport
* old_vp
= current_vp
;
292 for ( index
= 0; index
< LCDFN(scroll_info
).lines
; index
++ ) {
293 s
= &LCDFN(scroll_info
).scroll
[index
];
296 if (TIME_BEFORE(current_tick
, s
->start_tick
))
299 LCDFN(set_viewport
)(s
->vp
);
302 s
->offset
-= LCDFN(scroll_info
).step
;
304 s
->offset
+= LCDFN(scroll_info
).step
;
306 pf
= font_get(current_vp
->font
);
308 ypos
= s
->y
* pf
->height
;
310 if (s
->bidir
) { /* scroll bidirectional */
311 if (s
->offset
<= 0) {
312 /* at beginning of line */
315 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
* 2;
317 if (s
->offset
>= s
->width
- (current_vp
->width
- xpos
)) {
319 s
->offset
= s
->width
- (current_vp
->width
- xpos
);
321 s
->start_tick
= current_tick
+ LCDFN(scroll_info
).delay
* 2;
325 /* scroll forward the whole time */
326 if (s
->offset
>= s
->width
)
327 s
->offset
%= s
->width
;
329 LCDFN(putsxyofs_style
)(xpos
, ypos
, s
->line
, s
->style
, s
->width
,
330 pf
->height
, s
->offset
);
331 LCDFN(update_viewport_rect
)(xpos
, ypos
, current_vp
->width
- xpos
,
334 LCDFN(set_viewport
)(old_vp
);