]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/oswald_graphics.c
Shorten charger plug "tail"
[oswald.git] / ui / oswald_graphics.c
index eef4536a7c0fbc6be92be8b0a1e9abd98aaa8ab9..e64476d61ed50f26a8c1cc4e886a3b7c0f040591 100644 (file)
@@ -5,28 +5,13 @@
 
 #include "oswald_graphics.h"
 
-// dummies for MW replacement stuff
 
-void SetFont(etFontType Type)
+void oswald_draw_pixel(const unsigned int xstart, const unsigned int ystart)
 {
+       hal_lcd_set_pixel(xstart, ystart, TRUE);
 }
 
-u8t WriteLcdString(const uint8_t x, const uint8_t y, const char *str)
-{
-       return 1;
-}
-
-void WriteLcdNumber(const uint8_t x, const uint8_t y, const int16_t number)
-{
-}
-
-u8t WriteLcdCharacter(const uint8_t x, const uint8_t y, const uint8_t Character)
-{
-       return 1;
-}
-
-
-void oswald_draw_bitmap_offset(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 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 unsigned int bmp_width, const unsigned int bmp_height, const void *bmp)
 {
        unsigned int x, y;
        uint8_t *cb;
@@ -34,13 +19,22 @@ void oswald_draw_bitmap_offset(const unsigned int xstart, const unsigned int yst
        if (bmp == NULL)
                return;
 
+       //g_printerr("dbmp %d,%d off %d,%d\n", xstart, ystart, width, height);
+       cb = (uint8_t *)bmp;
+       //g_printerr("dat %02x %02x %02x\n", (uint8_t)cb[0], (uint8_t)cb[1], (uint8_t)cb[2]);
        // we only draw set pixel, unset pixel remain as they are
-       for (y=yoff; y<height; y++) {
-               for (x=xoff; x<width; x++) {
-                       cb = (uint8_t *)(bmp + (y * ((width / 8) + ((width % 8) ? 1 : 0))) + (x / 8));
-                       if (*cb & (1 << (x % 8)))
+       for (y=yoff; y<bmp_height && y<height; y++) {
+               for (x=xoff; x<bmp_width && x<width; x++) {
+                       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);
+                               // g_printerr("X");
+                       } /*else {
+                               g_printerr(".");
+                       }*/
                }
+               //g_printerr("\n");
        }
 }
 
@@ -68,7 +62,18 @@ void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, co
 
        num = (unsigned int) bmp;
 
-       oswald_draw_bitmap_offset(xstart, ystart, 0, 0, width, height, 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
 
@@ -207,27 +212,39 @@ uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_fo
        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;
 
        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 += (oswald_fonts[face].height / 8) + ((oswald_fonts[face].height % 8) ? 1 : 0);
 
        // g_printerr("fp = 0x%08lx cdata = 0x%08lx\n", font_7x12, cdata);
 
-       cdata = (cdata + (csize * (int)Character));
+       cdata = (cdata + ((int)csize * (int)Character));
 
        //g_printerr("%02x\n", oswald_fonts[face].data[0][0]);
        //g_printerr("char %02x face %d %dx%d csize %d\n", Character, face, oswald_fonts[face].width, oswald_fonts[face].height, csize);
        //g_printerr("char %02x %02x %02x\n", (uint8_t)cdata[0], (uint8_t)cdata[1], (uint8_t)cdata[2]);
 
        // oswald_draw_bitmap(x, y, oswald_fonts[face].height, oswald_fonts[face].height, cdata);
-       //oswald_draw_bitmap(x, y, ((oswald_fonts[face].width / 8) + ((oswald_fonts[face].width % 8) ? 1 : 0))*8, oswald_fonts[face].height, cdata);
-       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);
+       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) {
+               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_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 oswald_fonts[face].width;
+       return cwidth;
 #endif
 }