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