]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/oswald_graphics.c
Power saving changes, add new fonts, bitmaps and screens
[oswald.git] / ui / oswald_graphics.c
index e64476d61ed50f26a8c1cc4e886a3b7c0f040591..651d8e8b38a9e787d36826102abb7104fbf6edf0 100644 (file)
@@ -6,12 +6,19 @@
 #include "oswald_graphics.h"
 
 
-void oswald_draw_pixel(const unsigned int xstart, const unsigned int ystart)
+#if 0
+void oswald_draw_pixel(const unsigned int xstart, const unsigned int ystart, uint8_t color)
 {
        hal_lcd_set_pixel(xstart, ystart, TRUE);
 }
+#endif
 
-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)
+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 boolean invert,
+               const unsigned int bmp_width, const unsigned int bmp_height,
+               const void *bmp)
 {
        unsigned int x, y;
        uint8_t *cb;
@@ -28,55 +35,19 @@ void oswald_draw_bitmap_opts(const unsigned int xstart, const unsigned int ystar
                        cb = (uint8_t *)(bmp + (y * ((bmp_width / 8) + ((bmp_width % 8) ? 1 : 0))) + (x / 8));
                        // g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
                        if (*cb & (1 << (x % 8))) {
-                               hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
+                               if (!invert)
+                                       hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
                                // g_printerr("X");
-                       } /*else {
-                               g_printerr(".");
-                       }*/
+                       } else {
+                               if (invert)
+                                       hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
+                               // g_printerr(".");
+                       }
                }
                //g_printerr("\n");
        }
 }
 
-#if 0
-/*inline*/ void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
-{
-       unsigned int x, y;
-       uint8_t *cb;
-
-       // we only draw set pixel, unset pixel remain as they are
-       for (y=0; y<height; y++) {
-               for (x=0; x<width; x++) {
-                       cb = (uint8_t *)(bmp + (y * ((width / 8) + ((width % 8) ? 1 : 0))) + (x / 8));
-                       if (*cb & (1 << (x % 8)))
-                               hal_lcd_set_pixel((xstart + x), (ystart + y), TRUE);
-               }
-       }
-}
-#else
-void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
-{
-       // seems we are triggering a MSPGCC compiler bug here...
-       // if we do not do this trick then bmp becomes 0x00 when passed a livel higher!
-       volatile unsigned int num;
-
-       num = (unsigned int) bmp;
-
-       oswald_draw_bitmap_opts(xstart, ystart, 0, 0, width, height, width, height, bmp);
-}
-
-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)
-{
-       // seems we are triggering a MSPGCC compiler bug here...
-       // if we do not do this trick then bmp becomes 0x00 when passed a livel higher!
-       volatile unsigned int num;
-
-       num = (unsigned int) bmp;
-
-       oswald_draw_bitmap_opts(xstart, ystart, 0, 0, width, height, bmp_width, bmp_height, bmp);
-}
-#endif
-
 void oswald_draw_line(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend)
 {
        int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
@@ -119,7 +90,6 @@ void oswald_draw_line(const uint8_t xstart, const uint8_t ystart, const uint8_t
                }
                hal_lcd_set_pixel(x, y, TRUE);
        }
-       // hal_lcd_update_display();
 }
 
 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)
@@ -182,45 +152,21 @@ void oswald_draw_line_ww(const uint8_t xstart, const uint8_t ystart, const uint8
                        hal_lcd_set_pixel(x, y+i, TRUE);
                }
        }
-       // hal_lcd_update_display();
 }
 
-uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_font_face face, const uint8_t Character)
+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)
 {
-#if 0
-       u8t CharacterHeight = GetCharacterHeight();
-       u8t CharacterWidth = GetCharacterWidth(Character);
-       u16t bitmap[MAX_FONT_ROWS];
-       register lx, ly;
-
-       GetCharacterBitmap(Character, bitmap);
-
-       // printf("cw=%d ch=%d\n", CharacterWidth, CharacterHeight);
-       for (ly=0; ly<CharacterHeight; ly++) {
-               for (lx=0; lx<CharacterWidth; lx++) {
-                       if (bitmap[ly] & (1<<lx)) {
-                               hal_lcd_set_pixel(lx+x, ly+y, TRUE);
-                               // printf(".");
-                       } /*else {
-                               hal_lcd_set_pixel(lx+x, ly+y, FALSE);
-                               // printf(" ");
-                       }*/
-               }
-               // printf("\n");
-       }
-
-       return CharacterWidth + GetFontSpacing();
-#else
        uint8_t *cdata = oswald_fonts[face].data;
        uint8_t cwidth;
        int csize;
 
-       if (Character == 32) // space / blank
-               return oswald_fonts[face].width / 2;
+//     if (Character == 32) { // space, blank no need to draw one ;)
+//             return oswald_fonts[face].width / 2;
+//     }
 
        csize = ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0)) * oswald_fonts[face].height;
        if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL)
-               csize += 1;
+               csize += 1; // at least 1px spacing
 
        //csize += (oswald_fonts[face].height / 8) + ((oswald_fonts[face].height % 8) ? 1 : 0);
 
@@ -235,20 +181,22 @@ uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_fo
        // oswald_draw_bitmap(x, y, oswald_fonts[face].height, oswald_fonts[face].height, cdata);
        if (oswald_fonts[face].font_type == FONT_TYPE_MONOSPACE) {
                cwidth = oswald_fonts[face].width;
-               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);
-       }
-       if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL) {
+               //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);
+               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);
+       } else if (oswald_fonts[face].font_type == FONT_TYPE_PROPORTIONAL) {
                cwidth = cdata[0];
                cdata++;
-               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);
+               // 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);
+               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);
+       } else {
+               cwidth = 0;
        }
        // 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);
 
        return cwidth;
-#endif
 }
 
-void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_face face, char *str)
+void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_face face, const boolean invert, char *str)
 {
        uint8_t lx, i, strl;
 
@@ -258,12 +206,29 @@ void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_fac
 
        lx = x;
        for (i=0; i<strl; i++) {
-               lx += oswald_write_character(lx, y, face, str[i]);
+               lx += oswald_write_character(lx, y, face, invert, str[i]);
        }
 }
 
+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)
+{
+       uint8_t lx, i, strl;
+
+       strl = oswald_strlen(str);
+       if (strl == 0)
+               return;
 
-void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_face face, const int16_t number)
+       lx = x;
+       for (i=0; i<strl; i++) {
+               lx += oswald_write_character(lx, y, face, invert, str[i]);
+               if (lx > len)
+                       break;
+       }
+
+       return (i+1);
+}
+
+void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_face face, const boolean invert, const int16_t number)
 {
        uint8_t lx, i, strl;
        char str[8];
@@ -275,8 +240,7 @@ void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_fac
 
        lx = x;
        for (i=0; i<strl; i++) {
-               lx += oswald_write_character(lx, y, face, str[i]);
+               lx += oswald_write_character(lx, y, face, invert, str[i]);
        }
 }
 
-