home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
online
/
source
/
cpp
/
graphics
/
Conics.sit.hqx
/
Conics
/
Sources
/
MenuHandler.cpp
< prev
next >
Wrap
Text File
|
1996-11-13
|
5KB
|
203 lines
//Copyright 1996 Aidan Cully
//All rights reserved
#include <Devices.h>
#include <Dialogs.h>
#include "MenuHandler.h"
#include "Application.h"
#include "ConicWindow.h"
#include "DrawWindows.h"
char ToUpper( char );
float abs( float );
char ToUpper( char in ) {
if( (in >= 'a') && (in <= 'z') )
return( 'A'-'a'+in );
return( in );
}
float abs( float in ) {
return( in < 0 ? -in:in );
}
TConicHandler::TConicHandler() {
conicWindow = 0l;
instructWindow = 0l;
equWindow = 0l;
plotWindow = 0l;
}
TConicHandler::~TConicHandler() {
conicWindow->KillWindow();
instructWindow->KillWindow();
equWindow->KillWindow();
plotWindow->KillWindow();
}
SInt8 TConicHandler::Init( MActionHandler *superHandler ) {
MActionHandler::Init( superHandler );
TConicWindow::TConicInit cWinVals;
MenuHandle appleMenu;
Handle theMBar = GetNewMBar( 128 );
conicWindow = new TConicWindow;
plotWindow = new TPlotWindow;
equWindow = new TEquWindow;
instructWindow = new TInstructWindow;
cWinVals.superHandler = this;
cWinVals.windowRes = 130;
cWinVals.conic = &conic;
cWinVals.plane = &plane;
instructWindow->Init( &cWinVals );
cWinVals.windowRes = 131;
equWindow->Init( &cWinVals );
cWinVals.windowRes = 132;
plotWindow->Init( &cWinVals );
cWinVals.windowRes = 129;
cWinVals.theta = -50;
cWinVals.phi = -55;
conicWindow->Init( &cWinVals );
conic.Init();
plane.Init();
plane.RotPlane();
conic.CalcIntersect( plane );
conicWindow->DoShowWindow();
plotWindow->DoShowWindow();
equWindow->DoShowWindow();
instructWindow->DoShowWindow();
TApplication::theApp->SetEventHandler( keyDownMask|autoKeyMask, this );
SetMenuBar( theMBar );
if( theMBar ) {
appleMenu = GetMenuHandle( m_APPLE );
DisposeHandle( theMBar );
AppendResMenu( appleMenu, 'DRVR' );
DrawMenuBar();
return( true );
}
return( false );
}
SInt8 TConicHandler::HandleAction( UInt32 actionID ) {
UInt16 theMenu, menuID;
theMenu = (actionID>>16);
menuID = (actionID&0x0000FFFF);
switch( theMenu ) {
case m_APPLE:
switch( menuID ) {
case ma_ABOUT:
Alert( 128, 0l );
break;
default:
Str255 itemStr;
GetMenuItemText( GetMenuHandle( m_APPLE ), menuID, itemStr );
OpenDeskAcc( itemStr );
break;
}
break;
case m_FILE:
switch( menuID ) {
case mf_CLOSE:
((TBaseWindow*)GetWRefCon(FrontWindow()))->DoHideWindow();
break;
case mf_QUIT:
TApplication::theApp->AttemptQuit();
break;
}
break;
/* case m_EDIT:
switch( menuID ) {
case me_COPY:
if( ((TBaseWindow*)GetWRefCon( FrontWindow() )) != instructWindow )
((TDocWindow*)GetWRefCon( FrontWindow() ))->CopyWindow();
break;
}
break;*/
case m_WINDOW:
switch( menuID ) {
case mw_CONIC:
if( !conicWindow->IsOpen() )
conicWindow->DoShowWindow();
SelectWindow( conicWindow->GetWindow() );
break;
case mw_PLOT:
if( !plotWindow->IsOpen() )
plotWindow->DoShowWindow();
SelectWindow( plotWindow->GetWindow() );
break;
case mw_INSTRUCT:
if( !instructWindow->IsOpen() )
instructWindow->DoShowWindow();
SelectWindow( instructWindow->GetWindow() );
break;
case mw_EQU:
if( !equWindow->IsOpen() )
equWindow->DoShowWindow();
SelectWindow( equWindow->GetWindow() );
break;
}
break;
}
HiliteMenu( 0 );
}
SInt8 TConicHandler::ProcessEvent( const EventRecord &event ) {
int key,flag;
TConicWindow *temp;
key = event.message&charCodeMask;
flag = 1;
key = ToUpper(key);
temp = ((TConicWindow*)conicWindow);
// key=(event.message&keyCodeMask)>>8;
// MoveTo( 0, 20 );
// DrawString( IToA( key ) );
switch( key ) {
case 30:
temp->phi.SetAngle(temp->phi.GetAngle()+5);
break;
case 31:
temp->phi.SetAngle(temp->phi.GetAngle()-5);
break;
case 28:
temp->theta.SetAngle(temp->theta.GetAngle()+5);
break;
case 29:
temp->theta.SetAngle(temp->theta.GetAngle()-5);
break;
case '-':
plane.SetDistance(plane.GetDistance()-.25);
conic.CalcIntersect( plane );
plotWindow->DrawContent();
equWindow->DrawContent();
break;
case '+':
plane.SetDistance(plane.GetDistance()+.25);
conic.CalcIntersect( plane );
plotWindow->DrawContent();
equWindow->DrawContent();
break;
case 'W':
plane.SetAngle( plane.GetAngle()+5 );
conic.CalcIntersect( plane );
plotWindow->DrawContent();
equWindow->DrawContent();
break;
case 'Z':
plane.SetAngle( plane.GetAngle()-5 );
conic.CalcIntersect( plane );
plotWindow->DrawContent();
equWindow->DrawContent();
break;
default:
flag = 0;
}
if (flag)
conicWindow->DrawContent();
}