]> git.karo-electronics.de Git - oswald.git/blob - ui/oswald_graphics.c
add missing files
[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_Line(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         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                 lcd_set_pixel(x, y, TRUE);
49         }
50         lcd_update_display();
51 }
52
53 void oswald_draw_line_ww(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         lcd_set_pixel(x, y, TRUE);
82         for (i=1; i<thickness; i++) {
83                 lcd_set_pixel(x-i, y, TRUE);
84                 lcd_set_pixel(x+i, y, TRUE);
85                 lcd_set_pixel(x, y-i, TRUE);
86                 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                 lcd_set_pixel(x, y, TRUE);
100                 for (i=1; i<thickness; i++) {
101                         lcd_set_pixel(x-i, y, TRUE);
102                         lcd_set_pixel(x+i, y, TRUE);
103                         lcd_set_pixel(x, y-i, TRUE);
104                         lcd_set_pixel(x, y+i, TRUE);
105                 }
106         }
107         lcd_update_display();
108 }
109
110 u8t oswald_write_character(u8t x, u8t y, oswald_font_face face, u8t Character)
111 {
112 #if 0
113         u8t CharacterHeight = GetCharacterHeight();
114         u8t CharacterWidth = GetCharacterWidth(Character);
115         u16t bitmap[MAX_FONT_ROWS];
116         register 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                                 lcd_set_pixel(lx+x, ly+y, TRUE);
125                                 // printf(".");
126                         } else {
127                                 lcd_set_pixel(lx+x, ly+y, FALSE);
128                                 // printf(" ");
129                         }
130                 }
131                 // printf("\n");
132         }
133
134         return CharacterWidth + GetFontSpacing();
135 #endif
136         char *cdata = oswald_fonts[face].data[Character];
137
138         dbg_out("%c", cdata[1]);
139         return 0;
140 }
141
142 void oswald_write_string(u8t x, u8t y, oswald_font_face face, u8t *str)
143 {
144         register lx, i, strl;
145
146         strl = oswald_strlen(str);
147         if (strl == 0)
148                 return;
149
150         lx = x;
151         for (i=0; i<strl; i++) {
152                 lx += WriteLcdCharacter(lx, y, str[i]);
153         }
154 }
155
156
157 void oswald_Write_number(u8t x, u8t y, oswald_font_face face, s16t number)
158 {
159         register lx, i, strl;
160         u8t str[8];
161
162         itoa(number, str, 10);
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