home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Tool Chest / Games / Game Sample Code / SpriteWorld 1.0b3 / Examples / Utils / GameUtils.c < prev    next >
Encoding:
Text File  |  1993-06-12  |  2.3 KB  |  104 lines  |  [TEXT/KAHL]

  1. ///--------------------------------------------------------------------------------------
  2. //    GameUtils.c
  3. //
  4. //    Created:    9/19/90
  5. //    By:        Tony Myles
  6. //
  7. //    Copyright: © 1990-93 Tony Myles, All rights reserved worldwide
  8. //
  9. //    Description:    some utility functions for games
  10. ///--------------------------------------------------------------------------------------
  11.  
  12.  
  13. #ifndef __QUICKDRAW__
  14. #include <QuickDraw.h>
  15. #endif
  16.  
  17. #ifndef __GAMEUTILS__
  18. #include "GameUtils.h"
  19. #endif
  20.  
  21.  
  22. ///--------------------------------------------------------------------------------------
  23. //    GetRandom
  24. //
  25. //    generate a random number between min and max inclusive
  26. ///--------------------------------------------------------------------------------------
  27.  
  28. unsigned short GetRandom(
  29.     unsigned short min,
  30.     unsigned short max)
  31. {
  32.     unsigned short random;
  33.     long range, temp;
  34.  
  35.     random = Random();
  36.     range = (max - min) + 1;
  37.     temp = (random * range) / 65536;
  38.     random = temp + min;
  39.  
  40.     return random;
  41. }
  42.  
  43.  
  44. /*
  45.         // globals for the menubar showing/hiding stuff
  46. */
  47. RgnHandle gOldVisRgn = NULL;
  48.  
  49.  
  50. ///--------------------------------------------------------------------------------------
  51. //    HideMenuBar
  52. ///--------------------------------------------------------------------------------------
  53.  
  54. void HideMenuBar(
  55.     GrafPtr grafPort)
  56. {
  57.     RgnHandle newVisRgn, junkRgn;
  58.     GrafPtr savePort;
  59.  
  60.     GetPort(&savePort);
  61.     SetPort(grafPort);
  62.  
  63.         // save off vis region
  64.     gOldVisRgn = NewRgn();
  65.     CopyRgn(grafPort->visRgn, gOldVisRgn);
  66.  
  67.         // expand the vis region to the port rect
  68.     newVisRgn = NewRgn();
  69.     RectRgn(newVisRgn, &grafPort->portRect);
  70.     CopyRgn(newVisRgn, grafPort->visRgn);
  71.  
  72.     SetPort(savePort);
  73. }
  74.  
  75.  
  76. ///--------------------------------------------------------------------------------------
  77. //    ShowMenuBar
  78. ///--------------------------------------------------------------------------------------
  79.  
  80. void ShowMenuBar(
  81.     GrafPtr grafPort)
  82. {
  83.     RgnHandle junkRgn;
  84.     GrafPtr savePort;
  85.  
  86.     GetPort(&savePort);
  87.     SetPort(grafPort);
  88.  
  89.         // fill the rounded corners of the screen with black again
  90.     junkRgn = NewRgn();
  91.     CopyRgn(gOldVisRgn, junkRgn);
  92.     DiffRgn(grafPort->visRgn, junkRgn, junkRgn);
  93.     FillRgn(junkRgn, qd.black);
  94.     DisposeRgn(junkRgn);
  95.  
  96.         // restore the old vis region
  97.     CopyRgn(gOldVisRgn, grafPort->visRgn);
  98.     DisposeRgn(gOldVisRgn);
  99.     gOldVisRgn = NULL;
  100.  
  101.     DrawMenuBar();
  102. }
  103.  
  104.