// XOR
//
// CSCI 1300
// Wednesday, October 12, 2005
//
// Karl Winklmann

#include <winbgim.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>

#include "Button.h"

using namespace std;

const int WINDOW_SIZE = 512;

int main ()
{
    char inputChar = ' ';

    // setting up graphics window
    initwindow (
        WINDOW_SIZE, 
        WINDOW_SIZE, 
        "Bouncing balls and sliderbars, illustrating classes and objects"
    );

    int activepage = 0;
    setvisualpage (1 - activepage); // don't show initial drawing

    setbkcolor (LIGHTCYAN);
    cleardevice ();

    Button button (
        200, 50,      // location of button
        80,           // width of images
        80,           // height of images
        string ("appleUp.GIF"),  // four image file names
        string ("appleDown.GIF"),
        string ("appleUpWithWorm.GIF"),
        string ("appleDownWithWorm.GIF")
    );

    // main loop
    do
    {
        if (kbhit ())
            inputChar = getch ();

        if (ismouseclick (WM_LBUTTONDOWN))
        {
            button.mouseDown (mousex (), mousey ());
            clearmouseclick (WM_LBUTTONDOWN);
        }

        if (ismouseclick (WM_LBUTTONUP))
        {
            button.mouseUp (mousex (), mousey ());
            clearmouseclick (WM_LBUTTONUP);
        }

        if (ismouseclick (WM_MOUSEMOVE))
        {
            button.mouseMove (mousex (), mousey ());
            clearmouseclick (WM_MOUSEMOVE);
        }

        // re-draw whole window
        activepage = 1 - activepage;
        setactivepage (activepage);

        cleardevice ();

        button.draw ();

        setvisualpage (activepage);

        // slow things down a bit
        delay (10);
    } 
    while (inputChar != 'x' && inputChar != 'q');

    return EXIT_SUCCESS;
}
