// Author: Drunkie
// Description: Draws a table; useful for calendars or spreadsheets!

Main();

#include <drivers\drv_gl.txt>

float rows = 6;
float cols = 5;
float sizex = 476;
float sizey = 400;
float linewidth = 3;

float i, j, day;

void Main()
{
    dentrypoint 0,DrawThread;
    dentrypoint 4,AsyncThread;

    *regHWClear = 0
    *regAsyncFreq = 200000;
    *regAsyncClk = 1;
}

void DrawThread()
{
    dexit;
}

void AsyncThread()
{
    glBegin();

        glClear( 35, 35, 35 ); // Clear screen color

        glColor( 255, 255, 255 ); // Set draw color
        glFont( GL_FONT_ARIAL ); // Set font type
        glFontSize( 36 ); // Set font size
        glWriteString( 16, 6, 'Simple-Calendar 1.0');

        glColor( 120, 120, 120 );
        glOffset( 16, 64 ); // Set screen offset
        glRectWH( 0, 0, sizex + linewidth, sizey + linewidth); // Draw rectangle

        glFont( GL_FONT_TREBUCHET );
        glFontSize( 14 );

        // Calculate rectangle size
        float sx = (sizex / rows) - linewidth;
        float sy = (sizey / cols) - linewidth;

        // Loop through rows
        for (i = 0; i < rows; i++)
        {
            // Loop through columns
            for (j = 0; j < cols; j++)
            {
                // Calculate x,y coordinate to draw at
                float x = i * (sizex / rows);
                float y = j * (sizey / cols);

                glColor( 200, 200, 200 ); // Set draw color
                glRectWH( x + linewidth, y + linewidth, sx, sy ); // Draw rectangle

                glColor( 0, 0, 0 ); // Set draw color

                // Write integer to screen
                day = i + (j * rows)
                glWriteInt( x + linewidth + 2, y + linewidth + 2, day + 1 );
            }
        }

    glEnd();
}
