]> git.karo-electronics.de Git - oswald.git/blob - ui/oswald_graphics.c
Bluetooth handling, screen reworks for icons
[oswald.git] / ui / oswald_graphics.c
1 #include "oswald-ui.h"
2 #include "oswald_strings.h"
3 #include "oswald_fonts.h"
4
5 #include "oswald_graphics.h"
6
7
8 #if 0
9 void oswald_draw_bitmap(const uint8_t xstart, const uint8_t ystart, const uint8_t width, const uint8_t height, const void *bmp)
10 {
11         uint8_t x, y;
12         uint8_t *cb;
13
14         // we only draw set pixel, unset pixel remain as they are
15         for (y=0; y<height; y++) {
16                 for (x=0; x<width; x++) {
17                         cb = (uint8_t *)(bmp + (y * ((width / 8)+((width % 8) ? 1:0))) + (x / 8));
18                         if (*cb & (1 << (x % 8)))
19                                 hal_lcd_set_pixel(xstart + x, ystart + y, TRUE);
20                 }
21         }
22 }
23 #endif
24
25 void oswald_draw_Line(uint8_t xstart, uint8_t ystart, uint8_t xend, uint8_t yend)
26 {
27         uint8_t x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
28  
29         dx = xend - xstart;
30         dy = yend - ystart;
31  
32         incx = (dx >= 0) ? 1 : -1;
33         incy = (dy >= 0) ? 1 : -1;
34
35         if (dx<0)
36                 dx = -dx;
37         if (dy<0)
38                 dy = -dy;
39  
40         if (dx>dy) {
41                 pdx = incx; pdy = 0;
42                 ddx=incx; ddy=incy;
43                 es =dy;   el =dx;
44         } else {
45                 pdx=0;    pdy=incy;
46                 ddx=incx; ddy=incy;
47                 es =dx;   el =dy;
48         }
49  
50         x = xstart;
51         y = ystart;
52         err = el/2;
53         hal_lcd_set_pixel(x, y, TRUE);
54  
55         for (t = 0; t < el; ++t) {
56                 err -= es; 
57                 if (err < 0) {
58                         err += el;
59                         x += ddx;
60                         y += ddy;
61                 } else {
62                         x += pdx;
63                         y += pdy;
64                 }
65                 hal_lcd_set_pixel(x, y, TRUE);
66         }
67         hal_lcd_update_display();
68 }
69
70 void oswald_draw_line_ww(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickness)
71 {
72         int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
73  
74         dx = xend - xstart;
75         dy = yend - ystart;
76  
77         incx = (dx >= 0) ? 1 : -1;
78         incy = (dy >= 0) ? 1 : -1;
79
80         if (dx<0)
81                 dx = -dx;
82         if (dy<0)
83                 dy = -dy;
84  
85         if (dx>dy) {
86                 pdx = incx; pdy = 0;
87                 ddx=incx; ddy=incy;
88                 es =dy;   el =dx;
89         } else {
90                 pdx=0;    pdy=incy;
91                 ddx=incx; ddy=incy;
92                 es =dx;   el =dy;
93         }
94  
95         x = xstart;
96         y = ystart;
97         err = el/2;
98         hal_lcd_set_pixel(x, y, TRUE);
99         for (i=1; i<thickness; i++) {
100                 hal_lcd_set_pixel(x-i, y, TRUE);
101                 hal_lcd_set_pixel(x+i, y, TRUE);
102                 hal_lcd_set_pixel(x, y-i, TRUE);
103                 hal_lcd_set_pixel(x, y+i, TRUE);
104         }
105  
106         for (t = 0; t < el; ++t) {
107                 err -= es; 
108                 if (err < 0) {
109                         err += el;
110                         x += ddx;
111                         y += ddy;
112                 } else {
113                         x += pdx;
114                         y += pdy;
115                 }
116                 hal_lcd_set_pixel(x, y, TRUE);
117                 for (i=1; i<thickness; i++) {
118                         hal_lcd_set_pixel(x-i, y, TRUE);
119                         hal_lcd_set_pixel(x+i, y, TRUE);
120                         hal_lcd_set_pixel(x, y-i, TRUE);
121                         hal_lcd_set_pixel(x, y+i, TRUE);
122                 }
123         }
124         hal_lcd_update_display();
125 }
126
127 u8t oswald_write_character(u8t x, u8t y, oswald_font_face face, u8t Character)
128 {
129 #if 0
130         u8t CharacterHeight = GetCharacterHeight();
131         u8t CharacterWidth = GetCharacterWidth(Character);
132         u16t bitmap[MAX_FONT_ROWS];
133         register lx, ly;
134
135         GetCharacterBitmap(Character, bitmap);
136
137         // printf("cw=%d ch=%d\n", CharacterWidth, CharacterHeight);
138         for (ly=0; ly<CharacterHeight; ly++) {
139                 for (lx=0; lx<CharacterWidth; lx++) {
140                         if (bitmap[ly] & (1<<lx)) {
141                                 hal_lcd_set_pixel(lx+x, ly+y, TRUE);
142                                 // printf(".");
143                         } else {
144                                 hal_lcd_set_pixel(lx+x, ly+y, FALSE);
145                                 // printf(" ");
146                         }
147                 }
148                 // printf("\n");
149         }
150
151         return CharacterWidth + GetFontSpacing();
152 #endif
153         char *cdata = oswald_fonts[face].data[Character];
154
155         dbg_out("%c", cdata[1]);
156         return 0;
157 }
158
159 void oswald_write_string(u8t x, u8t y, oswald_font_face face, u8t *str)
160 {
161         register lx, i, strl;
162
163         strl = oswald_strlen(str);
164         if (strl == 0)
165                 return;
166
167         lx = x;
168         for (i=0; i<strl; i++) {
169                 lx += WriteLcdCharacter(lx, y, str[i]);
170         }
171 }
172
173
174 void oswald_Write_number(u8t x, u8t y, oswald_font_face face, s16t number)
175 {
176         register lx, i, strl;
177         u8t str[8];
178
179         itoa(number, str, 10);
180         strl = oswald_strlen(str);
181         if (strl == 0)
182                 return;
183
184         lx = x;
185         for (i=0; i<strl; i++) {
186                 lx += WriteLcdCharacter(lx, y, str[i]);
187         }
188 }
189