PDA

View Full Version : customizable calendar


Heinz
11-24-2006, 08:45 AM
Hi,

below you find a unit with a few calendar related commands, that might come in handy. The graphical stuff is designed for the game api, The other commands work with whatever API you like.
If you want to show a calendar in the game api, you have to add the following include:

#include "calendar.ppl"

if you start with the GameApi Skeleton (Users->PPL->GameApi->GameApi Skeleton), simple add the ShowCalendarline line like in the example below and you will have a nice calendar in your form :)

func GameProc(hWnd$, Msg$, wParam$, lParam$)
case (Msg$)
WM_PAINT:
g_clear(0);
ShowCalendar(20, 11, 2006, 20, 80, 220, 180, g_rgb(255, 255, 0), g_rgb(100, 255, 0), g_rgb(255, 0, 0));
RenderSprites;

WM_TIMER:
if (g_key.vkA$)
PostMessage(hWnd$, WM_CLOSE, 0, 0);
end;
end;
return (true);
end;

These commands are available in the calendar.ppl:

ShowCalendar(day$, month$, year$, xmin$, ymin$, xmax$, ymax$, gridcolor$, daycolor$, sundaycolor$)

Well, as the name already suggests, this command shows the calendar for the date which you determine with the variables day$, month$ and year$. The day$ is at the moment not yet used, but since it might for some applications be usefull to have it there (for example highlighting of the current day), I wanted to have it there to guarantee compatibility ;)
(xmin$,ymin$) are the coordinates of the upper left corner of the calendar and (xmax$,ymax$) are the coordinates of the lower right corner.
With gridcolor$ you determine the color of the grid, daycolor$ determines the color of the normal week days and sundaycolor$ determines the color of the sundays. Sorry that this function has so many parameters, but I thought it would be still more convenient then to change it always in the calendar.ppl whenever you need different colors, size or position. Kornalius, is there a way to set default parameters in PPL-functions, so that the user doesn't have to specify the colors for example?

monthlength(month$, year$)

This command simply shows you the length of a month (for example: February 2001: 28 days, February 2004: 29 days, February 1900: 28 days, February 2000: 29 days,...)

DayOfWeek(day$, month$, year$)

This command gives you for a certain date the day of the week as an integer number:
1 : Monday, 2 : Tuesday, ... , 7: Sunday


DayOfWeekName(day$, month$, year$)

If you don't need the Day of the week for your calculations, it is more convenient to get directly the name of the day ("Monday", "Tuesday",...). That is what this command is doing.

Well, I hope it is usefull and if you have any problems with the code or questions on how to use it, just let me know :)

Heinz
11-24-2006, 08:50 AM
This time with the proper version:

[br]1164358204_114_FT1928_calendar.zip

kornalius
11-24-2006, 02:28 PM
Thank you very much, it is greatly appreciated.

Solonn
11-25-2006, 10:05 AM
Good work!

matteo.m
11-25-2006, 10:06 AM
Nice Job i do like it :) thank you