home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-05-11 | 2.8 KB | 135 lines | [TEXT/CWIE] |
- /*
- //
- // generic utility routines for games
- //
- // By: Tony Myles
- // Date: 9/19/90
- //
- // Copyright: © 1991-93 Tony Myles, All rights reserved worldwide.
- */
-
- // MODIFIED: Slightly by Hiep Dam, Sat 11/20/93
- // UPDATED: April 4 1995, Hiep Dam (Changed calls to PaintBehind, CalcVis
- // for compat w/ the new universal headers.
-
- // April 30, 1995, Hiep Dam (Removed direct accesses to low globals
- // and added GetMenuBarRect())
-
- // ---------------------------------------------------------------------------
-
- #include "GameUtils.h"
- #include "LowMem.h"
-
- // ---------------------------------------------------------------------------
-
- /*
- // GetRandom
- //
- // generate a random number between min and max inclusive
- */
- unsigned short GetRandom(unsigned short min, unsigned short max)
- {
- unsigned short random;
- long range, temp;
-
- random = Random();
- range = (max - min) + 1;
- temp = (random * range) / 65536;
- random = temp + min;
-
- return random;
- }
-
- // ---------------------------------------------------------------------------
-
- // globals for the menubar showing/hiding stuff
- short gMenuBarHidden = false;
- short gAllowedClicks;
- static RgnHandle gOldGrayRgn = nil;
- static short gOldMBarHeight = 0;
- static short padding;
-
- // ---------------------------------------------------------------------------
-
- void HideMenuBar(Boolean allowClicks)
- {
- RgnHandle menuRgn;
-
- if (!gMenuBarHidden)
- {
- gOldMBarHeight = LMGetMBarHeight();
-
- gAllowedClicks = allowClicks;
- if (!allowClicks)
- LMSetMBarHeight(0);
-
- if (gOldGrayRgn == nil)
- {
- gOldGrayRgn = NewRgn();
- }
-
- CopyRgn(LMGetGrayRgn(), gOldGrayRgn);
-
- menuRgn = NewRgn();
- SetToMenuRect(menuRgn);
- UnionRgn(LMGetGrayRgn(), menuRgn, LMGetGrayRgn());
- PaintBehind(FrontWindow(), menuRgn);
- CalcVisBehind(FrontWindow(), menuRgn);
-
- DisposeRgn(menuRgn);
-
- gMenuBarHidden = true;
- }
- }
-
-
- void ShowMenuBar(void)
- {
- if (gMenuBarHidden)
- {
- if (!gAllowedClicks)
- LMSetMBarHeight(gOldMBarHeight);
-
- CopyRgn(gOldGrayRgn, LMGetGrayRgn());
- SetToMenuRect(gOldGrayRgn);
-
- PaintBehind(FrontWindow(), gOldGrayRgn);
- CalcVisBehind(FrontWindow(), gOldGrayRgn);
-
- DisposeRgn(gOldGrayRgn);
- gOldGrayRgn = nil;
-
- DrawMenuBar();
- gMenuBarHidden = false;
- }
- }
-
-
- void SetToMenuRect(RgnHandle menuRgn)
- {
- Rect menuRect;
-
- //menuRect = qd.screenBits.bounds;
- menuRect = (**GetMainDevice()).gdRect;
- menuRect.bottom = gOldMBarHeight;
-
- RectRgn(menuRgn, &menuRect);
- }
-
- // ---------------------------------------------------------------------------
-
- void GetMenuBarRect(Rect *mbarRect) {
- *mbarRect = (**GetMainDevice()).gdRect;
-
- if (gMenuBarHidden)
- mbarRect->bottom = gOldMBarHeight;
- else
- mbarRect->bottom = LMGetMBarHeight();
- } // END GetMenuBarRect
-
- // ---------------------------------------------------------------------------
-
- void Wait(long ticks) {
- long dummy;
- Delay(ticks, &dummy);
- } // END Wait