// Copyright (c) Sean Walton 1999-2006 All rights reserved // // Standard disclaimer: you use it --> you're responsible // Standard license: you can use it in any way, but keep // my copyright attached. #include "BBCalendar.h" #define ROWS 7 #define COLUMNS 7 /////////////////////////////////////////////////////////////////////////////////////// /// BBCalendar BBCalendar::BBCalendar(void) : BBGrid(ROWS, COLUMNS) { RimGetDateTime(&time); SetSelected(2, time.day); // SetSelected(time.day+(COLUMNS*2)); } void BBCalendar::SetDate(TIME& t) { time = t; Redraw(); } void BBCalendar::NowDisplaying(ubyte row, ubyte col, Graphics& area) { static const char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; static const char *months[] = {"January", "February", "March", "April", "June", "July", "August", "September", "October", "November", "December"}; if ( row == 0 ) { if ( col == 0 ) { char temps[15]; RimSprintf(temps, sizeof(temps), "%s %d", months[time.month-1], time.year); area.DrawString(DISPLAYWIDTH, 0, temps, strlen(temps), GetFont(), LCD_RIGHT_JUSTIFIED); } } else if ( row == 1 ) area.DrawString(0, 0, days[col], strlen(days[col]), GetFont(), 0); else if ( AllowSelect(row, col) ) { char temps[3]; int date=(row-2)*COLUMNS + col - (time.date-time.day+2)%7; RimSprintf(temps, sizeof(temps), "%d", date); area.DrawString(2, 0, temps, strlen(temps), GetFont(), 0); if ( date == time.date ) area.DrawRect(0, 0, GetColumnWidth(col), QueryLineHeight(0)); } } bool BBCalendar::AllowSelect(ubyte row, ubyte col) { static const ubyte month_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; ubyte month_day = month_days[time.month-1]; if ( time.month == 2 && time.year % 4 == 0 && time.year != 2000 ) // February and leapyear?? month_day = 29; int date=(row-2)*COLUMNS + col - (time.date-time.day+2)%7; return ( row > 1 && date >= 1 && date <= month_day ); }