Commit 97bb5845 authored by Steven Fuller's avatar Steven Fuller

Prepared makefile, time to start the port

parent 2fa9feb4
#include "hidemenubar.h"
static Boolean MenuBarHidden = FALSE; /* Current state of the menu bar. */
static Rect OldeMBarRect; /* Saves rectangle enclosing real menu bar. */
static RgnHandle OldeGrayRgn; /* Saves the region defining the desktop */
static short OldMBarHeight; /* Previous menu bar height */
extern GDHandle gMainGDH;
/********************************
Hide the menu bar (If visible)
********************************/
void HideMenuBar(void)
{
RgnHandle menuRgn;
WindowPeek theWindow;
GDHandle TempHand;
TempHand = GetMainDevice();
if (TempHand!=gMainGDH) { /* Main graphics handle */
return;
}
if (!MenuBarHidden) { /* Already hidden? */
OldMBarHeight = LMGetMBarHeight(); /* Get the height in pixels */
OldeGrayRgn = NewRgn(); /* Make a new region */
CopyRgn(GetGrayRgn(), OldeGrayRgn); /* Copy the background region */
OldeMBarRect = qd.screenBits.bounds; /* Make a region from the rect or the monitor width */
OldeMBarRect.bottom = OldeMBarRect.top + OldMBarHeight; /* Top to bottom of menu */
menuRgn = NewRgn(); /* Convert to region */
RectRgn(menuRgn, &OldeMBarRect);
UnionRgn(GetGrayRgn(), menuRgn, GetGrayRgn()); /* Add the menu area to background */
theWindow = (WindowPeek)FrontWindow();
PaintOne((WindowPtr)theWindow, menuRgn); /* Redraw the front window */
PaintBehind((WindowPtr)theWindow, menuRgn); /* Redraw all other windows */
CalcVis((WindowPtr)theWindow); /* Resize the visible region */
CalcVisBehind((WindowPtr)theWindow, menuRgn); /* Resize the visible regions for all others */
DisposeRgn(menuRgn); /* Release the menu region */
MenuBarHidden = TRUE; /* It is now hidden */
ZapMHeight(); /* Zap the height */
}
}
/********************************
Show the menu bar (If hidden)
********************************/
void ShowMenuBar(void)
{
WindowPeek theWindow;
if (MenuBarHidden) { /* Hidden? */
FixMHeight();
MenuBarHidden = FALSE; /* The bar is here */
CopyRgn(OldeGrayRgn, GetGrayRgn()); /* Get the region */
RectRgn(OldeGrayRgn, &OldeMBarRect); /* Convert menu rect to region */
theWindow = (WindowPeek)FrontWindow(); /* Get the front window */
CalcVis((WindowPtr)theWindow); /* Reset the visible region */
CalcVisBehind((WindowPtr)theWindow,OldeGrayRgn); /* Remove the menu bar from windows */
DisposeRgn(OldeGrayRgn); /* Bye bye region */
OldeGrayRgn = 0; /* Zap the handle */
HiliteMenu(0); /* Don't hilite any menu options */
DrawMenuBar(); /* Redraw the menu bar */
}
}
/********************************
Restore the menu bar height so that
the OS can handle menu bar events
********************************/
void FixMHeight(void)
{
if (MenuBarHidden) { /* Hidden? */
LMSetMBarHeight(OldMBarHeight); /* Reset the height */
}
}
/********************************
Zap the menu bar height so that things
like MenuClock won't draw
********************************/
void ZapMHeight(void)
{
if (MenuBarHidden) { /* Hidden? */
LMSetMBarHeight(0); /* Zap the height */
}
}
extern void HideMenuBar(void);
extern void ShowMenuBar(void);
extern void FixMHeight(void);
extern void ZapMHeight(void);
\ No newline at end of file
This diff is collapsed.
CC = gcc
#CFLAGS = -Wall -O6 -fomit-frame-pointer -ffast-math -funroll-loops -mpentiumpro -mcpu=pentiumpro -march=pentiumpro
#CFLAGS = -g -Wall
CFLAGS = -g
#CFLAGS = -Os
#CFLAGS = -g -Wall -I/home/relnev/cvs/oal/include
OBJS = Data.o Doors.o EnMove.o EnThink.o InterMis.o Intro.o Level.o \
Missiles.o Music.o PlMove.o PlStuff.o PlThink.o PushWall.o \
RefBsp.o RefSprite.o Refresh.o Refresh2.o Sight.o Main.o \
StateDef.o WolfMain.o WolfIO.o Burger.o
SOBJS = $(OBJS)
XOBJS = $(OBJS)
GOBJS = $(OBJS)
LFLAGS = -lm
#LFLAGS = -lm -L/home/relnev/cvs/oal/linux/src -lopenal -lpthread -ldl
SLFLAGS = $(LFLAGS) -lvga
XLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm -lXxf86dga
GLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lGL
NASM = nasm
.SUFFIXES: .asm
all: swolf3d xwolf3d gwolf3d
$(SOBJS):
$(XOBJS):
$(GOBJS):
.asm.o:
$(NASM) -f elf -o $@ $<
swolf3d: $(SOBJS)
gcc -o swolf3d $(SOBJS) $(SLFLAGS)
xwolf3d: $(XOBJS)
gcc -o xwolf3d $(XOBJS) $(XLFLAGS)
gwolf3d: $(GOBJS)
gcc -o gwolf3d $(GOBJS) $(GLFLAGS)
clean:
rm -rf swolf3d xwolf3d gwolf3d *.o
distclean: clean
rm -rf *~ DEADJOE
forced: distclean all
rm -rf *.o
#include "WolfDef.h"
#include <Palettes.h>
#include <gestalt.h>
#include "PickAMonitor.h"
#define PAMStrings 2001
#define NoColorString 1
#define NoDepthString 2
#define NoSizeString 3
#define NoProblemString 4
void CheckMonitor(DialogPtr theWindow, int bitDepth, Boolean colorRequired, short minWidth, short minHeight);
void OutlineOK(DialogPtr theDialog, Boolean enabled);
/**********************************
Take a window pointer and center it onto the
current video device
**********************************/
void CenterWindowOnMonitor(WindowPtr theWindow, GDHandle theMonitor)
{
short newH, newV;
Rect mRect;
mRect = (**theMonitor).gdRect; /* Get the rect of the monitor */
/* Find the difference between the two monitors' sizes */
newH = (mRect.right - mRect.left) - (theWindow->portRect.right - theWindow->portRect.left);
newV = (mRect.bottom - mRect.top) - (theWindow->portRect.bottom - theWindow->portRect.top);
/* Half the difference so that it's centered top-to-bottom and left-to-right */
/* Add that offset to the upper-left of the monitor */
MoveWindow(theWindow,(newH>>1)+mRect.left,(newV>>1)+mRect.top,TRUE); /* Move and bring to front */
}
/**********************************
Returns true if the device supports color
**********************************/
Boolean SupportsColor(GDHandle theMonitor)
{
return TestDeviceAttribute(theMonitor,gdDevType); /* Is it color? */
}
/**********************************
Returns true if the device supports a specific color depth
**********************************/
short SupportsDepth(GDHandle theMonitor, int theDepth, Boolean needsColor)
{
return HasDepth(theMonitor,theDepth,1<<gdDevType,needsColor);
}
/**********************************
Returns true if the device supports a specific video size
**********************************/
Boolean SupportsSize(GDHandle theMonitor, short theWidth, short theHeight)
{
Rect theRect;
/* Grab the dimensions of the monitor */
theRect = (**theMonitor).gdRect;
/* Offset it to (0, 0) references */
OffsetRect(&theRect, -theRect.left, -theRect.top);
/* Check the dimensions to see if they are large enough */
if ((theRect.right < theWidth) || (theRect.bottom < theHeight)) {
return FALSE; /* No good! */
}
return TRUE;
}
/**********************************
Return the GDevice from a specific quickdraw point
**********************************/
GDHandle MonitorFromPoint(Point *thePoint)
{
GDHandle theMonitor;
/* Loop through the list of monitors to see one encompasses the point */
theMonitor = GetDeviceList(); /* Get the first monitor */
do {
if (PtInRect(*thePoint,&(**theMonitor).gdRect)) { /* Is this it? */
break; /* Exit now */
}
theMonitor = GetNextDevice(theMonitor); /* Get the next device in list */
} while (theMonitor); /* All done now? */
/* Just in case some weird evil happened, return a fail value (THEORETICALLY can't happen) */
return theMonitor;
}
// ---------------------------------------- PickAMonitor
GDHandle PickAMonitor(int theDepth, Boolean colorRequired, short minWidth, short minHeight)
{
GDHandle theMonitor;
GDHandle tempMonitor;
Point thePoint;
EventRecord theEvent;
DialogPtr theDialog;
short itemHit;
char theChar;
Word validCount;
GrafPtr savedPort;
/* Loop through the monitor list once to make sure there is at least one good monitor */
theMonitor = GetDeviceList(); /* Get the first monitor */
tempMonitor = 0; /* No monitor found */
validCount = 0; /* None found */
do {
if (colorRequired && !SupportsColor(theMonitor)) { /* Check for color? */
continue;
}
if (!SupportsDepth(theMonitor, theDepth, colorRequired)) { /* Check for bit depth */
continue;
}
if (!SupportsSize(theMonitor, minWidth, minHeight)) { /* Check for monitor size */
continue;
}
tempMonitor = theMonitor; /* Save the valid record */
++validCount; /* Inc the count */
} while ((theMonitor = GetNextDevice(theMonitor)) != 0);
/* If there was only one valid monitor, goodMonitor will be referencing it. Return it immediately. */
if (validCount == 1) {
return (tempMonitor); /* Exit now */
}
/* If there are no valid monitors then put up a dialog saying so. Then return nil. */
if (!validCount) {
StopAlert(2001, nil);
return 0;
}
// Start an event loop going. Rather than using modalDialog with a gnarly filter, we'll just display the dialog
// then use a gnarly event loop to accommodate it. This will go on until the user selects either "This Monitor"
// (ok) or "Quit" (cancel).
theDialog = GetNewDialog(2000, nil, (WindowPtr) -1L);
CenterWindowOnMonitor((WindowPtr) theDialog, GetMainDevice());
InitCursor();
GetPort(&savedPort);
SetPort(theDialog);
ShowWindow(theDialog);
CheckMonitor(theDialog, theDepth, colorRequired, minWidth, minHeight);
do {
itemHit = 0;
/* Get next event from the event queue */
if (WaitNextEvent2(everyEvent&(~highLevelEventMask), &theEvent, 30, nil)) {
switch (theEvent.what) {
case keyDown:
theChar = theEvent.message & charCodeMask;
if ((theEvent.modifiers & cmdKey) && ((theChar == '.') || (theChar == 'q') || (theChar == 'Q'))) {
itemHit = cancel;
break;
}
if (theChar == 0x1B) {
itemHit = cancel;
break;
}
if ((theChar == 0x0D) || (theChar == 0x03)) {
itemHit = ok;
break;
}
break;
// Did we mouse-down in the dialogs drag-bar?
case mouseDown:
if (FindWindow(theEvent.where, (WindowPtr *) &theDialog) == inDrag)
{
DragWindow((WindowPtr) theDialog, theEvent.where, &qd.screenBits.bounds);
GetMouse(&thePoint);
LocalToGlobal(&thePoint);
tempMonitor = MonitorFromPoint(&thePoint);
CenterWindowOnMonitor((WindowPtr) theDialog, tempMonitor);
CheckMonitor(theDialog, theDepth, colorRequired, minWidth, minHeight);
break;
}
default:
// If not, perform regular dialog event processing
DialogSelect(&theEvent, &theDialog, &itemHit);
}
}
} while ((itemHit != ok) && (itemHit != cancel));
// Ok, the dialog is still the active grafport so all coordinates are in its local system. If I define a point
// as (0, 0) now it will be the upper left corner of the dialog's drawing area. I then turn this to a global screen
// coordinate and call GetMonitorFromPoint.
SetPt(&thePoint, 0, 0);
LocalToGlobal(&thePoint);
theMonitor = MonitorFromPoint(&thePoint);
// Restore our current graphics environment and return the monitor reference.
SetPort(savedPort);
DisposeDialog(theDialog);
if (itemHit == ok) {
return (theMonitor);
}
return (nil);
}
// ---------------------------------------- CheckMonitor
void CheckMonitor(DialogPtr theDialog, int bitDepth, Boolean colorRequired, short minWidth, short minHeight)
{
GDHandle theMonitor;
Point thePoint;
short theType;
Handle theHandle;
Rect theRect;
Str255 message;
Boolean badMonitor = FALSE;
GrafPtr savedPort;
GetPort(&savedPort);
SetPort((WindowPtr) theDialog);
SetPt(&thePoint, 0, 0);
LocalToGlobal(&thePoint);
theMonitor = MonitorFromPoint(&thePoint);
GetDialogItem(theDialog, 4, &theType, &theHandle, &theRect);
if (colorRequired && ! SupportsColor(theMonitor)) {
GetIndString(message, PAMStrings, NoColorString);
SetDialogItemText(theHandle, message);
badMonitor = TRUE;
}
if (!SupportsDepth(theMonitor, bitDepth, colorRequired)) {
GetIndString(message, PAMStrings, NoDepthString);
SetDialogItemText(theHandle, message);
badMonitor = TRUE;
}
if (! SupportsSize(theMonitor, minWidth, minHeight)) {
GetIndString(message, PAMStrings, NoDepthString);
SetDialogItemText(theHandle, message);
badMonitor = TRUE;
}
SetPort(savedPort);
if (badMonitor) {
// Gray-out the "This Monitor" button
GetDialogItem(theDialog, ok, &theType, &theHandle, &theRect);
HiliteControl((ControlHandle) theHandle, 255);
OutlineOK(theDialog, FALSE);
BeginUpdate((WindowPtr) theDialog);
UpdateDialog(theDialog, theDialog->visRgn);
EndUpdate((WindowPtr) theDialog);
return;
}
// Activate the "This Monitor" button and put up the no problem text.
GetIndString(message, PAMStrings, NoProblemString);
SetDialogItemText(theHandle, message);
GetDialogItem(theDialog, ok, &theType, &theHandle, &theRect);
HiliteControl((ControlHandle) theHandle, 0);
OutlineOK(theDialog, TRUE);
BeginUpdate((WindowPtr) theDialog);
UpdateDialog(theDialog, theDialog->visRgn);
EndUpdate((WindowPtr) theDialog);
}
// ---------------------------------------- OutlineOK
void OutlineOK(DialogPtr theDialog, Boolean enabled)
{
GrafPtr savedPort;
ColorSpec saveColor;
PenState savedState;
short theType;
Handle theHandle;
Rect theRect;
GetPenState(&savedState);
PenMode(patCopy);
PenSize(2, 2);
SaveFore(&saveColor);
ForeColor(blackColor);
GetPort(&savedPort);
SetPort((WindowPtr) theDialog);
GetDialogItem(theDialog, ok, &theType, &theHandle, &theRect);
InsetRect(&theRect, -4, -4);
if (enabled)
PenPat(&qd.black);
else
PenPat(&qd.gray);
FrameRoundRect(&theRect, 16, 16);
SetPort(savedPort);
RestoreFore(&saveColor);
SetPenState(&savedState);
}
extern void CenterWindowOnMonitor(WindowPtr theWindow, GDHandle theMonitor);
extern Boolean SupportsColor(GDHandle theMonitor);
extern short SupportsDepth(GDHandle theMonitor, int theDepth, Boolean needsColor);
extern Boolean SupportsSize(GDHandle theMonitor, short theWidth, short theHeight);
extern GDHandle MonitorFromPoint(Point *thePoint);
extern GDHandle PickAMonitor(int bitDepth, Boolean colorRequired, short minWidth, short minHeight);
extern Boolean WaitNextEvent2(short EventMask,EventRecord *theEvent,long sleep,RgnHandle mouseRgn);
\ No newline at end of file
void InitPrefsFile(OSType creator,Byte *PrefsName);
OSErr LoadPrefsFile(Byte *PrefsPtr,Word PrefsLen);
OSErr SavePrefsFile(Byte *PrefsPtr,Word PrefsLen);
#include <Folders.h>
#include <Gestalt.h>
#include <Processes.h>
#include "Wolfdef.h"
#include <String.h>
#include "prefs.h"
typedef struct {
Byte fileName[34]; /* Enough space for filename */
OSType creator; /* Creator TYPE */
OSType fileType; /* File type */
OSType resType; /* Resource type */
short resID; /* Open resource file ID */
} PrefsInfo;
static PrefsInfo prefsInfo; /* My internal prefs record */
static Boolean prefsInited = FALSE; /* Is the struct valid? */
/**********************************
I miss the Apple IIgs where all you need to set the prefs directory
was to pass a filename of "@:Prefs file" and it will automatically place
the prefs file in either the proper Network folder or system prefs folder...
Instead I have to do this bullshit to scan the volumes to find the prefs
folder and volume...
If the file was not found, then create it.
return TRUE if the file was found and could not be created
**********************************/
static Boolean FindPrefsFile(short *prefVRefNum, long *prefDirID)
{
OSErr theErr;
long response;
CInfoPBRec infoPB;
if (!prefsInited) { /* Only look if the prefs structure is valid */
return FALSE; /* Exit NOW! */
}
/* First, try it the easy way... */
if ( !Gestalt(gestaltFindFolderAttr, &response) && /* Is the easy way available? */
( (1<<gestaltFindFolderPresent) & response)) {
/* Call the OS to do the dirty work */
theErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
prefVRefNum, prefDirID);
/* OK, try it the hard way... :( */
} else {
SysEnvRec theSysEnv;
StringPtr prefFolderName = "\pPreferences";
/* yeachh -- we have to do it all by hand! */
if (SysEnvirons(1, &theSysEnv)) { /* Is the system disk present? */
return FALSE; /* Forget it! */
}
*prefVRefNum = theSysEnv.sysVRefNum; /* Save off the boot volume ID */
/* check whether Preferences folder already exists */
infoPB.hFileInfo.ioCompletion = 0; /* Wait for completion */
infoPB.hFileInfo.ioNamePtr = prefFolderName; /* Get folder name */
infoPB.hFileInfo.ioVRefNum = *prefVRefNum; /* Pass the volume # */
infoPB.hFileInfo.ioFDirIndex = 0; /* Scan directories */
infoPB.hFileInfo.ioDirID = 0; /* Init dir id */
theErr = PBGetCatInfo(&infoPB, FALSE); /* Get the catalog info */
if (!theErr) {
*prefDirID = infoPB.hFileInfo.ioDirID; /* Return the folder id */
} else if (theErr == fnfErr) { /* Preferences doesn't already exist */
HParamBlockRec dirPB;
/* create "Preferences" folder */
dirPB.fileParam.ioCompletion = 0;
dirPB.fileParam.ioVRefNum = *prefVRefNum;
dirPB.fileParam.ioNamePtr = prefFolderName;
dirPB.fileParam.ioDirID = 0;
theErr = PBDirCreate(&dirPB, FALSE); /* Create the folder */
if (!theErr) {
*prefDirID = dirPB.fileParam.ioDirID; /* Save the ID */
}
}
}
/* if we make it here OK, create Preferences file if necessary */
if (!theErr) {
infoPB.hFileInfo.ioCompletion = 0;
infoPB.hFileInfo.ioNamePtr = prefsInfo.fileName;
infoPB.hFileInfo.ioVRefNum = *prefVRefNum;
infoPB.hFileInfo.ioFDirIndex = 0;
infoPB.hFileInfo.ioDirID = *prefDirID;
theErr = PBGetCatInfo(&infoPB, FALSE); /* Get the file info */
if (theErr == fnfErr) { /* Not present? */
theErr = HCreate(*prefVRefNum, *prefDirID, prefsInfo.fileName,
prefsInfo.creator, prefsInfo.fileType);
if (!theErr) {
HCreateResFile(*prefVRefNum, *prefDirID, prefsInfo.fileName);
theErr = ResError(); /* Was there an error? */
}
}
}
return (!theErr);
}
/**********************************
Init the record for the "Prefs" file
All this does is preset the prefsfile structure
for the filename of the prefs file.
**********************************/
void InitPrefsFile(OSType creator,Byte *PrefsName)
{
Word FLen;
FLen = strlen((char *)PrefsName); /* How long is the string? */
prefsInfo.fileName[0] = FLen; /* Make a PASCAL string */
BlockMove(PrefsName,&prefsInfo.fileName[1],FLen); /* Copy the bulk */
prefsInfo.creator = creator; /* 4 Letter creator filetype */
prefsInfo.fileType = 'PREF'; /* Pref's filetype */
prefsInfo.resType = 'PREF'; /* Pref's resource */
prefsInfo.resID = 0; /* No resource ID assigned yet */
prefsInited = TRUE; /* All numbers are set... */
}
/**********************************
Load in a prefs file and store it
into a passed pointer IF the file was
loaded properly.
Return any error codes.
**********************************/
OSErr LoadPrefsFile(Byte *PrefsPtr,Word PrefsLen)
{
short prefVRefNum, prefRefNum;
long prefDirID;
Handle origHdl;
LongWord origSize;
if (!FindPrefsFile(&prefVRefNum, &prefDirID)) { /* Search for the file */
return fnfErr; /* File was NOT found error */
}
prefRefNum = HOpenResFile(prefVRefNum, prefDirID, prefsInfo.fileName, fsRdWrPerm);
if (prefRefNum == -1) { /* Resource error? */
return ResError(); /* Return the resource manager error */
}
/* Not finding the resource is not an error -- caller will use default data */
origHdl = Get1Resource(prefsInfo.resType, prefsInfo.resID);
if (origHdl) { /* Valid handle? */
origSize = GetHandleSize(origHdl); /* How much data is here? */
if (origSize < PrefsLen) { /* Less data than expected? */
PrefsLen = origSize; /* Use the smaller size */
}
BlockMove(*origHdl,PrefsPtr,PrefsLen); /* Copy the NEW prefs data */
ReleaseResource(origHdl); /* Release the data */
}
CloseResFile(prefRefNum); /* Close the resource file */
return ResError(); /* Return any errors */
}
/**********************************
Save data for a new prefs file
**********************************/
OSErr SavePrefsFile(Byte *PrefsPtr,Word PrefsLen)
{
short prefVRefNum, prefRefNum;
long prefDirID;
Handle origHdl;
LongWord origSize;
OSErr theErr = noErr;
if (!FindPrefsFile(&prefVRefNum, &prefDirID)) { /* File not present? */
return fnfErr; /* File not found error */
}
prefRefNum = HOpenResFile(prefVRefNum, prefDirID, prefsInfo.fileName, fsRdWrPerm);
if (prefRefNum == -1) { /* Bad resource fork? */
return ResError(); /* Return the error */
}
origHdl = Get1Resource(prefsInfo.resType, prefsInfo.resID); /* Get the resource */
if (origHdl) { /* Overwrite the existing resource */
origSize = GetHandleSize(origHdl); /* How large is it? */
if (PrefsLen != origSize) { /* Different size? */
SetHandleSize(origHdl, PrefsLen); /* Set the new size */
}
BlockMove(PrefsPtr,*origHdl,PrefsLen); /* Copy the data */
ChangedResource(origHdl); /* Mark as changed */
WriteResource(origHdl); /* Save to disk */
ReleaseResource(origHdl); /* Release it */
} else {
/* store specified preferences for the first time */
origHdl = NewHandle(PrefsLen); /* Make some temp memory */
if (origHdl) {
BlockMove(PrefsPtr,*origHdl,PrefsLen);
AddResource(origHdl, prefsInfo.resType, prefsInfo.resID, "\p");
WriteResource(origHdl); /* Write to disk */
ReleaseResource(origHdl); /* Release it */
}
}
CloseResFile(prefRefNum); /* Close the resource file */
if (!theErr) { /* No errors? */
return ResError(); /* Return any resource error */
}
return theErr; /* Return the last error */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment