CodeWarrior (OS 9)/menu.c

/*
    File:       menu.c
 
    Contains:   
 
    Written by: EL  
 
    Copyright:  Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                08/2000     JM              Carbonized, non-Carbon code is commented out
                                            for demonstration purposes.
                7/13/1999   KG              Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
 
#include "FX.h"
#include <Menus.h>
#include <Resources.h>
#include <ToolUtils.h>
#include <Devices.h>
#include <Fonts.h>
 
enum {
    appleID = 128,
    fileID = 129,
    exID = 130,
    srcID = 131
};
 
enum {
    quitItem = 1
};
 
#define WWIDTH      420
#define WHEIGHT     200
 
//#define WLEFT     (((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - WWIDTH) / 2)
//#define WTOP      (((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - WHEIGHT) / 2)
 
 
void setUpMenus()
{
    Handle      menuHandle;
    
    if ((menuHandle = GetNewMBar( 128 )) == nil)
        ExitToShell();
        
    SetMenuBar( menuHandle );
    AppendResMenu( GetMenu( appleID ), 'DRVR' );
        
    DrawMenuBar();
    ReleaseResource( menuHandle );
}
 
void adjustMenus()
{
    int     i;
 
    //EnableItem( GetMenuHandle( fileID ), quitItem );
    EnableMenuItem( GetMenuHandle( fileID ), quitItem );
    
    for (i = 1; i <= pixelAverageID; i++)
        setMenuItem( GetMenuHandle( exID ), i, (i == gCurrentExample / 10) );
    
    setMenuItem( GetMenuHandle( exID ), customID + 1, (customID == gCurrentExample / 10) );
}
 
void setMenuItem( MenuHandle menu, int itemNum, Boolean enabled )
{
    /*if (enabled)
        //CheckItem( menu, itemNum, true );
        CheckMenuItem( menu, itemNum, true );
    else
        //CheckItem( menu, itemNum, false );
        CheckMenuItem( menu, itemNum, false );*/
    CheckMenuItem( menu, itemNum, enabled );
}
 
void handleMenu( long mSelect )
 
{
    int         menuID = HiWord( mSelect );
    int         menuItem = LoWord( mSelect );
    //GrafPtr       savePort;
    //Str255        name;
    long        ticks;
 
    switch (menuID)
    {
        case appleID:
            if (menuItem == 1)
                doAboutBox();
            else
            {
                /*GetPort( &savePort );
                GetMenuItemText( GetMenu( appleID ), menuItem, name );
                OpenDeskAcc( name );
                SetPort( savePort );*/
            }
            break;
            
        case fileID:
            if (menuItem)
                ExitToShell();
            break;
            
        case exID:
            if (menuItem == 10)
                menuItem--;
 
            if (menuItem == gCurrentExample / 10)
                break;
            
            if (menuItem == 9)
                resetItems();
                
            gCurrentExample = (menuItem * 10) + 1;
            drawExampleName();
            drawSourceImage();
            
            ticks = drawFXImage();
            drawTime( ticks );
            drawAllItems();
            break;
            
        case srcID:
            createOffscreen( menuItem );
            drawSourceImage();
            
            ticks = drawFXImage();
            drawTime( ticks );
            break;
    }
    
    HiliteMenu( 0 );
}
 
void doAboutBox()
{
    int             col, row;
    int             width, height;
    WindowPtr       window;
    CIconHandle     cicn;
    Rect            rect;
    RGBColor        color;
    BitMap          bitMap;
    int             left, top;
 
    cicn = GetCIcon( 128 );
    HPurge( (Handle)cicn );
    
    GetQDGlobalsScreenBits(&bitMap);
    left = (((bitMap.bounds.right - bitMap.bounds.left) - WWIDTH) / 2);
    top = (((bitMap.bounds.bottom - bitMap.bounds.top) - WHEIGHT) / 2);
 
    //SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
    SetRect( &rect, left, top, left + WWIDTH, top + WHEIGHT );
    window = NewCWindow( 0L, &rect, "\p", true, plainDBox, (WindowPtr)-1L, false, 0L );                         
    //SetPort( window );
    SetPortWindowPort( window );
        
    TextFont( kFontIDGeneva );
    TextMode( srcOr );
    
    color.red = color.green = color.blue = 8700;
    RGBForeColor( &color );
        
    //rect = window->portRect;
    GetPortBounds(GetWindowPort(window), &rect);
    InsetRect( &rect, 1, 1 );
    PaintRect( &rect );
    
    width = 32 * 6;
    height = width;
    
    SetRect( &rect, 3, 3, width + 3, height + 3 );
    PlotCIcon( &rect, cicn );
 
    ForeColor( blackColor );
 
    for (row = 6; row < height; row += 6)
    {
        MoveTo( rect.left, rect.top + row );
        LineTo( rect.left + width, rect.top + row );
    }
    
    for (col = 6; col < width; col += 6)
    {
        MoveTo( rect.left + col, rect.top );
        LineTo( rect.left + col, rect.top + height );
    }
    
    col = width + 15;
    row = 35;
    
    TextFont( kFontIDTimes );
    TextSize( 36 );
    
    color.blue = 0xffff;
    color.red = color.green = 0;
    RGBForeColor( &color ); 
    drawMyString( col, &row, 30, "\pQuickDrawª" );
    
    color.blue = 0x9fff;
    RGBForeColor( &color );
    drawMyString( col + 45, &row, -5, "\pFX" );
    
    TextFont( kFontIDGeneva );
    TextSize( 9 );
    ForeColor( whiteColor );
    
    col += 10;
    
    drawMyString( col + 115, &row, 25, "\pVersion 1.0" );
    drawMyString( col, &row, 20, "\pBrought to you by Edgar Lee." );
    
    drawMyString( col, &row, 13, "\pFor any suggestions or comments," );
    drawMyString( col, &row, 13, "\pplease write to edgar@apple.com" );
    drawMyString( col, &row, 20, "\por appleLink EDGAR." );
    
    drawMyString( col, &row, 15, "\p© 1992-1999 Apple Computer, Inc." );
    drawMyString( col, &row, 25, "\pAll rights reserved." );
    
    TextFont( kFontIDTimes );
    TextSize( 36 );
    
    color.green = 0x8fff;
    color.red = color.blue = 0;
    RGBForeColor( &color );
    drawMyString( col + 125, &row, 0, "\pDTS" );
    
    while (!Button());
    
    DisposeWindow( window );
}
 
void drawMyString( int col, int *row, int increment, Str255 string)
{
    RGBColor    color;
    
    GetForeColor( &color );
    
    ForeColor( blackColor );
    MoveTo( col + 2, *row + 2 );
    DrawString( string );
    
    RGBForeColor( &color );
    MoveTo( col, *row );
    DrawString( string );
    
    *row += increment;
}