View Single Post
Old 03-19-2003, 06:28 PM   #9 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Wink This prgrammer is a crazy addict!

CHECK THIS OUT!
Click on screen and watch the windows title bar!!
U will love this demo I think . Also a bit of comment added.

Cut and paste this code to use instead of the original one.
Code:
#include <iostream.h>
#include <CMUgraphics.h>
#include <string.h>


//These variables are added by Valmont.
char chKeyData;
int ix,iy;
bool bQuit=false;

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);
		
	//*******************
	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);

	//By Valmont:
	//We start here with the ESC option and mouseclick demo. YOU MUST PRESS
	//ESC THEN 2 TIMES LEFT CLICK TO END PROGRAM ENTIRELY!!
	
	// Flush out the input queues before beginning
    testWindow.FlushMouseQueue();
    testWindow.FlushKeyQueue();
	//Few vars to demonstrate co-ordinates in window title.
	char chNum[5]; //Make a char for upcomimg int-string conversion.
	string szX,szY,szComb;//Use strings to make a pretty output.And ChangeTitle() method demands a string.

	//Start loop for esc input until esc is pressed. bool value bQuit will be true then.
	do
	{
		if(testWindow.GetKeyPress(chKeyData) == ESCAPE) //Is the esc key pressed?
		{
			bQuit=true; //yes, the esc key is pressed.
			break;//Get out of loop then. So click twice to end program entirely.
		}
		testWindow.WaitMouseClick(ix,iy);
		
		itoa(ix,chNum,10); //conversion from int to char. Find more about itoa on the net if u like.
		szX=chNum;//auto conversion from char to string. Must do since ChangeTitle needs a string, NOT a char*!
		itoa(iy,chNum,10);
		szY=chNum;

		szComb="Coordinates are: ("+szX+","+szY+")";//Coordinates are: (szX,szY)
		testWindow.ChangeTitle(szComb); //Update the current windows title area.
				
	}
	while (bQuit==false);	

//End by Valmont.
	
	return 0;
}
Valmont is offline   Reply With Quote