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