This is what I got, but for some reason the last mouse inputs draws the line of the screen, I thing it has to do in the writting process but I can't figure it out.
//This program allows the user to click points on the window
//screen until the spacebar key is pressed. The program saves
//the mouses X and Y coordinates to an output file as the
//user clicks the mouse. When the user presses the spacebar, the
//output file is closed and reopened as an input file. The coordinates
//are read and lines are drawn from the users mouse clicks.
#include "DarkGDK.h"
//Declare Constants
const int FILE_NUM = 1;
const int REFRESH_RATE = 60;
//Function Prototype
void setUp();
void openInputFile();
/***********************************************************
DarkGDK Function
***********************************************************/
void DarkGDK()
{
//Declare variable for mouses X and Y position.
int mouseX, mouseY;
//Variable to hold the starting X and Y coordinate
//of the first mouse click.
int xCoordinate, yCoordinate;
//Variables to hold the lines starting and ending
//points.
int startX, startY, endX, endY;
//Perform the set Up function
setUp();
while(LoopGDK() && !dbSpaceKey()) //Perform loop until the user pressed the Esc Key or the SpaceBar Key.
{
//If the left mouse button is fully clicked
//assign the X and Y coordinates values to mouseX
//and MouseY and write the coordinates in the output file.
if(dbMouseClick() == 1)
{
//Set the mouse pointer's coordiantes.
mouseX = dbMouseX();
mouseY = dbMouseY();
//Write the mouse pointer's X and Y coordinates to the output file.
dbWriteFile(FILE_NUM, mouseX);
dbWriteFile(FILE_NUM, mouseY);
}
//Refresh the Screen.
dbSync();
}
//Enable automatic sync rate.
dbSyncOff();
//Close The Output File.
dbCloseFile(FILE_NUM);
//Clear the screen.
dbCLS();
//Perform the openInputFile function to check for the
//input file and if exists open it.
openInputFile();
//If the End of the input file has not reached, set the
//mouse pointer's x and y coordinates from the input file.
if(!dbFileEnd(FILE_NUM))
{
//Set the mouse pointers X and Y coordinates from the input file
xCoordinate = dbReadFile(FILE_NUM);
yCoordinate = dbReadFile(FILE_NUM);
}
//If the end of the input file has not reached, set the starting X and Y
//coordinates of the line and draw the line connecting the users clicked points.
while(!dbFileEnd(FILE_NUM))
{
//Set the lines starting and ending line coordinates.
startX = xCoordinate;
startY = yCoordinate;
endX = dbReadFile(FILE_NUM);
endY = dbReadFile(FILE_NUM);
//For some reason the !dbFileEnd producing another statement, I think
//it has to do in the writting part of the coordinates.dat file.
//Because when used with the bool function, both points have 480 > results.
if(endX < 640)
{
//Draw the line based on users mouse clicks
dbLine(startX, startY, endX, endY);
//Set the next starting coordinates to the ending coordinates of
//the previous line drawn.
xCoordinate = endX;
yCoordinate = endY;
}
}
//Close the Input File.
dbCloseFile(FILE_NUM);
//Prompt the user to press any key to exit the program.
dbCenterText(319, 440, "Press Any Key To Exit The Program.");
//Wait for the user to press a key.
dbWaitKey();
}
/*********************************************************************
The setUp function checks if the coordinates.dat file exists and if
it does deletes it and opens a new output file. Sets the Title screen
to "Connecting the Dots", Prompts the user, and disables automatic
sync rate and sets the refresh rate to 60.
**********************************************************************/
void setUp() //Function Header
{
/*Check if the file coordinates.dat exists, if the .dat file exists
delete it, and open an output file to store the mouses X and Y
Coordinates*/
if(dbFileExist("coordinates.dat"))
{
//If the MouseCoordinates.dat exists delete it.
dbDeleteFile("coordinates.dat");
//Open a output file to store mouse clicked
//X and Y coordinates.
dbOpenToWrite(FILE_NUM, "coordinates.dat");
}
else //If the file does not exist open output file
{
//Open a output file to store mouse clicked
//X and Y coordinates.
dbOpenToWrite(FILE_NUM, "coordinates.dat");
}
//Set the window Title
dbSetWindowTitle("Connect The Dots");
//Prompt the user to click the mouse anywhere on the screen
dbCenterText(319, 40, "Click The Mouse Anywhere On The Screen.");
//Prompt the user to press the space bar when he is done.
dbCenterText(319, 449, "Press The Space Bar When You Are Done.");
//Disable the automatic sync rate.
dbSyncOn();
//Set the refresh rate to 60.
dbSyncRate(REFRESH_RATE);
}
/**************************************************************************
The openInputFile function checks if the coordinates.dat input file exists
and opens it if it does. If the file does not exist Prompts the user an
Error message stating the file does not exist..
**************************************************************************/
void openInputFile() //Function Header.
{
//Check if the file exists.
if(dbFileExist("coordinates.dat") )
{
//Open the input file.
dbOpenToRead(FILE_NUM, "coordinates.dat");
}
else //the file does not exist
{
//Print an error message.
dbPrint("Error! The file does not exist.");
}
}
Dimo