Download
Mu0n
/MovieCrawl
/Misc.c
(View History)
1 | /* Misc.c |
2 | */ |
3 | |
4 | #include "Misc.h" |
5 | /*------ InitMacStuff |
6 | Inits all the Toolbox managers |
7 | ---------*/ |
8 | void InitMacStuff(void) |
9 | { |
10 | InitGraf(&qd.thePort); |
11 | InitFonts(); |
12 | InitWindows(); |
13 | InitMenus(); |
14 | TEInit(); |
15 | InitDialogs(nil); |
16 | InitCursor(); |
17 | GetDateTime((unsigned long *)(&qd.randSeed)); |
18 | FlushEvents(everyEvent,0); |
19 | } |
20 | /*------ End of initMacStuff ------*/ |
21 | |
22 | /*------ Hide Menu bar |
23 | 1) HideMyMenuBar(); Explicit use |
24 | 2) ShowMyMenuBar(); Explicit use |
25 | |
26 | ----------*/ |
27 | void HideMyMenuBar(void) |
28 | { |
29 | Rect rcMBar; |
30 | short *setMBarHeight; |
31 | |
32 | setMBarHeight=(short *)0x0BAA; |
33 | |
34 | if ( gs_hrgnMBar == 0L) { |
35 | |
36 | gs_dyMBar = GetMBarHeight(); |
37 | |
38 | *setMBarHeight=0; |
39 | |
40 | rcMBar = qd.screenBits.bounds; |
41 | rcMBar.bottom = rcMBar.top + gs_dyMBar; |
42 | |
43 | gs_hrgnMBar = NewRgn(); |
44 | RectRgn( gs_hrgnMBar, &rcMBar ); |
45 | UnionRgn( GetGrayRgn(), gs_hrgnMBar, GetGrayRgn() ); |
46 | PaintOne(nil,gs_hrgnMBar); |
47 | } |
48 | } |
49 | |
50 | void ShowMyMenuBar(void) |
51 | { |
52 | short *setMBarHeight; |
53 | setMBarHeight=(short *)0x0BAA; |
54 | |
55 | if( gs_hrgnMBar) { |
56 | |
57 | *setMBarHeight=gs_dyMBar; |
58 | DiffRgn(GetGrayRgn(), gs_hrgnMBar, GetGrayRgn()); |
59 | DisposeRgn(gs_hrgnMBar); |
60 | gs_hrgnMBar=0L; |
61 | } |
62 | } |
63 | /*------- End of Hide Menu Bar -------*/ |
64 | |
65 | |
66 | /*--------- Ranged Random -----------*/ |
67 | unsigned short rangeRandom( unsigned short min, unsigned short max ) |
68 | /* the function will calculate the correct max and min values */ |
69 | { |
70 | long range; |
71 | long randomNumber; |
72 | |
73 | range = MAX(min,max) - MIN(min,max) + 1; |
74 | randomNumber=Random(); |
75 | randomNumber=ABS(randomNumber); |
76 | |
77 | return( (randomNumber * range)/kRandomUpperLimit+min); |
78 | } |
79 | /*--------- End of Ranged Random -----------*/ |
80 | |
81 | |
82 | |
83 | /* Mac Plus Area - creates a 512x342 screen centered in the middle, with correct |
84 | Clip region. If the screen is larger than that, makes a border with borderPat as its |
85 | pattern. */ |
86 | |
87 | void MacPlusArea(Pattern borderPat, Pattern middlePat,Boolean wantMenus) |
88 | { |
89 | WindowPtr window; |
90 | Rect r; |
91 | |
92 | r=qd.screenBits.bounds; |
93 | r.top=kMenuBarHeight; |
94 | |
95 | if(kScreenWidth <=512 && kScreenHeight <=342) |
96 | { |
97 | WholeScreen(middlePat,wantMenus); |
98 | } |
99 | else |
100 | { |
101 | |
102 | if(wantMenus) window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); |
103 | else window=NewWindow(nil,&(qd.screenBits.bounds),nil,true,plainDBox,kMoveToFront,false,0); |
104 | |
105 | SetPort(window); |
106 | FillRect(&(window->portRect), borderPat); |
107 | |
108 | if(wantMenus) { |
109 | PortSize(512,362); |
110 | MovePortTo((kScreenWidth-512)/2,(kScreenHeight-342-kMenuBarHeight)/2); |
111 | } |
112 | else { |
113 | MovePortTo((kScreenWidth-512)/2,(kScreenHeight-342)/2); |
114 | PortSize(512,342); |
115 | } |
116 | ClipRect(&(window->portRect)); |
117 | CLS(middlePat,wantMenus); |
118 | } |
119 | } |
120 | |
121 | WindowPtr ForceMacPlusScreen(Pattern thePat, Boolean wantMenus){ |
122 | WindowPtr window; |
123 | Rect r; |
124 | |
125 | SetRect(&r,0,0,512,342); |
126 | if(wantMenus) window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); |
127 | else window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); |
128 | SetPort(window); |
129 | |
130 | FillRect(&(window->portRect), thePat); |
131 | return window; |
132 | } |
133 | |
134 | |
135 | |
136 | /*--------- CLS ---------------*/ |
137 | void CLS(Pattern thePat, Boolean wantMenus) |
138 | { |
139 | Rect r; |
140 | WindowPtr window; |
141 | |
142 | GetPort(&window); |
143 | |
144 | r=window->portRect; |
145 | r.top=kMenuBarHeight; |
146 | |
147 | if(wantMenus) FillRect(&r,thePat); |
148 | else FillRect(&(window->portRect),thePat); |
149 | } |
150 | /*--------- End of CLS --------*/ |
151 | |
152 | /* WholeScreen - Will create a screen-sized featureless window filled with the pattern |
153 | of your choice. You are responsible to deal with any previous windows and ports |
154 | NOTE: use DisposeWindow to get rid of it */ |
155 | |
156 | WindowPtr WholeScreen(Pattern thePat, Boolean wantMenus) |
157 | { |
158 | WindowPtr window; |
159 | Rect r; |
160 | |
161 | r=qd.screenBits.bounds; |
162 | r.top=kMenuBarHeight; |
163 | |
164 | if(wantMenus) window=NewWindow(nil,&r,nil,true,plainDBox,kMoveToFront,false,0); |
165 | else window=NewWindow(nil,&(qd.screenBits.bounds),nil,true,plainDBox,kMoveToFront,false,0); |
166 | SetPort(window); |
167 | |
168 | FillRect(&(window->portRect), thePat); |
169 | return window; |
170 | } |
171 | |
172 | short OldLoadFile(SFTypeList myTypes) |
173 | { |
174 | SFReply reply; //GetFile reply |
175 | short openResult=0; //trails file number |
176 | long count; //used to read the data |
177 | Point where={50,50};//SFGetFile dialog location |
178 | |
179 | SFGetFile(where,"\pSelect a file",0L,1,myTypes,0L,&reply); |
180 | |
181 | if(reply.good) FSOpen(reply.fName,reply.vRefNum,&openResult); |
182 | return openResult; |
183 | } |
184 | |
185 | int GetScreenWidth(void) |
186 | { |
187 | return qd.screenBits.bounds.right-qd.screenBits.bounds.left; |
188 | } |
189 | |
190 | int GetScreenHeight(void) |
191 | { |
192 | return qd.screenBits.bounds.bottom-qd.screenBits.bounds.top; |
193 | } |
194 | |
195 | void PStringCat(Str255 a, Str255 b) |
196 | { |
197 | short len; |
198 | |
199 | if((a[0]+b[0]) > 255) len = 255-a[0]; |
200 | else len = b[0]; |
201 | |
202 | BlockMove(&(b[1]),&(a[a[0]+1]),len); |
203 | a[0] += len; |
204 | } |
205 | |
206 | void PStringCopy(Str255 a, Str255 b) |
207 | { |
208 | BlockMove(a,b,a[0]+1); |
209 | } |