View Single Post
Old 03-19-2003, 04:50 PM   #8 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road

Code:
#include <iostream.h>
#include <CMUgraphics.h>


keytype ktInput;
char chKeyData;
int ix,iy;

int main()
{
	//****************
	// Variables    **
	int sizebutx = 35;
	int counter2 = 0;
	int counter = 0;
	int sizebuty = 35;
	int spacebutx = 17;
	int spacebuty = 34;
	
	int buttonx1 = (20+spacebutx);
	int buttony1 = (500-spacebuty);
	int buttonx2 = (20+spacebutx+sizebutx);
	int buttony2 = (500-spacebuty-sizebuty);
	//int ix,iy;
	bool bQuit=false;
	
	//*******************
	window testWindow(650,520,0,0);//550 was 500
	testWindow.SetPen(RED);
	testWindow.SetBrush(BLUE);
	testWindow.DrawRectangle(20,20,300,500,FILLED);
	
	testWindow.SetPen(GREEN);
	testWindow.SetBrush(RED);
	do
	{
		
		//Draws Columns
		counter2++;
		do
		{
			//Draws Rows
			testWindow. DrawRectangle(buttonx1,buttony1,buttonx2,buttony2,FILLED);
			buttonx1 = buttonx1+sizebutx+spacebutx;
			buttonx2 = buttonx2+sizebutx+spacebutx;
			counter++;
		}
		while (counter < 5);
		
		buttony1 = buttony1-sizebuty-spacebuty;
		buttony2 = buttony2-spacebuty-sizebuty;
		buttonx1 = (20+spacebutx);
		buttonx2 = (20+spacebutx+sizebutx);
		counter = 0;
	}
	while (counter2 < 5);

	// Flush out the input queues before beginning
    testWindow.FlushMouseQueue();
    testWindow.FlushKeyQueue();

//BEGIN loop to enable esc to enable click-to-end option.

	do
	{
		//ktInput = testWindow.GetKeyPress(chKeyData) 
		if(testWindow.GetKeyPress(chKeyData) == ESCAPE) 
		{
//ESC pressed so click to end available again!!
			bQuit=true;
		}
//You can use this only once, then quit program and re-run.
		testWindow.WaitMouseClick(ix,iy);
		testWindow.DrawInteger(100,100,ix);
		testWindow.DrawInteger(100,120,iy);
	}
	while (bQuit==false);	
//END loop to enable esc to enable click-to-end option.
	
	return 0;
}
Code:

I changed your proggie a bit to make it a lil more readable (removed a few "one time used) vars and replaced the vars when used with actual numbers).

Stupid UBB messes up the tabs but I am too tired to correct it.

Press esc THEN click twice slowly on the window to end.

Here is the main.cpp file I made. Download it and test it:
Click here to download


The rest is up to you. My line of expertise is Qt not CMU .

- Val -
Valmont is offline   Reply With Quote