home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / SpriteFight 2002 v2.0a1 / SpriteHelp.c < prev    next >
Encoding:
Text File  |  1996-01-11  |  4.3 KB  |  196 lines  |  [TEXT/SPM ]

  1. //• SpriteHelp.c by Stefan C. Sinclair Copyright © 1996 All Rights Reserved
  2.  
  3. #include "SpriteHelp.h"
  4.  
  5. /**************/
  6. /*  Globals      */
  7. /**************/
  8.  
  9. extern CWindowPtr    gWindowP;
  10.  
  11. ControlActionUPP    gActionUPP;
  12. Rect        pictRect, windRect;
  13. PicHandle    helpPict;
  14. Boolean    helpDone;
  15. short        numScreens;
  16.  
  17. void Helper(short whichOne)
  18. {
  19.     short pictWide, pictHigh, windWide, windHigh;
  20.     Rect    oldWindRect;
  21.     
  22.     helpPict = GetPicture(whichOne);
  23.     if(helpPict == nil)
  24.         CantFindResource();
  25.     
  26.     HLock((Handle)helpPict);
  27.     pictRect = (**helpPict).picFrame;
  28.     HUnlock((Handle)helpPict);
  29.     
  30.     pictWide = pictRect.right - pictRect.left;
  31.     pictHigh = pictRect.bottom - pictRect.top;
  32.     
  33.     oldWindRect = gWindowP->portRect;
  34.     
  35.     windRect = oldWindRect;
  36.     windRect.right = windRect.left + kScrollBarWidth + pictWide;
  37.     windWide = windRect.right - windRect.left;
  38.     windHigh = windRect.bottom - windRect.top;
  39.     
  40.     /*pictRect.top = windRect.top;
  41.     pictRect.left = windRect.left;
  42.     pictRect.bottom = pictRect.top + pictHigh;
  43.     pictRect.right = pictRect.left + pictWide; */
  44.     
  45.     numScreens = 4*pictHigh/(windRect.bottom - windRect.top);
  46.     gActionUPP = NewControlActionProc( ScrollProc );
  47.     
  48.     SizeWindow((WindowPtr)gWindowP, windWide, windHigh, FALSE);
  49.     SetUpScrollBar((WindowPtr)gWindowP);
  50.     InvalRect(&gWindowP->portRect);
  51.     
  52.     // Event loop
  53.     FlushEvents(everyEvent, 0);
  54.     HelpEventLoop();
  55.     FlushEvents(everyEvent, 0);
  56.     
  57.     // All done
  58.     ReleaseResource((Handle)helpPict);
  59.     KillControls((WindowPtr)gWindowP);
  60.     windWide = oldWindRect.right - oldWindRect.left;
  61.     windHigh = oldWindRect.bottom - oldWindRect.top;
  62.     SizeWindow((WindowPtr)gWindowP, windWide, windHigh, FALSE);
  63.     InvalRect(&gWindowP->portRect);
  64. }
  65.  
  66. void    SetUpScrollBar( WindowPtr window )
  67. {
  68.     Rect            vScrollRect;
  69.     ControlHandle    scrollBarH;
  70.     
  71.     vScrollRect = window->portRect;
  72.     vScrollRect.left = vScrollRect.right - kScrollBarWidth;
  73.     
  74.     scrollBarH = NewControl( window, &vScrollRect,
  75.             kEmptyTitle, kVisible, kStartValue, kMinValue,
  76.             numScreens+1, scrollBarProc, kNilRefCon );
  77. }
  78.  
  79. pascal void ScrollProc( ControlHandle theControl, short partCode )
  80. {
  81.     short        curCtlValue, maxCtlValue, minCtlValue, scrollAmt;
  82.     WindowPtr    window;
  83.     
  84.     scrollAmt = (pictRect.bottom - pictRect.top)/(numScreens+1);
  85.     
  86.     maxCtlValue = GetCtlMax( theControl );
  87.     curCtlValue = GetCtlValue( theControl );
  88.     minCtlValue = GetCtlMin( theControl );
  89.     
  90.     window = (**theControl).contrlOwner;
  91.     
  92.     switch ( partCode )
  93.     {
  94.         case inPageDown:
  95.         case inDownButton:
  96.             if ( curCtlValue < maxCtlValue )
  97.             {
  98.                 curCtlValue += 1;
  99.                 SetCtlValue( theControl, curCtlValue );
  100.                 pictRect.top-=scrollAmt;
  101.                 pictRect.bottom-=scrollAmt;
  102.                 InvalRect(&window->portRect);
  103.             }
  104.             break;
  105.         case inPageUp:
  106.         case inUpButton:
  107.             if ( curCtlValue > minCtlValue )
  108.             {
  109.                 curCtlValue -= 1;
  110.                 SetCtlValue( theControl, curCtlValue );
  111.                 pictRect.top+=scrollAmt;
  112.                 pictRect.bottom+=scrollAmt;
  113.                 InvalRect(&window->portRect);
  114.             }
  115.             break;
  116.     }
  117. }
  118.  
  119. void    HelpEventLoop( void )
  120. {        
  121.     EventRecord        event;
  122.     
  123.     helpDone = false;
  124.     
  125.     while ( helpDone == false )
  126.     {
  127.         if ( WaitNextEvent( everyEvent, &event, kSleep, nil ) )
  128.             HelpDoEvent( &event );
  129.     }
  130. }
  131.  
  132. void    HelpDoEvent( EventRecord *eventPtr )
  133. {
  134.     WindowPtr    window;
  135.     Rect        viewRect;
  136.     
  137.     switch ( eventPtr->what )
  138.     {
  139.         case mouseDown: 
  140.             HelpHandleMouseDown( eventPtr );
  141.             break;
  142.         case updateEvt:
  143.             window = (WindowPtr)eventPtr->message;
  144.             viewRect = window->portRect;
  145.             viewRect.right -= kScrollBarWidth;
  146.             BeginUpdate( window );
  147.             EraseRect(&viewRect);
  148.             HLock((Handle)helpPict);
  149.             DrawPicture(helpPict, &pictRect );
  150.             HUnlock((Handle)helpPict);
  151.             DrawControls( window );
  152.             EndUpdate( window );
  153.             break;
  154.     }
  155. }
  156.  
  157. void    HelpHandleMouseDown( EventRecord *eventPtr )
  158. {
  159.     WindowPtr            window;
  160.     short                thePart;
  161.     Point                thePoint;
  162.     ControlHandle        theControl;
  163.     
  164.     thePart = FindWindow( eventPtr->where, &window );
  165.     switch ( thePart )
  166.     {
  167.         case inSysWindow : 
  168.             //SystemClick( eventPtr, window );
  169.             break;
  170.         case inDrag : 
  171.             DragWindow( window, eventPtr->where, &qd.screenBits.bounds );
  172.             break;
  173.         case inContent:
  174.             thePoint = eventPtr->where;
  175.             GlobalToLocal( &thePoint );
  176.             
  177.             thePart = FindControl(thePoint, window, &theControl);
  178.             
  179.             if ( theControl == ((WindowPeek)window)->controlList )
  180.             {
  181.                 if ( thePart == inThumb )
  182.                 {
  183.                     return;
  184.                 }
  185.                 else
  186.                 {
  187.                     thePart = TrackControl( theControl, thePoint, gActionUPP );
  188.                 }
  189.             }
  190.             break;
  191.         case inGoAway:
  192.             if(TrackGoAway(window, eventPtr->where)) 
  193.                 helpDone = TRUE;
  194.             break;
  195.     }
  196. }