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