2002-03-08 17:23:31 +00:00
|
|
|
|
/* 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>
|
|
|
|
|
|
2002-04-07 18:32:20 +00:00
|
|
|
|
#include "stdafx.h"
|
2002-03-08 17:23:31 +00:00
|
|
|
|
#include "scumm.h"
|
|
|
|
|
#include "gui.h"
|
2002-04-07 18:32:20 +00:00
|
|
|
|
#include "cdmusic.h"
|
|
|
|
|
#include "gameDetector.h"
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
|
|
|
|
#define SRC_WIDTH 320
|
|
|
|
|
#define SRC_HEIGHT 200
|
|
|
|
|
#define SRC_PITCH (320)
|
|
|
|
|
|
2002-04-07 18:32:20 +00:00
|
|
|
|
#define MS_PER_TICK (1000.0/60.0)
|
|
|
|
|
|
|
|
|
|
int Time()
|
|
|
|
|
{
|
|
|
|
|
UnsignedWide ms;
|
|
|
|
|
|
|
|
|
|
Microseconds(&ms);
|
|
|
|
|
//return(ms.lo * MS_PER_TICK);
|
|
|
|
|
return(ms.lo / 1000);
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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:
|
|
|
|
|
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();
|
|
|
|
|
|
2002-03-10 15:36:32 +00:00
|
|
|
|
void ChangeScaling(short scaling);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
bool handleMessage();
|
|
|
|
|
void run();
|
|
|
|
|
void writeToScreen();
|
|
|
|
|
void setPalette(byte *ctab, int first, int num);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int sel;
|
2002-04-07 18:32:20 +00:00
|
|
|
|
Scumm *scumm;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
ScummDebugger debugger;
|
|
|
|
|
Gui gui;
|
2002-04-14 18:13:08 +00:00
|
|
|
|
IMuse sound;
|
2002-03-14 14:16:20 +00:00
|
|
|
|
SOUND_DRIVER_TYPE snd_driv;
|
2002-04-07 18:32:20 +00:00
|
|
|
|
OSystem _system;
|
|
|
|
|
GameDetector detector;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
|
|
|
|
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 },
|
2002-03-18 16:34:57 +00:00
|
|
|
|
{ kEventClassCommand, kEventProcessCommand }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const EventTypeSpec kWindowEvents[] =
|
|
|
|
|
{
|
|
|
|
|
{ kEventClassWindow, kEventWindowDrawContent },
|
|
|
|
|
{ kEventClassWindow, kEventWindowHandleContentClick },
|
2002-03-08 17:23:31 +00:00
|
|
|
|
{ kEventClassWindow, kEventWindowClose }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pascal OSErr QuitEventHandler(const AppleEvent *theEvent, AppleEvent *theReply, SInt32 refCon)
|
|
|
|
|
{
|
|
|
|
|
Quit();
|
|
|
|
|
return(noErr);
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-18 16:34:57 +00:00
|
|
|
|
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:
|
|
|
|
|
if(CommandKeyDown())
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_rightBtnPressed |= msClicked|msDown;
|
2002-03-18 16:34:57 +00:00
|
|
|
|
else
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_leftBtnPressed |= msClicked|msDown;
|
|
|
|
|
|
|
|
|
|
if(wm->wPtr != FrontWindow())
|
|
|
|
|
{
|
|
|
|
|
ActivateWindow(wm->wPtr, true);
|
|
|
|
|
BringToFront(wm->wPtr);
|
|
|
|
|
}
|
2002-03-18 16:34:57 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kEventWindowClose:
|
|
|
|
|
Quit();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
char mapKey(char key, char code, byte mod)
|
|
|
|
|
{
|
|
|
|
|
switch(code)
|
|
|
|
|
{
|
|
|
|
|
case 0x35:
|
|
|
|
|
key = 27;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x31:
|
|
|
|
|
key = 32;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 0x60:
|
|
|
|
|
key = 601;
|
|
|
|
|
}
|
|
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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:
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_saveLoadSlot = 0;
|
|
|
|
|
scumm->_saveLoadFlag = 2;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kSaveGameCmd:
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_saveLoadSlot = 0;
|
|
|
|
|
sprintf(scumm->_saveLoadName, "Quicksave %d", scumm->_saveLoadSlot);
|
|
|
|
|
scumm->_saveLoadFlag = 1;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kQuitCmd:
|
|
|
|
|
Quit();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kPrefsCmd:
|
|
|
|
|
Preferences();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kAboutCmd:
|
|
|
|
|
About();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kEventClassKeyboard:
|
|
|
|
|
if(GetEventKind(inEvent) == kEventRawKeyDown)
|
|
|
|
|
{
|
2002-04-09 18:24:08 +00:00
|
|
|
|
char key;
|
|
|
|
|
UInt32 mod, code;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
GetEventParameter(inEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &code);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
GetEventParameter(inEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &key);
|
2002-04-09 18:24:08 +00:00
|
|
|
|
GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &mod);
|
|
|
|
|
scumm->_keyPressed = (int)mapKey(key, code, mod);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kEventClassMouse:
|
|
|
|
|
switch(GetEventKind(inEvent))
|
2002-03-18 16:34:57 +00:00
|
|
|
|
{
|
2002-03-08 17:23:31 +00:00
|
|
|
|
case kEventMouseDown:
|
2002-03-18 16:34:57 +00:00
|
|
|
|
WindowRef theWin;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-03-18 16:34:57 +00:00
|
|
|
|
GetEventParameter(inEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef),
|
|
|
|
|
NULL, &theWin);
|
|
|
|
|
if(theWin != FrontWindow())
|
2002-03-08 17:23:31 +00:00
|
|
|
|
{
|
2002-03-18 16:34:57 +00:00
|
|
|
|
ActivateWindow(theWin, true);
|
2002-04-09 18:24:08 +00:00
|
|
|
|
BringToFront(theWin);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case kEventMouseUp:
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_rightBtnPressed &= ~msDown;
|
|
|
|
|
scumm->_leftBtnPressed &= ~msDown;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2002-03-18 16:34:57 +00:00
|
|
|
|
case kEventMouseMoved:
|
|
|
|
|
GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mouse);
|
|
|
|
|
Rect winRect;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-03-18 16:34:57 +00:00
|
|
|
|
GetWindowBounds(wm->wPtr, kWindowContentRgn, &winRect);
|
|
|
|
|
if(PtInRect(mouse, &winRect))
|
2002-03-08 17:23:31 +00:00
|
|
|
|
{
|
2002-03-18 16:34:57 +00:00
|
|
|
|
CGrafPtr oldPort;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-03-18 16:34:57 +00:00
|
|
|
|
GetPort(&oldPort);
|
|
|
|
|
SetPortWindowPort(wm->wPtr);
|
|
|
|
|
GlobalToLocal(&mouse);
|
2002-04-07 18:32:20 +00:00
|
|
|
|
scumm->mouse.x = mouse.h/wm->scale;
|
|
|
|
|
scumm->mouse.y = mouse.v/wm->scale;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
2002-04-10 16:01:25 +00:00
|
|
|
|
Point offset = {0, 0};
|
|
|
|
|
ShieldCursor(&winRect, offset);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pascal void DoGameLoop(EventLoopTimerRef theTimer, void *userData)
|
|
|
|
|
{
|
2002-04-07 18:32:20 +00:00
|
|
|
|
scumm->mainRun();
|
2002-03-08 17:23:31 +00:00
|
|
|
|
QuitApplicationEventLoop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WndMan::init()
|
|
|
|
|
{
|
|
|
|
|
Rect rectWin;
|
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_scale = scale;
|
2002-03-10 15:36:32 +00:00
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
DEST_WIDTH = 320 * scumm->_scale;
|
|
|
|
|
DEST_HEIGHT = 200 * scumm->_scale;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2002-03-18 16:34:57 +00:00
|
|
|
|
UInt32 WinAttrib = (kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute |
|
|
|
|
|
kWindowInWindowMenuAttribute | kWindowStandardHandlerAttribute);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2002-03-18 16:34:57 +00:00
|
|
|
|
InstallStandardEventHandler(GetWindowEventTarget(wPtr));
|
|
|
|
|
InstallWindowEventHandler(wPtr, NewEventHandlerUPP(WindowEventHandler),
|
|
|
|
|
GetEventTypeCount(kWindowEvents), kWindowEvents, 0, NULL);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
|
|
|
|
OSStatus err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitEventHandler), 0L, false);
|
|
|
|
|
|
|
|
|
|
EventLoopTimerRef theTimer;
|
|
|
|
|
InstallEventLoopTimer(GetCurrentEventLoop(), 0, 0, NewEventLoopTimerUPP(DoGameLoop),
|
|
|
|
|
NULL, &theTimer);
|
2002-03-18 16:34:57 +00:00
|
|
|
|
|
|
|
|
|
NewGWorldFromPtr(&screenBuf, 8, &srcRect, pal, nil, 0, (char *)_vgabuf, SRC_WIDTH);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-10 15:36:32 +00:00
|
|
|
|
void WndMan::ChangeScaling(short scaling)
|
|
|
|
|
{
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_scale = scaling;
|
2002-03-10 15:36:32 +00:00
|
|
|
|
scale = scaling;
|
|
|
|
|
|
|
|
|
|
Rect rectWin;
|
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
DEST_WIDTH = 320 * scumm->_scale;
|
|
|
|
|
DEST_HEIGHT = 200 * scumm->_scale;
|
2002-03-10 15:36:32 +00:00
|
|
|
|
|
|
|
|
|
SetRect(&rectWin, 0, 0, DEST_WIDTH, DEST_HEIGHT);
|
|
|
|
|
|
|
|
|
|
SetWindowBounds(wPtr, kWindowContentRgn, &rectWin);
|
|
|
|
|
RepositionWindow(wPtr, NULL, kWindowCenterOnMainScreen);
|
|
|
|
|
dstRect = rectWin;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
CopyBits(GetPortBitMapForCopyBits(screenBuf),
|
|
|
|
|
GetPortBitMapForCopyBits(GetWindowPort(wPtr)),
|
2002-03-10 15:36:32 +00:00
|
|
|
|
&srcRect, &dstRect, srcCopy, 0L);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void waitForTimer(Scumm *s, int delay)
|
|
|
|
|
{
|
|
|
|
|
uint32 start_time;
|
|
|
|
|
|
|
|
|
|
if(s->_fastMode&2)
|
|
|
|
|
delay = 0;
|
|
|
|
|
else if(s->_fastMode&1)
|
|
|
|
|
delay = 10;
|
|
|
|
|
|
2002-04-07 18:32:20 +00:00
|
|
|
|
start_time = Time();
|
2002-03-08 17:23:31 +00:00
|
|
|
|
do {
|
|
|
|
|
wm->handleMessage();
|
2002-04-07 18:32:20 +00:00
|
|
|
|
if(Time() >= start_time + delay)
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2002-03-18 16:34:57 +00:00
|
|
|
|
NewGWorldFromPtr(&screenBuf, 8, &srcRect, pal, nil, 0, (char *)_vgabuf, SRC_WIDTH);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2002-04-10 16:01:25 +00:00
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
wm->writeToScreen();
|
2002-04-10 16:01:25 +00:00
|
|
|
|
s->drawMouse();
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void initGraphics(Scumm *s, bool fullScreen, unsigned int scaleFactor) {
|
2002-03-10 15:36:32 +00:00
|
|
|
|
s->_scale = scaleFactor;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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;
|
2002-03-10 17:48:48 +00:00
|
|
|
|
|
|
|
|
|
case 20:
|
|
|
|
|
gameTitle = "dig";
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
2002-04-10 16:01:25 +00:00
|
|
|
|
wm->scale = 2;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2002-04-10 16:01:25 +00:00
|
|
|
|
SetWTitle(aboutWin, "\pPlease Select a Game<6D>");
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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);
|
2002-04-10 16:01:25 +00:00
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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<56>", 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<56>");
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-17 15:10:18 +00:00
|
|
|
|
ControlRef radioGroupRef, musicVolumeSlider, masterVolumeSlider;
|
2002-03-10 15:36:32 +00:00
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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')
|
|
|
|
|
{
|
2002-04-09 18:24:08 +00:00
|
|
|
|
scumm->_noSubtitles = (Boolean)!GetControlValue(checkBoxControlRef);
|
2002-03-10 15:36:32 +00:00
|
|
|
|
short scale = GetControlValue(radioGroupRef);
|
2002-04-09 18:24:08 +00:00
|
|
|
|
if(scale != scumm->_scale)
|
2002-03-10 15:36:32 +00:00
|
|
|
|
wm->ChangeScaling(scale);
|
2002-03-17 15:10:18 +00:00
|
|
|
|
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);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
QuitAppModalLoopForWindow((WindowRef)userData);
|
|
|
|
|
DisposeWindow((WindowRef)userData);
|
|
|
|
|
result = noErr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Preferences()
|
|
|
|
|
{
|
|
|
|
|
WindowRef prefsWin;
|
2002-03-17 15:10:18 +00:00
|
|
|
|
OSStatus osError = noErr;
|
|
|
|
|
Rect rect = { 0,0,210,300 };
|
|
|
|
|
Rect okButtonRect;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2002-03-17 15:10:18 +00:00
|
|
|
|
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);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
SetWindowDefaultButton(prefsWin,controlRef);
|
|
|
|
|
controlID.id = 'okay';
|
|
|
|
|
SetControlID(controlRef,&controlID);
|
|
|
|
|
AutoEmbedControl(controlRef,prefsWin);
|
|
|
|
|
|
2002-03-17 15:10:18 +00:00
|
|
|
|
SetRect(&rect, 150, 35, 260, 51);
|
|
|
|
|
|
|
|
|
|
CreateCheckBoxControl(prefsWin,&rect, CFSTR("Subtitles"), 1, true, &checkBoxControlRef);
|
|
|
|
|
AutoEmbedControl(checkBoxControlRef, prefsWin);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
if(scumm->_noSubtitles)
|
2002-03-08 17:23:31 +00:00
|
|
|
|
SetControlValue(checkBoxControlRef, false);
|
|
|
|
|
|
2002-03-17 15:10:18 +00:00
|
|
|
|
OffsetRect(&rect, 0, 20);
|
|
|
|
|
|
|
|
|
|
CreateCheckBoxControl(prefsWin,&rect, CFSTR("Fullscreen"), 0, true, &controlRef);
|
|
|
|
|
AutoEmbedControl(controlRef, prefsWin);
|
|
|
|
|
DeactivateControl(controlRef);
|
|
|
|
|
|
2002-03-10 15:36:32 +00:00
|
|
|
|
Rect RadioGroupRect;
|
2002-03-17 15:10:18 +00:00
|
|
|
|
SetRect(&RadioGroupRect, 5, 35, 120, 100);
|
2002-03-10 15:36:32 +00:00
|
|
|
|
CreateRadioGroupControl(prefsWin, &RadioGroupRect, &radioGroupRef);
|
|
|
|
|
AutoEmbedControl(radioGroupRef, prefsWin);
|
|
|
|
|
|
|
|
|
|
ControlRef radioButton;
|
|
|
|
|
|
|
|
|
|
Rect RadioButtonRect;
|
2002-03-17 15:10:18 +00:00
|
|
|
|
SetRect(&RadioButtonRect, 5, 35, 120, 51);
|
2002-03-10 15:36:32 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
SetControlValue(radioGroupRef, scumm->_scale);
|
2002-03-17 15:10:18 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
InstallWindowEventHandler(prefsWin, NewEventHandlerUPP((EventHandlerProcPtr) prefsEventHandler),
|
|
|
|
|
GetEventTypeCount(dialogEvents),dialogEvents,prefsWin,NULL);
|
|
|
|
|
ShowWindow(prefsWin);
|
|
|
|
|
osError = RunAppModalLoopForWindow(prefsWin);
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-16 05:33:25 +00:00
|
|
|
|
/* FIXME: CD Music Stubs */
|
|
|
|
|
void cd_playtrack(int track, int offset, int delay) {;}
|
2002-04-07 18:32:20 +00:00
|
|
|
|
void cd_play(Scumm *s, int track, int num_loops, int start_frame, int end_frame) {;}
|
2002-03-16 05:33:25 +00:00
|
|
|
|
void cd_stop() {;}
|
|
|
|
|
int cd_is_running() {return 0;}
|
|
|
|
|
|
|
|
|
|
void launcherLoop() {
|
2002-03-17 13:46:18 +00:00
|
|
|
|
/* No launcher an Mac yet, probably there won't ever be one, as */
|
|
|
|
|
/* there is a nice Mac-like Launcher already. */
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BoxTest(int num) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setShakePos(Scumm *s, int shake_pos) {}
|
|
|
|
|
|
2002-04-12 21:26:59 +00:00
|
|
|
|
void drawMouse(int xdraw, int ydraw, int w, int h, byte *buf, bool visible)
|
2002-04-10 16:01:25 +00:00
|
|
|
|
{
|
|
|
|
|
int x, y;
|
|
|
|
|
byte *mask, *src, *dst;
|
|
|
|
|
byte color;
|
|
|
|
|
Point mouse;
|
|
|
|
|
GrafPtr oldPort;
|
|
|
|
|
Rect r, r2;
|
|
|
|
|
|
|
|
|
|
if(visible)
|
|
|
|
|
{
|
|
|
|
|
GWorldPtr gw, gw2;
|
|
|
|
|
|
|
|
|
|
src = buf;
|
|
|
|
|
mask = (byte*)malloc(sizeof(byte) * w * h);
|
|
|
|
|
dst = mask;
|
|
|
|
|
for(y = 0; y < h; y++, dst += w, src += w)
|
|
|
|
|
{
|
|
|
|
|
if((uint)y < h)
|
|
|
|
|
{
|
|
|
|
|
for(x = 0; x < w; x++)
|
|
|
|
|
{
|
|
|
|
|
if((uint)x < w)
|
|
|
|
|
{
|
|
|
|
|
if(src[x] != 0xFF)
|
|
|
|
|
dst[x] = 0xFF;
|
|
|
|
|
else
|
|
|
|
|
dst[x] = 0x00;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetRect(&r, 0, 0, w, h);
|
|
|
|
|
|
|
|
|
|
NewGWorldFromPtr(&gw, 8, &r, wm->pal, nil, 0, (char *)buf, w);
|
|
|
|
|
NewGWorldFromPtr(&gw2, 8, &r, NULL, nil, 0, (char *)mask, w);
|
|
|
|
|
SetRect(&r2, (s->mouse.x - w / 2) * s->_scale, (s->mouse.y - h / 2) * s->_scale,
|
|
|
|
|
(s->mouse.x + w / 2) * s->_scale, (s->mouse.y + h / 2) * s->_scale);
|
|
|
|
|
CopyMask(GetPortBitMapForCopyBits(gw), GetPortBitMapForCopyBits(gw2),
|
|
|
|
|
GetPortBitMapForCopyBits(GetWindowPort(wm->wPtr)),
|
|
|
|
|
&r, &r, &r2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
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;
|
2002-04-07 18:32:20 +00:00
|
|
|
|
SIOUXSettings.toppixel = 40;
|
|
|
|
|
SIOUXSettings.leftpixel = 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InitScummStuff()
|
|
|
|
|
{
|
|
|
|
|
detector.detectMain(2, &gameTitle);
|
|
|
|
|
|
|
|
|
|
if(detector._features & GF_OLD256)
|
|
|
|
|
scumm = new Scumm_v3;
|
|
|
|
|
else
|
|
|
|
|
if(detector._features & GF_SMALL_HEADER) // this force loomCD as v4
|
|
|
|
|
scumm = new Scumm_v4;
|
|
|
|
|
else
|
|
|
|
|
if(detector._features & GF_AFTER_V7)
|
|
|
|
|
scumm = new Scumm_v7;
|
|
|
|
|
else
|
|
|
|
|
if(detector._features & GF_AFTER_V6) // this force SamnmaxCD as v6
|
|
|
|
|
scumm = new Scumm_v6;
|
|
|
|
|
else
|
|
|
|
|
scumm = new Scumm_v5;
|
|
|
|
|
|
|
|
|
|
scumm->_fullScreen = detector._fullScreen;
|
|
|
|
|
scumm->_debugMode = detector._debugMode;
|
|
|
|
|
scumm->_bootParam = detector._bootParam;
|
|
|
|
|
scumm->_scale = detector._scale;
|
|
|
|
|
scumm->_gameDataPath = detector._gameDataPath;
|
|
|
|
|
scumm->_gameTempo = detector._gameTempo;
|
|
|
|
|
scumm->_videoMode = detector._videoMode;
|
|
|
|
|
scumm->_exe_name = detector._exe_name;
|
|
|
|
|
scumm->_gameId = detector._gameId;
|
|
|
|
|
scumm->_gameText = detector._gameText;
|
|
|
|
|
scumm->_features = detector._features;
|
|
|
|
|
scumm->_soundCardType = detector._soundCardType;
|
|
|
|
|
scumm->_noSubtitles = detector._noSubtitles;
|
|
|
|
|
scumm->_midi_driver = detector._midi_driver;
|
|
|
|
|
scumm->_cdrom = detector._cdrom;
|
|
|
|
|
|
|
|
|
|
scumm->delta=6;
|
|
|
|
|
scumm->_gui = &gui;
|
|
|
|
|
sound.initialize(scumm,&snd_driv);
|
|
|
|
|
|
|
|
|
|
scumm->delta=0;
|
|
|
|
|
scumm->_system = &_system;
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-17 13:46:18 +00:00
|
|
|
|
void setWindowName(Scumm *scumm)
|
|
|
|
|
{
|
2002-04-07 18:32:20 +00:00
|
|
|
|
char buf[512], *gameName;
|
|
|
|
|
|
|
|
|
|
sprintf(buf, "ScummVM - %s", gameName = detector.getGameName());
|
|
|
|
|
free(gameName);
|
|
|
|
|
StringPtr gameText = CToPascal(buf);
|
2002-03-17 13:46:18 +00:00
|
|
|
|
SetWTitle(wm->wPtr, gameText);
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-10 16:01:25 +00:00
|
|
|
|
UInt8 *buffer[2];
|
|
|
|
|
CmpSoundHeader header;
|
|
|
|
|
SndChannelPtr channel;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
void fill_sound(uint8 *stream, int len) {
|
|
|
|
|
scumm->mixWaves((int16*)stream, len>>1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pascal void callBackProc (SndChannel *chan, SndCommand *cmd_passed)
|
|
|
|
|
{
|
|
|
|
|
UInt32 fill_me, play_me;
|
|
|
|
|
SndCommand cmd;
|
|
|
|
|
|
|
|
|
|
fill_me = cmd_passed->param2;
|
|
|
|
|
play_me = ! fill_me;
|
|
|
|
|
|
|
|
|
|
header.samplePtr = (Ptr)buffer[play_me];
|
|
|
|
|
|
|
|
|
|
cmd.cmd = bufferCmd;
|
|
|
|
|
cmd.param1 = 0;
|
|
|
|
|
cmd.param2 = (long)&header;
|
|
|
|
|
|
|
|
|
|
SndDoCommand(chan, &cmd, 0);
|
|
|
|
|
|
|
|
|
|
memset(buffer[fill_me], 0, size);
|
|
|
|
|
fill_sound(buffer[fill_me], size);
|
|
|
|
|
|
|
|
|
|
cmd.cmd = callBackCmd;
|
|
|
|
|
cmd.param1 = 0;
|
|
|
|
|
cmd.param2 = play_me;
|
|
|
|
|
|
|
|
|
|
SndDoCommand(chan, &cmd, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InitSound()
|
|
|
|
|
{
|
|
|
|
|
SndCallBackUPP callback;
|
|
|
|
|
int sample_size;
|
|
|
|
|
|
|
|
|
|
memset(&header, 0, sizeof(header));
|
|
|
|
|
callback = NewSndCallBackUPP(callBackProc);
|
|
|
|
|
size = ((0x9010 & 0xFF) / 8) * 2048;
|
|
|
|
|
sample_size = size / 2048 * 8;
|
|
|
|
|
header.numChannels = 1;
|
|
|
|
|
header.sampleSize = sample_size;
|
|
|
|
|
header.sampleRate = SAMPLES_PER_SEC << 16;
|
|
|
|
|
header.numFrames = 2048;
|
|
|
|
|
header.encode = cmpSH;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
buffer[i] = (UInt8*)malloc(sizeof(UInt8) * size);
|
|
|
|
|
memset(buffer[i], 0, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
channel = (SndChannelPtr)malloc(sizeof(*channel));
|
|
|
|
|
channel->qLength = 128;
|
|
|
|
|
SndNewChannel(&channel, sampledSynth, initMono, callback);
|
|
|
|
|
|
|
|
|
|
SndCommand cmd;
|
|
|
|
|
cmd.cmd = callBackCmd;
|
|
|
|
|
cmd.param2 = 0;
|
|
|
|
|
SndDoCommand(channel, &cmd, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
void main(void)
|
|
|
|
|
{
|
|
|
|
|
InitMacStuff();
|
|
|
|
|
SelectGame();
|
|
|
|
|
|
|
|
|
|
wm->_vgabuf = (byte*)calloc(320,200);
|
|
|
|
|
|
2002-04-07 18:32:20 +00:00
|
|
|
|
InitScummStuff();
|
2002-03-14 14:16:20 +00:00
|
|
|
|
|
2002-04-07 18:32:20 +00:00
|
|
|
|
scumm->launch();
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-04-07 18:32:20 +00:00
|
|
|
|
gui.init(scumm);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-04-09 18:24:08 +00:00
|
|
|
|
setWindowName(scumm);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
|
2002-04-10 16:01:25 +00:00
|
|
|
|
InitSound();
|
|
|
|
|
|
2002-03-08 17:23:31 +00:00
|
|
|
|
RunApplicationEventLoop();
|
|
|
|
|
|
|
|
|
|
return;
|
2002-04-07 18:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OSystem::OSystem()
|
|
|
|
|
{
|
|
|
|
|
last_time = Time();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int OSystem::waitTick(int delta)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
updateScreen(scumm);
|
|
|
|
|
new_time = Time();
|
|
|
|
|
waitForTimer(scumm, delta * 15 + last_time - new_time);
|
|
|
|
|
last_time = Time();
|
|
|
|
|
if(gui._active)
|
|
|
|
|
{
|
|
|
|
|
gui.loop(scumm);
|
|
|
|
|
delta = 5;
|
|
|
|
|
}
|
2002-04-10 16:01:25 +00:00
|
|
|
|
sound.on_timer();
|
2002-04-07 18:32:20 +00:00
|
|
|
|
} while(gui._active);
|
2002-04-10 16:01:25 +00:00
|
|
|
|
|
2002-04-07 18:32:20 +00:00
|
|
|
|
return(delta);
|
2002-03-08 17:23:31 +00:00
|
|
|
|
}
|