]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/oswald_graphics.c
Starting to get rid of borrowed code (LcdDisplay, Fonts), integrate
[oswald.git] / ui / oswald_graphics.c
index 304aa7af6154c31939ac6c1322781a7815c2b93e..eef4536a7c0fbc6be92be8b0a1e9abd98aaa8ab9 100644 (file)
@@ -1,30 +1,80 @@
-#include "oswald-ui.h"
+#include "oswald.h"
 #include "oswald_strings.h"
 #include "oswald_fonts.h"
+#include "oswald_hal.h"
 
 #include "oswald_graphics.h"
 
+// dummies for MW replacement stuff
+
+void SetFont(etFontType Type)
+{
+}
+
+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)
+{
+       unsigned int x, y;
+       uint8_t *cb;
+
+       if (bmp == NULL)
+               return;
+
+       // 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)))
+                               hal_lcd_set_pixel((xstart + x) - xoff, (ystart + y) - yoff, TRUE);
+               }
+       }
+}
 
 #if 0
-void oswald_draw_bitmap(const uint8_t xstart, const uint8_t ystart, const uint8_t width, const uint8_t height, const void *bmp)
+/*inline*/ void oswald_draw_bitmap(const unsigned int xstart, const unsigned int ystart, const unsigned int width, const unsigned int height, const void *bmp)
 {
-       uint8_t x, y;
+       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));
+                       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);
+                               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_offset(xstart, ystart, 0, 0, width, height, bmp);
+}
 #endif
 
-void oswald_draw_Line(uint8_t xstart, uint8_t ystart, uint8_t xend, uint8_t yend)
+void oswald_draw_line(const uint8_t xstart, const uint8_t ystart, const uint8_t xend, const uint8_t yend)
 {
-       uint8_t x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
+       int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
  
        dx = xend - xstart;
        dy = yend - ystart;
@@ -64,10 +114,10 @@ void oswald_draw_Line(uint8_t xstart, uint8_t ystart, uint8_t xend, uint8_t yend
                }
                hal_lcd_set_pixel(x, y, TRUE);
        }
-       hal_lcd_update_display();
+       // hal_lcd_update_display();
 }
 
-void oswald_draw_line_ww(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickness)
+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)
 {
        int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
  
@@ -83,13 +133,19 @@ void oswald_draw_line_ww(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickne
                dy = -dy;
  
        if (dx>dy) {
-               pdx = incx; pdy = 0;
-               ddx=incx; ddy=incy;
-               es =dy;   el =dx;
+               pdx = incx;
+               pdy = 0;
+               ddx=incx;
+               ddy=incy;
+               es =dy;
+               el =dx;
        } else {
-               pdx=0;    pdy=incy;
-               ddx=incx; ddy=incy;
-               es =dx;   el =dy;
+               pdx=0;
+               pdy=incy;
+               ddx=incx;
+               ddy=incy;
+               es =dx;
+               el =dy;
        }
  
        x = xstart;
@@ -121,10 +177,10 @@ void oswald_draw_line_ww(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickne
                        hal_lcd_set_pixel(x, y+i, TRUE);
                }
        }
-       hal_lcd_update_display();
+       // hal_lcd_update_display();
 }
 
-u8t oswald_write_character(u8t x, u8t y, oswald_font_face face, u8t Character)
+uint8_t oswald_write_character(const uint8_t x, const uint8_t y, const oswald_font_face face, const uint8_t Character)
 {
 #if 0
        u8t CharacterHeight = GetCharacterHeight();
@@ -140,25 +196,44 @@ u8t oswald_write_character(u8t x, u8t y, oswald_font_face face, u8t Character)
                        if (bitmap[ly] & (1<<lx)) {
                                hal_lcd_set_pixel(lx+x, ly+y, TRUE);
                                // printf(".");
-                       } else {
+                       } /*else {
                                hal_lcd_set_pixel(lx+x, ly+y, FALSE);
                                // printf(" ");
-                       }
+                       }*/
                }
                // printf("\n");
        }
 
        return CharacterWidth + GetFontSpacing();
-#endif
-       char *cdata = oswald_fonts[face].data[Character];
+#else
+       uint8_t *cdata = oswald_fonts[face].data;
+       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;
+       //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);
 
-       dbg_out("%c", cdata[1]);
-       return 0;
+       cdata = (cdata + (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);
+
+       return oswald_fonts[face].width;
+#endif
 }
 
-void oswald_write_string(u8t x, u8t y, oswald_font_face face, u8t *str)
+void oswald_write_string(const uint8_t x, const uint8_t y, const oswald_font_face face, char *str)
 {
-       register lx, i, strl;
+       uint8_t lx, i, strl;
 
        strl = oswald_strlen(str);
        if (strl == 0)
@@ -166,15 +241,15 @@ void oswald_write_string(u8t x, u8t y, oswald_font_face face, u8t *str)
 
        lx = x;
        for (i=0; i<strl; i++) {
-               lx += WriteLcdCharacter(lx, y, str[i]);
+               lx += oswald_write_character(lx, y, face, str[i]);
        }
 }
 
 
-void oswald_Write_number(u8t x, u8t y, oswald_font_face face, s16t number)
+void oswald_write_number(const uint8_t x, const uint8_t y, const oswald_font_face face, const int16_t number)
 {
-       register lx, i, strl;
-       u8t str[8];
+       uint8_t lx, i, strl;
+       char str[8];
 
        itoa(number, str, 10);
        strl = oswald_strlen(str);
@@ -183,7 +258,8 @@ void oswald_Write_number(u8t x, u8t y, oswald_font_face face, s16t number)
 
        lx = x;
        for (i=0; i<strl; i++) {
-               lx += WriteLcdCharacter(lx, y, str[i]);
+               lx += oswald_write_character(lx, y, face, str[i]);
        }
 }
 
+