-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMandyWindow.c
More file actions
248 lines (211 loc) · 8.17 KB
/
Copy pathMandyWindow.c
File metadata and controls
248 lines (211 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*****
* MandyWindow.c
*
* A simple fractal generator
*
*
*****/
#include "mwMenus.h"
#include "mwWindow.h"
#include "mwInfo.h"
#include "mwColourCycle.h"
#include "mwZoom.h"
#include <GestaltEqu.h>
extern WindowPtr mwWindow;
extern Rect dragRect;
Boolean gHasColourQD;
Boolean gHasFPU;
/* Arrow key character codes - the low byte of a keyDown/autoKey
event's message field when the key pressed is an arrow key, with no
modifiers changing it. These are long-standing, fixed values (in
use since the original 128K Mac) rather than anything tied to a
particular header set, so they're given directly here instead of
relying on a symbolic constant that may or may not be defined in
this project's (System 6/7-era) headers - the same reasoning
that's kept this project away from newer, occasionally-unlinked
Toolbox calls elsewhere (see mwColourCycle.c). */
#define kLeftArrowKeyCode 0x1C
#define kRightArrowKeyCode 0x1D
#define kUpArrowKeyCode 0x1E
#define kDownArrowKeyCode 0x1F
void InitMacintosh(void);
void HandleMouseDown (EventRecord *theEvent);
void HandleEvent(void);
static Boolean HasColourQuickDraw(void);
static Boolean HasFPU(void);
/* InitMacintosh()
Initialize all the managers & memory */
void InitMacintosh(void) {
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
gHasColourQD = HasColourQuickDraw();
gHasFPU = HasFPU();
}
/* HasColourQuickDraw()
This gates not just RGBForeColor()/PaintRect()/NewCWindow() (which
only need basic Color QuickDraw, gestalt8BitQD) but also NewGWorld()
and friends, which are a distinct, later capability - "32-Bit
QuickDraw" - that a real machine can lack even with basic colour
present (an early colour Mac on a System without that extension,
for instance). Checking gestalt32BitQD covers both, since it
implies gestalt8BitQD. Calling a GWorld routine on a system that
only has basic Color QuickDraw is exactly the kind of thing that
can crash instead of failing gracefully, since the call may not
exist as a real trap at all rather than returning an error.
The SysEnvirons() fallback is for systems old enough to predate the
Gestalt Manager - in practice that's early System 6 on 68000 Macs,
which never had colour hardware anyway, so this branch is mostly
defensive completeness. It can only report basic colour presence,
not 32-Bit QuickDraw specifically, so it's a narrower guarantee
than the Gestalt check above - accepted here since a real machine
old enough to lack Gestalt but with a GWorld-capable colour card is
vanishingly unlikely to exist. */
static Boolean HasColourQuickDraw(void) {
long qdVersion;
if (Gestalt(gestaltQuickdrawVersion, &qdVersion) == noErr)
return qdVersion >= gestalt32BitQD;
{
SysEnvRec environment;
if (SysEnvirons(1, &environment) == noErr)
return environment.hasColorQD;
}
return false;
}
/* HasFPU()
Checks for a real 68881/68882/68040 FPU via gestaltFPUType, per
Apple's own explicit guidance that no CPU generation should be
assumed to imply - or lack - one: some 68020/68030 Macs (the IIsi
among them) shipped with the FPU as an optional, user-installed
part, so a conditional branch to floating-point code must check
this directly rather than infer it from the processor type.
Chooses between two entirely different numeric representations for
the fractal iteration loop - see mwFractalMath.c's IterateEscapeTimeDouble()
(double, for real hardware floating point) and
IterateEscapeTimeFixed() (fixed-point, avoiding SANE's software
floating-point emulation on this project's stated minimum target,
a Mac Plus, entirely).
Defaults to false (no FPU) if Gestalt itself is unavailable - a
pre-Gestalt, System 6.0.4-or-earlier machine, vanishingly rare in
practice, and, if it exists, no worse served by the fixed-point
path than a real 68000 already is. */
static Boolean HasFPU(void) {
long fpuType;
if (Gestalt(gestaltFPUType, &fpuType) == noErr)
return fpuType != gestaltNoFPU;
return false;
}
void HandleMouseDown (EventRecord *theEvent) {
WindowPtr theWindow;
int windowCode = FindWindow (theEvent->where, &theWindow);
switch (windowCode) {
case inSysWindow:
SystemClick (theEvent, theWindow);
break;
case inMenuBar:
AdjustMenus();
HandleMenu(MenuSelect(theEvent->where));
break;
case inDrag:
if (theWindow == mwWindow)
DragWindow(mwWindow, theEvent->where, &dragRect);
else if (IsInfoWindow(theWindow))
DragWindow(theWindow, theEvent->where, &dragRect);
break;
case inContent:
if (theWindow == mwWindow) {
if (theWindow != FrontWindow())
SelectWindow(mwWindow);
else
TrackMarqueeAndZoom(theEvent->where);
} else if (IsInfoWindow(theWindow)) {
if (theWindow != FrontWindow())
SelectWindow(theWindow);
else
HandleInfoWindowClick(theEvent->where);
}
break;
case inGoAway:
if (theWindow == mwWindow &&
TrackGoAway(mwWindow, theEvent->where))
HideWindow(mwWindow);
else if (IsInfoWindow(theWindow) &&
TrackGoAway(theWindow, theEvent->where))
CloseInfoWindow();
break;
case inGrow:
if (theWindow == mwWindow)
TrackWindowResize(theEvent->where);
break;
}
}
void HandleEvent(void) {
int ok;
EventRecord theEvent;
HiliteMenu(0);
SystemTask (); /* Handle desk accessories */
ok = GetNextEvent (everyEvent, &theEvent);
if (ok) {
switch (theEvent.what) {
case mouseDown:
HandleMouseDown(&theEvent);
break;
case keyDown:
case autoKey:
if ((theEvent.modifiers & cmdKey) != 0) {
char keyChar = (char) (theEvent.message & charCodeMask);
if (keyChar == '.') {
AbortFractalRender();
} else {
AdjustMenus();
HandleMenu(MenuKey(keyChar));
}
} else {
unsigned char keyCode = (unsigned char) (theEvent.message & charCodeMask);
if (keyCode == kUpArrowKeyCode || keyCode == kRightArrowKeyCode)
AnimationArrowKeyPressed(true);
else if (keyCode == kDownArrowKeyCode || keyCode == kLeftArrowKeyCode)
AnimationArrowKeyPressed(false);
else if (keyCode == '+')
KeyboardZoom(true);
else if (keyCode == '-')
KeyboardZoom(false);
}
break;
case updateEvt: {
WindowPtr windowToUpdate = (WindowPtr) theEvent.message;
if (windowToUpdate == mwWindow) {
BeginUpdate(mwWindow);
DrawContent(((WindowPeek) mwWindow)->hilited);
EndUpdate(mwWindow);
} else if (IsInfoWindow(windowToUpdate)) {
BeginUpdate(windowToUpdate);
DrawInfoWindowContent();
EndUpdate(windowToUpdate);
}
break;
}
case activateEvt:
InvalRect(&mwWindow->portRect);
break;
}
} else {
AdvanceFractalRender();
RefreshInfoWindowIfNeeded();
AnimationTask();
}
}
void main(void) {
InitMacintosh();
SetUpMenus();
SetUpWindow();
for (;;) {
HandleEvent();
}
}