AmendHub

Download:

Mu0n

/

MovieCrawl

/

amendments

/

3

Added Misc.c and Misc.h which contain helper functions that I made a long time ago that are used in the project; MacPlusArea sets up an centered, active 512x342 area; HideMyMenuBar and ShowMyMenuBar are self-explanatory.


Mu0n made amendment 3 over 2 years ago
--- Misc.c Tue Jan 19 15:19:45 2021 +++ Misc.c Tue Jan 19 15:19:45 2021 @@ -0,0 +1,209 @@ +/* Misc.c + */ + +#include "Misc.h" +/*------ InitMacStuff + Inits all the Toolbox managers + ---------*/ +void InitMacStuff(void) +{ +InitGraf(&qd.thePort); +InitFonts(); +InitWindows(); +InitMenus(); +TEInit(); +InitDialogs(nil); +InitCursor(); +GetDateTime((unsigned long *)(&qd.randSeed)); +FlushEvents(everyEvent,0); +} +/*------ End of initMacStuff ------*/ + +/*------ Hide Menu bar + 1) HideMyMenuBar(); Explicit use + 2) ShowMyMenuBar(); Explicit use + + ----------*/ +void HideMyMenuBar(void) + { + Rect rcMBar; + short *setMBarHeight; + + setMBarHeight=(short *)0x0BAA; + + if ( gs_hrgnMBar == 0L) { + + gs_dyMBar = GetMBarHeight(); + + *setMBarHeight=0; + + rcMBar = qd.screenBits.bounds; + rcMBar.bottom = rcMBar.top + gs_dyMBar; + + gs_hrgnMBar = NewRgn(); + RectRgn( gs_hrgnMBar, &rcMBar ); + UnionRgn( GetGrayRgn(), gs_hrgnMBar, GetGrayRgn() ); + PaintOne(nil,gs_hrgnMBar); + } + } + +void ShowMyMenuBar(void) + { + short *setMBarHeight; + setMBarHeight=(short *)0x0BAA; + + if( gs_hrgnMBar) { + + *setMBarHeight=gs_dyMBar; + DiffRgn(GetGrayRgn(), gs_hrgnMBar, GetGrayRgn()); + DisposeRgn(gs_hrgnMBar); + gs_hrgnMBar=0L; + } + } + /*------- End of Hide Menu Bar -------*/ + + +/*--------- Ranged Random -----------*/ +unsigned short rangeRandom( unsigned short min, unsigned short max ) +/* the function will calculate the correct max and min values */ +{ + long range; + long randomNumber; + + range = MAX(min,max) - MIN(min,max) + 1; + randomNumber=Random(); + randomNumber=ABS(randomNumber); + + return( (randomNumber * range)/kRandomUpperLimit+min); +} +/*--------- End of Ranged Random -----------*/ + + + +/* Mac Plus Area - creates a 512x342 screen centered in the middle, with correct +Clip region. If the screen is larger than that, makes a border with borderPat as its +pattern. */ + +void MacPlusArea(Pattern borderPat, Pattern middlePat,Boolean wantMenus) +{ +WindowPtr window; +Rect r; + +r=qd.screenBits.bounds; +r.top=kMenuBarHeight; + +if(kScreenWidth <=512 && kScreenHeight <=342) + { + WholeScreen(middlePat,wantMenus); + } +else + { + + if(wantMenus) window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); + else window=NewWindow(nil,&(qd.screenBits.bounds),nil,true,plainDBox,kMoveToFront,false,0); + + SetPort(window); + FillRect(&(window->portRect), borderPat); + + if(wantMenus) { + PortSize(512,362); + MovePortTo((kScreenWidth-512)/2,(kScreenHeight-342-kMenuBarHeight)/2); + } + else { + MovePortTo((kScreenWidth-512)/2,(kScreenHeight-342)/2); + PortSize(512,342); + } + ClipRect(&(window->portRect)); + CLS(middlePat,wantMenus); + } +} + +WindowPtr ForceMacPlusScreen(Pattern thePat, Boolean wantMenus){ +WindowPtr window; +Rect r; + +SetRect(&r,0,0,512,342); +if(wantMenus) window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); +else window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); +SetPort(window); + +FillRect(&(window->portRect), thePat); +return window; +} + + + +/*--------- CLS ---------------*/ +void CLS(Pattern thePat, Boolean wantMenus) +{ +Rect r; +WindowPtr window; + +GetPort(&window); + +r=window->portRect; +r.top=kMenuBarHeight; + +if(wantMenus) FillRect(&r,thePat); +else FillRect(&(window->portRect),thePat); +} +/*--------- End of CLS --------*/ + +/* WholeScreen - Will create a screen-sized featureless window filled with the pattern + of your choice. You are responsible to deal with any previous windows and ports + NOTE: use DisposeWindow to get rid of it */ + +WindowPtr WholeScreen(Pattern thePat, Boolean wantMenus) +{ +WindowPtr window; +Rect r; + +r=qd.screenBits.bounds; +r.top=kMenuBarHeight; + +if(wantMenus) window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); +else window=NewWindow(nil,&(qd.screenBits.bounds),nil,true,plainDBox,kMoveToFront,false,0); +SetPort(window); + +FillRect(&(window->portRect), thePat); +return window; +} + +short OldLoadFile(SFTypeList myTypes) + { + SFReply reply; //GetFile reply + short openResult=0; //trails file number + long count; //used to read the data + Point where={50,50};//SFGetFile dialog location + + SFGetFile(where,"\pSelect a file",0L,1,myTypes,0L,&reply); + + if(reply.good) FSOpen(reply.fName,reply.vRefNum,&openResult); + return openResult; + } + +int GetScreenWidth(void) + { + return qd.screenBits.bounds.right-qd.screenBits.bounds.left; + } + +int GetScreenHeight(void) + { + return qd.screenBits.bounds.bottom-qd.screenBits.bounds.top; + } + +void PStringCat(Str255 a, Str255 b) + { + short len; + + if((a[0]+b[0]) > 255) len = 255-a[0]; + else len = b[0]; + + BlockMove(&(b[1]),&(a[a[0]+1]),len); + a[0] += len; + } + +void PStringCopy(Str255 a, Str255 b) + { + BlockMove(a,b,a[0]+1); + } --- Misc.h Tue Jan 19 14:48:42 2021 +++ Misc.h Tue Jan 19 14:48:42 2021 @@ -0,0 +1,45 @@ +/* Misc.h + */ + + +#ifndef __MISCH__ +#define __MISCH__ + +#define kBaseResID 128 +#define kMoveToFront (WindowPtr)-1L +#define kRandomUpperLimit 32768 +#define kScrollBarAdjust (16-1) +#define kScrollBarWidth 16 +#define kScreenWidth (qd.screenBits.bounds.right-qd.screenBits.bounds.left) +#define kScreenHeight (qd.screenBits.bounds.bottom-qd.screenBits.bounds.top) +#define kMacPlusHeight 342 +#define kMacPlusWidth 512 +#define kMenuBarHeight 20 + +#define MAX(A,B) (A>B?A:B) +#define MIN(A,B) (A>B?B:A) +#define SQUARE(A) A*A +#define ABS(A) (A<0?-A:A) + +/*------ Constants -------*/ +/* Part 1: Used in menu bar hiding*/ +static short gs_dyMBar = 0; +static RgnHandle gs_hrgnMBar = 0; +/* Part 2: */ +/*------ End of Constants -------*/ + +void InitMacStuff(void); +void HideMyMenuBar(void); +void ShowMyMenuBar(void); +unsigned short rangeRandom( unsigned short min, unsigned short max ); +WindowPtr WholeScreen(Pattern thePat, Boolean wantMenus); +void MacPlusArea(Pattern borderPat, Pattern middlePat, Boolean wantMenus); +WindowPtr ForceMacPlusScreen(Pattern thePath, Boolean wantMenus); +void CLS(Pattern thePat, Boolean wantMenus); +short OldLoadFile(SFTypeList myTypes); // Must FSClose the short it returns when finished with the file +int GetScreenWidth(void); +int GetScreenHeight(void); +void PStringCat(Str255 a, Str255 b); +void PStringCopy(Str255 a, Str255 b); + +#endif