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