2 #include "oswald_strings.h"
3 #include "oswald_fonts.h"
4 #include "oswald_hal.h"
6 #include "oswald_graphics.h"
9 void oswald_draw_pixel(const unsigned int xstart, const unsigned int ystart)
11 hal_lcd_set_pixel(xstart, ystart, TRUE);
14 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)
22 //g_printerr("dbmp %d,%d off %d,%d\n", xstart, ystart, width, height);
24 //g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
25 // we only draw set pixel, unset pixel remain as they are
26 for (y=yoff; y<bmp_height && y<height; y++) {
27 for (x=xoff; x<bmp_width && x<width; x++) {
28 cb = (uint8_t *)(bmp + (y * ((bmp_width / 8) + ((bmp_width % 8) ? 1 : 0))) + (x / 8));
29 // g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
30 if (*cb & (1 << (x % 8))) {
31 hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
42 /*inline*/ void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
47 // we only draw set pixel, unset pixel remain as they are
48 for (y=0; y<height; y++) {
49 for (x=0; x<width; x++) {
50 cb = (uint8_t *)(bmp + (y * ((width / 8) + ((width % 8) ? 1 : 0))) + (x / 8));
51 if (*cb & (1 << (x % 8)))
52 hal_lcd_set_pixel((xstart + x), (ystart + y), TRUE);
57 void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
59 // seems we are triggering a MSPGCC compiler bug here...
60 // if we do not do this trick then bmp becomes 0x00 when passed a livel higher!
61 volatile unsigned int num;
63 num = (unsigned int) bmp;
65 oswald_draw_bitmap_opts(xstart, ystart, 0, 0, width, height, width, height, bmp);
68 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)
70 // seems we are triggering a MSPGCC compiler bug here...
71 // if we do not do this trick then bmp becomes 0x00 when passed a livel higher!
72 volatile unsigned int num;
74 num = (unsigned int) bmp;
76 oswald_draw_bitmap_opts(xstart, ystart, 0, 0, width, height, bmp_width, bmp_height, bmp);
80 void oswald_draw_line(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend)
82 int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
87 incx = (dx >= 0) ? 1 : -1;
88 incy = (dy >= 0) ? 1 : -1;
108 hal_lcd_set_pixel(x, y, TRUE);
110 for (t = 0; t < el; ++t) {
120 hal_lcd_set_pixel(x, y, TRUE);
122 // hal_lcd_update_display();
125 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)
127 int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
132 incx = (dx >= 0) ? 1 : -1;
133 incy = (dy >= 0) ? 1 : -1;
159 hal_lcd_set_pixel(x, y, TRUE);
160 for (i=1; i<thickness; i++) {
161 hal_lcd_set_pixel(x-i, y, TRUE);
162 hal_lcd_set_pixel(x+i, y, TRUE);
163 hal_lcd_set_pixel(x, y-i, TRUE);
164 hal_lcd_set_pixel(x, y+i, TRUE);
167 for (t = 0; t < el; ++t) {
177 hal_lcd_set_pixel(x, y, TRUE);
178 for (i=1; i<thickness; i++) {
179 hal_lcd_set_pixel(x-i, y, TRUE);
180 hal_lcd_set_pixel(x+i, y, TRUE);
181 hal_lcd_set_pixel(x, y-i, TRUE);
182 hal_lcd_set_pixel(x, y+i, TRUE);
185 // hal_lcd_update_display();
188 uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_font_face face, const uint8_t Character)
191 u8t CharacterHeight = GetCharacterHeight();
192 u8t CharacterWidth = GetCharacterWidth(Character);
193 u16t bitmap[MAX_FONT_ROWS];
196 GetCharacterBitmap(Character, bitmap);
198 // printf("cw=%d ch=%d\n", CharacterWidth, CharacterHeight);
199 for (ly=0; ly<CharacterHeight; ly++) {
200 for (lx=0; lx<CharacterWidth; lx++) {
201 if (bitmap[ly] & (1<<lx)) {
202 hal_lcd_set_pixel(lx+x, ly+y, TRUE);
205 hal_lcd_set_pixel(lx+x, ly+y, FALSE);
212 return CharacterWidth + GetFontSpacing();
214 uint8_t *cdata = oswald_fonts[face].data;
218 if (Character == 32) // space / blank
219 return oswald_fonts[face].width / 2;
221 csize = ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0)) * oswald_fonts[face].height;
222 if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL)
225 //csize += (oswald_fonts[face].height / 8) + ((oswald_fonts[face].height % 8) ? 1 : 0);
227 // g_printerr("fp = 0x%08lx cdata = 0x%08lx\n", font_7x12, cdata);
229 cdata = (cdata + ((int)csize * (int)Character));
231 //g_printerr("%02x\n", oswald_fonts[face].data[0][0]);
232 //g_printerr("char %02x face %d %dx%d csize %d\n", Character, face, oswald_fonts[face].width, oswald_fonts[face].height, csize);
233 //g_printerr("char %02x %02x %02x\n", (uint8_t)cdata[0], (uint8_t)cdata[1], (uint8_t)cdata[2]);
235 // oswald_draw_bitmap(x, y, oswald_fonts[face].height, oswald_fonts[face].height, cdata);
236 if (oswald_fonts[face].font_type == FONT_TYPE_MONOSPACE) {
237 cwidth = oswald_fonts[face].width;
238 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);
240 if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL) {
243 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);
245 // 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);
251 void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_face face, char *str)
255 strl = oswald_strlen(str);
260 for (i=0; i<strl; i++) {
261 lx += oswald_write_character(lx, y, face, str[i]);
266 void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_face face, const int16_t number)
271 itoa(number, str, 10);
272 strl = oswald_strlen(str);
277 for (i=0; i<strl; i++) {
278 lx += oswald_write_character(lx, y, face, str[i]);