home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 10.9 KB | 478 lines | [TEXT/CWIE] |
- //===================================================================
- //======================= Headers =============================
-
- #include "MenuItemWindow.h"
- #include "GameUtilities.h"
- #include "Screen.h"
- #include "ApplicationEvents.h"
- #include "ApplicationHandler.h"
-
- #include <string.h>
-
- //===================================================================
- //======================= Globals =============================
-
- OffScreenBuff menuStuff;
-
- rect rectMenuStuff[ 1 ];
-
- //===================================================================
- //======================= #define =============================
-
-
- #define kMenuLine 0
-
- //===================================================================
- //======================= Function Prototypes =====================
-
- /*----------------------------------------------------------------------------\
-
- InitMenuItemWindow
-
- \----------------------------------------------------------------------------*/
- void InitMenuItemWindow( void )
- {
- if( !menuStuff.LoadPicBuff( 132 ) )
- {
- DebugStr("\p AAAAAhhhhhhhhhhh InitMenuItemWindow() ");
- ExitToShell();
- }
-
- MySetRect( &rectMenuStuff[ 0 ] , 0 , 0 , 200 , 20 );
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: Constructor
-
- \----------------------------------------------------------------------------*/
- MenuItemWindow :: MenuItemWindow( void )
- {
- numItems = 0;
- shaded = true;
- type = 0;
-
- short i;
-
- for( i = 0; i < kMaxMenuItemName; i++ )
- {
- items[ i ][ 0 ] = NULL;
- }
-
- selectedItem = 0xff;
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: SetMaxItems
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: SetMaxItems( uchar num )
- {
- if( numItems != num )
- {
- if( numItems > 0 )
- {
- window.DeleteBuff();
- }
-
- numItems = num;
-
- CalcWindowSize();
-
- if( numItems > 0 )
- {
- if( !window.NewBuff( width , height ) )
- DebugStr( "\p Something went wrong MenuItemWindow :: SetMaxItems");
-
- FirstDraw(); // this is a hack tso this is ok
- }
-
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: AddItem
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: AddItem( uchar num , char *name , Boolean active )
- {
- if( num + 1 > numItems )
- {
- SetMaxItems( num + 1);
- }
-
- if( name == NULL )
- {
- items[ num ][ 0 ] = NULL;
- itemActive[ num ] = false;
- }
- else
- {
- strcpy( items[ num ] , name );
- itemActive[ num ] = active;
- }
-
- WriteName( num , false );
-
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: RemoveItem
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: RemoveItem( uchar num )
- {
- if( num < numItems )
- {
- items[ num ][ 0 ] = NULL;
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: MenuItemRect
-
- - assume all the items have been added
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: MenuItemRect( const rect *menuItem )
- {
- MySetRectWH( &screenLoc , menuItem->left , menuItem->bottom ,
- width , height );
-
- if( !screen.RectAllInScreen( &screenLoc ) )
- {
- MySetRect( &screenLoc , menuItem->right - width ,(int)menuItem->bottom
- , (int)menuItem->right , height + menuItem->bottom );
-
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: SetType
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: SetType( uchar t )
- {
- type = t;
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: SetActive
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: SetActive( Boolean a )
- {
- if( shaded != !a )
- {
- shaded = !a;
-
- screen.AddRectToUpdate( screenLoc );
-
- if( shaded )
- {
- if( selectedItem != 0xff )
- {
- WriteName( selectedItem , false );
- selectedItem = 0;
- }
- }
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: GetNumItems
-
- \----------------------------------------------------------------------------*/
- uchar MenuItemWindow :: GetNumItems( void )
- {
- return numItems;
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: Init
-
- - this hsould be called after all window setts are set
- \----------------------------------------------------------------------------*/
- Boolean MenuItemWindow :: Init( void )
- {
-
- shaded = true;
- FirstDraw();
-
- return true;
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: HandleMouseClick
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: HandleMouseClick( Boolean down , point where )
- {
- if( shaded )
- return;
-
- if( !SectPtRect( where , screenLoc ) )
- return;
-
- if( down )
- {
-
- }
- else
- {
- if( selectedItem != 0xff )
- {
- WriteName( selectedItem , false );
- SendSelectEvent( selectedItem );
- selectedItem = 0;
- }
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: HandleMouseMove
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: HandleMouseMove( point where )
- {
- if( shaded )
- return;
-
- if( !SectPtRect( where , screenLoc ) )
- {
- if( selectedItem != 0xff )
- {
- WriteName( selectedItem , false );
- AddItemToUpdate( selectedItem );
- selectedItem = 0xff;
- }
- return;
- }
- // find which one is selected and highlight
- short which;
-
- which = ( where.y - screenLoc.top ) / kMenuItemHeight;
-
- if( which != selectedItem && selectedItem != 0xff)
- {
- WriteName( selectedItem , false );
- AddItemToUpdate( selectedItem );
- }
-
- if( ((which != selectedItem) && itemActive[ which ]) && (items[ which ][ 0 ] != NULL) )
- {
- WriteName( which , true );
- selectedItem = which;
- AddItemToUpdate( which );
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: PointInWindow
-
- - just saids if the point it inside the window area or not
- \----------------------------------------------------------------------------*/
- Boolean MenuItemWindow :: PointInWindow( point where )
- {
- if( shaded )
- return false;
-
- return SectPtRect( where , screenLoc );
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: Active
-
- \----------------------------------------------------------------------------*/
- Boolean MenuItemWindow :: Front( void )
- {
- return( front );
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: SetFront
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: SetFront( Boolean f )
- {
-
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: DrawToScreen
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: DrawToScreen( rect *where , Boolean highlighted )
- {
- if( shaded )
- return;
-
- if( where == NULL )
- {
- screen.DrawGeneric( &window , &window.GetBoundsSize() , &screenLoc ,
- NULL , 0 , 0 , 0 );
- }
- else
- {
- screen.DrawGeneric( &window , &window.GetBoundsSize() , &screenLoc ,
- where , 0 , 0 , 0 );
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: FirstDraw
-
- - creates the menu list the first time with no thrils
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: FirstDraw( void )
- {
- // draw the colored back ground
-
- PaintRect( &window , &window.GetBoundsSize() , kMenuGrey );
-
- // write all the text names
-
- uchar i;
-
- for( i = 0; i < numItems; i++ )
- {
- WriteName( i , false );
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: FirstDraw
-
- - creates the menu list the first time with no thrils
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: WriteName( uchar which , Boolean highlighted )
- {
- rect loc;
- RGBColor oldColor;
- RGBColor grey;
- CGrafPtr oldCPort;
- GDHandle oldDevice;
-
- MySetRectWH( &loc , 0 , 20 * which , 200 , 20 );
-
- if( items[ which ][ 0 ] == NULL )
- {
- DrawPicture( &menuStuff , &rectMenuStuff[ kMenuLine ] , &window , &loc );
- }
- else if( itemActive[ which ] )
- {
- PaintRect( &window , &loc , kMenuGrey );
-
- grey.red = 0x3333;
- grey.blue = 0x3333;
- grey.green = 0x3333;
-
- GetGWorld( &oldCPort, &oldDevice );
-
- SetGWorld( (window.GetOffScreen())->GWorld , ( GDHandle )nil );
-
- GetForeColor( &oldColor );
-
- RGBForeColor( &grey );
-
- MoveTo( loc.left + 20, loc.bottom - 7 );
- DrawString( c2pstr( items[ which ] ) );
- p2cstr( (StringPtr)items[ which ] );
- RGBForeColor( &oldColor );
-
- SetGWorld( oldCPort, oldDevice );
-
- if( highlighted )
- DrawGeneric( &window , &loc , &window , &loc ,
- &window.GetBoundsSize() , kDrawCrop1 | kDrawInverse , 0 , 0x0000 );
- }
- else
- {
- PaintRect( &window , &loc , kMenuGrey );
-
- grey.red = 0x9999;
- grey.blue = 0x9999;
- grey.green = 0x9999;
-
- GetGWorld( &oldCPort, &oldDevice );
-
- SetGWorld( (window.GetOffScreen())->GWorld , ( GDHandle )nil );
-
- GetForeColor( &oldColor );
-
- RGBForeColor( &grey );
-
- MoveTo( loc.left + 20, loc.bottom - 7 );
- DrawString( c2pstr( items[ which ] ) );
- p2cstr( (StringPtr)items[ which ] );
- RGBForeColor( &oldColor );
-
- SetGWorld( oldCPort, oldDevice );
-
- // &window.GetBoundsSize() , kDrawCrop1 , 0 , 0x0000 );
- }
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: CalcWindowSize
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: CalcWindowSize( void)
- {
- width = 200;
- height = numItems * kMenuItemHeight;
-
- MySetRectWH( &screenLoc , screenLoc.left , screenLoc.top ,
- width , height );
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: SendSelectEvent
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: SendSelectEvent( uchar num )
- {
- AEMenuWhere blarg;
-
- blarg.which = type;
- blarg.num = num;
-
- AH.SendEventToCurrentApp( kAEMenuSelect , (void *)&blarg );
- }
-
- /*----------------------------------------------------------------------------\
-
- MenuItemWindow :: AddItemToUpdate
-
- \----------------------------------------------------------------------------*/
- void MenuItemWindow :: AddItemToUpdate( uchar which )
- {
- rect loc;
-
- loc.left = screenLoc.left;
- loc.top = screenLoc.top + which * kMenuItemHeight;
- loc.right = loc.left + 200;
- loc.bottom = loc.top + kMenuItemHeight;
-
- screen.AddRectToUpdate( loc );
- }