]> Pileus Git - lackey/commitdiff
Add month view
authorAndy Spencer <andy753421@gmail.com>
Sun, 14 Oct 2012 06:08:50 +0000 (06:08 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 14 Oct 2012 06:08:50 +0000 (06:08 +0000)
src/date.c
src/date.h
src/screen.c
view/month.c
view/week.c

index 2e1f7f8af1bd0a2666896454acba64e0a0732e9d..f55ae3468b34722fb364e00ec7c7fd19d4f63d0c 100644 (file)
@@ -37,7 +37,7 @@ void date_init(void)
        MONTH = tm->tm_mon;
        DAY   = tm->tm_mday-1;
 
-       // Testing */
+       /* Testing */
        //YEAR  = 2009;
        //MONTH = MAY;
        //DAY   = 1;
@@ -126,6 +126,16 @@ int get_mins(date_t *start, date_t *end)
        return (get_time(end)-get_time(start))/60;
 }
 
+int before(date_t *start, int year, int month, int day, int hour, int min)
+{
+       int rval = start->year  < year  ? 1 : start->year  > year ? 0 :
+                  start->month < month ? 1 : start->month > month? 0 :
+                  start->day   < day   ? 1 : start->day   > day  ? 0 :
+                  start->hour  < hour  ? 1 : start->hour  > hour ? 0 :
+                  start->min   < min   ? 1 : start->min   > min  ? 0 : 0;
+       return rval;
+}
+
 /* Debug functions */
 const char *month_to_str(month_t month)
 {
index 673b3b33ef43481a18835dbd15f2a86a2065b474..df5f250c0bb9b4ae6e1f509386a01523103210b8 100644 (file)
@@ -77,6 +77,7 @@ void add_months(year_t *year, month_t *month, int months);
 
 stamp_t get_stamp(date_t *date);
 int get_mins(date_t *start, date_t *end);
+int before(date_t *start, int year, int month, int day, int hour, int min);
 
 /* Time to string functions */
 const char *month_to_str(month_t month);
index 6fbda206291fc72d2c15d7d57130a76d1bb55cbe..1a7dd4be865f417c720011227a2f007256bfeffa 100644 (file)
@@ -47,7 +47,7 @@ view_t views[] = {
        { "Help",     help_init,     help_size,     help_draw,     help_run,     {KEY_F(8), '8', '?'} },
 };
 
-int active = 1;
+int active = 2;
 
 /* Local functions */
 void draw_header(void)
index 3849492e9205388159d3eeeeeb686eb1a281983a..4e8b237a9942f356be668d3feeecab7e35a1ee59 100644 (file)
 
 #include "util.h"
 #include "date.h"
+#include "event.h"
+#include "screen.h"
 
 /* Static data */
 static WINDOW *win;
 
+/* Local functions */
+static void print_event(event_t *event, int y, int x, int w)
+{
+       int color = event->cat == NULL           ? 0           :
+                   !strcmp(event->cat, "class") ? COLOR_CLASS :
+                   !strcmp(event->cat, "ec")    ? COLOR_EC    :
+                   !strcmp(event->cat, "work")  ? COLOR_WORK  : COLOR_OTHER ;
+
+       if (color) wattron(win, COLOR_PAIR(color));
+       mvwaddch(win, y, x+0, ACS_BLOCK);
+       if (color) wattroff(win, COLOR_PAIR(color));
+
+       mvwprintw(win, y, x+1, "%-*.*s", w-1, w-1, event->name);
+}
+
 /* Month init */
 void month_init(WINDOW *_win)
 {
@@ -68,6 +85,23 @@ void month_draw(void)
                if (d == DAY) wattroff(win, A_BOLD);
        }
 
+       /* Print events */
+       event_t *event = EVENTS;
+       for (int d = 0; d < days; d++) {
+               int y = ROUND(4+(((start + d) / 7)  )*vstep);
+               int e = ROUND(4+(((start + d) / 7)+1)*vstep)-2;
+               int x = ROUND(1+(((start + d) % 7)  )*hstep)+3;
+               int w = ROUND(1+(((start + d) % 7)+1)*hstep)-x-1;
+               while (event && before(&event->start, YEAR, MONTH, d, 24, 0)) {
+                       if (!before(&event->start, YEAR, MONTH, d, 0, 0)){
+                               if (y == e) mvwhline(win, y, x-3, ACS_DARROW, 2);
+                               if (y <= e) print_event(event, y, x, w);
+                               y++;
+                       }
+                       event = event->next;
+               }
+       }
+
        /* Print lines */
        for (int w = 1; w < weeks; w++)
                mvwhline(win, ROUND(3+w*vstep), 1, ACS_HLINE, COLS-2);
index 2b005d8731e573ba7ec0528010aef235a72e5c5c..94adfe573f64aa97f500364617c97c43191b4abb 100644 (file)
@@ -63,19 +63,6 @@ static void print_event(event_t *event, wday_t day, hour_t hour, min_t min, floa
        debug("week: event = %s\n", event->name);
 }
 
-static int before(date_t *start, int year, int month, int day, int hour, int min)
-{
-       int rval = start->year  < year  ? 1 : start->year  > year ? 0 :
-                  start->month < month ? 1 : start->month > month? 0 :
-                  start->day   < day   ? 1 : start->day   > day  ? 0 :
-                  start->hour  < hour  ? 1 : start->hour  > hour ? 0 :
-                  start->min   < min   ? 1 : start->min   > min  ? 0 : 0;
-       debug("week: %04d-%02d-%02d %02d:%02d < %04d-%02d-%02d %02d:%02d == %d\n",
-                       start->year, start->month, start->day, start->hour, start->min,
-                       year, month, day, hour, min, rval);
-       return rval;
-}
-
 /* Week init */
 void week_init(WINDOW *_win)
 {