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 >
Text File  |  1996-11-13  |  5KB  |  203 lines

  1. //Copyright 1996 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include <Devices.h>
  5. #include <Dialogs.h>
  6. #include "MenuHandler.h"
  7. #include "Application.h"
  8. #include "ConicWindow.h"
  9. #include "DrawWindows.h"
  10.  
  11. char ToUpper( char );
  12. float abs( float );
  13.  
  14. char ToUpper( char in ) {
  15.     if( (in >= 'a') && (in <= 'z') )
  16.         return( 'A'-'a'+in );
  17.     return( in );
  18. }
  19.  
  20. float abs( float in ) {
  21.     return( in < 0 ? -in:in );
  22. }
  23.  
  24. TConicHandler::TConicHandler() {
  25.     conicWindow = 0l;
  26.     instructWindow = 0l;
  27.     equWindow = 0l;
  28.     plotWindow = 0l;
  29. }
  30.  
  31. TConicHandler::~TConicHandler() {
  32.     conicWindow->KillWindow();
  33.     instructWindow->KillWindow();
  34.     equWindow->KillWindow();
  35.     plotWindow->KillWindow();
  36. }
  37.  
  38. SInt8 TConicHandler::Init( MActionHandler *superHandler ) {
  39.     MActionHandler::Init( superHandler );
  40.     TConicWindow::TConicInit cWinVals;
  41.     MenuHandle appleMenu;
  42.     Handle theMBar = GetNewMBar( 128 );
  43.  
  44.  
  45.     conicWindow = new TConicWindow;
  46.     plotWindow = new TPlotWindow;
  47.     equWindow = new TEquWindow;
  48.     instructWindow = new TInstructWindow;
  49.     cWinVals.superHandler = this;
  50.     cWinVals.windowRes = 130;
  51.     cWinVals.conic = &conic;
  52.     cWinVals.plane = &plane;
  53.     instructWindow->Init( &cWinVals );
  54.     cWinVals.windowRes = 131;
  55.     equWindow->Init( &cWinVals );
  56.     cWinVals.windowRes = 132;
  57.     plotWindow->Init( &cWinVals );
  58.     cWinVals.windowRes = 129;
  59.     cWinVals.theta = -50;
  60.     cWinVals.phi = -55;
  61.     conicWindow->Init( &cWinVals );
  62.  
  63.     conic.Init();
  64.     plane.Init();
  65.  
  66.     plane.RotPlane();
  67.     conic.CalcIntersect( plane );
  68.     conicWindow->DoShowWindow();
  69.     plotWindow->DoShowWindow();
  70.     equWindow->DoShowWindow();
  71.     instructWindow->DoShowWindow();
  72.     TApplication::theApp->SetEventHandler( keyDownMask|autoKeyMask, this );
  73.  
  74.     SetMenuBar( theMBar );
  75.     if( theMBar ) {
  76.         appleMenu = GetMenuHandle( m_APPLE );
  77.         DisposeHandle( theMBar );
  78.         AppendResMenu( appleMenu, 'DRVR' );
  79.         DrawMenuBar();
  80.         return( true );
  81.     }
  82.     return( false );
  83. }
  84.  
  85. SInt8 TConicHandler::HandleAction( UInt32 actionID ) {
  86.     UInt16 theMenu, menuID;
  87.  
  88.     theMenu = (actionID>>16);
  89.     menuID = (actionID&0x0000FFFF);
  90.     switch( theMenu ) {
  91.     case m_APPLE:
  92.         switch( menuID ) {
  93.         case ma_ABOUT:
  94.             Alert( 128, 0l );
  95.             break;
  96.         default:
  97.             Str255 itemStr;
  98.             GetMenuItemText( GetMenuHandle( m_APPLE ), menuID, itemStr );
  99.             OpenDeskAcc( itemStr );
  100.             break;
  101.         }
  102.         break;
  103.     case m_FILE:
  104.         switch( menuID ) {
  105.         case mf_CLOSE:
  106.             ((TBaseWindow*)GetWRefCon(FrontWindow()))->DoHideWindow();
  107.             break;
  108.         case mf_QUIT:
  109.             TApplication::theApp->AttemptQuit();
  110.             break;
  111.         }
  112.         break;
  113. /*    case m_EDIT:
  114.         switch( menuID ) {
  115.         case me_COPY:
  116.             if( ((TBaseWindow*)GetWRefCon( FrontWindow() )) != instructWindow )
  117.                 ((TDocWindow*)GetWRefCon( FrontWindow() ))->CopyWindow();
  118.             break;
  119.         }
  120.         break;*/
  121.     case m_WINDOW:
  122.         switch( menuID ) {
  123.         case mw_CONIC:
  124.             if( !conicWindow->IsOpen() )
  125.                 conicWindow->DoShowWindow();
  126.             SelectWindow( conicWindow->GetWindow() );
  127.             break;
  128.         case mw_PLOT:
  129.             if( !plotWindow->IsOpen() )
  130.                 plotWindow->DoShowWindow();
  131.             SelectWindow( plotWindow->GetWindow() );
  132.             break;
  133.         case mw_INSTRUCT:
  134.             if( !instructWindow->IsOpen() )
  135.                 instructWindow->DoShowWindow();
  136.             SelectWindow( instructWindow->GetWindow() );
  137.             break;
  138.         case mw_EQU:
  139.             if( !equWindow->IsOpen() )
  140.                 equWindow->DoShowWindow();
  141.             SelectWindow( equWindow->GetWindow() );
  142.             break;
  143.         }
  144.         break;
  145.     }
  146.     HiliteMenu( 0 );
  147. }
  148.  
  149. SInt8 TConicHandler::ProcessEvent( const EventRecord &event ) {
  150.     int key,flag;
  151.     TConicWindow *temp;
  152.  
  153.     key = event.message&charCodeMask;
  154.     flag = 1;
  155.     key = ToUpper(key);
  156.     temp = ((TConicWindow*)conicWindow);
  157. //        key=(event.message&keyCodeMask)>>8;
  158. //        MoveTo( 0, 20 );
  159. //        DrawString( IToA( key ) );
  160.  
  161.     switch( key ) {
  162.     case 30:
  163.         temp->phi.SetAngle(temp->phi.GetAngle()+5);
  164.         break;
  165.     case 31:
  166.         temp->phi.SetAngle(temp->phi.GetAngle()-5);
  167.         break;
  168.     case 28:
  169.         temp->theta.SetAngle(temp->theta.GetAngle()+5);
  170.         break;
  171.     case 29:
  172.         temp->theta.SetAngle(temp->theta.GetAngle()-5);
  173.         break;
  174.     case '-':
  175.         plane.SetDistance(plane.GetDistance()-.25);
  176.         conic.CalcIntersect( plane );
  177.         plotWindow->DrawContent();
  178.         equWindow->DrawContent();
  179.         break;
  180.     case '+':
  181.         plane.SetDistance(plane.GetDistance()+.25);
  182.         conic.CalcIntersect( plane );
  183.         plotWindow->DrawContent();
  184.         equWindow->DrawContent();
  185.         break;
  186.     case 'W':
  187.         plane.SetAngle( plane.GetAngle()+5 );
  188.         conic.CalcIntersect( plane );
  189.         plotWindow->DrawContent();
  190.         equWindow->DrawContent();
  191.         break;
  192.     case 'Z':
  193.         plane.SetAngle( plane.GetAngle()-5 );
  194.         conic.CalcIntersect( plane );
  195.         plotWindow->DrawContent();
  196.         equWindow->DrawContent();
  197.         break;
  198.     default:
  199.         flag = 0;
  200.     }
  201.     if (flag)
  202.         conicWindow->DrawContent();
  203. }