MONTH = tm->tm_mon;
DAY = tm->tm_mday-1;
- // Testing */
+ /* Testing */
//YEAR = 2009;
//MONTH = MAY;
//DAY = 1;
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)
{
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);
{ "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)
#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)
{
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);
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)
{