]> git.kernelconcepts.de Git - metawatch.git/commitdiff
Add new hackish bresenham line function to draw thicker lines, now used in analog...
authorNils Faerber <nils.faerber@kernelconcepts.de>
Wed, 30 Nov 2011 23:21:11 +0000 (00:21 +0100)
committerNils Faerber <nils.faerber@kernelconcepts.de>
Wed, 30 Nov 2011 23:21:11 +0000 (00:21 +0100)
Makefile
mw_main.c
mw_utility.c
mw_utility.h

index 83894dff501ddb562ba5aa260130253c51cc1839..7a11d8642a3da5ddeb4c9000a84372f31d80684c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ PREFIX = /usr/local/
 CFLAGS = -Wall -g -DDEBUG -O2 $(CCFLAGS) `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags libsoup-2.4`
 #CFLAGS = -Wall -O2 $(CCFLAGS)
 
 CFLAGS = -Wall -g -DDEBUG -O2 $(CCFLAGS) `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags libsoup-2.4`
 #CFLAGS = -Wall -O2 $(CCFLAGS)
 
-LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1` `pkg-config --libs libxml-2.0` `pkg-config --libs libsoup-2.4`
+LDFLAGS = -lm `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1` `pkg-config --libs libxml-2.0` `pkg-config --libs libsoup-2.4`
 
 PRGNAME = metawatch
 
 
 PRGNAME = metawatch
 
index eb98255d2d85ed836d7a58b0cdc9aa7388d7b663..af499c64d6a3fa3b5307b8aca91a16efbfec7c8d 100644 (file)
--- a/mw_main.c
+++ b/mw_main.c
@@ -461,7 +461,7 @@ void draw_app_ana_clock(mwdevice_t *mwdevice, int hour, int minute, unsigned cha
                x2 =  tmp;
                tmp = 48 + (48. * sin(((2. * M_PI) / 12.) * (double)i));
                y2 =  tmp;
                x2 =  tmp;
                tmp = 48 + (48. * sin(((2. * M_PI) / 12.) * (double)i));
                y2 =  tmp;
-               mw_buf_draw_line_bresenham(mwbuf, x, y, x2, y2, MW_WHITE);
+               mw_buf_draw_line_bresenham_w(mwbuf, x, y, x2, y2, 2, MW_WHITE);
        };
        // Hour
        g_print("hour = %d -> %f (%f)\n", hour, (double)hour + mf, mf);
        };
        // Hour
        g_print("hour = %d -> %f (%f)\n", hour, (double)hour + mf, mf);
@@ -469,13 +469,13 @@ void draw_app_ana_clock(mwdevice_t *mwdevice, int hour, int minute, unsigned cha
        x =  tmp;
        tmp = 48 + (30. * sin(((2. * M_PI) / 12.) * ((double)hour + mf)));
        y =  tmp;
        x =  tmp;
        tmp = 48 + (30. * sin(((2. * M_PI) / 12.) * ((double)hour + mf)));
        y =  tmp;
-       mw_buf_draw_line_bresenham(mwbuf, 48, 48, x, y, MW_WHITE);
+       mw_buf_draw_line_bresenham_w(mwbuf, 48, 48, x, y, 2, MW_WHITE);
        // Minute
        tmp = 48. + (40. * cos(((2. * M_PI) / 60.) * (double)minute));
        x =  tmp;
        tmp = 48 + (40. * sin(((2. * M_PI) / 60.) * (double)minute));
        y =  tmp;
        // Minute
        tmp = 48. + (40. * cos(((2. * M_PI) / 60.) * (double)minute));
        x =  tmp;
        tmp = 48 + (40. * sin(((2. * M_PI) / 60.) * (double)minute));
        y =  tmp;
-       mw_buf_draw_line_bresenham(mwbuf, 48, 48, x, y, MW_WHITE);
+       mw_buf_draw_line_bresenham_w(mwbuf, 48, 48, x, y, 2, MW_WHITE);
 
        snprintf(daystr, 5, "%d", day);
        mw_buf_print(mwbuf, 74, 45, daystr, 0, MW_WHITE, MW_BLACK);
 
        snprintf(daystr, 5, "%d", day);
        mw_buf_print(mwbuf, 74, 45, daystr, 0, MW_WHITE, MW_BLACK);
@@ -733,7 +733,7 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata)
        }
        if (strncmp(cmd, "dana", 4) == 0) {
                if (pcnt < 3)
        }
        if (strncmp(cmd, "dana", 4) == 0) {
                if (pcnt < 3)
-                       g_print("two few params, hour minute\n");
+                       g_print("two few params, hour minute, day of month\ndana h m d\n");
                else {
                        draw_app_ana_clock(&mwdata->mwdevice, atoi(params[0]), atoi(params[1]), atoi(params[2]));
                }
                else {
                        draw_app_ana_clock(&mwdata->mwdevice, atoi(params[0]), atoi(params[1]), atoi(params[2]));
                }
index 53c5f7ab3000e401e5d4f511d25eefe6453763f4..6d7ab8aac41ffde2eebd25e8310dec0136510654 100644 (file)
@@ -256,6 +256,61 @@ void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned
        }
 }
 
        }
 }
 
+void mw_buf_draw_line_bresenham_w(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, unsigned char thickness, mw_color clr)
+{
+       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;
+       mw_buf_draw_pixel(mwbuf, x, y, clr);
+       for (i=1; i<thickness; i++) {
+               mw_buf_draw_pixel(mwbuf, x-i, y, clr);
+               mw_buf_draw_pixel(mwbuf, x+i, y, clr);
+               mw_buf_draw_pixel(mwbuf, x, y-i, clr);
+               mw_buf_draw_pixel(mwbuf, x, y+i, clr);
+       }
+       for (t = 0; t < el; ++t) {
+               err -= es; 
+               if (err < 0) {
+                       err += el;
+                       x += ddx;
+                       y += ddy;
+               } else {
+                       x += pdx;
+                       y += pdy;
+               }
+               mw_buf_draw_pixel(mwbuf, x, y, clr);
+               for (i=1; i<thickness; i++) {
+                       mw_buf_draw_pixel(mwbuf, x-i, y, clr);
+                       mw_buf_draw_pixel(mwbuf, x+i, y, clr);
+                       mw_buf_draw_pixel(mwbuf, x, y-i, clr);
+                       mw_buf_draw_pixel(mwbuf, x, y+i, clr);
+               }
+       }
+}
 
 /* ----------------------------------------------------------------------
  * Complex combined functions, for user convenience
 
 /* ----------------------------------------------------------------------
  * Complex combined functions, for user convenience
index 7092818a86b0e8fd0ec1b53c4f684e0d5bf01b28..efd233289a70a04ae33a8399545f15c267f0a958 100644 (file)
@@ -53,6 +53,7 @@ void mw_buf_draw_pixel(mw_buffer *mwbuf, unsigned int x, unsigned int y, mw_colo
 void mw_buf_print(mw_buffer *mwbuf, unsigned int x, unsigned int y, char *text, unsigned char fsize, mw_color fgclr, mw_color bgclr);
 
 void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, mw_color clr);
 void mw_buf_print(mw_buffer *mwbuf, unsigned int x, unsigned int y, char *text, unsigned char fsize, mw_color fgclr, mw_color bgclr);
 
 void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, mw_color clr);
+void mw_buf_draw_line_bresenham_w(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, unsigned char thickness, mw_color clr);
 
 
 void mw_do_notification(mwdevice_t *mwdevice, char *title, char *text, unsigned char vibrate);
 
 
 void mw_do_notification(mwdevice_t *mwdevice, char *title, char *text, unsigned char vibrate);