X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=views%2Fday.c;h=3e75480724d2cd748c2bf65c434a3cf455b530c9;hb=aaf85fc92a6805319f8c7193aa0802935ce155b5;hp=672f855cf66eddb26764fda74bc1f47719985597;hpb=335d816efb8dd7c003e285a19e9434c4119ec13f;p=lackey diff --git a/views/day.c b/views/day.c index 672f855..3e75480 100644 --- a/views/day.c +++ b/views/day.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Andy Spencer + * Copyright (C) 2012-2013 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,7 +28,6 @@ /* Static data */ static int line; static WINDOW *win; -static WINDOW *head; static WINDOW *times; static WINDOW *body; @@ -92,34 +91,54 @@ static int get_col(event_t **list, int n, event_t *event, int *ncols) /* Day init */ void day_init(WINDOW *_win) { - win = _win; // lines cols y x - head = derwin(win, 1, COLS, 0, 0); - times = derwin(win, LINES-2-2, 5, 2, 0); - body = derwin(win, LINES-2-2, COLS-6, 2, 6); + win = _win; // lines cols y x + times = derwin(win, LINES-2, 5, 0, 0); + body = derwin(win, LINES-2, COLS-5, 0, 5); line = 10*4; // 10:00 } /* Day size */ void day_size(int rows, int cols) { - mvderwin(times, 2-COMPACT, 0); - mvderwin(body, 2-COMPACT, 6); - wresize(head, 1, cols); - wresize(times, rows-2-COMPACT, 5); - wresize(body, rows-2-COMPACT, cols-6); + int hdr = 2-COMPACT; + wmvresize(times, hdr, 0, rows-hdr, 5); + wmvresize(body, hdr, 5, rows-hdr, cols-5); } /* Day draw */ void day_draw(void) { - const char *mstr = month_to_string(MONTH); - const char *dstr = day_to_string(day_of_week(YEAR, MONTH, DAY)); + const char *mstr = month_to_string(SEL.month); + const char *dstr = day_to_string(day_of_week(SEL.year, SEL.month, SEL.day)); + + int y = !COMPACT+1; + event_t *event; + + /* Load cal data */ + cal_load(SEL.year, SEL.month, SEL.day, 1); /* Print Header */ - if (COMPACT) wattron(head, A_REVERSE | A_BOLD); - mvwprintw(head, 0, 0, "%s, %s %-*d", dstr, mstr, COLS, DAY+1); - mvwprintw(head, 0, COLS-10, "%d-%02d-%02d", YEAR, MONTH, DAY+1); - if (COMPACT) wattroff(head, A_REVERSE | A_BOLD); + if (COMPACT) wattron(win, A_REVERSE | A_BOLD); + mvwhline(win, 0, 0, ' ', COLS); + mvwprintw(win, 0, 0, "%s, %s %d", dstr, mstr, SEL.day+1); + mvwprintw(win, 0, COLS-10, "%d-%02d-%02d", SEL.year, SEL.month+1, SEL.day+1); + if (COMPACT) wattroff(win, A_REVERSE | A_BOLD); + + /* Print all day events */ + event = EVENTS; + int allday = 0; + while (event && before(&event->start, SEL.year, SEL.month, SEL.day, 24, 0)) { + if (!before(&event->end, SEL.year, SEL.month, SEL.day, 0, 1) && + get_mins(&event->start, &event->end) > 23*60) + event_line(win, event, y+allday++, 6, COLS, SHOW_DETAILS); + event = event->next; + } + if (allday && !COMPACT) + allday++; + + /* Resize body */ + wshrink(times, y+allday); + wshrink(body, y+allday); /* Print times */ mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60); @@ -127,17 +146,18 @@ void day_draw(void) mvwprintw(times, h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0); /* Print events */ - event_t *event = EVENTS; + event = EVENTS; event_t *active[10] = {}; int ncols = 0; for (int h = 0; h < 24; h++) for (int m = 0; m < 60; m+=15) while (event && before(&event->start, - YEAR, MONTH, DAY, h+(m+15)/60, (m+15)%60)) { - if (!before(&event->start, YEAR, MONTH, DAY, h, m)) { + SEL.year, SEL.month, SEL.day, h+(m+15)/60, (m+15)%60)) { + if (!before(&event->start, SEL.year, SEL.month, SEL.day, h, m) && + get_mins(&event->start, &event->end) <= 23*60) { int col = get_col(active, N_ELEMENTS(active), event, &ncols); - int left = ROUND((col+0.0)*(COLS-6)/ncols); - int right = ROUND((col+1.0)*(COLS-6)/ncols); + int left = ROUND((col+0.0)*(COLS-6)/ncols) + 1; + int right = ROUND((col+1.0)*(COLS-6)/ncols) + 1; int row = h*4 + m/15 - line; int height = (get_mins(&event->start, &event->end)-1)/15+1; event_box(body, event, row, left, height, right-left); @@ -148,7 +168,9 @@ void day_draw(void) /* Print lines */ if (!COMPACT) mvwhline(win, 1, 0, ACS_HLINE, COLS); - mvwvline(win, 2-COMPACT, 5, ACS_VLINE, LINES-4+COMPACT+COMPACT); + if (!COMPACT && allday) + mvwhline(win, allday+1, 0, ACS_HLINE, COLS); + mvwvline(body, 0, 0, ACS_VLINE, LINES-4+COMPACT+COMPACT); } /* Day run */ @@ -166,7 +188,7 @@ int day_run(int key, mmask_t btn, int row, int col) } line = CLAMP(line, 0, 24*4); if (days) - add_days(&YEAR, &MONTH, &DAY, days); + add_days(&SEL.year, &SEL.month, &SEL.day, days); if (ref) { werase(win); day_draw();