From 328bd5c03655ddda1b43aadc72b1753d69048d74 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 14 Oct 2012 06:08:50 +0000 Subject: [PATCH] Add month view --- src/date.c | 12 +++++++++++- src/date.h | 1 + src/screen.c | 2 +- view/month.c | 34 ++++++++++++++++++++++++++++++++++ view/week.c | 13 ------------- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/date.c b/src/date.c index 2e1f7f8..f55ae34 100644 --- a/src/date.c +++ b/src/date.c @@ -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) { diff --git a/src/date.h b/src/date.h index 673b3b3..df5f250 100644 --- a/src/date.h +++ b/src/date.h @@ -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); diff --git a/src/screen.c b/src/screen.c index 6fbda20..1a7dd4b 100644 --- a/src/screen.c +++ b/src/screen.c @@ -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) diff --git a/view/month.c b/view/month.c index 3849492..4e8b237 100644 --- a/view/month.c +++ b/view/month.c @@ -22,10 +22,27 @@ #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); diff --git a/view/week.c b/view/week.c index 2b005d8..94adfe5 100644 --- a/view/week.c +++ b/view/week.c @@ -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) { -- 2.43.2