May 03, 2024, 12:05:41 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


The 'lines' program

Started by Ionic Wind Support Team, December 13, 2005, 11:04:31 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Ionic Wind Support Team

One of the first example programs I create with all of my languages is the 'lines' program.  Here is how it looks in Aurora:


/*the lines program
displays random lines forever
For Aurora 1.0 or greater
Compile as a WINDOWS target*/

class linewin : window
{
//virtual overrides used by our window
declare OnCreate(),int;
declare OnClose(),int;
declare OnMenuPick(int nID),int;
declare OnSize(int nType,int cx,int cy),int;
declare OnTimer(int nIDEvent),int;
declare OnMenuInit(unsigned int hmenu),int;
//variables used by our window
int l,t,w,h,size,run;
}

linewin::OnCreate(),int
{
CenterWindow();
size = 1;
run = 1;
//draw the lines every 10 millesceonds
StartTimer(10);
return true;
}

linewin::OnClose(),int
{
StopTimer();
run = 0;
return true;
}

linewin::OnMenuPick(int nID),int
{
select nID
{
CASE 1:
DrawRect(0,0,w,h,RGB(255,255,255),RGB(255,255,255));
CASE 2:
CASE& 3:
CASE& 4:
SetLineStyle(LSSOLID,nID - 1);
size = nID - 1;
CASE 5:
StopTimer();
run = 0;
}
return true;
}

linewin::OnSize(int nType,int cx,int cy),int
{
rc = GetClientRect();
l = rc.Left;
t = rc.Top;
w = rc.Right - rc.Left;
h = rc.Bottom - rc.Top;
return true;
}

linewin::OnTimer(int nIDEvent),int
{
for( x = 0; x < 10; x++)
{
line( rnd(w),rnd(h),rnd(w),rnd(h),RGB(rnd(255),rnd(255),rnd(255)));
}
return true;
}

linewin::OnMenuInit(unsigned int hmenu),int
{
menu m;
m.Attach(hmenu);
m.CheckMenuItem(2,size = 1);
m.CheckMenuItem(3,size = 2);
m.CheckMenuItem(4,size = 3);
m.Detach();
DrawMenuBar();
return false;
}

global sub main()
{
linewin win;
menu m;
m.BeginMenu();
m.MenuTitle("&Options");
m.MenuItem("Clear",0,1);
m.BeginPopup("Line Size");
m.MenuItem( "1",0,2 );
m.MenuItem( "2",0,3 );
m.MenuItem( "3",0,4 );
m.EndPopup();
m.MenuItem( "Quit",0,5 );
m.EndMenu();

win.Create(0,0,400,300,AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_AUTODRAW|AWS_SIZE,0,"Lines",NULL);
win.SetMenu(m.Detach());
do
{
wait();
}until win.run = 0;
return;
//'win' is automatically closed here since the class destructor calls Destroy();
}


Included with the next update.,

Ionic Wind Support Team

Zen

Cool. Im reallly loving the idea of oop classes to do everything. It makes things a lot easier and you save a lot of room on variable declarations too.

All compiled ok here.

Lewis