Wolf3D-Mac/PickAMonitor.c

1 line
9.0 KiB
C
Raw Normal View History

#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; } //<2F> ---------------------------------------- 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. */ i