1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 by Linus Nielsen Feltzing
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
31 #include "rbunicode.h"
33 #include "scroll_engine.h"
37 fb_data lcd_framebuffer
[LCD_FBHEIGHT
][LCD_FBWIDTH
] IBSS_ATTR
;
39 const unsigned char lcd_dibits
[16] ICONST_ATTR
= {
40 0x00, 0x03, 0x0C, 0x0F, 0x30, 0x33, 0x3C, 0x3F,
41 0xC0, 0xC3, 0xCC, 0xCF, 0xF0, 0xF3, 0xFC, 0xFF
44 static const unsigned char pixmask
[4] ICONST_ATTR
= {
45 0x03, 0x0C, 0x30, 0xC0
48 static fb_data
* lcd_backdrop
= NULL
;
49 static long lcd_backdrop_offset IDATA_ATTR
= 0;
51 static struct viewport default_vp
=
57 .font
= FONT_SYSFIXED
,
58 .drawmode
= DRMODE_SOLID
,
61 .fg_pattern
= LCD_DEFAULT_FG
,
62 .bg_pattern
= LCD_DEFAULT_BG
65 static struct viewport
* current_vp IBSS_ATTR
;
66 static unsigned fg_pattern IBSS_ATTR
;
67 static unsigned bg_pattern IBSS_ATTR
;
72 /* Initialise the viewport */
73 lcd_set_viewport(NULL
);
76 /* Call device specific init */
83 void lcd_set_viewport(struct viewport
* vp
)
86 current_vp
= &default_vp
;
90 fg_pattern
= 0x55 * (~current_vp
->fg_pattern
& 3);
91 bg_pattern
= 0x55 * (~current_vp
->bg_pattern
& 3);
94 void lcd_update_viewport(void)
96 lcd_update_rect(current_vp
->x
, current_vp
->y
,
97 current_vp
->width
, current_vp
->height
);
100 void lcd_update_viewport_rect(int x
, int y
, int width
, int height
)
102 lcd_update_rect(current_vp
->x
+ x
, current_vp
->y
+ y
, width
, height
);
106 /*** parameter handling ***/
108 void lcd_set_drawmode(int mode
)
110 current_vp
->drawmode
= mode
& (DRMODE_SOLID
|DRMODE_INVERSEVID
);
113 int lcd_get_drawmode(void)
115 return current_vp
->drawmode
;
118 void lcd_set_foreground(unsigned brightness
)
120 current_vp
->fg_pattern
= brightness
;
121 fg_pattern
= 0x55 * (~brightness
& 3);
124 unsigned lcd_get_foreground(void)
126 return current_vp
->fg_pattern
;
129 void lcd_set_background(unsigned brightness
)
131 current_vp
->bg_pattern
= brightness
;
132 bg_pattern
= 0x55 * (~brightness
& 3);
135 unsigned lcd_get_background(void)
137 return current_vp
->bg_pattern
;
140 void lcd_set_drawinfo(int mode
, unsigned fg_brightness
, unsigned bg_brightness
)
142 lcd_set_drawmode(mode
);
143 lcd_set_foreground(fg_brightness
);
144 lcd_set_background(bg_brightness
);
147 void lcd_setmargins(int x
, int y
)
149 current_vp
->xmargin
= x
;
150 current_vp
->ymargin
= y
;
153 int lcd_getxmargin(void)
155 return current_vp
->xmargin
;
158 int lcd_getymargin(void)
160 return current_vp
->ymargin
;
163 int lcd_getwidth(void)
165 return current_vp
->width
;
168 int lcd_getheight(void)
170 return current_vp
->height
;
173 void lcd_setfont(int newfont
)
175 current_vp
->font
= newfont
;
178 int lcd_getfont(void)
180 return current_vp
->font
;
183 int lcd_getstringsize(const unsigned char *str
, int *w
, int *h
)
185 return font_getstringsize(str
, w
, h
, current_vp
->font
);
188 /*** low-level drawing functions ***/
190 static void setpixel(int x
, int y
)
192 unsigned mask
= pixmask
[y
& 3];
193 fb_data
*address
= &lcd_framebuffer
[y
>>2][x
];
194 unsigned data
= *address
;
196 *address
= data
^ ((data
^ fg_pattern
) & mask
);
199 static void clearpixel(int x
, int y
)
201 unsigned mask
= pixmask
[y
& 3];
202 fb_data
*address
= &lcd_framebuffer
[y
>>2][x
];
203 unsigned data
= *address
;
205 *address
= data
^ ((data
^ bg_pattern
) & mask
);
208 static void clearimgpixel(int x
, int y
)
210 unsigned mask
= pixmask
[y
& 3];
211 fb_data
*address
= &lcd_framebuffer
[y
>>2][x
];
212 unsigned data
= *address
;
214 *address
= data
^ ((data
^ *(address
+ lcd_backdrop_offset
)) & mask
);
217 static void flippixel(int x
, int y
)
219 unsigned mask
= pixmask
[y
& 3];
220 fb_data
*address
= &lcd_framebuffer
[y
>>2][x
];
225 static void nopixel(int x
, int y
)
231 lcd_pixelfunc_type
* const lcd_pixelfuncs_bgcolor
[8] = {
232 flippixel
, nopixel
, setpixel
, setpixel
,
233 nopixel
, clearpixel
, nopixel
, clearpixel
236 lcd_pixelfunc_type
* const lcd_pixelfuncs_backdrop
[8] = {
237 flippixel
, nopixel
, setpixel
, setpixel
,
238 nopixel
, clearimgpixel
, nopixel
, clearimgpixel
242 lcd_pixelfunc_type
* const * lcd_pixelfuncs
= lcd_pixelfuncs_bgcolor
;
244 /* 'mask' and 'bits' contain 2 bits per pixel */
245 static void ICODE_ATTR
flipblock(fb_data
*address
, unsigned mask
,
248 *address
^= bits
& mask
;
251 static void ICODE_ATTR
bgblock(fb_data
*address
, unsigned mask
,
254 unsigned data
= *address
;
256 *address
= data
^ ((data
^ bg_pattern
) & mask
& ~bits
);
259 static void ICODE_ATTR
bgimgblock(fb_data
*address
, unsigned mask
,
262 unsigned data
= *address
;
264 *address
= data
^ ((data
^ *(address
+ lcd_backdrop_offset
)) & mask
& ~bits
);
267 static void ICODE_ATTR
fgblock(fb_data
*address
, unsigned mask
,
270 unsigned data
= *address
;
272 *address
= data
^ ((data
^ fg_pattern
) & mask
& bits
);
275 static void ICODE_ATTR
solidblock(fb_data
*address
, unsigned mask
,
278 unsigned data
= *address
;
279 unsigned bgp
= bg_pattern
;
281 bits
= bgp
^ ((bgp
^ fg_pattern
) & bits
);
282 *address
= data
^ ((data
^ bits
) & mask
);
285 static void ICODE_ATTR
solidimgblock(fb_data
*address
, unsigned mask
,
288 unsigned data
= *address
;
289 unsigned bgp
= *(address
+ lcd_backdrop_offset
);
291 bits
= bgp
^ ((bgp
^ fg_pattern
) & bits
);
292 *address
= data
^ ((data
^ bits
) & mask
);
295 static void ICODE_ATTR
flipinvblock(fb_data
*address
, unsigned mask
,
298 *address
^= ~bits
& mask
;
301 static void ICODE_ATTR
bginvblock(fb_data
*address
, unsigned mask
,
304 unsigned data
= *address
;
306 *address
= data
^ ((data
^ bg_pattern
) & mask
& bits
);
309 static void ICODE_ATTR
bgimginvblock(fb_data
*address
, unsigned mask
,
312 unsigned data
= *address
;
314 *address
= data
^ ((data
^ *(address
+ lcd_backdrop_offset
)) & mask
& bits
);
317 static void ICODE_ATTR
fginvblock(fb_data
*address
, unsigned mask
,
320 unsigned data
= *address
;
322 *address
= data
^ ((data
^ fg_pattern
) & mask
& ~bits
);
325 static void ICODE_ATTR
solidinvblock(fb_data
*address
, unsigned mask
,
328 unsigned data
= *address
;
329 unsigned fgp
= fg_pattern
;
331 bits
= fgp
^ ((fgp
^ bg_pattern
) & bits
);
332 *address
= data
^ ((data
^ bits
) & mask
);
335 static void ICODE_ATTR
solidimginvblock(fb_data
*address
, unsigned mask
,
338 unsigned data
= *address
;
339 unsigned fgp
= fg_pattern
;
341 bits
= fgp
^ ((fgp
^ *(address
+ lcd_backdrop_offset
)) & bits
);
342 *address
= data
^ ((data
^ bits
) & mask
);
345 lcd_blockfunc_type
* const lcd_blockfuncs_bgcolor
[8] = {
346 flipblock
, bgblock
, fgblock
, solidblock
,
347 flipinvblock
, bginvblock
, fginvblock
, solidinvblock
350 lcd_blockfunc_type
* const lcd_blockfuncs_backdrop
[8] = {
351 flipblock
, bgimgblock
, fgblock
, solidimgblock
,
352 flipinvblock
, bgimginvblock
, fginvblock
, solidimginvblock
355 lcd_blockfunc_type
* const * lcd_blockfuncs
= lcd_blockfuncs_bgcolor
;
358 void lcd_set_backdrop(fb_data
* backdrop
)
360 lcd_backdrop
= backdrop
;
363 lcd_backdrop_offset
= (long)backdrop
- (long)lcd_framebuffer
;
364 lcd_pixelfuncs
= lcd_pixelfuncs_backdrop
;
365 lcd_blockfuncs
= lcd_blockfuncs_backdrop
;
369 lcd_backdrop_offset
= 0;
370 lcd_pixelfuncs
= lcd_pixelfuncs_bgcolor
;
371 lcd_blockfuncs
= lcd_blockfuncs_bgcolor
;
375 fb_data
* lcd_get_backdrop(void)
381 static inline void setblock(fb_data
*address
, unsigned mask
, unsigned bits
)
383 unsigned data
= *address
;
386 *address
= data
^ (bits
& mask
);
389 /*** drawing functions ***/
391 /* Clear the whole display */
392 void lcd_clear_display(void)
394 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
396 memset(lcd_framebuffer
, fg_pattern
, sizeof lcd_framebuffer
);
401 memcpy(lcd_framebuffer
, lcd_backdrop
, sizeof lcd_framebuffer
);
403 memset(lcd_framebuffer
, bg_pattern
, sizeof lcd_framebuffer
);
406 lcd_scroll_info
.lines
= 0;
409 /* Clear the current viewport */
410 void lcd_clear_viewport(void)
414 if (current_vp
== &default_vp
)
420 lastmode
= current_vp
->drawmode
;
422 /* Invert the INVERSEVID bit and set basic mode to SOLID */
423 current_vp
->drawmode
= (~lastmode
& DRMODE_INVERSEVID
) |
426 lcd_fillrect(0, 0, current_vp
->width
, current_vp
->height
);
428 current_vp
->drawmode
= lastmode
;
430 lcd_scroll_stop(current_vp
);
434 /* Set a single pixel */
435 void lcd_drawpixel(int x
, int y
)
437 if (((unsigned)x
< (unsigned)current_vp
->width
) &&
438 ((unsigned)y
< (unsigned)current_vp
->height
))
439 lcd_pixelfuncs
[current_vp
->drawmode
](current_vp
->x
+ x
, current_vp
->y
+ y
);
443 void lcd_drawline(int x1
, int y1
, int x2
, int y2
)
451 lcd_pixelfunc_type
*pfunc
= lcd_pixelfuncs
[current_vp
->drawmode
];
453 deltax
= abs(x2
- x1
);
456 DEBUGF("lcd_drawline() called for vertical line - optimisation.\n");
457 lcd_vline(x1
, y1
, y2
);
460 deltay
= abs(y2
- y1
);
463 DEBUGF("lcd_drawline() called for horizontal line - optimisation.\n");
464 lcd_hline(x1
, x2
, y1
);
470 if (deltax
>= deltay
)
473 d
= 2 * deltay
- deltax
;
475 dinc2
= (deltay
- deltax
) * 2;
482 d
= 2 * deltax
- deltay
;
484 dinc2
= (deltax
- deltay
) * 2;
488 numpixels
++; /* include endpoints */
505 for (i
= 0; i
< numpixels
; i
++)
507 if (((unsigned)x
< (unsigned)current_vp
->width
) &&
508 ((unsigned)y
< (unsigned)current_vp
->height
))
509 pfunc(current_vp
->x
+ x
, current_vp
->y
+ y
);
526 /* Draw a horizontal line (optimised) */
527 void lcd_hline(int x1
, int x2
, int y
)
531 fb_data
*dst
, *dst_end
;
533 lcd_blockfunc_type
*bfunc
;
543 /* nothing to draw? */
544 if (((unsigned)y
>= (unsigned)current_vp
->height
) || (x1
>= current_vp
->width
)
551 if (x2
>= current_vp
->width
)
552 x2
= current_vp
->width
-1;
556 /* adjust x1 and y to viewport */
560 bfunc
= lcd_blockfuncs
[current_vp
->drawmode
];
561 dst
= &lcd_framebuffer
[y
>>2][x1
];
562 mask
= pixmask
[y
& 3];
564 dst_end
= dst
+ width
;
566 bfunc(dst
++, mask
, 0xFFu
);
567 while (dst
< dst_end
);
570 /* Draw a vertical line (optimised) */
571 void lcd_vline(int x
, int y1
, int y2
)
575 unsigned mask
, mask_bottom
;
576 lcd_blockfunc_type
*bfunc
;
586 /* nothing to draw? */
587 if (((unsigned)x
>= (unsigned)current_vp
->width
) || (y1
>= current_vp
->height
)
594 if (y2
>= current_vp
->height
)
595 y2
= current_vp
->height
-1;
597 /* adjust for viewport */
602 bfunc
= lcd_blockfuncs
[current_vp
->drawmode
];
603 dst
= &lcd_framebuffer
[y1
>>2][x
];
605 mask
= 0xFFu
<< (2 * (y1
& 3));
606 mask_bottom
= 0xFFu
>> (2 * (~ny
& 3));
608 for (; ny
>= 4; ny
-= 4)
610 bfunc(dst
, mask
, 0xFFu
);
615 bfunc(dst
, mask
, 0xFFu
);
618 /* Draw a rectangular box */
619 void lcd_drawrect(int x
, int y
, int width
, int height
)
621 if ((width
<= 0) || (height
<= 0))
624 int x2
= x
+ width
- 1;
625 int y2
= y
+ height
- 1;
628 lcd_vline(x2
, y
, y2
);
630 lcd_hline(x
, x2
, y2
);
633 /* Fill a rectangular area */
634 void lcd_fillrect(int x
, int y
, int width
, int height
)
637 fb_data
*dst
, *dst_end
;
638 unsigned mask
, mask_bottom
;
640 lcd_blockfunc_type
*bfunc
;
641 bool fillopt
= false;
643 /* nothing to draw? */
644 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
)
645 || (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
659 if (x
+ width
> current_vp
->width
)
660 width
= current_vp
->width
- x
;
661 if (y
+ height
> current_vp
->height
)
662 height
= current_vp
->height
- y
;
664 /* adjust for viewport */
668 if (current_vp
->drawmode
& DRMODE_INVERSEVID
)
670 if ((current_vp
->drawmode
& DRMODE_BG
) && !lcd_backdrop
)
678 if (current_vp
->drawmode
& DRMODE_FG
)
684 bfunc
= lcd_blockfuncs
[current_vp
->drawmode
];
685 dst
= &lcd_framebuffer
[y
>>2][x
];
686 ny
= height
- 1 + (y
& 3);
687 mask
= 0xFFu
<< (2 * (y
& 3));
688 mask_bottom
= 0xFFu
>> (2 * (~ny
& 3));
690 for (; ny
>= 4; ny
-= 4)
692 if (fillopt
&& (mask
== 0xFFu
))
693 memset(dst
, bits
, width
);
696 fb_data
*dst_row
= dst
;
698 dst_end
= dst_row
+ width
;
700 bfunc(dst_row
++, mask
, 0xFFu
);
701 while (dst_row
< dst_end
);
709 if (fillopt
&& (mask
== 0xFFu
))
710 memset(dst
, bits
, width
);
713 dst_end
= dst
+ width
;
715 bfunc(dst
++, mask
, 0xFFu
);
716 while (dst
< dst_end
);
720 /* About Rockbox' internal monochrome bitmap format:
722 * A bitmap contains one bit for every pixel that defines if that pixel is
723 * black (1) or white (0). Bits within a byte are arranged vertically, LSB
725 * The bytes are stored in row-major order, with byte 0 being top left,
726 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
727 * 0..7, the second row defines pixel row 8..15 etc.
729 * This is similar to the internal lcd hw format. */
731 /* Draw a partial monochrome bitmap */
732 void ICODE_ATTR
lcd_mono_bitmap_part(const unsigned char *src
, int src_x
,
733 int src_y
, int stride
, int x
, int y
,
734 int width
, int height
)
737 fb_data
*dst
, *dst_end
;
738 unsigned mask
, mask_bottom
;
739 lcd_blockfunc_type
*bfunc
;
741 /* nothing to draw? */
742 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
) ||
743 (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
759 if (x
+ width
> current_vp
->width
)
760 width
= current_vp
->width
- x
;
761 if (y
+ height
> current_vp
->height
)
762 height
= current_vp
->height
- y
;
764 /* adjust for viewport */
768 src
+= stride
* (src_y
>> 3) + src_x
; /* move starting point */
771 dst
= &lcd_framebuffer
[y
>>2][x
];
773 ny
= height
- 1 + shift
+ src_y
;
775 bfunc
= lcd_blockfuncs
[current_vp
->drawmode
];
776 mask
= 0xFFu
<< (shift
+ src_y
);
777 mask_bottom
= 0xFFu
>> (~ny
& 7);
781 unsigned dmask1
, dmask2
, data
;
783 for (; ny
>= 8; ny
-= 8)
785 const unsigned char *src_row
= src
;
786 fb_data
*dst_row
= dst
+ LCD_WIDTH
;
788 dmask1
= lcd_dibits
[mask
&0x0F];
789 dmask2
= lcd_dibits
[(mask
>>4)&0x0F];
790 dst_end
= dst_row
+ width
;
797 bfunc(dst_row
- LCD_WIDTH
, dmask1
, lcd_dibits
[data
&0x0F]);
798 bfunc(dst_row
++, dmask2
, lcd_dibits
[(data
>>4)&0x0F]);
800 while (dst_row
< dst_end
);
805 bfunc(dst_row
++, dmask2
, lcd_dibits
[((*src_row
++)>>4)&0x0F]);
806 while (dst_row
< dst_end
);
813 dmask1
= lcd_dibits
[mask
&0x0F];
814 dmask2
= lcd_dibits
[(mask
>>4)&0x0F];
815 dst_end
= dst
+ width
;
824 bfunc(dst
, dmask1
, lcd_dibits
[data
&0x0F]);
825 bfunc((dst
++) + LCD_WIDTH
, dmask2
, lcd_dibits
[(data
>>4)&0x0F]);
827 while (dst
< dst_end
);
832 bfunc(dst
++, dmask1
, lcd_dibits
[(*src
++)&0x0F]);
833 while (dst
< dst_end
);
839 bfunc((dst
++) + LCD_WIDTH
, dmask2
, lcd_dibits
[((*src
++)>>4)&0x0F]);
840 while (dst
< dst_end
);
845 dst_end
= dst
+ width
;
848 const unsigned char *src_col
= src
++;
849 fb_data
*dst_col
= dst
++;
850 unsigned mask_col
= mask
;
853 for (y
= ny
; y
>= 8; y
-= 8)
855 data
|= *src_col
<< shift
;
857 if (mask_col
& 0xFFu
)
860 bfunc(dst_col
, lcd_dibits
[mask_col
&0x0F], lcd_dibits
[data
&0x0F]);
861 bfunc(dst_col
+ LCD_WIDTH
, lcd_dibits
[(mask_col
>>4)&0x0F],
862 lcd_dibits
[(data
>>4)&0x0F]);
869 dst_col
+= 2*LCD_WIDTH
;
872 data
|= *src_col
<< shift
;
873 mask_bottom
&= mask_col
;
874 if (mask_bottom
& 0x0F)
875 bfunc(dst_col
, lcd_dibits
[mask_bottom
&0x0F], lcd_dibits
[data
&0x0F]);
876 if (mask_bottom
& 0xF0)
877 bfunc(dst_col
+ LCD_WIDTH
, lcd_dibits
[(mask_bottom
&0xF0)>>4],
878 lcd_dibits
[(data
>>4)&0x0F]);
880 while (dst
< dst_end
);
884 /* Draw a full monochrome bitmap */
885 void lcd_mono_bitmap(const unsigned char *src
, int x
, int y
, int width
, int height
)
887 lcd_mono_bitmap_part(src
, 0, 0, width
, x
, y
, width
, height
);
890 /* About Rockbox' internal native bitmap format:
892 * A bitmap contains two bits for every pixel. 00 = white, 01 = light grey,
893 * 10 = dark grey, 11 = black. Bits within a byte are arranged vertically, LSB
895 * The bytes are stored in row-major order, with byte 0 being top left,
896 * byte 1 2nd from left etc. The first row of bytes defines pixel rows
897 * 0..3, the second row defines pixel row 4..7 etc.
899 * This is the same as the internal lcd hw format. */
901 /* Draw a partial native bitmap */
902 void ICODE_ATTR
lcd_bitmap_part(const fb_data
*src
, int src_x
, int src_y
,
903 int stride
, int x
, int y
, int width
,
907 fb_data
*dst
, *dst_end
;
908 unsigned mask
, mask_bottom
;
910 /* nothing to draw? */
911 if ((width
<= 0) || (height
<= 0) || (x
>= current_vp
->width
)
912 || (y
>= current_vp
->height
) || (x
+ width
<= 0) || (y
+ height
<= 0))
928 if (x
+ width
> current_vp
->width
)
929 width
= current_vp
->width
- x
;
930 if (y
+ height
> current_vp
->height
)
931 height
= current_vp
->height
- y
;
933 /* adjust for viewport */
937 src
+= stride
* (src_y
>> 2) + src_x
; /* move starting point */
940 dst
= &lcd_framebuffer
[y
>>2][x
];
942 ny
= height
- 1 + shift
+ src_y
;
944 mask
= 0xFFu
<< (2 * (shift
+ src_y
));
945 mask_bottom
= 0xFFu
>> (2 * (~ny
& 3));
949 for (; ny
>= 4; ny
-= 4)
952 memcpy(dst
, src
, width
);
955 const fb_data
*src_row
= src
;
956 fb_data
*dst_row
= dst
;
958 dst_end
= dst_row
+ width
;
960 setblock(dst_row
++, mask
, *src_row
++);
961 while (dst_row
< dst_end
);
970 memcpy(dst
, src
, width
);
973 dst_end
= dst
+ width
;
975 setblock(dst
++, mask
, *src
++);
976 while (dst
< dst_end
);
982 dst_end
= dst
+ width
;
985 const fb_data
*src_col
= src
++;
986 fb_data
*dst_col
= dst
++;
987 unsigned mask_col
= mask
;
990 for (y
= ny
; y
>= 4; y
-= 4)
992 data
|= *src_col
<< shift
;
994 if (mask_col
& 0xFFu
)
996 setblock(dst_col
, mask_col
, data
);
1003 dst_col
+= LCD_WIDTH
;
1006 data
|= *src_col
<< shift
;
1007 setblock(dst_col
, mask_col
& mask_bottom
, data
);
1009 while (dst
< dst_end
);
1013 /* Draw a full native bitmap */
1014 void lcd_bitmap(const fb_data
*src
, int x
, int y
, int width
, int height
)
1016 lcd_bitmap_part(src
, 0, 0, width
, x
, y
, width
, height
);
1019 /* put a string at a given pixel position, skipping first ofs pixel columns */
1020 static void lcd_putsxyofs(int x
, int y
, int ofs
, const unsigned char *str
)
1023 unsigned short *ucs
;
1024 struct font
* pf
= font_get(current_vp
->font
);
1026 ucs
= bidi_l2v(str
, 1);
1028 while ((ch
= *ucs
++) != 0 && x
< current_vp
->width
)
1031 const unsigned char *bits
;
1033 /* get proportional width and glyph bits */
1034 width
= font_get_width(pf
,ch
);
1042 bits
= font_get_bits(pf
, ch
);
1044 lcd_mono_bitmap_part(bits
, ofs
, 0, width
, x
, y
, width
- ofs
,
1052 /* put a string at a given pixel position */
1053 void lcd_putsxy(int x
, int y
, const unsigned char *str
)
1055 lcd_putsxyofs(x
, y
, 0, str
);
1058 /*** line oriented text output ***/
1060 /* put a string at a given char position */
1061 void lcd_puts(int x
, int y
, const unsigned char *str
)
1063 lcd_puts_style_offset(x
, y
, str
, STYLE_DEFAULT
, 0);
1066 void lcd_puts_style(int x
, int y
, const unsigned char *str
, int style
)
1068 lcd_puts_style_offset(x
, y
, str
, style
, 0);
1071 void lcd_puts_offset(int x
, int y
, const unsigned char *str
, int offset
)
1073 lcd_puts_style_offset(x
, y
, str
, STYLE_DEFAULT
, offset
);
1076 /* put a string at a given char position, style, and pixel position,
1077 * skipping first offset pixel columns */
1078 void lcd_puts_style_offset(int x
, int y
, const unsigned char *str
,
1079 int style
, int offset
)
1081 int xpos
,ypos
,w
,h
,xrect
;
1082 int lastmode
= current_vp
->drawmode
;
1084 /* make sure scrolling is turned off on the line we are updating */
1085 lcd_scroll_stop_line(current_vp
, y
);
1090 lcd_getstringsize(str
, &w
, &h
);
1091 xpos
= current_vp
->xmargin
+ x
*w
/ utf8length((char *)str
);
1092 ypos
= current_vp
->ymargin
+ y
*h
;
1093 current_vp
->drawmode
= (style
& STYLE_INVERT
) ?
1094 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
1095 lcd_putsxyofs(xpos
, ypos
, offset
, str
);
1096 current_vp
->drawmode
^= DRMODE_INVERSEVID
;
1097 xrect
= xpos
+ MAX(w
- offset
, 0);
1098 lcd_fillrect(xrect
, ypos
, current_vp
->width
- xrect
, h
);
1099 current_vp
->drawmode
= lastmode
;
1104 void lcd_puts_scroll(int x
, int y
, const unsigned char *string
)
1106 lcd_puts_scroll_style(x
, y
, string
, STYLE_DEFAULT
);
1109 void lcd_puts_scroll_style(int x
, int y
, const unsigned char *string
, int style
)
1111 lcd_puts_scroll_style_offset(x
, y
, string
, style
, 0);
1114 void lcd_puts_scroll_offset(int x
, int y
, const unsigned char *string
, int offset
)
1116 lcd_puts_scroll_style_offset(x
, y
, string
, STYLE_DEFAULT
, offset
);
1119 void lcd_puts_scroll_style_offset(int x
, int y
, const unsigned char *string
,
1120 int style
, int offset
)
1122 struct scrollinfo
* s
;
1125 if ((unsigned)y
>= (unsigned)current_vp
->height
)
1128 /* remove any previously scrolling line at the same location */
1129 lcd_scroll_stop_line(current_vp
, y
);
1131 if (lcd_scroll_info
.lines
>= LCD_SCROLLABLE_LINES
) return;
1133 s
= &lcd_scroll_info
.scroll
[lcd_scroll_info
.lines
];
1135 s
->start_tick
= current_tick
+ lcd_scroll_info
.delay
;
1137 if (style
& STYLE_INVERT
) {
1138 lcd_puts_style_offset(x
,y
,string
,STYLE_INVERT
,offset
);
1141 lcd_puts_offset(x
,y
,string
,offset
);
1143 lcd_getstringsize(string
, &w
, &h
);
1145 if (current_vp
->width
- x
* 8 - current_vp
->xmargin
< w
) {
1146 /* prepare scroll line */
1149 memset(s
->line
, 0, sizeof s
->line
);
1150 strcpy(s
->line
, (char *)string
);
1153 s
->width
= lcd_getstringsize((unsigned char *)s
->line
, &w
, &h
);
1155 /* scroll bidirectional or forward only depending on the string
1157 if ( lcd_scroll_info
.bidir_limit
) {
1158 s
->bidir
= s
->width
< (current_vp
->width
- current_vp
->xmargin
) *
1159 (100 + lcd_scroll_info
.bidir_limit
) / 100;
1164 if (!s
->bidir
) { /* add spaces if scrolling in the round */
1165 strcat(s
->line
, " ");
1166 /* get new width incl. spaces */
1167 s
->width
= lcd_getstringsize((unsigned char *)s
->line
, &w
, &h
);
1170 end
= strchr(s
->line
, '\0');
1171 strncpy(end
, (char *)string
, current_vp
->width
/2);
1175 s
->len
= utf8length((char *)string
);
1177 s
->startx
= current_vp
->xmargin
+ x
* s
->width
/ s
->len
;
1178 s
->backward
= false;
1180 lcd_scroll_info
.lines
++;
1184 void lcd_scroll_fn(void)
1187 struct scrollinfo
* s
;
1191 struct viewport
* old_vp
= current_vp
;
1193 for ( index
= 0; index
< lcd_scroll_info
.lines
; index
++ ) {
1194 s
= &lcd_scroll_info
.scroll
[index
];
1197 if (TIME_BEFORE(current_tick
, s
->start_tick
))
1200 lcd_set_viewport(s
->vp
);
1203 s
->offset
-= lcd_scroll_info
.step
;
1205 s
->offset
+= lcd_scroll_info
.step
;
1207 pf
= font_get(current_vp
->font
);
1209 ypos
= current_vp
->ymargin
+ s
->y
* pf
->height
;
1211 if (s
->bidir
) { /* scroll bidirectional */
1212 if (s
->offset
<= 0) {
1213 /* at beginning of line */
1215 s
->backward
= false;
1216 s
->start_tick
= current_tick
+ lcd_scroll_info
.delay
* 2;
1218 if (s
->offset
>= s
->width
- (current_vp
->width
- xpos
)) {
1219 /* at end of line */
1220 s
->offset
= s
->width
- (current_vp
->width
- xpos
);
1222 s
->start_tick
= current_tick
+ lcd_scroll_info
.delay
* 2;
1226 /* scroll forward the whole time */
1227 if (s
->offset
>= s
->width
)
1228 s
->offset
%= s
->width
;
1231 lastmode
= current_vp
->drawmode
;
1232 current_vp
->drawmode
= (s
->style
&STYLE_INVERT
) ?
1233 (DRMODE_SOLID
|DRMODE_INVERSEVID
) : DRMODE_SOLID
;
1234 lcd_putsxyofs(xpos
, ypos
, s
->offset
, s
->line
);
1235 current_vp
->drawmode
= lastmode
;
1236 lcd_update_viewport_rect(xpos
, ypos
,
1237 current_vp
->width
- xpos
, pf
->height
);
1240 lcd_set_viewport(old_vp
);