#include <SDL/SDL.h>
#include "gfxMR.hpp"
#include "sdlMR.hpp"
#include "fturtleMR.hpp"

int main()
{
    SDL_Surface *screen;
    SDL_Event event;

    int keypress = 0;

    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(512, 384, 8, SDL_SWSURFACE);

    sdlPutPixel plot(screen);
    sdlGetPixel get(screen);
    ploter * pp = &plot;
    bresenhamCircle cercle(plot);
    bresenhamLine ligne(plot);
    floodFill paint(plot,get);

    sdlFPS fps(60);

    Uint8 *keystates = SDL_GetKeyState( NULL );

    while(!keypress)
    {
        fps();
        SDL_Flip(screen);
        SDL_FillRect(screen,0,0);

        plot(64,32,255);
        cercle(64,32,255,20);
        ligne(16,16,48,48,255);
        ligne(16,48,48,16,255);
        ligne(50,18,18,50,255);
        paint(65,33,112,0);

        while(SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_QUIT:
                    keypress = 1;
                    break;
                case SDL_KEYDOWN:
                    keypress = 1;
                    break;
            }
        }


//         if (keystates[SDLK_UP])
//         {
//             plot(10,10,255);
//         }


        fturtle un(200,200,plot);
        ftfwd deux(un,110);
        ftleft trois(deux, 1.618);
        ftfwd quatre(trois,70);
        ftpush cinq(quatre);
        ftleft six(cinq,3.1415);
        ftfwd sept(six, 200);
        ftpop huit(sept);
        ftright neuf(huit,1);
        ftfwd dix(neuf,50);
         dix();

        gcfturtle * gc = new gcfturtle();
        fturtle * turtle = new fturtle(255,255,plot);
        gc = gc->add(turtle);
        turtle = new ftcolor(turtle, 3);
        gc = gc->add(turtle);

        for (int i=0;i<40;i++)
        {
            turtle = new ftright(turtle, 0.2);
            gc = gc->add(turtle);
            turtle = new ftpush(turtle);
            gc = gc->add(turtle);
            turtle = new ftfwd(turtle, 100);
            gc = gc->add(turtle);
            turtle = new ftpop(turtle);
            gc = gc->add(turtle);
        }

        (*turtle)();

        delete gc;

    }



    SDL_Quit();

    return 0;
}
