]> git.karo-electronics.de Git - oswald.git/blob - ui/LcdDisplay.c
Add support for more screens
[oswald.git] / ui / LcdDisplay.c
1 #include "oswald-ui.h"
2 #include "oswald_strings.h"
3 #include "Fonts.h"
4
5 #include "LcdDisplay.h"
6
7 #define NUM_LCD_ROWS  96
8 #define NUM_LCD_COL_BYTES  ( 12 )
9 #define MAX_FONT_ROWS ( 19 )
10
11
12 void DrawLcdLineBresenham(u8t xstart, u8t ystart, u8t xend, u8t yend)
13 {
14         int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
15  
16         dx = xend - xstart;
17         dy = yend - ystart;
18  
19         incx = (dx >= 0) ? 1 : -1;
20         incy = (dy >= 0) ? 1 : -1;
21
22         if (dx<0)
23                 dx = -dx;
24         if (dy<0)
25                 dy = -dy;
26  
27         if (dx>dy) {
28                 pdx = incx; pdy = 0;
29                 ddx=incx; ddy=incy;
30                 es =dy;   el =dx;
31         } else {
32                 pdx=0;    pdy=incy;
33                 ddx=incx; ddy=incy;
34                 es =dx;   el =dy;
35         }
36  
37         x = xstart;
38         y = ystart;
39         err = el/2;
40         lcd_set_pixel(x, y, TRUE);
41  
42         for (t = 0; t < el; ++t) {
43                 err -= es; 
44                 if (err < 0) {
45                         err += el;
46                         x += ddx;
47                         y += ddy;
48                 } else {
49                         x += pdx;
50                         y += pdy;
51                 }
52                 lcd_set_pixel(x, y, TRUE);
53         }
54 }
55
56 void DrawLcdLineBresenhamWW(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickness)
57 {
58         int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
59  
60         dx = xend - xstart;
61         dy = yend - ystart;
62  
63         incx = (dx >= 0) ? 1 : -1;
64         incy = (dy >= 0) ? 1 : -1;
65
66         if (dx<0)
67                 dx = -dx;
68         if (dy<0)
69                 dy = -dy;
70  
71         if (dx>dy) {
72                 pdx = incx; pdy = 0;
73                 ddx=incx; ddy=incy;
74                 es =dy;   el =dx;
75         } else {
76                 pdx=0;    pdy=incy;
77                 ddx=incx; ddy=incy;
78                 es =dx;   el =dy;
79         }
80  
81         x = xstart;
82         y = ystart;
83         err = el/2;
84         lcd_set_pixel(x, y, TRUE);
85         for (i=1; i<thickness; i++) {
86                 lcd_set_pixel(x-i, y, TRUE);
87                 lcd_set_pixel(x+i, y, TRUE);
88                 lcd_set_pixel(x, y-i, TRUE);
89                 lcd_set_pixel(x, y+i, TRUE);
90         }
91  
92         for (t = 0; t < el; ++t) {
93                 err -= es; 
94                 if (err < 0) {
95                         err += el;
96                         x += ddx;
97                         y += ddy;
98                 } else {
99                         x += pdx;
100                         y += pdy;
101                 }
102                 lcd_set_pixel(x, y, TRUE);
103                 for (i=1; i<thickness; i++) {
104                         lcd_set_pixel(x-i, y, TRUE);
105                         lcd_set_pixel(x+i, y, TRUE);
106                         lcd_set_pixel(x, y-i, TRUE);
107                         lcd_set_pixel(x, y+i, TRUE);
108                 }
109         }
110 }
111
112
113 u8t WriteLcdCharacter(u8t x, u8t y, u8t Character)
114 {
115         u8t CharacterHeight = GetCharacterHeight();
116         u8t CharacterWidth = GetCharacterWidth(Character);
117         unsigned int bitmap[MAX_FONT_ROWS];
118         register lx, ly;
119
120         GetCharacterBitmap(Character,(unsigned int*)&bitmap);
121
122         // printf("cw=%d ch=%d\n", CharacterWidth, CharacterHeight);
123         for (ly=0; ly<CharacterHeight; ly++) {
124                 for (lx=0; lx<CharacterWidth; lx++) {
125                         if (bitmap[ly] & (1<<lx)) {
126                                 lcd_set_pixel(lx+x, ly+y, TRUE);
127                                 // printf(".");
128                         } else {
129                                 lcd_set_pixel(lx+x, ly+y, FALSE);
130                                 // printf(" ");
131                         }
132                 }
133                 // printf("\n");
134         }
135
136         return CharacterWidth + GetFontSpacing();
137 }
138
139 void WriteLcdString(u8t x, u8t y, u8t *str)
140 {
141         register lx, i, strl;
142
143         strl = oswald_strlen(str);
144         if (strl == 0)
145                 return;
146
147         lx = x;
148         for (i=0; i<strl; i++) {
149                 lx += WriteLcdCharacter(lx, y, str[i]);
150         }
151 }
152