29 #include "../../idlib/precompiled.h"
30 #include <Carbon/Carbon.h>
37 #define kMaxMonitors 16
56 static GDHandle sSelectedDevice;
57 static int sNumMonitors;
60 static RGBColor rgbBlack = { 0x0000, 0x0000, 0x0000 };
61 static RGBColor rgbWhite = { 0xffff, 0xffff, 0xffff };
62 static RGBColor rgbGray = { 0x5252, 0x8A8A, 0xCCCC };
87 ControlUserPaneDrawProcPtr inDrawProc,
88 ControlUserPaneHitTestProcPtr inHitTestProc,
89 ControlUserPaneTrackingProcPtr inTrackingProc)
92 ControlUserPaneDrawUPP drawUPP;
93 ControlUserPaneHitTestUPP hitTestUPP;
94 ControlUserPaneTrackingUPP trackingUPP;
96 if (0 == inUserPane)
return paramErr;
98 if (inDrawProc && noErr == err)
100 drawUPP = NewControlUserPaneDrawUPP(inDrawProc);
105 err = SetControlData( inUserPane,
106 kControlEntireControl,
107 kControlUserPaneDrawProcTag,
108 sizeof(ControlUserPaneDrawUPP),
111 if (inHitTestProc && noErr == err)
113 hitTestUPP = NewControlUserPaneHitTestUPP(inHitTestProc);
118 err = SetControlData( inUserPane,
119 kControlEntireControl,
120 kControlUserPaneHitTestProcTag,
121 sizeof(ControlUserPaneHitTestUPP),
124 if (inTrackingProc && noErr == err)
126 trackingUPP = NewControlUserPaneTrackingUPP(inTrackingProc);
128 if (0 == trackingUPP)
131 err = SetControlData( inUserPane,
132 kControlEntireControl,
133 kControlUserPaneTrackingProcTag,
134 sizeof(ControlUserPaneTrackingUPP),
149 ControlUserPaneDrawUPP drawUPP;
150 ControlUserPaneHitTestUPP hitTestUPP;
151 ControlUserPaneTrackingUPP trackingUPP;
155 err = GetControlData(inUserPane, kControlEntireControl, kControlUserPaneDrawProcTag,
sizeof(ControlUserPaneDrawUPP), (Ptr)&drawUPP, &actualSize);
156 if (err == noErr) DisposeControlUserPaneDrawUPP(drawUPP);
158 err = GetControlData(inUserPane, kControlEntireControl, kControlUserPaneHitTestProcTag,
sizeof(ControlUserPaneHitTestUPP), (Ptr)&hitTestUPP, &actualSize);
159 if (err == noErr) DisposeControlUserPaneHitTestUPP(hitTestUPP);
161 err = GetControlData(inUserPane, kControlEntireControl, kControlUserPaneTrackingProcTag,
sizeof(ControlUserPaneTrackingUPP), (Ptr)&trackingUPP, &actualSize);
162 if (err == noErr) DisposeControlUserPaneTrackingUPP(trackingUPP);
174 static pascal
void drawProc(ControlRef inControl, SInt16 inPart)
176 #pragma unused(inControl, inPart)
179 RGBColor saveForeColor;
180 RGBColor saveBackColor;
181 PenState savePenState;
183 GetForeColor(&saveForeColor);
184 GetBackColor(&saveBackColor);
185 GetPenState(&savePenState);
187 RGBForeColor(&rgbBlack);
188 RGBBackColor(&rgbWhite);
191 for (i = 0; i < sNumMonitors; i++)
193 RGBForeColor(&rgbGray);
194 PaintRect(&sMonitors[i].scaledRect);
195 if (sMonitors[i].isMain)
199 r.bottom = r.top + 6;
200 RGBForeColor(&rgbWhite);
202 RGBForeColor(&rgbBlack);
204 MoveTo(r.left, r.bottom);
205 LineTo(r.right, r.bottom);
207 if (sMonitors[i].device == sSelectedDevice)
210 RGBForeColor(&rgbBlack);
211 FrameRect(&sMonitors[i].scaledRect);
216 RGBForeColor(&rgbBlack);
217 FrameRect(&sMonitors[i].scaledRect);
222 RGBForeColor(&saveForeColor);
223 RGBBackColor(&saveBackColor);
224 SetPenState(&savePenState);
235 static pascal ControlPartCode hitTestProc(ControlRef inControl, Point inWhere)
238 return kControlButtonPart;
249 static pascal ControlPartCode trackingProc (
250 ControlRef inControl,
252 ControlActionUPP inActionProc)
254 #pragma unused (inControl, inStartPt, inActionProc)
257 for (i = 0; i < sNumMonitors; i++)
259 if (PtInRect(inStartPt, &sMonitors[i].scaledRect))
261 if (sMonitors[i].device != sSelectedDevice)
263 sSelectedDevice = sMonitors[
i].
device;
264 DrawOneControl(inControl);
270 return kControlNoPart;
287 GDHandle dev = GetDeviceList();
291 if (inDefaultMonitor)
292 DMGetGDeviceByDisplayID(inDefaultMonitor, &sSelectedDevice,
true);
294 sSelectedDevice = GetMainDevice();
300 if (TestDeviceAttribute(dev, screenDevice) && TestDeviceAttribute(dev, screenActive))
302 sMonitors[sNumMonitors].
device = dev;
303 sMonitors[sNumMonitors].
origRect = (**dev).gdRect;
304 sMonitors[sNumMonitors].
isMain = (dev == GetMainDevice());
307 dev = GetNextDevice(dev);
313 Rect origPaneRect, paneRect;
314 Rect origGrayRect, grayRect, scaledGrayRect;
315 float srcAspect, dstAspect,
scale;
318 GetControlBounds(inPane, &origPaneRect);
319 paneRect = origPaneRect;
320 OffsetRect(&paneRect, -paneRect.left, -paneRect.top);
322 GetRegionBounds(GetGrayRgn(), &origGrayRect);
323 grayRect = origGrayRect;
324 OffsetRect(&grayRect, -grayRect.left, -grayRect.top);
326 srcAspect = (
float)grayRect.right / (
float)grayRect.bottom;
327 dstAspect = (
float)paneRect.right / (
float)paneRect.bottom;
329 scaledGrayRect = paneRect;
331 if (srcAspect < dstAspect)
333 scaledGrayRect.right = (
float)paneRect.bottom * srcAspect;
334 scale = (
float)scaledGrayRect.right / grayRect.right;
338 scaledGrayRect.bottom = (
float)paneRect.right / srcAspect;
339 scale = (
float)scaledGrayRect.bottom / grayRect.bottom;
342 for (i = 0; i < sNumMonitors; i++)
348 OffsetRect(&r, -r.left, -r.top);
349 r.bottom = (
float)r.bottom * scale;
350 r.right = (
float)r.right *
scale;
353 OffsetRect(&r, (
float)(r2.left - origGrayRect.left) * scale,
354 (
float)(r2.top - origGrayRect.top) * scale);
360 OffsetRect(&scaledGrayRect, (paneRect.right - scaledGrayRect.right) / 2,
361 (paneRect.bottom - scaledGrayRect.bottom) / 2);
364 for (i = 0; i < sNumMonitors; i++)
365 OffsetRect(&sMonitors[i].scaledRect, scaledGrayRect.left, scaledGrayRect.top);
397 static pascal OSStatus PickMonitorHandler( EventHandlerCallRef inHandler, EventRef inEvent,
void* inUserData )
399 #pragma unused( inHandler )
402 OSStatus
result = eventNotHandledErr;
403 WindowRef theWindow = (WindowRef)inUserData;
408 GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand,
NULL,
sizeof( cmd ),
NULL, &cmd );
410 switch ( cmd.commandID )
413 QuitAppModalLoopForWindow( theWindow );
417 case kHICommandCancel:
420 QuitAppModalLoopForWindow( theWindow );
438 GDHandle dev = GetDeviceList();
446 if (TestDeviceAttribute(dev, screenDevice) && TestDeviceAttribute(dev, screenActive))
450 dev = GetNextDevice(dev);
453 if (numMonitors > 1)
return true;
462 OSStatus
PickMonitor (DisplayIDType *inOutDisplayID, WindowRef parentWindow)
465 OSStatus status = noErr;
466 static const ControlID kUserPane = {
'MONI', 1 };
471 CFBundleRef
theBundle = CFBundleGetMainBundle();
472 status = CreateNibReferenceWithCFBundle(theBundle, CFSTR(
"ASLCore"), &aslNib);
473 status = ::CreateWindowFromNib(aslNib, CFSTR(
"Pick Monitor" ), &theWindow );
477 return userCanceledErr;
484 GetWTitle(theWindow, windowTitle);
485 FormatPStringWithGameName(windowTitle);
486 SetWTitle(theWindow, windowTitle);
491 ControlRef monitorPane;
499 EventTypeSpec
cmdEvent = { kEventClassCommand, kEventCommandProcess };
500 EventHandlerUPP
handler = NewEventHandlerUPP( PickMonitorHandler );
506 ShowSheetWindow( theWindow, parentWindow );
508 ShowWindow( theWindow );
514 RunAppModalLoopForWindow( theWindow );
524 HideSheetWindow( theWindow );
525 DisposeWindow( theWindow );
526 DisposeEventHandlerUPP( handler );
530 if (sSelectedDevice != 0)
533 DMGetDisplayIDByGDevice (sSelectedDevice, &*inOutDisplayID,
true);
537 return userCanceledErr;
GetControlByID(prefInfo.window,&kFullscreenBtn,&prefInfo.fullscreenBtn)
OSStatus PickMonitor(DisplayIDType *inOutDisplayID, WindowRef parentWindow)
assert(prefInfo.fullscreenBtn)
GLenum GLenum GLenum GLenum GLenum scale
OSErr TearDownPickMonitorPane(ControlRef inPane)
InstallWindowEventHandler(prefInfo.window, handler, 1,&cmdEvent,&prefInfo, NULL)
OSErr SetupUserPaneProcs(ControlRef inUserPane, ControlUserPaneDrawProcPtr inDrawProc, ControlUserPaneHitTestProcPtr inHitTestProc, ControlUserPaneTrackingProcPtr inTrackingProc)
OSErr DisposeUserPaneProcs(ControlRef inUserPane)
GLdouble GLdouble GLdouble r
static WindowRef ValidModeCallbackProc inCallback OSStatus err
OSErr SetupPickMonitorPane(ControlRef inPane, DisplayIDType inDefaultMonitor)
Boolean CanUserPickMonitor(void)