]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/oswald_graphics.c
add missing files
[oswald.git] / ui / oswald_graphics.c
diff --git a/ui/oswald_graphics.c b/ui/oswald_graphics.c
new file mode 100644 (file)
index 0000000..36894ab
--- /dev/null
@@ -0,0 +1,172 @@
+#include "oswald-ui.h"
+#include "oswald_strings.h"
+#include "oswald_fonts.h"
+
+#include "oswald_graphics.h"
+
+
+void oswald_draw_Line(u8t xstart, u8t ystart, u8t xend, u8t yend)
+{
+       int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
+       dx = xend - xstart;
+       dy = yend - ystart;
+       incx = (dx >= 0) ? 1 : -1;
+       incy = (dy >= 0) ? 1 : -1;
+
+       if (dx<0)
+               dx = -dx;
+       if (dy<0)
+               dy = -dy;
+       if (dx>dy) {
+               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;
+       }
+       x = xstart;
+       y = ystart;
+       err = el/2;
+       lcd_set_pixel(x, y, TRUE);
+       for (t = 0; t < el; ++t) {
+               err -= es; 
+               if (err < 0) {
+                       err += el;
+                       x += ddx;
+                       y += ddy;
+               } else {
+                       x += pdx;
+                       y += pdy;
+               }
+               lcd_set_pixel(x, y, TRUE);
+       }
+       lcd_update_display();
+}
+
+void oswald_draw_line_ww(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickness)
+{
+       int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
+       dx = xend - xstart;
+       dy = yend - ystart;
+       incx = (dx >= 0) ? 1 : -1;
+       incy = (dy >= 0) ? 1 : -1;
+
+       if (dx<0)
+               dx = -dx;
+       if (dy<0)
+               dy = -dy;
+       if (dx>dy) {
+               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;
+       }
+       x = xstart;
+       y = ystart;
+       err = el/2;
+       lcd_set_pixel(x, y, TRUE);
+       for (i=1; i<thickness; i++) {
+               lcd_set_pixel(x-i, y, TRUE);
+               lcd_set_pixel(x+i, y, TRUE);
+               lcd_set_pixel(x, y-i, TRUE);
+               lcd_set_pixel(x, y+i, TRUE);
+       }
+       for (t = 0; t < el; ++t) {
+               err -= es; 
+               if (err < 0) {
+                       err += el;
+                       x += ddx;
+                       y += ddy;
+               } else {
+                       x += pdx;
+                       y += pdy;
+               }
+               lcd_set_pixel(x, y, TRUE);
+               for (i=1; i<thickness; i++) {
+                       lcd_set_pixel(x-i, y, TRUE);
+                       lcd_set_pixel(x+i, y, TRUE);
+                       lcd_set_pixel(x, y-i, TRUE);
+                       lcd_set_pixel(x, y+i, TRUE);
+               }
+       }
+       lcd_update_display();
+}
+
+u8t oswald_write_character(u8t x, u8t y, oswald_font_face face, u8t 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)) {
+                               lcd_set_pixel(lx+x, ly+y, TRUE);
+                               // printf(".");
+                       } else {
+                               lcd_set_pixel(lx+x, ly+y, FALSE);
+                               // printf(" ");
+                       }
+               }
+               // printf("\n");
+       }
+
+       return CharacterWidth + GetFontSpacing();
+#endif
+       char *cdata = oswald_fonts[face].data[Character];
+
+       dbg_out("%c", cdata[1]);
+       return 0;
+}
+
+void oswald_write_string(u8t x, u8t y, oswald_font_face face, u8t *str)
+{
+       register lx, i, strl;
+
+       strl = oswald_strlen(str);
+       if (strl == 0)
+               return;
+
+       lx = x;
+       for (i=0; i<strl; i++) {
+               lx += WriteLcdCharacter(lx, y, str[i]);
+       }
+}
+
+
+void oswald_Write_number(u8t x, u8t y, oswald_font_face face, s16t number)
+{
+       register lx, i, strl;
+       u8t str[8];
+
+       itoa(number, str, 10);
+       strl = oswald_strlen(str);
+       if (strl == 0)
+               return;
+
+       lx = x;
+       for (i=0; i<strl; i++) {
+               lx += WriteLcdCharacter(lx, y, str[i]);
+       }
+}
+