1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Dave Chapman
12 * Rockbox driver for 16-bit colour LCDs
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
34 #include "rbunicode.h"
36 #include "scroll_engine.h"
45 fb_data lcd_framebuffer
[LCD_FBHEIGHT
][LCD_FBWIDTH
]
46 IRAM_LCDFRAMEBUFFER
CACHEALIGN_AT_LEAST_ATTR(16);
49 static fb_data
* lcd_backdrop
= NULL
;
50 static long lcd_backdrop_offset IDATA_ATTR
= 0;
52 static struct viewport default_vp
=
58 .font
= FONT_SYSFIXED
,
59 .drawmode
= DRMODE_SOLID
,
62 .fg_pattern
= LCD_DEFAULT_FG
,
63 .bg_pattern
= LCD_DEFAULT_BG
,
64 .lss_pattern
= LCD_DEFAULT_BG
,
65 .lse_pattern
= LCD_DEFAULT_BG
,
66 .lst_pattern
= LCD_DEFAULT_BG
,
69 /* The Gigabeat target build requires access to the current fg_pattern
71 #if (!defined(TOSHIBA_GIGABEAT_F)&& !defined(TOSHIBA_GIGABEAT_S)) || defined(SIMULATOR)
72 static struct viewport
* current_vp IDATA_ATTR
= &default_vp
;
74 struct viewport
* current_vp IDATA_ATTR
= &default_vp
;
82 /* Call device specific init */
89 void lcd_set_viewport(struct viewport
* vp
)
92 current_vp
= &default_vp
;
97 void lcd_update_viewport(void)
99 lcd_update_rect(current_vp
->x
, current_vp
->y
,
100 current_vp
->width
, current_vp
->height
);
103 void lcd_update_viewport_rect(int x
, int y
, int width
, int height
)
105 lcd_update_rect(current_vp
->x
+ x
, current_vp
->y
+ y
, width
, height
);
108 /*** parameter handling ***/
110 void lcd_set_drawmode(int mode
)
112 current_vp
->drawmode
= mode
& (DRMODE_SOLID
|DRMODE_INVERSEVID
);
115 int lcd_get_drawmode(void)
117 return current_vp
->drawmode
;
120 void lcd_set_foreground(unsigned color
)
122 current_vp
->fg_pattern
= color
;
125 unsigned lcd_get_foreground(void)
127 return current_vp
->fg_pattern
;
130 void lcd_set_background(unsigned color
)
132 current_vp
->bg_pattern
= color
;
135 unsigned lcd_get_background(void)
137 return current_vp
->bg_pattern
;
140 void lcd_set_selector_start(unsigned color
)
142 current_vp
->lss_pattern
= color
;
145 void lcd_set_selector_end(unsigned color
)
147 current_vp
->lse_pattern
= color
;
150 void lcd_set_selector_text(unsigned color
)
152 current_vp
->lst_pattern
= color
;
155 void lcd_set_drawinfo(int mode
, unsigned fg_color
, unsigned bg_color
)
157 lcd_set_drawmode(mode
);
158 current_vp
->fg_pattern
= fg_color
;
159 current_vp
->bg_pattern
= bg_color
;
162 void lcd_setmargins(int x
, int y
)
164 current_vp
->xmargin
= x
;
165 current_vp
->ymargin
= y
;
168 int lcd_getwidth(void)
170 return current_vp
->width
;
173 int lcd_getheight(void)
175 return current_vp
->height
;
178 int lcd_getxmargin(void)
180 return current_vp
->xmargin
;
183 int lcd_getymargin(void)
185 return current_vp
->ymargin
;
188 void lcd_setfont(int newfont
)
190 current_vp
->font
= newfont
;
193 int lcd_getfont(void)
195 return current_vp
->font
;
198 int lcd_getstringsize(const unsigned char *str
, int *w
, int *h
)
200 return font_getstringsize(str
, w
, h
, current_vp
->font
);
203 /*** low-level drawing functions ***/
205 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
207 static void ICODE_ATTR
setpixel(fb_data
*address
)
209 *address
= current_vp
->fg_pattern
;
212 static void ICODE_ATTR
clearpixel(fb_data
*address
)
214 *address
= current_vp
->bg_pattern
;
217 static void ICODE_ATTR
clearimgpixel(fb_data
*address
)
219 *address
= *(fb_data
*)((long)address
+ lcd_backdrop_offset
);
222 static void ICODE_ATTR
flippixel(fb_data
*address
)
224 *address
= ~(*address
);
227 static void ICODE_ATTR
nopixel(fb_data
*address
)
232 lcd_fastpixelfunc_type
* const lcd_fastpixelfuncs_bgcolor
[8] = {
233 flippixel
, nopixel
, setpixel
, setpixel
,
234 nopixel
, clearpixel
, nopixel
, clearpixel
237 lcd_fastpixelfunc_type
* const lcd_fastpixelfuncs_backdrop
[8] = {
238 flippixel
, nopixel
, setpixel
, setpixel
,
239 nopixel
, clearimgpixel
, nopixel
, clearimgpixel
242 lcd_fastpixelfunc_type
* const * lcd_fastpixelfuncs
= lcd_fastpixelfuncs_bgcolor
;
244 void lcd_set_backdrop(fb_data
* backdrop
)
246 lcd_backdrop
= backdrop
;
249 lcd_backdrop_offset
= (long)backdrop
- (long)&lcd_framebuffer
[0][0];
250 lcd_fastpixelfuncs
= lcd_fastpixelfuncs_backdrop
;
254 lcd_backdrop_offset
= 0;
255 lcd_fastpixelfuncs
= lcd_fastpixelfuncs_bgcolor
;
259 fb_data
* lcd_get_backdrop(void)
264 /*** drawing functions ***/
266 /* Clear the current viewport */
267 void lcd_clear_viewport(void)
269 fb_data
*dst
, *dst_end
;
271 dst
= LCDADDR(current_vp
->x
, current_vp
->y
);
272 dst_end
= dst
+ current_vp
->height
* LCD_WIDTH
;
274 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
278 memset16(dst
, current_vp
->fg_pattern
, current_vp
->width
);
281 while (dst
< dst_end
);
289 memset16(dst
, current_vp
->bg_pattern
, current_vp
->width
);
292 while (dst
< dst_end
);
298 memcpy(dst
, (void *)((long)dst
+ lcd_backdrop_offset
),
299 current_vp
->width
* sizeof(fb_data
));
302 while (dst
< dst_end
);
306 if (current_vp
== &default_vp
)
308 lcd_scroll_info
.lines
= 0;
312 lcd_scroll_stop(current_vp
);
316 /* Clear the whole display */
317 void lcd_clear_display(void)
319 struct viewport
* old_vp
= current_vp
;
321 current_vp
= &default_vp
;
323 lcd_clear_viewport();
328 /* Set a single pixel */
329 void lcd_drawpixel(int x
, int y
)
331 if (((unsigned)x
< (unsigned)current_vp
->width
) &&
332 ((unsigned)y
< (unsigned)current_vp
->height
))
333 lcd_fastpixelfuncs
[current_vp
->drawmode
](LCDADDR(current_vp
->x
+x
, current_vp
->y
+y
));
337 void lcd_drawline(int x1
, int y1
, int x2
, int y2
)
345 lcd_fastpixelfunc_type
*pfunc
= lcd_fastpixelfuncs
[current_vp
->drawmode
];
347 deltay
= abs(y2
- y1
);
350 DEBUGF("lcd_drawline() called for horizontal line - optimisation.\n");
351 lcd_hline(x1
, x2
, y1
);
354 deltax
= abs(x2
- x1
);
357 DEBUGF("lcd_drawline() called for vertical line - optimisation.\n");
358 lcd_vline(x1
, y1
, y2
);
364 if (deltax
>= deltay
)
367 d
= 2 * deltay
- deltax
;
369 dinc2
= (deltay
- deltax
) * 2;
376 d
= 2 * deltax
- deltay
;
378 dinc2
= (deltax
- deltay
) * 2;
382 numpixels
++; /* include endpoints */
399 for (i
= 0; i
< numpixels
; i
++)
401 if (((unsigned)x
< (unsigned)current_vp
->width
) && ((unsigned)y
< (unsigned)current_vp
->height
))
402 pfunc(LCDADDR(x
+ current_vp
->x
, y
+ current_vp
->y
));
419 /* Draw a horizontal line (optimised) */
420 void lcd_hline(int x1
, int x2
, int y
)
424 enum fill_opt fillopt
= OPT_NONE
;
425 fb_data
*dst
, *dst_end
;
426 lcd_fastpixelfunc_type
*pfunc
= lcd_fastpixelfuncs
[current_vp
->drawmode
];
436 /* nothing to draw? */
437 if (((unsigned)y
>= (unsigned)current_vp
->height
) ||
438 (x1
>= current_vp
->width
) ||
445 if (x2
>= current_vp
->width
)
446 x2
= current_vp
->width
-1;
450 /* Adjust x1 and y to viewport */
454 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
456 if (current_vp
->drawmode
& DRMODE_BG
)
461 bits
= current_vp
->bg_pattern
;
469 if (current_vp
->drawmode
& DRMODE_FG
)
472 bits
= current_vp
->fg_pattern
;
475 dst
= LCDADDR(x1
, y
);
480 memset16(dst
, bits
, width
);
484 memcpy(dst
, (void *)((long)dst
+ lcd_backdrop_offset
),
485 width
* sizeof(fb_data
));
489 dst_end
= dst
+ width
;
492 while (dst
< dst_end
);
497 /* Draw a vertical line (optimised) */
498 void lcd_vline(int x
, int y1
, int y2
)
501 fb_data
*dst
, *dst_end
;
502 lcd_fastpixelfunc_type
*pfunc
= lcd_fastpixelfuncs
[current_vp
->drawmode
];
512 /* nothing to draw? */
513 if ((x
>= current_vp
->width
) ||
514 (y1
>= current_vp
->height
) ||
521 if (y2
>= current_vp
->height
)
522 y2
= current_vp
->height
-1;
524 dst
= LCDADDR(x
+ current_vp
->x
, y1
+ current_vp
->y
);
525 dst_end
= dst
+ (y2
- y1
) * LCD_WIDTH
;
532 while (dst
<= dst_end
);
535 /* Draw a rectangular box */
536 void lcd_drawrect(int x
, int y
, int width
, int height
)
538 if ((width
<= 0) || (height
<= 0))
541 int x2
= x
+ width
- 1;
542 int y2
= y
+ height
- 1;
545 lcd_vline(x2
, y
, y2
);
547 lcd_hline(x
, x2
, y2
);
550 /* Fill a rectangular area */
551 void lcd_fillrect(int x
, int y
, int width
, int height
)
554 enum fill_opt fillopt
= OPT_NONE
;
555 fb_data
*dst
, *dst_end
;
556 lcd_fastpixelfunc_type
*pfunc
= lcd_fastpixelfuncs
[current_vp
->drawmode
];
558 /* nothing to draw? */
559 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
) ||
560 (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
574 if (x
+ width
> current_vp
->width
)
575 width
= current_vp
->width
- x
;
576 if (y
+ height
> current_vp
->height
)
577 height
= current_vp
->height
- y
;
579 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
581 if (current_vp
->drawmode
& DRMODE_BG
)
586 bits
= current_vp
->bg_pattern
;
594 if (current_vp
->drawmode
& DRMODE_FG
)
597 bits
= current_vp
->fg_pattern
;
600 dst
= LCDADDR(current_vp
->x
+ x
, current_vp
->y
+ y
);
601 dst_end
= dst
+ height
* LCD_WIDTH
;
605 fb_data
*dst_row
, *row_end
;
610 memset16(dst
, bits
, width
);
614 memcpy(dst
, (void *)((long)dst
+ lcd_backdrop_offset
),
615 width
* sizeof(fb_data
));
620 row_end
= dst_row
+ width
;
623 while (dst_row
< row_end
);
628 while (dst
< dst_end
);
631 /* Fill a rectangle with a gradient */
632 static void lcd_gradient_rect(int x1
, int x2
, int y
, int h
)
634 int old_pattern
= current_vp
->fg_pattern
;
638 int h_r
= RGB_UNPACK_RED(current_vp
->lss_pattern
) << 16;
639 int h_b
= RGB_UNPACK_BLUE(current_vp
->lss_pattern
) << 16;
640 int h_g
= RGB_UNPACK_GREEN(current_vp
->lss_pattern
) << 16;
641 int rstep
= (h_r
- ((signed)RGB_UNPACK_RED(current_vp
->lse_pattern
) << 16)) / h
;
642 int gstep
= (h_g
- ((signed)RGB_UNPACK_GREEN(current_vp
->lse_pattern
) << 16)) / h
;
643 int bstep
= (h_b
- ((signed)RGB_UNPACK_BLUE(current_vp
->lse_pattern
) << 16)) / h
;
646 current_vp
->fg_pattern
= current_vp
->lss_pattern
;
647 for(count
= 0; count
< h
; count
++) {
648 lcd_hline(x1
, x2
, y
+ count
);
652 current_vp
->fg_pattern
= LCD_RGBPACK(h_r
>> 16, h_g
>> 16, h_b
>> 16);
655 current_vp
->fg_pattern
= old_pattern
;
658 #define H_COLOR(lss, lse, cur_line, max_line) \
659 (((lse) - (lss)) * (cur_line) / (max_line) + (lss))
661 /* Fill a rectangle with a gradient for scrolling line. To draw a gradient that
662 covers several lines, we need to know how many lines will be covered
663 (the num_lines arg), and which one is the current line within the selection
664 (the cur_line arg). */
665 static void lcd_gradient_rect_scroll(int x1
, int x2
, int y
, int h
,
666 unsigned char num_lines
, unsigned char cur_line
)
668 if (h
== 0 || num_lines
== 0) return;
670 unsigned tmp_lss
= current_vp
->lss_pattern
;
671 unsigned tmp_lse
= current_vp
->lse_pattern
;
672 int lss_r
= (signed)RGB_UNPACK_RED(current_vp
->lss_pattern
);
673 int lss_b
= (signed)RGB_UNPACK_BLUE(current_vp
->lss_pattern
);
674 int lss_g
= (signed)RGB_UNPACK_GREEN(current_vp
->lss_pattern
);
675 int lse_r
= (signed)RGB_UNPACK_RED(current_vp
->lse_pattern
);
676 int lse_b
= (signed)RGB_UNPACK_BLUE(current_vp
->lse_pattern
);
677 int lse_g
= (signed)RGB_UNPACK_GREEN(current_vp
->lse_pattern
);
679 int h_r
= H_COLOR(lss_r
, lse_r
, cur_line
, num_lines
);
680 int h_g
= H_COLOR(lss_g
, lse_g
, cur_line
, num_lines
);
681 int h_b
= H_COLOR(lss_b
, lse_b
, cur_line
, num_lines
);
682 lcd_set_selector_start(LCD_RGBPACK(h_r
, h_g
, h_b
));
684 int l_r
= H_COLOR(lss_r
, lse_r
, cur_line
+1, num_lines
);
685 int l_g
= H_COLOR(lss_g
, lse_g
, cur_line
+1, num_lines
);
686 int l_b
= H_COLOR(lss_b
, lse_b
, cur_line
+1, num_lines
);
687 lcd_set_selector_end(LCD_RGBPACK(l_r
, l_g
, l_b
));
689 lcd_gradient_rect(x1
, x2
, y
, h
);
691 current_vp
->lss_pattern
= tmp_lss
;
692 current_vp
->lse_pattern
= tmp_lse
;
695 /* About Rockbox' internal monochrome bitmap format:
697 * A bitmap contains one bit for every pixel that defines if that pixel is
698 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
700 * The bytes are stored in row-major order, with byte 0 being top left,
701 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
702 * 0..7, the second row defines pixel row 8..15 etc.
704 * This is the mono bitmap format used on all other targets so far; the
705 * pixel packing doesn't really matter on a 8bit+ target. */
707 /* Draw a partial monochrome bitmap */
709 void ICODE_ATTR
lcd_mono_bitmap_part(const unsigned char *src
, int src_x
,
710 int src_y
, int stride
, int x
, int y
,
711 int width
, int height
)
713 const unsigned char *src_end
;
715 fb_data
*dst
, *dst_end
, *backdrop
;
716 lcd_fastpixelfunc_type
*fgfunc
, *bgfunc
;
718 /* nothing to draw? */
719 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
) ||
720 (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
736 if (x
+ width
> current_vp
->width
)
737 width
= current_vp
->width
- x
;
738 if (y
+ height
> current_vp
->height
)
739 height
= current_vp
->height
- y
;
741 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
743 src_end
= src
+ width
;
745 dst
= LCDADDR(current_vp
->x
+ x
, current_vp
->y
+ y
);
746 has_backdrop
= (lcd_backdrop
!= NULL
);
747 backdrop
= lcd_backdrop
+ (current_vp
->y
+ y
) * LCD_WIDTH
+ current_vp
->x
+ x
;
748 fgfunc
= lcd_fastpixelfuncs
[current_vp
->drawmode
];
749 bgfunc
= lcd_fastpixelfuncs
[current_vp
->drawmode
^ DRMODE_INVERSEVID
];
752 const unsigned char *src_col
= src
++;
753 unsigned data
= *src_col
>> src_y
;
754 fb_data
*dst_col
= dst
++;
755 int numbits
= 8 - src_y
;
756 fb_data
*backdrop_col
= backdrop
++;
757 dst_end
= dst_col
+ height
* LCD_WIDTH
;
760 switch (current_vp
->drawmode
)
764 *dst_col
= current_vp
->fg_pattern
;
766 *dst_col
= has_backdrop
? *backdrop_col
: current_vp
->bg_pattern
;
770 *dst_col
= current_vp
->fg_pattern
;
772 case (DRMODE_SOLID
|DRMODE_INVERSEVID
):
774 *dst_col
= has_backdrop
? *backdrop_col
: current_vp
->bg_pattern
;
776 *dst_col
= current_vp
->fg_pattern
;
785 dst_col
+= LCD_WIDTH
;
786 backdrop_col
+= LCD_WIDTH
;
795 while (dst_col
< dst_end
);
797 while (src
< src_end
);
799 /* Draw a full monochrome bitmap */
800 void lcd_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
, int height
)
802 lcd_mono_bitmap_part(src
, 0, 0, width
, x
, y
, width
, height
);
805 /* Draw a partial native bitmap */
806 void ICODE_ATTR
lcd_bitmap_part(const fb_data
*src
, int src_x
, int src_y
,
807 int stride
, int x
, int y
, int width
,
810 fb_data
*dst
, *dst_end
;
812 /* nothing to draw? */
813 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
) ||
814 (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
830 if (x
+ width
> current_vp
->width
)
831 width
= current_vp
->width
- x
;
832 if (y
+ height
> current_vp
->height
)
833 height
= current_vp
->height
- y
;
835 src
+= stride
* src_y
+ src_x
; /* move starting point */
836 dst
= LCDADDR(current_vp
->x
+ x
, current_vp
->y
+ y
);
837 dst_end
= dst
+ height
* LCD_WIDTH
;
841 memcpy(dst
, src
, width
* sizeof(fb_data
));
845 while (dst
< dst_end
);
848 /* Draw a full native bitmap */
849 void lcd_bitmap(const fb_data
*src
, int x
, int y
, int width
, int height
)
851 lcd_bitmap_part(src
, 0, 0, width
, x
, y
, width
, height
);
854 #if !defined(TOSHIBA_GIGABEAT_F) && !defined(TOSHIBA_GIGABEAT_S) \
855 || defined(SIMULATOR)
856 /* Draw a partial native bitmap */
857 void ICODE_ATTR
lcd_bitmap_transparent_part(const fb_data
*src
, int src_x
,
858 int src_y
, int stride
, int x
,
859 int y
, int width
, int height
)
861 fb_data
*dst
, *dst_end
;
863 /* nothing to draw? */
864 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
) ||
865 (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
881 if (x
+ width
> current_vp
->width
)
882 width
= current_vp
->width
- x
;
883 if (y
+ height
> current_vp
->height
)
884 height
= current_vp
->height
- y
;
886 src
+= stride
* src_y
+ src_x
; /* move starting point */
887 dst
= LCDADDR(current_vp
->x
+ x
, current_vp
->y
+ y
);
888 dst_end
= dst
+ height
* LCD_WIDTH
;
893 for(i
= 0;i
< width
;i
++)
895 if (src
[i
] == REPLACEWITHFG_COLOR
)
896 dst
[i
] = current_vp
->fg_pattern
;
897 else if(src
[i
] != TRANSPARENT_COLOR
)
903 while (dst
< dst_end
);
905 #endif /* !defined(TOSHIBA_GIGABEAT_F) || defined(SIMULATOR) */
907 /* Draw a full native bitmap with a transparent color */
908 void lcd_bitmap_transparent(const fb_data
*src
, int x
, int y
,
909 int width
, int height
)
911 lcd_bitmap_transparent_part(src
, 0, 0, width
, x
, y
, width
, height
);
914 /* put a string at a given pixel position, skipping first ofs pixel columns */
915 static void lcd_putsxyofs(int x
, int y
, int ofs
, const unsigned char *str
)
919 struct font
* pf
= font_get(current_vp
->font
);
921 ucs
= bidi_l2v(str
, 1);
923 while ((ch
= *ucs
++) != 0 && x
< current_vp
->width
)
926 const unsigned char *bits
;
928 /* get proportional width and glyph bits */
929 width
= font_get_width(pf
,ch
);
937 bits
= font_get_bits(pf
, ch
);
939 lcd_mono_bitmap_part(bits
, ofs
, 0, width
, x
, y
, width
- ofs
, pf
->height
);
946 /* put a string at a given pixel position */
947 void lcd_putsxy(int x
, int y
, const unsigned char *str
)
949 lcd_putsxyofs(x
, y
, 0, str
);
952 /*** line oriented text output ***/
954 /* put a string at a given char position */
955 void lcd_puts(int x
, int y
, const unsigned char *str
)
957 lcd_puts_style_offset(x
, y
, str
, STYLE_DEFAULT
, 0);
960 void lcd_puts_style(int x
, int y
, const unsigned char *str
, int style
)
962 lcd_puts_style_offset(x
, y
, str
, style
, 0);
965 void lcd_puts_offset(int x
, int y
, const unsigned char *str
, int offset
)
967 lcd_puts_style_offset(x
, y
, str
, STYLE_DEFAULT
, offset
);
970 /* put a string at a given char position, style, and pixel position,
971 * skipping first offset pixel columns */
972 void lcd_puts_style_offset(int x
, int y
, const unsigned char *str
, int style
,
975 int xpos
,ypos
,w
,h
,xrect
;
976 int lastmode
= current_vp
->drawmode
;
977 int oldfgcolor
= current_vp
->fg_pattern
;
978 int oldbgcolor
= current_vp
->bg_pattern
;
980 /* make sure scrolling is turned off on the line we are updating */
981 lcd_scroll_stop_line(current_vp
, y
);
986 lcd_getstringsize(str
, &w
, &h
);
987 xpos
= current_vp
->xmargin
+ x
*w
/ utf8length(str
);
988 ypos
= current_vp
->ymargin
+ y
*h
;
989 current_vp
->drawmode
= (style
& STYLE_INVERT
) ?
990 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
991 if (style
& STYLE_COLORED
) {
992 if (current_vp
->drawmode
== DRMODE_SOLID
)
993 current_vp
->fg_pattern
= style
& STYLE_COLOR_MASK
;
995 current_vp
->bg_pattern
= style
& STYLE_COLOR_MASK
;
997 current_vp
->drawmode
^= DRMODE_INVERSEVID
;
998 xrect
= xpos
+ MAX(w
- offset
, 0);
1000 if (style
& STYLE_GRADIENT
) {
1001 current_vp
->drawmode
= DRMODE_FG
;
1002 if (CURLN_UNPACK(style
) == 0)
1003 lcd_gradient_rect(xpos
, current_vp
->width
, ypos
, h
*NUMLN_UNPACK(style
));
1004 current_vp
->fg_pattern
= current_vp
->lst_pattern
;
1006 else if (style
& STYLE_COLORBAR
) {
1007 current_vp
->drawmode
= DRMODE_FG
;
1008 current_vp
->fg_pattern
= current_vp
->lss_pattern
;
1009 lcd_fillrect(xpos
, ypos
, current_vp
->width
- xpos
, h
);
1010 current_vp
->fg_pattern
= current_vp
->lst_pattern
;
1013 lcd_fillrect(xrect
, ypos
, current_vp
->width
- xrect
, h
);
1014 current_vp
->drawmode
= (style
& STYLE_INVERT
) ?
1015 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
1017 lcd_putsxyofs(xpos
, ypos
, offset
, str
);
1018 current_vp
->drawmode
= lastmode
;
1019 current_vp
->fg_pattern
= oldfgcolor
;
1020 current_vp
->bg_pattern
= oldbgcolor
;
1024 void lcd_puts_scroll(int x
, int y
, const unsigned char *string
)
1026 lcd_puts_scroll_style(x
, y
, string
, STYLE_DEFAULT
);
1029 void lcd_puts_scroll_style(int x
, int y
, const unsigned char *string
, int style
)
1031 lcd_puts_scroll_style_offset(x
, y
, string
, style
, 0);
1034 void lcd_puts_scroll_offset(int x
, int y
, const unsigned char *string
, int offset
)
1036 lcd_puts_scroll_style_offset(x
, y
, string
, STYLE_DEFAULT
, offset
);
1039 /* Initialise a scrolling line at (x,y) in current viewport */
1041 void lcd_puts_scroll_style_offset(int x
, int y
, const unsigned char *string
,
1042 int style
, int offset
)
1044 struct scrollinfo
* s
;
1047 if ((unsigned)y
>= (unsigned)current_vp
->height
)
1050 /* remove any previously scrolling line at the same location */
1051 lcd_scroll_stop_line(current_vp
, y
);
1053 if (lcd_scroll_info
.lines
>= LCD_SCROLLABLE_LINES
) return;
1055 s
= &lcd_scroll_info
.scroll
[lcd_scroll_info
.lines
];
1057 s
->start_tick
= current_tick
+ lcd_scroll_info
.delay
;
1059 lcd_puts_style_offset(x
,y
,string
,style
,offset
);
1061 lcd_getstringsize(string
, &w
, &h
);
1063 if (current_vp
->width
- x
* 8 - current_vp
->xmargin
< w
) {
1064 /* prepare scroll line */
1067 memset(s
->line
, 0, sizeof s
->line
);
1068 strcpy(s
->line
, string
);
1071 s
->width
= lcd_getstringsize(s
->line
, &w
, &h
);
1073 /* scroll bidirectional or forward only depending on the string
1075 if ( lcd_scroll_info
.bidir_limit
) {
1076 s
->bidir
= s
->width
< (current_vp
->width
- current_vp
->xmargin
) *
1077 (100 + lcd_scroll_info
.bidir_limit
) / 100;
1082 if (!s
->bidir
) { /* add spaces if scrolling in the round */
1083 strcat(s
->line
, " ");
1084 /* get new width incl. spaces */
1085 s
->width
= lcd_getstringsize(s
->line
, &w
, &h
);
1088 end
= strchr(s
->line
, '\0');
1089 strncpy(end
, string
, current_vp
->width
/2);
1093 s
->len
= utf8length(string
);
1095 s
->startx
= current_vp
->xmargin
+ x
* s
->width
/ s
->len
;
1096 s
->backward
= false;
1097 lcd_scroll_info
.lines
++;
1101 void lcd_scroll_fn(void)
1104 struct scrollinfo
* s
;
1108 unsigned old_fgcolor
;
1109 unsigned old_bgcolor
;
1110 struct viewport
* old_vp
= current_vp
;
1112 for ( index
= 0; index
< lcd_scroll_info
.lines
; index
++ ) {
1113 s
= &lcd_scroll_info
.scroll
[index
];
1116 if (TIME_BEFORE(current_tick
, s
->start_tick
))
1119 lcd_set_viewport(s
->vp
);
1120 old_fgcolor
= current_vp
->fg_pattern
;
1121 old_bgcolor
= current_vp
->bg_pattern
;
1123 if (s
->style
&STYLE_COLORED
) {
1124 if (s
->style
&STYLE_MODE_MASK
) {
1125 current_vp
->fg_pattern
= old_fgcolor
;
1126 current_vp
->bg_pattern
= s
->style
&STYLE_COLOR_MASK
;
1129 current_vp
->fg_pattern
= s
->style
&STYLE_COLOR_MASK
;
1130 current_vp
->bg_pattern
= old_bgcolor
;
1135 s
->offset
-= lcd_scroll_info
.step
;
1137 s
->offset
+= lcd_scroll_info
.step
;
1139 pf
= font_get(current_vp
->font
);
1141 ypos
= current_vp
->ymargin
+ s
->y
* pf
->height
;
1143 if (s
->bidir
) { /* scroll bidirectional */
1144 if (s
->offset
<= 0) {
1145 /* at beginning of line */
1147 s
->backward
= false;
1148 s
->start_tick
= current_tick
+ lcd_scroll_info
.delay
* 2;
1150 if (s
->offset
>= s
->width
- (current_vp
->width
- xpos
)) {
1151 /* at end of line */
1152 s
->offset
= s
->width
- (current_vp
->width
- xpos
);
1154 s
->start_tick
= current_tick
+ lcd_scroll_info
.delay
* 2;
1158 /* scroll forward the whole time */
1159 if (s
->offset
>= s
->width
)
1160 s
->offset
%= s
->width
;
1163 lastmode
= current_vp
->drawmode
;
1164 switch (s
->style
&STYLE_MODE_MASK
) {
1166 current_vp
->drawmode
= DRMODE_SOLID
|DRMODE_INVERSEVID
;
1168 case STYLE_COLORBAR
:
1169 /* Solid colour line selector */
1170 current_vp
->drawmode
= DRMODE_FG
;
1171 current_vp
->fg_pattern
= current_vp
->lss_pattern
;
1172 lcd_fillrect(xpos
, ypos
, current_vp
->width
- xpos
, pf
->height
);
1173 current_vp
->fg_pattern
= current_vp
->lst_pattern
;
1175 case STYLE_GRADIENT
:
1176 /* Gradient line selector */
1177 current_vp
->drawmode
= DRMODE_FG
;
1178 lcd_gradient_rect_scroll(xpos
, current_vp
->width
, ypos
, (signed)pf
->height
,
1179 NUMLN_UNPACK(s
->style
),
1180 CURLN_UNPACK(s
->style
));
1181 current_vp
->fg_pattern
= current_vp
->lst_pattern
;
1184 current_vp
->drawmode
= DRMODE_SOLID
;
1187 lcd_putsxyofs(xpos
, ypos
, s
->offset
, s
->line
);
1188 current_vp
->drawmode
= lastmode
;
1189 current_vp
->fg_pattern
= old_fgcolor
;
1190 current_vp
->bg_pattern
= old_bgcolor
;
1191 lcd_update_viewport_rect(xpos
, ypos
, current_vp
->width
- xpos
, pf
->height
);
1194 lcd_set_viewport(old_vp
);