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