2 #include "oswald_strings.h"
3 #include "oswald_fonts.h"
4 #include "oswald_hal.h"
6 #include "oswald_graphics.h"
10 void oswald_draw_pixel(const unsigned int xstart, const unsigned int ystart, uint8_t color)
12 hal_lcd_set_pixel(xstart, ystart, TRUE);
16 void oswald_draw_bitmap_opts(const unsigned int xstart, const unsigned int ystart,
17 const unsigned int xoff, const unsigned int yoff,
18 const unsigned int width, const unsigned int height,
20 const unsigned int bmp_width, const unsigned int bmp_height,
29 //g_printerr("dbmp %d,%d off %d,%d\n", xstart, ystart, width, height);
31 //g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
32 // we only draw set pixel, unset pixel remain as they are
33 for (y=yoff; y<bmp_height && y<height; y++) {
34 for (x=xoff; x<bmp_width && x<width; x++) {
35 cb = (uint8_t *)(bmp + (y * ((bmp_width / 8) + ((bmp_width % 8) ? 1 : 0))) + (x / 8));
36 // g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
37 if (*cb & (1 << (x % 8))) {
39 hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
43 hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
51 void oswald_draw_line(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend)
53 int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
58 incx = (dx >= 0) ? 1 : -1;
59 incy = (dy >= 0) ? 1 : -1;
79 hal_lcd_set_pixel(x, y, TRUE);
81 for (t = 0; t < el; ++t) {
91 hal_lcd_set_pixel(x, y, TRUE);
95 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)
97 int16_t i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
102 incx = (dx >= 0) ? 1 : -1;
103 incy = (dy >= 0) ? 1 : -1;
129 hal_lcd_set_pixel(x, y, TRUE);
130 for (i=1; i<thickness; i++) {
131 hal_lcd_set_pixel(x-i, y, TRUE);
132 hal_lcd_set_pixel(x+i, y, TRUE);
133 hal_lcd_set_pixel(x, y-i, TRUE);
134 hal_lcd_set_pixel(x, y+i, TRUE);
137 for (t = 0; t < el; ++t) {
147 hal_lcd_set_pixel(x, y, TRUE);
148 for (i=1; i<thickness; i++) {
149 hal_lcd_set_pixel(x-i, y, TRUE);
150 hal_lcd_set_pixel(x+i, y, TRUE);
151 hal_lcd_set_pixel(x, y-i, TRUE);
152 hal_lcd_set_pixel(x, y+i, TRUE);
157 uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_font_face face, const boolean invert, const uint8_t Character)
159 uint8_t *cdata = oswald_fonts[face].data;
163 // if (Character == 32) { // space, blank no need to draw one ;)
164 // return oswald_fonts[face].width / 2;
167 csize = ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0)) * oswald_fonts[face].height;
168 if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL)
169 csize += 1; // at least 1px spacing
171 //csize += (oswald_fonts[face].height / 8) + ((oswald_fonts[face].height % 8) ? 1 : 0);
173 // g_printerr("fp = 0x%08lx cdata = 0x%08lx\n", font_7x12, cdata);
175 cdata = (cdata + ((int)csize * (int)Character));
177 //g_printerr("%02x\n", oswald_fonts[face].data[0][0]);
178 //g_printerr("char %02x face %d %dx%d csize %d\n", Character, face, oswald_fonts[face].width, oswald_fonts[face].height, csize);
179 //g_printerr("char %02x %02x %02x\n", (uint8_t)cdata[0], (uint8_t)cdata[1], (uint8_t)cdata[2]);
181 // oswald_draw_bitmap(x, y, oswald_fonts[face].height, oswald_fonts[face].height, cdata);
182 if (oswald_fonts[face].font_type == FONT_TYPE_MONOSPACE) {
183 cwidth = oswald_fonts[face].width;
184 //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);
185 oswald_draw_bitmap_opts(x,y,0,0,((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0)) * 8,oswald_fonts[face].height,invert,((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0)) * 8,oswald_fonts[face].height,(uint8_t *)cdata);
186 } else if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL) {
189 // 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);
190 oswald_draw_bitmap_opts(x,y,0,0,(cwidth+1),oswald_fonts[face].height,invert,((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0))*8,oswald_fonts[face].height,(uint8_t *)cdata);
194 // 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);
199 void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_face face, const boolean invert, char *str)
203 strl = oswald_strlen(str);
208 for (i=0; i<strl; i++) {
209 lx += oswald_write_character(lx, y, face, invert, str[i]);
213 uint8_t oswald_write_string_length(const uint8_t x, const uint8_t y, const uint8_t len, const oswald_font_face face, const boolean invert, char *str)
217 strl = oswald_strlen(str);
222 for (i=0; i<strl; i++) {
223 lx += oswald_write_character(lx, y, face, invert, str[i]);
231 void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_face face, const boolean invert, const int16_t number)
236 itoa(number, str, 10);
237 strl = oswald_strlen(str);
242 for (i=0; i<strl; i++) {
243 lx += oswald_write_character(lx, y, face, invert, str[i]);