]> Pileus Git - lackey/commitdiff
Move drawing code to screen.c, work on day view
authorAndy Spencer <andy753421@gmail.com>
Sun, 14 Oct 2012 21:02:18 +0000 (21:02 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 14 Oct 2012 21:02:18 +0000 (21:02 +0000)
doc/screen.txt
src/date.c
src/screen.c
src/screen.h
src/util.c
src/util.h
view/day.c
view/month.c
view/week.c
view/year.c

index 293f2d00fdf85a7c30abe712415519cd3a87280a..4fc812ac89d65d180f025a6279b9382cf347d513 100644 (file)
@@ -1,6 +1,6 @@
 Day view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │ 2012-09-27                                    Saturday September 27 │
    │ ─────────────────────────────────────────────────────────────────── │
@@ -34,7 +34,7 @@ Day view
 
 Week view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │         09/24       09/25       09/26       09/27       09/28       │
    │         Monday      Tuesday     Wednesday   Thursday    Friday      │
@@ -65,7 +65,7 @@ Week view
 
 Month view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │                          September  2012                            │
    │ Sun      Mon       Tue       Wed       Thu       Fri       Sat      │
@@ -98,7 +98,7 @@ Month view
 
 Year view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │                                2012                                 │
    │        January       │       February       │         March         │
@@ -137,9 +137,9 @@ Year view
    │                                                                     │
    └─────────────────────────────────────────────────────────────────────┘
 
-Notes view
+Events view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │                                                                     │
    │ 2012-09-24                                                          │
@@ -166,9 +166,9 @@ Notes view
    └─────────────────────────────────────────────────────────────────────┘
 
 
-Notes view
+Todo view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │                                                                     │
    │ ???                                                                 │
@@ -181,7 +181,7 @@ Notes view
 
 Settings view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │                                                                     │
    │ ???                                                                 │
@@ -195,7 +195,7 @@ Settings view
 
 Help view
    ┌─────────────────────────────────────────────────────────────────────┐
-   │ Day  Week  Month  Year │ Todo  Notes │ Settings  Help               │
+   │ Day  Week  Month  Year │ Events Todo │ Settings  Help               │
    │ ─────────────────────────────────────────────────────────────────── │
    │                                                                     │
    │ ???                                                                 │
index f55ae3468b34722fb364e00ec7c7fd19d4f63d0c..9503b4c2a37e49e3fe211b4d4cddd0a0debeb1cd 100644 (file)
@@ -38,9 +38,9 @@ void date_init(void)
        DAY   = tm->tm_mday-1;
 
        /* Testing */
-       //YEAR  = 2009;
-       //MONTH = MAY;
-       //DAY   = 1;
+       //YEAR  = 2008;
+       //MONTH = OCT;
+       //DAY   = 21;
 }
 
 /* Time functions */
index 1a7dd4be865f417c720011227a2f007256bfeffa..0cbbd887d00d5f371b4f91c86525454ef325a475 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define _XOPEN_SOURCE_EXTENDED
+
 #include <string.h>
 #include <ncurses.h>
 
 #include "util.h"
 #include "date.h"
+#include "event.h"
 #include "screen.h"
 
 /* Types */
@@ -47,7 +50,7 @@ view_t views[] = {
        { "Help",     help_init,     help_size,     help_draw,     help_run,     {KEY_F(8), '8', '?'} },
 };
 
-int active = 2;
+int active = 0;
 
 /* Local functions */
 void draw_header(void)
@@ -66,6 +69,51 @@ void draw_header(void)
        refresh();
 }
 
+/* Helper functions */
+void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w)
+{
+       int l = 0;
+       int s = y < 0 ? -y-1 : 0;
+
+       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));
+
+       if (h >= 2) mvwhline_set(win, y,     x+1,   WACS_T_HLINE, w-2);
+       if (h <= 1) mvwadd_wch(win,   y,     x,     WACS_BULLET);
+       if (h >= 2) mvwadd_wch(win,   y,     x,     WACS_T_ULCORNER);
+       if (h >= 2) mvwadd_wch(win,   y,     x+w-1, WACS_T_URCORNER);
+       if (h >= 3) mvwvline_set(win, y+1+s, x,     WACS_T_VLINE, h-2-s);
+       if (h >= 3) mvwvline_set(win, y+1+s, x+w-1, WACS_T_VLINE, h-2-s);
+       if (h >= 2) mvwadd_wch(win,   y+h-1, x,     WACS_T_LLCORNER);
+       if (h >= 2) mvwadd_wch(win,   y+h-1, x+w-1, WACS_T_LRCORNER);
+       if (h >= 2) mvwhline_set(win, y+h-1, x+1,   WACS_T_HLINE, w-2);
+
+       if (color) wattroff(win, COLOR_PAIR(color));
+
+       if (l<h && event->name) mvwprintw(win, y+l++, x+1, "%.*s",     w-2,      event->name);
+       if (l<h && event->loc)  mvwprintw(win, y+l++, x+1, "@ %-*.*s", w-4, w-4, event->loc);
+       if (l<h && event->desc) mvwprintw(win, y+l++, x+1, "%-*.*s",   w-2, w-2, event->desc);
+}
+
+void event_line(WINDOW *win, 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);
+}
+
+
 /* Screen init */
 void screen_init(void)
 {
index 46cdf94156448a73697e728a5f36b55e2404422b..cf83b6e68dabcef7f8dd97c91fc1ed856b0cdcef 100644 (file)
 #define COLOR_WORK  5
 #define COLOR_OTHER 6
 
+/* Helper functions */
+void event_box(WINDOW *win, event_t *event, int y, int x, int h, int w);
+void event_line(WINDOW *win, event_t *event, int y, int x, int w);
+
 /* Screen functions */
 void screen_init(void);
 void screen_resize(void);
index f13ad443c5f560418e5a30f4e27d4ad09abcebea..86bc3730701a21d2f5d1d4abc96a6929db769325 100644 (file)
@@ -21,6 +21,8 @@
 #include <string.h>
 #include <ncurses.h>
 
+#include "date.h"
+#include "event.h"
 #include "screen.h"
 
 /* Static data */
@@ -32,17 +34,6 @@ void util_init(void)
        debug_fd = fopen("/tmp/lackey.log", "w+");
 }
 
-/* Misc functions */
-char *sdup(const char *str)
-{
-       if (str == NULL)
-               return NULL;
-       int len = strlen(str);
-       char *dup = malloc(len+1);
-       memcpy(dup, str, len+1);
-       return dup;
-}
-
 /* Debugging functions */
 int debug(char *fmt, ...)
 {
index 25e6d8d753d8169621e36a4a806cf7c4b47ea8d1..b40f8b3e5a47cabeb5d4058fef40b9788d3119be 100644 (file)
@@ -25,9 +25,6 @@
 /* Debug functions */
 void util_init(void);
 
-/* Misc functions */
-char *sdup(const char *str);
-
 /* Debug functions */
 #ifdef DEBUG
 int debug(char *fmt, ...);
index 37f9e2f4b6d7d289f6144dec9ad2578e5bb922ea..027474b809c3657df54f153d13c7c852f28635c7 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define _XOPEN_SOURCE_EXTENDED
+
+#include <string.h>
 #include <ncurses.h>
 
+#include "util.h"
 #include "date.h"
+#include "event.h"
+#include "screen.h"
 
 /* Static data */
+static int     line;
 static WINDOW *win;
+static WINDOW *head;
+static WINDOW *times;
+static WINDOW *body;
 
 /* Day init */
 void day_init(WINDOW *_win)
 {
-       win = _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);
+       line  = 10*4; // 10:00
 }
 
 /* Day size */
 void day_size(int rows, int cols)
 {
+       wresize(head,       1, cols  );
+       wresize(times, rows-2,      5);
+       wresize(body,  rows-2, cols-6);
 }
 
 /* Day draw */
@@ -39,34 +56,54 @@ void day_draw(void)
        const char *mstr = month_to_string(MONTH);
        const char *dstr = day_to_string(day_of_week(YEAR, MONTH, DAY));
 
-       /* Clear */
-       werase(win);
-
        /* Print Header */
-       mvwprintw(win, 0, 0, "%s, %s %d", dstr, mstr, DAY+1);
-       mvwprintw(win, 0, COLS-10, "%d-%02d-%02d", YEAR, MONTH, DAY+1);
-       mvwhline(win, 1, 0, ACS_HLINE, COLS);
+       mvwprintw(head, 0, 0, "%s, %s %d", dstr, mstr, DAY+1);
+       mvwprintw(head, 0, COLS-10, "%d-%02d-%02d", YEAR, MONTH, DAY+1);
 
        /* Print times */
-       int start = 8;
-       for (int h = 0; h < (LINES-5)/4+1; h++)
-               mvwprintw(win, 2+h*4, 0,"%02d:%02d", (start+h)%12, 0);
+       mvwprintw(times, 0, 0, "%02d:%02d", ((line/4)-1)%12+1, (line*15)%60);
+       for (int h = 0; h < 24; h++)
+               mvwprintw(times, h*4-line, 0, "%02d:%02d", (h-1)%12+1, 0);
+
+       /* Print events */
+       event_t *event = EVENTS;
+       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)) {
+                       int y = h*4 + m/15 - line;
+                       int x = 0;
+                       int h = (get_mins(&event->start, &event->end)-1)/15+1;
+                       int w = COLS-6;
+                       event_box(body, event, y, x, h, w);
+               }
+               event = event->next;
+       }
+
+       /* Print lines */
+       mvwhline(win, 1, 0, ACS_HLINE, COLS);
        mvwvline(win, 2, 5, ACS_VLINE, LINES-4);
 }
 
 /* Day run */
 int day_run(int key, mmask_t btn, int row, int col)
 {
-       int days = 0;
+       int days = 0, ref = 0;
        switch (key)
        {
-               case 'h': days = -1; break;
-               case 'l': days =  1; break;
-               case 'i': days = -7; break;
-               case 'o': days =  7; break;
+               case 'h': ref = 1; days = -1; break;
+               case 'l': ref = 1; days =  1; break;
+               case 'i': ref = 1; days = -7; break;
+               case 'o': ref = 1; days =  7; break;
+               case 'k': ref = 1; line--;    break;
+               case 'j': ref = 1; line++;    break;
        }
-       if (days) {
+       line = CLAMP(line, 0, 24*4);
+       if (days)
                add_days(&YEAR, &MONTH, &DAY, days);
+       if (ref) {
+               werase(win);
                day_draw();
                wrefresh(win);
        }
index b8e3eb189a539c4a49fb53337a0292152caad64e..2179f4f2c178f9e611d6a696375eb7311eb70ea5 100644 (file)
 /* 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)
 {
@@ -65,9 +50,6 @@ void month_draw(void)
        const float hstep = (float)(COLS-1)/7.0;
        const float vstep = (float)(LINES-6)/weeks;
 
-       /* Clear */
-       werase(win);
-
        /* Print Header */
        mvwprintw(win, 0, midpt, "%s %d", name, YEAR);
        for (int d = 0; d < 7; d++) {
@@ -95,7 +77,7 @@ void month_draw(void)
                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);
+                               if (y <= e) event_line(win, event, y, x, w);
                                y++;
                        }
                        event = event->next;
@@ -150,6 +132,7 @@ int month_run(int key, mmask_t btn, int row, int col)
        if (days || months) {
                add_days(&YEAR, &MONTH, &DAY, days);
                add_months(&YEAR, &MONTH, months);
+               werase(win);
                month_draw();
                wrefresh(win);
        }
index 98d12f371391b936beaa590f2f5bb28825db7e5b..e9d7c04505435d53736b2a5487bbc78c1bde3eb7 100644 (file)
@@ -32,42 +32,6 @@ static WINDOW *head;
 static WINDOW *times;
 static WINDOW *body;
 
-/* Local functions */
-static void print_event(event_t *event, wday_t day, hour_t hour, min_t min, float hstep)
-{
-       int x = ROUND(day*hstep);
-       int y = hour*4 + min/15 - line;
-       int w = ROUND((day+1)*hstep) - 1 - x;
-       int h = (get_mins(&event->start, &event->end)-1)/15+1;
-       int l = 0;
-       int s = y < 0 ? -y-1 : 0;
-
-       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(body, COLOR_PAIR(color));
-
-       if (h >= 2) mvwhline_set(body, y,     x+1,   WACS_T_HLINE, w-2);
-       if (h <= 1) mvwadd_wch(body,   y,     x,     WACS_BULLET);
-       if (h >= 2) mvwadd_wch(body,   y,     x,     WACS_T_ULCORNER);
-       if (h >= 2) mvwadd_wch(body,   y,     x+w-1, WACS_T_URCORNER);
-       if (h >= 3) mvwvline_set(body, y+1+s, x,     WACS_T_VLINE, h-2-s);
-       if (h >= 3) mvwvline_set(body, y+1+s, x+w-1, WACS_T_VLINE, h-2-s);
-       if (h >= 2) mvwadd_wch(body,   y+h-1, x,     WACS_T_LLCORNER);
-       if (h >= 2) mvwadd_wch(body,   y+h-1, x+w-1, WACS_T_LRCORNER);
-       if (h >= 2) mvwhline_set(body, y+h-1, x+1,   WACS_T_HLINE, w-2);
-
-       if (color) wattroff(body, COLOR_PAIR(color));
-
-       if (l<h && event->name) mvwprintw(body, y+l++, x+1, "%.*s",     w-2,      event->name);
-       if (l<h && event->loc)  mvwprintw(body, y+l++, x+1, "@ %-*.*s", w-4, w-4, event->loc);
-       if (l<h && event->desc) mvwprintw(body, y+l++, x+1, "%-*.*s",   w-2, w-2, event->desc);
-
-       debug("week: event = %s\n", event->name);
-}
-
 /* Week init */
 void week_init(WINDOW *_win)
 {
@@ -93,9 +57,6 @@ void week_draw(void)
        int y = 3;
        const float hstep = (float)(COLS-x)/7.0;
 
-       /* Clear */
-       werase(win);
-
        /* Get start of week */
        year_t  year  = YEAR;
        month_t month = MONTH;
@@ -128,8 +89,13 @@ void week_draw(void)
        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))
-                       print_event(event, d, h, m, hstep);
+               if (!before(&event->start, year, month, day, h, m)) {
+                       int y = h*4 + m/15 - line;
+                       int x = ROUND(d*hstep);
+                       int h = (get_mins(&event->start, &event->end)-1)/15+1;
+                       int w = ROUND((d+1)*hstep) - 1 - x;
+                       event_box(body, event, y, x, h, w);
+               }
                event = event->next;
        }
 
@@ -138,12 +104,17 @@ void week_draw(void)
        for (int d = 0; d < 7; d++)
                mvwvline(win, y, x+ROUND(d*hstep)-1, ACS_VLINE, LINES-y-2);
 
+
        /* Draw today */
        int l = x+ROUND((shift+0)*hstep)-1;
        int r = x+ROUND((shift+1)*hstep)-1;
        mvwhline    (win, y-1, l, ACS_BLOCK, r-l+1);
        mvwvline_set(win, y,   l, WACS_T_VLINE, LINES-y-2);
        mvwvline_set(win, y,   r, WACS_T_VLINE, LINES-y-2);
+       for (int h = (line+3)/4; h < 24; h++) {
+               mvwadd_wch(win, y+h*4-line, l, WACS_T_LTEE);
+               mvwadd_wch(win, y+h*4-line, r, WACS_T_RTEE);
+       }
 }
 
 /* Week run */
@@ -163,6 +134,7 @@ int week_run(int key, mmask_t btn, int row, int col)
        if (days)
                add_days(&YEAR, &MONTH, &DAY, days);
        if (ref) {
+               werase(win);
                week_draw();
                wrefresh(win);
        }
index 17a5c92d539d44012af23a5bba4e3679d7882130..086c0e8e2f4efb6a47082a542711c852239e7763 100644 (file)
@@ -81,9 +81,6 @@ void year_draw(void)
        int y = 0;
        int h[4] = {};
 
-       /* Clear */
-       werase(win);
-
        /* Determine heights */
        for (int m = 0; m < 12; m++) {
                int weeks = weeks_in_month(YEAR, m);
@@ -167,6 +164,7 @@ int year_run(int key, mmask_t btn, int row, int col)
        }
 
        /* Refresh */
+       werase(win);
        year_draw();
        wrefresh(win);
        return 0;