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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2002 Mutwin Kraus (Mac Port)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#include <Carbon.h>
#include <CarbonEvents.h>
#include <sioux.h>
#include <string.h>
#include <assert.h>
#include "scumm.h"
#include "sound.h"
#include "gui.h"
#define SRC_WIDTH 320
#define SRC_HEIGHT 200
#define SRC_PITCH (320)
int DEST_WIDTH, DEST_HEIGHT;
static bool shutdown;
KeyMap fKeyMap;
Rect srcRect, dstRect;
enum
{
kNewGameCmd = 'newG',
kQuitCmd = kHICommandQuit,
kOpenGameCmd = 'opnG',
kSaveGameCmd = 'savG',
kPrefsCmd = kHICommandPreferences,
kAboutCmd = 'abtG'
};
static unsigned char *CToPascal(char *str);
Boolean OptionKeyDown()
{
GetKeys(fKeyMap); // get info
if (fKeyMap[1] & 4)
return true;
else
return false;
}
Boolean CommandKeyDown()
{
GetKeys(fKeyMap); // get info
if (fKeyMap[1] & 0x8000)
return true;
else
return false;
}
Boolean ShiftKeyDown()
{
GetKeys(fKeyMap); // get info
if (fKeyMap[1] & 1)
return true;
else
return false;
}
// Fast macro for testing key codes.
#define KeyCode(x,y) (BitTst(&(x), (y) ^ 0x07))
Boolean IsKeyDown(unsigned short key)
{
GetKeys(fKeyMap); // get info
return (KeyCode(fKeyMap, key));
}
class WndMan
{
bool terminated;
public:
Scumm *_scumm;
byte *_vgabuf;
GWorldPtr screenBuf;
WindowRef wPtr;
CTabHandle pal;
bool newPal;
CCrsrHandle theCrsr;
bool fullscreen;
StringPtr gameName;
int scale;
GWorldPtr workSrcMap, backSrcMap;
GDHandle thisGDevice;
void init();
void ChangeScaling(short scaling);
bool handleMessage();
void run();
void writeToScreen();
void setPalette(byte *ctab, int first, int num);
};
int sel;
Scumm scumm;
ScummDebugger debugger;
Gui gui;
SoundEngine sound;
SOUND_DRIVER_TYPE snd_driv;
WndMan wm[1];
byte veryFastMode;
void About();
void Preferences();
void Quit()
{
QuitApplicationEventLoop();
ExitToShell();
}
void Error(const char* msg)
{
//DebugStr((const unsigned char*)msg);
//ExitToShell();
}
const EventTypeSpec kCmdEvents[] =
{
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp },
{ kEventClassMouse, kEventMouseMoved },
{ kEventClassKeyboard, kEventRawKeyDown },
{ kEventClassCommand, kEventProcessCommand }
};
const EventTypeSpec kWindowEvents[] =
{
{ kEventClassWindow, kEventWindowDrawContent },
{ kEventClassWindow, kEventWindowHandleContentClick },
{ kEventClassWindow, kEventWindowClose }
};
pascal OSErr QuitEventHandler(const AppleEvent *theEvent, AppleEvent *theReply, SInt32 refCon)
{
Quit();
return(noErr);
}
static pascal OSStatus WindowEventHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* userData )
{
OSStatus result = eventNotHandledErr;
if(GetEventClass(inEvent) == kEventClassWindow)
{
switch(GetEventKind(inEvent))
{
case kEventWindowDrawContent:
wm->writeToScreen();
break;
case kEventWindowHandleContentClick:
//debug(1, "Sending MouseDown");
if(CommandKeyDown())
wm->_scumm->_rightBtnPressed |= msClicked|msDown;
else
wm->_scumm->_leftBtnPressed |= msClicked|msDown;
break;
case kEventWindowClose:
Quit();
break;
}
}
return result;
}
static pascal OSStatus EventHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* userData )
{
OSStatus result = eventNotHandledErr;
HICommand command;
Point mouse;
GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL,
sizeof( HICommand ), NULL, &command );
switch(GetEventClass(inEvent))
{
case kEventClassCommand:
switch(command.commandID)
{
case kNewGameCmd:
break;
case kOpenGameCmd:
wm->_scumm->_saveLoadSlot = 0;
wm->_scumm->_saveLoadFlag = 2;
break;
case kSaveGameCmd:
wm->_scumm->_saveLoadSlot = 0;
sprintf(wm->_scumm->_saveLoadName, "Quicksave %d", wm->_scumm->_saveLoadSlot);
wm->_scumm->_saveLoadFlag = 1;
break;
case kQuitCmd:
Quit();
break;
case kPrefsCmd:
Preferences();
break;
case kAboutCmd:
About();
break;
}
break;
break;
case kEventClassKeyboard:
if(GetEventKind(inEvent) == kEventRawKeyDown)
{
char key;
GetEventParameter(inEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key);
wm->_scumm->_keyPressed = (int)key;
}
break;
case kEventClassMouse:
switch(GetEventKind(inEvent))
{
case kEventMouseDown:
WindowRef theWin;
GetEventParameter(inEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef),
NULL, &theWin);
if(theWin != FrontWindow())
{
ActivateWindow(theWin, true);
}
break;
case kEventMouseUp:
wm->_scumm->_rightBtnPressed &= ~msDown;
wm->_scumm->_leftBtnPressed &= ~msDown;
break;
case kEventMouseMoved:
GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mouse);
Rect winRect;
GetWindowBounds(wm->wPtr, kWindowContentRgn, &winRect);
if(PtInRect(mouse, &winRect))
{
CGrafPtr oldPort;
GetPort(&oldPort);
SetPortWindowPort(wm->wPtr);
GlobalToLocal(&mouse);
scumm.mouse.x = mouse.h/wm->scale;
scumm.mouse.y = mouse.v/wm->scale;
//debug(1, "Mouse X:%i Y:%i", scumm.mouse.x, scumm.mouse.y);
}
break;
}
break;
}
return result;
}
void pc_loop()
{
int delta;
int last_time, new_time, old_time = TickCount();
delta = 0;
do {
updateScreen(&scumm);
new_time = TickCount();
waitForTimer(&scumm, delta * 15 + last_time - new_time);
last_time = TickCount();
sound.on_timer();
if(gui._active) {
gui.loop();
delta = 3;
} else {
delta = scumm.scummLoop(delta);
}
} while(1);
}
pascal void DoGameLoop(EventLoopTimerRef theTimer, void *userData)
{
pc_loop();
QuitApplicationEventLoop();
}
void WndMan::init()
{
Rect rectWin;
_scumm->_scale = scale;
DEST_WIDTH = 320 * _scumm->_scale;
DEST_HEIGHT = 200 * _scumm->_scale;
MenuRef AppleMenu = GetMenu(1000);
InsertMenu(AppleMenu, 0);
SetMenuItemCommandID(AppleMenu, 1, kAboutCmd);
MenuRef FileMenu = GetMenu(1001);
SetMenuItemCommandID(FileMenu, 1, kNewGameCmd);
SetMenuItemCommandID(FileMenu, 2, kOpenGameCmd);
SetMenuItemCommandID(FileMenu, 3, kSaveGameCmd);
SetMenuItemCommandID(FileMenu, 5, kQuitCmd);
DeleteMenuItems(FileMenu, CountMenuItems(FileMenu)-1, 2);
InsertMenu(FileMenu, 0);
MenuRef windMenu;
CreateStandardWindowMenu(0, &windMenu);
InsertMenu(windMenu, 0);
EnableMenuCommand(NULL, kPrefsCmd);
DrawMenuBar();
SetRect(&rectWin, 0, 0, DEST_WIDTH, DEST_HEIGHT);
UInt32 WinAttrib = (kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute |
kWindowInWindowMenuAttribute | kWindowStandardHandlerAttribute);
if(noErr != CreateNewWindow(kDocumentWindowClass, WinAttrib, &rectWin, &wPtr))
{
Error("Couldn't create Window!");
}
RepositionWindow(wPtr, NULL, kWindowCenterOnMainScreen);
Str255 WindowTitle = "\pScummVM";
SetWTitle(wPtr, WindowTitle);
SetPortWindowPort(wPtr);
ShowWindow(wPtr);
SetRect(&dstRect, 0, 0, DEST_WIDTH, DEST_HEIGHT);
SetRect(&srcRect, 0, 0, SRC_WIDTH, SRC_HEIGHT);
InstallApplicationEventHandler(NewEventHandlerUPP(EventHandler),
GetEventTypeCount(kCmdEvents), kCmdEvents, 0, NULL);
InstallStandardEventHandler(GetWindowEventTarget(wPtr));
InstallWindowEventHandler(wPtr, NewEventHandlerUPP(WindowEventHandler),
GetEventTypeCount(kWindowEvents), kWindowEvents, 0, NULL);
OSStatus err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitEventHandler), 0L, false);
EventLoopTimerRef theTimer;
InstallEventLoopTimer(GetCurrentEventLoop(), 0, 0, NewEventLoopTimerUPP(DoGameLoop),
NULL, &theTimer);
NewGWorldFromPtr(&screenBuf, 8, &srcRect, pal, nil, 0, (char *)_vgabuf, SRC_WIDTH);
}
void WndMan::ChangeScaling(short scaling)
{
_scumm->_scale = scaling;
scale = scaling;
Rect rectWin;
DEST_WIDTH = 320 * _scumm->_scale;
DEST_HEIGHT = 200 * _scumm->_scale;
SetRect(&rectWin, 0, 0, DEST_WIDTH, DEST_HEIGHT);
SetWindowBounds(wPtr, kWindowContentRgn, &rectWin);
RepositionWindow(wPtr, NULL, kWindowCenterOnMainScreen);
dstRect = rectWin;
}
bool WndMan::handleMessage()
{
EventRef theEvent;
EventTargetRef theTarget;
OSStatus theErr;
theTarget = GetEventDispatcherTarget();
theErr = ReceiveNextEvent(GetEventTypeCount(kCmdEvents), kCmdEvents, kEventDurationNoWait,true, &theEvent);
if(theErr == noErr && theEvent != NULL)
{
SendEventToEventTarget (theEvent, theTarget);
ReleaseEvent(theEvent);
}
}
void WndMan::run()
{
}
void WndMan::writeToScreen()
{
//NewGWorldFromPtr(&screenBuf, 8, &srcRect, pal, nil, 0, (char *)_vgabuf, SRC_WIDTH);
CopyBits(GetPortBitMapForCopyBits(screenBuf),
GetPortBitMapForCopyBits(GetWindowPort(wPtr)),
&srcRect, &dstRect, srcCopy, 0L);
}
void waitForTimer(Scumm *s, int delay)
{
uint32 start_time;
if(s->_fastMode&2)
delay = 0;
else if(s->_fastMode&1)
delay = 10;
start_time = TickCount();
do {
wm->handleMessage();
if(TickCount() >= start_time + delay)
break;
} while (1);
}
void WndMan::setPalette(byte *ctab, int first, int num)
{
pal = (CTabHandle)NewHandleClear(sizeof(ColorTable) + 255 * sizeof(ColorSpec));
(*pal)->ctSeed = TickCount();
(*pal)->ctFlags = 0;
(*pal)->ctSize = 256;
for(int i = 0; i < 256; i++, ctab +=3)
{
(*pal)->ctTable[i].value = i;
(*pal)->ctTable[i].rgb.red = ctab[0]<<8;
(*pal)->ctTable[i].rgb.green = ctab[1]<<8;
(*pal)->ctTable[i].rgb.blue = ctab[2]<<8;
}
NewGWorldFromPtr(&screenBuf, 8, &srcRect, pal, nil, 0, (char *)_vgabuf, SRC_WIDTH);
}
void blitToScreen(Scumm *s, byte *src,int x, int y, int w, int h)
{
byte *dst;
int i;
dst = (byte*)wm->_vgabuf + y*320 + x;
do {
memcpy(dst, src, w);
dst += 320;
src += 320;
} while (--h);
}
void updateScreen(Scumm *s)
{
if (s->_palDirtyMax != -1) {
wm->setPalette(s->_currentPalette, 0, 256);
s->_palDirtyMax = -1;
}
wm->writeToScreen();
}
void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) {
s->_scale = scaleFactor;
wm->init();
}
static unsigned char *CToPascal(char *str)
{
register char *p,*q;
register long len;
len = strlen(str);
if (len > 255) len = 255;
p = str + len;
q = p-1;
while (p != str) *p-- = *q--;
*str = len;
return((unsigned char *)str);
}
static char *PascalToC(unsigned char *str)
{
register unsigned char *p,*q,*end;
end = str + *str;
q = (p=str) + 1;
while (p < end) *p++ = *q++;
*p = '\0';
return((char *)str);
}
ControlRef popUpControlRef, checkBoxControlRef;
char *gameTitle;
void LaunchGame(int id)
{
switch(id)
{
case 6:
gameTitle = "indy3";
break;
case 7:
gameTitle = "zak256";
break;
case 8:
gameTitle = "loom";
break;
case 9:
gameTitle = "monkeyEGA";
break;
case 10:
gameTitle = "loomcd";
break;
case 11:
gameTitle = "monkey";
break;
case 12:
gameTitle = "monkey2";
break;
case 13:
gameTitle = "atlantis";
break;
case 14:
gameTitle = "playfate";
break;
case 15:
gameTitle = "tentacle";
break;
case 16:
gameTitle = "dottdemo";
break;
case 17:
gameTitle = "samnmax";
break;
case 18:
gameTitle = "snmdemo";
break;
case 19:
gameTitle = "ft";
break;
case 20:
gameTitle = "dig";
}
}
OSStatus dialogEventHandler(EventHandlerCallRef eventHandlerCallRef,EventRef eventRef,
void *userData)
{
OSStatus result = eventNotHandledErr;
UInt32 eventClass;
UInt32 eventKind;
ControlRef controlRef;
ControlID controlID;
eventClass = GetEventClass(eventRef);
eventKind = GetEventKind(eventRef);
if(eventClass == kEventClassControl)
{
if(eventKind == kEventControlHit)
{
GetEventParameter(eventRef,kEventParamDirectObject,typeControlRef,NULL,
sizeof(ControlRef),NULL,&controlRef);
GetControlID(controlRef,&controlID);
if(controlID.id == 'okay')
{
QuitAppModalLoopForWindow((WindowRef)userData);
LaunchGame(GetControlValue(popUpControlRef));
if((Boolean)GetControlValue(checkBoxControlRef))
wm->scale = 2;
else
wm->scale = 3;
DisposeWindow((WindowRef)userData);
result = noErr;
}
else if(controlID.id == 'cncl')
{
QuitAppModalLoopForWindow((WindowRef)userData);
DisposeWindow((WindowRef)userData);
ExitToShell();
}
}
}
return result;
}
void SelectGame()
{
WindowRef aboutWin;
OSStatus osError = noErr;
Rect rect = { 0,0,120,350 };
Rect pushButtonRect = { 75,250,96,330 };
Rect popupRect = { 10, 10, 26, 330 };
ControlID controlID;
ControlRef controlRef;
Rect checkboxRect = { 36, 10, 50, 80 };
EventTypeSpec dialogEvents[] = { kEventClassControl, kEventControlHit };
osError = CreateNewWindow(kMovableModalWindowClass,kWindowStandardHandlerAttribute,&rect, &aboutWin);
RepositionWindow(aboutWin,FrontWindow(),kWindowAlertPositionOnMainScreen);
SetThemeWindowBackground(aboutWin,kThemeBrushDialogBackgroundActive,false);
CreateRootControl(aboutWin,&controlRef);
CreatePushButtonControl(aboutWin,&pushButtonRect,CFSTR("OK"),&controlRef);
SetWindowDefaultButton(aboutWin,controlRef);
controlID.id = 'okay';
SetControlID(controlRef,&controlID);
AutoEmbedControl(controlRef,aboutWin);
OffsetRect(&pushButtonRect, -100, 0);
CreatePushButtonControl(aboutWin,&pushButtonRect,CFSTR("Cancel"),&controlRef);
SetWindowCancelButton(aboutWin,controlRef);
controlID.id = 'cncl';
SetControlID(controlRef,&controlID);
AutoEmbedControl(controlRef,aboutWin);
CreateCheckBoxControl(aboutWin,&checkboxRect, CFSTR("Scaling"), 1,
true, &checkBoxControlRef);
AutoEmbedControl(checkBoxControlRef,aboutWin);
CreatePopupButtonControl(aboutWin, &popupRect, CFSTR("Game: "), 999, false, -1, 0, NULL, &popUpControlRef);
SetWindowDefaultButton(aboutWin,popUpControlRef);
controlID.id = 'game';
SetControlID(popUpControlRef,&controlID);
AutoEmbedControl(controlRef,aboutWin);
InstallWindowEventHandler(aboutWin, NewEventHandlerUPP((EventHandlerProcPtr) dialogEventHandler),
GetEventTypeCount(dialogEvents),dialogEvents,aboutWin,NULL);
ShowWindow(aboutWin);
osError = RunAppModalLoopForWindow(aboutWin);
}
static void DrawCenteredStringAt(Str255 theString, short yLocation)
{
Rect portRect;
CGrafPtr thePort = GetQDGlobalsThePort();
GetPortBounds(thePort, &portRect);
MoveTo(portRect.left + ((portRect.right-portRect.left) >> 1) -
(StringWidth(theString) >> 1), yLocation);
DrawString(theString);
}
void DrawAboutText(WindowRef win)
{
CGrafPtr oldPort;
GetPort(&oldPort);
SetPortWindowPort(win);
TextFont(systemFont);
TextSize(12);
DrawCenteredStringAt("\pAbout ScummVM�", 32);
TextFont(applFont);
TextSize(9);
DrawCenteredStringAt("\pScummVM", 50);
DrawCenteredStringAt("\pLet's you run all your favourite Scumm Games", 65);
DrawCenteredStringAt("\pon MacOS 9 and X", 80);
SetPort(oldPort);
}
OSStatus aboutEventHandler(EventHandlerCallRef eventHandlerCallRef,EventRef eventRef,
void *userData)
{
OSStatus result = eventNotHandledErr;
UInt32 eventClass;
UInt32 eventKind;
ControlRef controlRef;
ControlID controlID;
eventClass = GetEventClass(eventRef);
eventKind = GetEventKind(eventRef);
if(eventClass == kEventClassControl)
{
if(eventKind == kEventControlHit)
{
GetEventParameter(eventRef,kEventParamDirectObject,typeControlRef,NULL,
sizeof(ControlRef),NULL,&controlRef);
GetControlID(controlRef,&controlID);
if(controlID.id == 'okay')
{
QuitAppModalLoopForWindow((WindowRef)userData);
DisposeWindow((WindowRef)userData);
result = noErr;
}
}
}
else if(eventClass == kEventClassWindow)
{
if(eventKind == kEventWindowUpdate)
{
DrawAboutText((WindowRef)userData);
}
}
return result;
}
void About()
{
WindowRef aboutWin;
OSStatus osError = noErr;
Rect rect = { 0,0,150,300 };
Rect pushButtonRect = { 125,125,145,175 };
ControlID controlID;
ControlRef controlRef;
EventTypeSpec dialogEvents[] = { { kEventClassControl, kEventControlHit },
{ kEventClassWindow, kEventWindowUpdate} };
osError = CreateNewWindow(kMovableModalWindowClass,kWindowStandardHandlerAttribute,&rect, &aboutWin);
SetWTitle(aboutWin, "\pAbout ScummVM�");
RepositionWindow(aboutWin,FrontWindow(),kWindowAlertPositionOnMainScreen);
SetThemeWindowBackground(aboutWin,kThemeBrushDialogBackgroundActive,false);
CreateRootControl(aboutWin,&controlRef);
DrawAboutText(aboutWin);
CreatePushButtonControl(aboutWin,&pushButtonRect,CFSTR("OK"),&controlRef);
SetWindowDefaultButton(aboutWin,controlRef);
controlID.id = 'okay';
SetControlID(controlRef,&controlID);
AutoEmbedControl(controlRef,aboutWin);
InstallWindowEventHandler(aboutWin, NewEventHandlerUPP((EventHandlerProcPtr) aboutEventHandler),
GetEventTypeCount(dialogEvents),dialogEvents,aboutWin,NULL);
ShowWindow(aboutWin);
osError = RunAppModalLoopForWindow(aboutWin);
}
ControlRef radioGroupRef, musicVolumeSlider, masterVolumeSlider;
OSStatus prefsEventHandler(EventHandlerCallRef eventHandlerCallRef,EventRef eventRef,
void *userData)
{
OSStatus result = eventNotHandledErr;
UInt32 eventClass;
UInt32 eventKind;
ControlRef controlRef;
ControlID controlID;
eventClass = GetEventClass(eventRef);
eventKind = GetEventKind(eventRef);
if(eventClass == kEventClassControl)
{
if(eventKind == kEventControlHit)
{
GetEventParameter(eventRef,kEventParamDirectObject,typeControlRef,NULL,
sizeof(ControlRef),NULL,&controlRef);
GetControlID(controlRef,&controlID);
if(controlID.id == 'okay')
{
wm->_scumm->_noSubtitles = (Boolean)!GetControlValue(checkBoxControlRef);
short scale = GetControlValue(radioGroupRef);
if(scale != wm->_scumm->_scale)
wm->ChangeScaling(scale);
short music_vol = GetControlValue(musicVolumeSlider);
if(music_vol != sound.get_music_volume())
sound.set_music_volume(music_vol);
short master_vol = GetControlValue(masterVolumeSlider);
if(master_vol != sound.get_master_volume())
sound.set_master_volume(master_vol);
QuitAppModalLoopForWindow((WindowRef)userData);
DisposeWindow((WindowRef)userData);
result = noErr;
}
}
}
}
void Preferences()
{
WindowRef prefsWin;
OSStatus osError = noErr;
Rect rect = { 0,0,210,300 };
Rect okButtonRect;
ControlID controlID;
ControlRef controlRef;
EventTypeSpec dialogEvents[] = { kEventClassControl, kEventControlHit };
osError = CreateNewWindow(kMovableModalWindowClass,kWindowStandardHandlerAttribute,&rect, &prefsWin);
SetWTitle(prefsWin, "\pPreferences");
RepositionWindow(prefsWin,FrontWindow(),kWindowAlertPositionOnMainScreen);
SetThemeWindowBackground(prefsWin,kThemeBrushDialogBackgroundActive,false);
CreateRootControl(prefsWin,&controlRef);
SetRect(&rect, 5, 5, 150, 21);
CreateStaticTextControl(prefsWin, &rect, CFSTR("ScummVM Preferences"), NULL, &controlRef);
AutoEmbedControl(controlRef, prefsWin);
SetRect(&okButtonRect, 225, 180, 295, 200);
CreatePushButtonControl(prefsWin,&okButtonRect,CFSTR("OK"),&controlRef);
SetWindowDefaultButton(prefsWin,controlRef);
controlID.id = 'okay';
SetControlID(controlRef,&controlID);
AutoEmbedControl(controlRef,prefsWin);
SetRect(&rect, 150, 35, 260, 51);
CreateCheckBoxControl(prefsWin,&rect, CFSTR("Subtitles"), 1, true, &checkBoxControlRef);
AutoEmbedControl(checkBoxControlRef, prefsWin);
if(wm->_scumm->_noSubtitles)
SetControlValue(checkBoxControlRef, false);
OffsetRect(&rect, 0, 20);
CreateCheckBoxControl(prefsWin,&rect, CFSTR("Fullscreen"), 0, true, &controlRef);
AutoEmbedControl(controlRef, prefsWin);
DeactivateControl(controlRef);
Rect RadioGroupRect;
SetRect(&RadioGroupRect, 5, 35, 120, 100);
CreateRadioGroupControl(prefsWin, &RadioGroupRect, &radioGroupRef);
AutoEmbedControl(radioGroupRef, prefsWin);
ControlRef radioButton;
Rect RadioButtonRect;
SetRect(&RadioButtonRect, 5, 35, 120, 51);
CreateRadioButtonControl(prefsWin, &RadioButtonRect, CFSTR("Scaling 1x"), 0, true, &radioButton);
AutoEmbedControl(radioButton, prefsWin);
OffsetRect(&RadioButtonRect, 0, 20);
CreateRadioButtonControl(prefsWin, &RadioButtonRect, CFSTR("Scaling 2x"), 0, true, &radioButton);
AutoEmbedControl(radioButton, prefsWin);
OffsetRect(&RadioButtonRect, 0, 20);
CreateRadioButtonControl(prefsWin, &RadioButtonRect, CFSTR("Scaling 3x"), 0, true, &radioButton);
AutoEmbedControl(radioButton, prefsWin);
SetControlValue(radioGroupRef, wm->_scumm->_scale);
SetRect(&rect, 5, 110, 175, 146);
CreateSliderControl(prefsWin, &rect, sound.get_music_volume(), 1, 100,
kControlSliderPointsDownOrRight, 10, false, NULL, &musicVolumeSlider);
AutoEmbedControl(musicVolumeSlider, prefsWin);
OffsetRect(&rect, 0, 36);
CreateSliderControl(prefsWin, &rect, sound.get_master_volume(), 1, 100,
kControlSliderPointsDownOrRight, 10, false, NULL, &masterVolumeSlider);
AutoEmbedControl(masterVolumeSlider, prefsWin);
OffsetRect(&rect, 180, -36);
CreateStaticTextControl(prefsWin, &rect, CFSTR("Music Volume"), NULL, &controlRef);
AutoEmbedControl(controlRef, prefsWin);
OffsetRect(&rect, 0, 36);
CreateStaticTextControl(prefsWin, &rect, CFSTR("Master Volume"), NULL, &controlRef);
AutoEmbedControl(controlRef, prefsWin);
InstallWindowEventHandler(prefsWin, NewEventHandlerUPP((EventHandlerProcPtr) prefsEventHandler),
GetEventTypeCount(dialogEvents),dialogEvents,prefsWin,NULL);
ShowWindow(prefsWin);
osError = RunAppModalLoopForWindow(prefsWin);
}
/* FIXME: CD Music Stubs */
void cd_playtrack(int track, int offset, int delay) {;}
void cd_play(int track, int num_loops, int start_frame, int end_frame) {;}
void cd_stop() {;}
int cd_is_running() {return 0;}
void launcherLoop() {
/* No launcher an Mac yet, probably there won't ever be one, as */
/* there is a nice Mac-like Launcher already. */
}
void BoxTest(int num) {
}
void setShakePos(Scumm *s, int shake_pos) {}
void InitMacStuff()
{
InitCursor();
SIOUXSettings.autocloseonquit = true;
SIOUXSettings.asktosaveonclose = false;
SIOUXSettings.showstatusline = false;
SIOUXSettings.fontsize = 9;
GetFNum("\pMonaco",&SIOUXSettings.fontid);
SIOUXSettings.standalone = false;
SIOUXSettings.setupmenus = false;
}
void setWindowName(Scumm *scumm)
{
StringPtr gameText = CToPascal(scumm->getGameName());
SetWTitle(wm->wPtr, gameText);
}
void main(void)
{
InitMacStuff();
SelectGame();
// initGraphics(&scumm, wm->fullscreen, wm->scale);
wm->_vgabuf = (byte*)calloc(320,200);
wm->_scumm = &scumm;
sound.initialize(&scumm,&snd_driv);
scumm._gui = &gui;
scumm.scummMain(2, &gameTitle);
setWindowName(wm->_scumm);
if (!(scumm._features & GF_SMALL_HEADER))
gui.init(&scumm);
scumm._fastMode = true;
veryFastMode = true;
RunApplicationEventLoop();
return;
}
|