2 #include "oswald_strings.h"
3 #include "oswald_fonts.h"
4 #include "oswald_hal.h"
6 #include "oswald_graphics.h"
9 void oswald_draw_bitmap_opts(const unsigned int xstart, const unsigned int ystart, const unsigned int xoff, const unsigned int yoff, const unsigned int width, const unsigned int height, const unsigned int bmp_width, const unsigned int bmp_height, const void *bmp)
17 //g_printerr("dbmp %d,%d off %d,%d\n", xstart, ystart, width, height);
19 //g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
20 // we only draw set pixel, unset pixel remain as they are
21 for (y=yoff; y<bmp_height && y<height; y++) {
22 for (x=xoff; x<bmp_width && x<width; x++) {
23 cb = (uint8_t *)(bmp + (y * ((bmp_width / 8) + ((bmp_width % 8) ? 1 : 0))) + (x / 8));
24 // g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
25 if (*cb & (1 << (x % 8))) {
26 hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
37 /*inline*/ void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
42 // we only draw set pixel, unset pixel remain as they are
43 for (y=0; y<height; y++) {
44 for (x=0; x<width; x++) {
45 cb = (uint8_t *)(bmp + (y * ((width / 8) + ((width % 8) ? 1 : 0))) + (x / 8));
46 if (*cb & (1 << (x % 8)))
47 hal_lcd_set_pixel((xstart + x), (ystart + y), TRUE);
52 void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
54 // seems we are triggering a MSPGCC compiler bug here...
55 // if we do not do this trick then bmp becomes 0x00 when passed a livel higher!
56 volatile unsigned int num;
58 num = (unsigned int) bmp;
60 oswald_draw_bitmap_opts(xstart, ystart, 0, 0, width, height, width, height, bmp);
63 void oswald_draw_bitmap_size(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const unsigned int bmp_width, const unsigned int bmp_height, const void *bmp)
65 // seems we are triggering a MSPGCC compiler bug here...
66 // if we do not do this trick then bmp becomes 0x00 when passed a livel higher!
67 volatile unsigned int num;
69 num = (unsigned int) bmp;
71 oswald_draw_bitmap_opts(xstart, ystart, 0, 0, width, height, bmp_width, bmp_height, bmp);
75 void oswald_draw_line(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend)
77 int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
82 incx = (dx >= 0) ? 1 : -1;
83 incy = (dy >= 0) ? 1 : -1;
103 hal_lcd_set_pixel(x, y, TRUE);
105 for (t = 0; t < el; ++t) {
115 hal_lcd_set_pixel(x, y, TRUE);
117 // hal_lcd_update_display();
120 void oswald_draw_line_ww(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend, const uint8_t thickness)
122 int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
127 incx = (dx >= 0) ? 1 : -1;
128 incy = (dy >= 0) ? 1 : -1;
154 hal_lcd_set_pixel(x, y, TRUE);
155 for (i=1; i<thickness; i++) {
156 hal_lcd_set_pixel(x-i, y, TRUE);
157 hal_lcd_set_pixel(x+i, y, TRUE);
158 hal_lcd_set_pixel(x, y-i, TRUE);
159 hal_lcd_set_pixel(x, y+i, TRUE);
162 for (t = 0; t < el; ++t) {
172 hal_lcd_set_pixel(x, y, TRUE);
173 for (i=1; i<thickness; i++) {
174 hal_lcd_set_pixel(x-i, y, TRUE);
175 hal_lcd_set_pixel(x+i, y, TRUE);
176 hal_lcd_set_pixel(x, y-i, TRUE);
177 hal_lcd_set_pixel(x, y+i, TRUE);
180 // hal_lcd_update_display();
183 uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_font_face face, const uint8_t Character)
186 u8t CharacterHeight = GetCharacterHeight();
187 u8t CharacterWidth = GetCharacterWidth(Character);
188 u16t bitmap[MAX_FONT_ROWS];
191 GetCharacterBitmap(Character, bitmap);
193 // printf("cw=%d ch=%d\n", CharacterWidth, CharacterHeight);
194 for (ly=0; ly<CharacterHeight; ly++) {
195 for (lx=0; lx<CharacterWidth; lx++) {
196 if (bitmap[ly] & (1<<lx)) {
197 hal_lcd_set_pixel(lx+x, ly+y, TRUE);
200 hal_lcd_set_pixel(lx+x, ly+y, FALSE);
207 return CharacterWidth + GetFontSpacing();
209 uint8_t *cdata = oswald_fonts[face].data;
213 if (Character == 32) // space / blank
214 return oswald_fonts[face].width / 2;
216 csize = ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0)) * oswald_fonts[face].height;
217 if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL)
220 //csize += (oswald_fonts[face].height / 8) + ((oswald_fonts[face].height % 8) ? 1 : 0);
222 // g_printerr("fp = 0x%08lx cdata = 0x%08lx\n", font_7x12, cdata);
224 cdata = (cdata + ((int)csize * (int)Character));
226 //g_printerr("%02x\n", oswald_fonts[face].data[0][0]);
227 //g_printerr("char %02x face %d %dx%d csize %d\n", Character, face, oswald_fonts[face].width, oswald_fonts[face].height, csize);
228 //g_printerr("char %02x %02x %02x\n", (uint8_t)cdata[0], (uint8_t)cdata[1], (uint8_t)cdata[2]);
230 // oswald_draw_bitmap(x, y, oswald_fonts[face].height, oswald_fonts[face].height, cdata);
231 if (oswald_fonts[face].font_type == FONT_TYPE_MONOSPACE) {
232 cwidth = oswald_fonts[face].width;
233 oswald_draw_bitmap(x, y, ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0))*8, oswald_fonts[face].height, (uint8_t *)cdata);
235 if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL) {
238 oswald_draw_bitmap_size(x, y, cwidth+1, oswald_fonts[face].height, ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0))*8, oswald_fonts[face].height, (uint8_t *)cdata);
240 // oswald_draw_bitmap_offset(x, y, (oswald_fonts[face].width % 8) > 0 ? (8-(oswald_fonts[face].width % 8)) : 0, 0, ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0))*8, oswald_fonts[face].height, cdata);
246 void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_face face, char *str)
250 strl = oswald_strlen(str);
255 for (i=0; i<strl; i++) {
256 lx += oswald_write_character(lx, y, face, str[i]);
261 void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_face face, const int16_t number)
266 itoa(number, str, 10);
267 strl = oswald_strlen(str);
272 for (i=0; i<strl; i++) {
273 lx += oswald_write_character(lx, y, face, str[i]);