]> Pileus Git - lackey/commitdiff
Add year view
authorAndy Spencer <andy753421@gmail.com>
Thu, 4 Oct 2012 08:51:50 +0000 (08:51 +0000)
committerAndy Spencer <andy753421@gmail.com>
Thu, 4 Oct 2012 08:51:50 +0000 (08:51 +0000)
src/screen.c
src/view/year.c

index b02d068ab71c28ce1356c3c0d41cf184b18fd469..1fdedc8680402e89910f88bab08f1a32e2e6185a 100644 (file)
@@ -27,7 +27,7 @@ view_t views[] = {
        { "Help",     help_init,     help_draw,     help_run,     {KEY_F(8), '8', 'h', '?'} },
 };
 
-int active = 2;
+int active = 3;
 
 /* Local functions */
 void draw_header(void)
index 7e3e51a0149e685dcefe5e36d260af4123b8b0a3..dd9494d076fbc12fa2081e87b285e98976400bdc 100644 (file)
@@ -1,8 +1,37 @@
+#include <string.h>
 #include <ncurses.h>
 
+#include "util.h"
+
+/* Macros */
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#define MW (2*7+6)
+
 /* Static data */
 static WINDOW *win;
 
+/* Test data */
+const static int YEAR  = 2012;
+const static int MONTH = SEP;
+const static int DAY   = 29;
+
+/* Helper functions */
+static void print_month(month_t month, int y, int x)
+{
+       const char *name  = month_to_string(month);
+       const int   start = start_of_month(YEAR, month);
+       const char  days  = days_in_month(YEAR, month);
+       mvwprintw(win, y, x+MW/2-strlen(name)/2, "%s", name);
+       wmove(win, y+1, x);
+       for (int d = 0; d < 7; d++)
+               wprintw(win, "%-3s", day_to_st(d));
+       for (int d = 0; d < days; d++) {
+               int row = (start + d) / 7;
+               int col = (start + d) % 7;
+               mvwprintw(win, y+2+row, x+col*3, "%d", d+1);
+       }
+}
+
 /* Year init */
 void year_init(WINDOW *_win)
 {
@@ -12,8 +41,43 @@ void year_init(WINDOW *_win)
 /* Year draw */
 void year_draw(void)
 {
-       mvwprintw(win, 0, 1, "%s\n", "year");
-       wrefresh(win);
+       int w = MW*3 + 2*3;
+       int x = COLS/2 - w/2;
+       int y = 0;
+       int h[4] = {};
+
+       /* Determine heights */
+       for (int m = 0; m < 12; m++) {
+               int weeks = weeks_in_month(YEAR, m);
+               h[m/3] = MAX(h[m/3], weeks+2);
+       }
+       int sum = h[0]+h[1]+h[2]+h[3];
+
+       /* Print Header */
+       mvwprintw(win, y++, COLS/2-2, "%d", YEAR);
+
+       /* Print Months */
+       for (int m = 0; m < 12; m++) {
+               print_month(m, y, x);
+               if (m % 3 == 2) {
+                       x  = COLS/2 - w/2;
+                       y += h[m/3]+1;
+               } else {
+                       x += 3+MW;
+               }
+       }
+
+       /* Print Lines */
+       y = 1;
+       mvwvline(win, y, x+(MW+3)*1-2, ACS_VLINE, sum+3);
+       mvwvline(win, y, x+(MW+3)*2-2, ACS_VLINE, sum+3);
+       for (int i = 0; i < 3; i++) {
+               y += h[i];
+               mvwhline(win, y, x,        ACS_HLINE, w);
+               mvwaddch(win, y, x+(MW+3)*1-2, ACS_PLUS);
+               mvwaddch(win, y, x+(MW+3)*2-2, ACS_PLUS);
+               y++;
+       }
 }
 
 /* Year run */