Remove: [OSX] Stuff that is pre-10.7 from the Cocoa/Quartz video driver.

This commit is contained in:
Michael Lutz 2020-04-10 23:47:01 +02:00
parent 0e5be3887c
commit 9dd8b3d430
5 changed files with 41 additions and 242 deletions

View File

@ -16,9 +16,6 @@
#include "../core/string_compare_type.hpp" #include "../core/string_compare_type.hpp"
#include <map> #include <map>
#if defined(WITH_COCOA)
bool QZ_CanDisplay8bpp();
#endif /* defined(WITH_COCOA) */
/** /**
* The base factory, keeping track of all blitters. * The base factory, keeping track of all blitters.
@ -113,19 +110,11 @@ public:
{ {
#if defined(DEDICATED) #if defined(DEDICATED)
const char *default_blitter = "null"; const char *default_blitter = "null";
#elif defined(WITH_COCOA)
const char *default_blitter = "32bpp-anim";
#else #else
const char *default_blitter = "8bpp-optimized"; const char *default_blitter = "8bpp-optimized";
#endif
#if defined(WITH_COCOA)
/* Some people reported lack of fullscreen support in 8 bpp mode.
* While we prefer 8 bpp since it's faster, we will still have to test for support. */
if (!QZ_CanDisplay8bpp()) {
/* The main display can't go to 8 bpp fullscreen mode.
* We will have to switch to 32 bpp by default. */
default_blitter = "32bpp-anim";
}
#endif /* defined(WITH_COCOA) */
#endif /* defined(DEDICATED) */
if (GetBlitters().size() == 0) return nullptr; if (GetBlitters().size() == 0) return nullptr;
const char *bname = (StrEmpty(name)) ? default_blitter : name; const char *bname = (StrEmpty(name)) ? default_blitter : name;

View File

@ -190,10 +190,8 @@ public:
extern CocoaSubdriver *_cocoa_subdriver; extern CocoaSubdriver *_cocoa_subdriver;
#ifdef ENABLE_COCOA_QUARTZ #ifdef ENABLE_COCOA_QUARTZ
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp); CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
#endif #endif
#endif
void QZ_GameSizeChanged(); void QZ_GameSizeChanged();
@ -223,16 +221,7 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i
@end @end
/** Subclass of NSView to fix Quartz rendering and mouse awareness */ /** Subclass of NSView to fix Quartz rendering and mouse awareness */
@interface OTTD_CocoaView : NSView @interface OTTD_CocoaView : NSView <NSTextInputClient>
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
# if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
<NSTextInputClient, NSTextInput>
# else
<NSTextInputClient>
# endif /* MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 */
#else
<NSTextInput>
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 */
{ {
CocoaSubdriver *driver; CocoaSubdriver *driver;
NSTrackingRectTag trackingtag; NSTrackingRectTag trackingtag;
@ -252,10 +241,7 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i
@end @end
/** Delegate for our NSWindow to send ask for quit on close */ /** Delegate for our NSWindow to send ask for quit on close */
@interface OTTD_CocoaWindowDelegate : NSObject @interface OTTD_CocoaWindowDelegate : NSObject <NSWindowDelegate>
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSWindowDelegate>
#endif
{ {
CocoaSubdriver *driver; CocoaSubdriver *driver;
} }

View File

@ -45,10 +45,7 @@
*/ */
@interface OTTDMain : NSObject @interface OTTDMain : NSObject <NSApplicationDelegate>
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
<NSApplicationDelegate>
#endif
@end @end
@ -159,7 +156,9 @@ static void setApplicationMenu()
/* Tell the application object that this is now the application menu. /* Tell the application object that this is now the application menu.
* This interesting Objective-C construct is used because not all SDK * This interesting Objective-C construct is used because not all SDK
* versions define this method publicly. */ * versions define this method publicly. */
[ NSApp performSelector:@selector(setAppleMenu:) withObject:appleMenu ]; if ([ NSApp respondsToSelector:@selector(setAppleMenu:) ]) {
[ NSApp performSelector:@selector(setAppleMenu:) withObject:appleMenu ];
}
/* Finally give up our references to the objects */ /* Finally give up our references to the objects */
[ appleMenu release ]; [ appleMenu release ];
@ -204,13 +203,9 @@ static void setupApplication()
/* Ensure the application object is initialised */ /* Ensure the application object is initialised */
[ NSApplication sharedApplication ]; [ NSApplication sharedApplication ];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
/* Tell the dock about us */ /* Tell the dock about us */
if (MacOSVersionIsAtLeast(10, 3, 0)) { OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToForegroundApplication);
OSStatus returnCode = TransformProcessType(&psn, kProcessTransformToForegroundApplication); if (returnCode != 0) DEBUG(driver, 0, "Could not change to foreground application. Error %d", (int)returnCode);
if (returnCode != 0) DEBUG(driver, 0, "Could not change to foreground application. Error %d", (int)returnCode);
}
#endif
/* Disable the system-wide tab feature as we only have one window. */ /* Disable the system-wide tab feature as we only have one window. */
if ([ NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:) ]) { if ([ NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:) ]) {
@ -243,57 +238,27 @@ static bool ModeSorter(const OTTD_Point &p1, const OTTD_Point &p2)
static void QZ_GetDisplayModeInfo(CFArrayRef modes, CFIndex i, int &bpp, uint16 &width, uint16 &height) static void QZ_GetDisplayModeInfo(CFArrayRef modes, CFIndex i, int &bpp, uint16 &width, uint16 &height)
{ {
bpp = 0; CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
width = 0;
height = 0;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) width = (uint16)CGDisplayModeGetWidth(mode);
if (MacOSVersionIsAtLeast(10, 6, 0)) { height = (uint16)CGDisplayModeGetHeight(mode);
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(modes, i);
width = (uint16)CGDisplayModeGetWidth(mode);
height = (uint16)CGDisplayModeGetHeight(mode);
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11) #if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
/* Extract bit depth from mode string. */ /* Extract bit depth from mode string. */
CFAutoRelease<CFStringRef> pixEnc(CGDisplayModeCopyPixelEncoding(mode)); CFAutoRelease<CFStringRef> pixEnc(CGDisplayModeCopyPixelEncoding(mode));
if (CFStringCompare(pixEnc.get(), CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 32; if (CFStringCompare(pixEnc.get(), CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 32;
if (CFStringCompare(pixEnc.get(), CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 16; if (CFStringCompare(pixEnc.get(), CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 16;
if (CFStringCompare(pixEnc.get(), CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 8; if (CFStringCompare(pixEnc.get(), CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) bpp = 8;
#else #else
/* CGDisplayModeCopyPixelEncoding is deprecated on OSX 10.11+, but there are no 8 bpp modes anyway... */ /* CGDisplayModeCopyPixelEncoding is deprecated on OSX 10.11+, but there are no 8 bpp modes anyway... */
bpp = 32; bpp = 32;
#endif #endif
} else
#endif
{
int intvalue;
CFDictionaryRef onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(modes, i);
CFNumberRef number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel);
CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
bpp = intvalue;
number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth);
CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
width = (uint16)intvalue;
number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight);
CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
height = (uint16)intvalue;
}
} }
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth) uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int device_depth)
{ {
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6) CFAutoRelease<CFArrayRef> mode_list(CGDisplayCopyAllDisplayModes(display_id, nullptr));
CFArrayRef mode_list = MacOSVersionIsAtLeast(10, 6, 0) ? CGDisplayCopyAllDisplayModes(display_id, NULL) : CGDisplayAvailableModes(display_id); CFIndex num_modes = CFArrayGetCount(mode_list.get());
#elif (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
CFArrayRef mode_list = CGDisplayCopyAllDisplayModes(display_id, NULL);
#else
CFArrayRef mode_list = CGDisplayAvailableModes(display_id);
#endif
CFIndex num_modes = CFArrayGetCount(mode_list);
/* Build list of modes with the requested bpp */ /* Build list of modes with the requested bpp */
uint count = 0; uint count = 0;
@ -301,7 +266,7 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i
int bpp; int bpp;
uint16 width, height; uint16 width, height;
QZ_GetDisplayModeInfo(mode_list, i, bpp, width, height); QZ_GetDisplayModeInfo(mode_list.get(), i, bpp, width, height);
if (bpp != device_depth) continue; if (bpp != device_depth) continue;
@ -325,29 +290,9 @@ uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_i
/* Sort list smallest to largest */ /* Sort list smallest to largest */
std::sort(modes, modes + count, ModeSorter); std::sort(modes, modes + count, ModeSorter);
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
if (MacOSVersionIsAtLeast(10, 6, 0)) CFRelease(mode_list);
#endif
return count; return count;
} }
/** Small function to test if the main display can display 8 bpp in fullscreen */
bool QZ_CanDisplay8bpp()
{
/* 8bpp modes are deprecated starting in 10.5. CoreGraphics will return them
* as available in the display list, but many features (e.g. palette animation)
* will be broken. */
if (MacOSVersionIsAtLeast(10, 5, 0)) return false;
OTTD_Point p;
/* We want to know if 8 bpp is possible in fullscreen and not anything about
* resolutions. Because of this we want to fill a list of 1 resolution of 8 bpp
* on display 0 (main) and return if we found one. */
return QZ_ListModes(&p, 1, 0, 8);
}
/** /**
* Update the video modus. * Update the video modus.
* *
@ -395,7 +340,7 @@ void QZ_GameSizeChanged()
*/ */
static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp) static CocoaSubdriver *QZ_CreateWindowSubdriver(int width, int height, int bpp)
{ {
#if defined(ENABLE_COCOA_QUARTZ) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4) #if defined(ENABLE_COCOA_QUARTZ)
return QZ_CreateWindowQuartzSubdriver(width, height, bpp); return QZ_CreateWindowQuartzSubdriver(width, height, bpp);
#else #else
return nullptr; return nullptr;
@ -453,7 +398,7 @@ void VideoDriver_Cocoa::Stop()
*/ */
const char *VideoDriver_Cocoa::Start(const char * const *parm) const char *VideoDriver_Cocoa::Start(const char * const *parm)
{ {
if (!MacOSVersionIsAtLeast(10, 3, 0)) return "The Cocoa video driver requires Mac OS X 10.3 or later."; if (!MacOSVersionIsAtLeast(10, 6, 0)) return "The Cocoa video driver requires Mac OS X 10.6 or later.";
if (_cocoa_video_started) return "Already started"; if (_cocoa_video_started) return "Already started";
_cocoa_video_started = true; _cocoa_video_started = true;
@ -554,16 +499,7 @@ bool VideoDriver_Cocoa::AfterBlitterChange()
*/ */
void VideoDriver_Cocoa::EditBoxLostFocus() void VideoDriver_Cocoa::EditBoxLostFocus()
{ {
if (_cocoa_subdriver != NULL) { if (_cocoa_subdriver != NULL) [ [ _cocoa_subdriver->cocoaview inputContext ] discardMarkedText ];
if ([ _cocoa_subdriver->cocoaview respondsToSelector:@selector(inputContext) ] && [ [ _cocoa_subdriver->cocoaview performSelector:@selector(inputContext) ] respondsToSelector:@selector(discardMarkedText) ]) {
[ [ _cocoa_subdriver->cocoaview performSelector:@selector(inputContext) ] performSelector:@selector(discardMarkedText) ];
}
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
else {
[ [ NSInputManager currentInputManager ] markedTextAbandoned:_cocoa_subdriver->cocoaview ];
}
#endif
}
/* Clear any marked string from the current edit box. */ /* Clear any marked string from the current edit box. */
HandleTextInput(NULL, true); HandleTextInput(NULL, true);
} }
@ -589,22 +525,13 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
return; return;
} }
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) NSAlert *alert = [ [ NSAlert alloc ] init ];
if (MacOSVersionIsAtLeast(10, 3, 0)) { [ alert setAlertStyle: NSCriticalAlertStyle ];
NSAlert *alert = [ [ NSAlert alloc ] init ]; [ alert setMessageText:[ NSString stringWithUTF8String:title ] ];
[ alert setAlertStyle: NSCriticalAlertStyle ]; [ alert setInformativeText:[ NSString stringWithUTF8String:message ] ];
[ alert setMessageText:[ NSString stringWithUTF8String:title ] ]; [ alert addButtonWithTitle: [ NSString stringWithUTF8String:buttonLabel ] ];
[ alert setInformativeText:[ NSString stringWithUTF8String:message ] ]; [ alert runModal ];
[ alert addButtonWithTitle: [ NSString stringWithUTF8String:buttonLabel ] ]; [ alert release ];
[ alert runModal ];
[ alert release ];
} else
#endif
{
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3)
NSRunAlertPanel([ NSString stringWithUTF8String:title ], [ NSString stringWithUTF8String:message ], [ NSString stringWithUTF8String:buttonLabel ], nil, nil);
#endif
}
if (!wasstarted && VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop(); if (!wasstarted && VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
@ -1030,17 +957,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
{ {
if (!EditBoxInGlobalFocus()) return NSNotFound; if (!EditBoxInGlobalFocus()) return NSNotFound;
NSPoint view_pt = NSZeroPoint; NSPoint view_pt = [ self convertRect:[ [ self window ] convertRectFromScreen:NSMakeRect(thePoint.x, thePoint.y, 0, 0) ] fromView:nil ].origin;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
if ([ [ self window ] respondsToSelector:@selector(convertRectFromScreen:) ]) {
view_pt = [ self convertRect:[ [ self window ] convertRectFromScreen:NSMakeRect(thePoint.x, thePoint.y, 0, 0) ] fromView:nil ].origin;
} else
#endif
{
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7)
view_pt = [ self convertPoint:[ [ self window ] convertScreenToBase:thePoint ] fromView:nil ];
#endif
}
Point pt = { (int)view_pt.x, (int)[ self frame ].size.height - (int)view_pt.y }; Point pt = { (int)view_pt.x, (int)[ self frame ].size.height - (int)view_pt.y };
@ -1063,19 +980,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
Rect r = _focused_window->GetTextBoundingRect(start, end); Rect r = _focused_window->GetTextBoundingRect(start, end);
NSRect view_rect = NSMakeRect(_focused_window->left + r.left, [ self frame ].size.height - _focused_window->top - r.bottom, r.right - r.left, r.bottom - r.top); NSRect view_rect = NSMakeRect(_focused_window->left + r.left, [ self frame ].size.height - _focused_window->top - r.bottom, r.right - r.left, r.bottom - r.top);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 return [ [ self window ] convertRectToScreen:[ self convertRect:view_rect toView:nil ] ];
if ([ [ self window ] respondsToSelector:@selector(convertRectToScreen:) ]) {
return [ [ self window ] convertRectToScreen:[ self convertRect:view_rect toView:nil ] ];
}
#endif
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
NSRect window_rect = [ self convertRect:view_rect toView:nil ];
NSPoint origin = [ [ self window ] convertBaseToScreen:window_rect.origin ];
return NSMakeRect(origin.x, origin.y, window_rect.size.width, window_rect.size.height);
#else
return NSMakeRect(0, 0, 0, 0);;
#endif
} }
/** Get the bounding rect for the given range. */ /** Get the bounding rect for the given range. */
@ -1090,16 +995,6 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
return [ NSArray array ]; return [ NSArray array ];
} }
/** Identifier for this text input instance. */
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
- (long)conversationIdentifier
#else
- (NSInteger)conversationIdentifier
#endif
{
return 0;
}
/** Delete single character left of the cursor. */ /** Delete single character left of the cursor. */
- (void)deleteBackward:(id)sender - (void)deleteBackward:(id)sender
{ {

View File

@ -59,28 +59,12 @@ enum RightMouseButtonEmulationState {
static unsigned int _current_mods; static unsigned int _current_mods;
static bool _tab_is_down; static bool _tab_is_down;
static bool _emulating_right_button; static bool _emulating_right_button;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
static float _current_magnification; static float _current_magnification;
#endif
#ifdef _DEBUG #ifdef _DEBUG
static uint32 _tEvent; static uint32 _tEvent;
#endif #endif
/* Support for touch gestures is only available starting with the
* 10.6 SDK, even if it says that support starts in fact with 10.5.2.
* Replicate the needed stuff for older SDKs. */
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 && MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6)
static const NSUInteger NSEventTypeMagnify = 30;
static const NSUInteger NSEventTypeEndGesture = 20;
@interface NSEvent ()
/* This message is valid for events of type NSEventTypeMagnify, on 10.5.2 or later */
- (CGFloat)magnification WEAK_IMPORT_ATTRIBUTE;
@end
#endif
static uint32 GetTick() static uint32 GetTick()
{ {
struct timeval tim; struct timeval tim;
@ -579,16 +563,13 @@ static bool QZ_PollEvent()
CGFloat deltaY; CGFloat deltaY;
/* Use precise scrolling-specific deltas if they're supported. */ /* Use precise scrolling-specific deltas if they're supported. */
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
if ([event respondsToSelector:@selector(hasPreciseScrollingDeltas)]) { if ([event respondsToSelector:@selector(hasPreciseScrollingDeltas)]) {
/* No precise deltas indicates a scroll wheel is being used, so we don't want 2D scrolling. */ /* No precise deltas indicates a scroll wheel is being used, so we don't want 2D scrolling. */
if (![ event hasPreciseScrollingDeltas ]) break; if (![ event hasPreciseScrollingDeltas ]) break;
deltaX = [ event scrollingDeltaX ] * 0.5f; deltaX = [ event scrollingDeltaX ] * 0.5f;
deltaY = [ event scrollingDeltaY ] * 0.5f; deltaY = [ event scrollingDeltaY ] * 0.5f;
} else } else {
#endif
{
deltaX = [ event deltaX ] * 5; deltaX = [ event deltaX ] * 5;
deltaY = [ event deltaY ] * 5; deltaY = [ event deltaY ] * 5;
} }
@ -598,7 +579,6 @@ static bool QZ_PollEvent()
break; break;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
case NSEventTypeMagnify: case NSEventTypeMagnify:
/* Pinch open or close gesture. */ /* Pinch open or close gesture. */
_current_magnification += [ event magnification ] * 5.0f; _current_magnification += [ event magnification ] * 5.0f;
@ -619,7 +599,6 @@ static bool QZ_PollEvent()
/* Gesture ended. */ /* Gesture ended. */
_current_magnification = 0.0f; _current_magnification = 0.0f;
break; break;
#endif
case NSCursorUpdate: case NSCursorUpdate:
case NSMouseEntered: case NSMouseEntered:

View File

@ -17,8 +17,6 @@
#include "../../stdafx.h" #include "../../stdafx.h"
#include "../../os/macosx/macos.h" #include "../../os/macosx/macos.h"
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
#define Rect OTTDRect #define Rect OTTDRect
#define Point OTTDPoint #define Point OTTDPoint
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
@ -194,21 +192,6 @@ void WindowQuartzSubdriver::GetDeviceInfo()
/* Initialize the video settings; this data persists between mode switches /* Initialize the video settings; this data persists between mode switches
* and gather some information that is useful to know about the display */ * and gather some information that is useful to know about the display */
# if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
/* This way is deprecated as of OSX 10.6 but continues to work.Thus use it
* always, unless allowed to skip compatibility with 10.5 and earlier */
CFDictionaryRef cur_mode = CGDisplayCurrentMode(kCGDirectMainDisplay);
CFNumberGetValue(
(const __CFNumber*)CFDictionaryGetValue(cur_mode, kCGDisplayWidth),
kCFNumberSInt32Type, &this->device_width
);
CFNumberGetValue(
(const __CFNumber*)CFDictionaryGetValue(cur_mode, kCGDisplayHeight),
kCFNumberSInt32Type, &this->device_height
);
# else
/* Use the new API when compiling for OSX 10.6 or later */ /* Use the new API when compiling for OSX 10.6 or later */
CGDisplayModeRef cur_mode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay); CGDisplayModeRef cur_mode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
if (cur_mode == NULL) { return; } if (cur_mode == NULL) { return; }
@ -217,7 +200,6 @@ void WindowQuartzSubdriver::GetDeviceInfo()
this->device_height = CGDisplayModeGetHeight(cur_mode); this->device_height = CGDisplayModeGetHeight(cur_mode);
CGDisplayModeRelease(cur_mode); CGDisplayModeRelease(cur_mode);
# endif
} }
/** Switch to full screen mode on OSX 10.7 /** Switch to full screen mode on OSX 10.7
@ -265,18 +247,11 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp)
return false; return false;
} }
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
/* Add built in full-screen support when available (OS X 10.7 and higher) /* Add built in full-screen support when available (OS X 10.7 and higher)
* This code actually compiles for 10.5 and later, but only makes sense in conjunction * This code actually compiles for 10.5 and later, but only makes sense in conjunction
* with the quartz fullscreen support as found only in 10.7 and later * with the quartz fullscreen support as found only in 10.7 and later
*/ */
if ([this->window respondsToSelector:@selector(toggleFullScreen:)]) { if ([this->window respondsToSelector:@selector(toggleFullScreen:)]) {
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
/* Constants needed to build on pre-10.7 SDKs. Source: NSWindow documentation. */
const int NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7;
const int NSWindowFullScreenButton = 7;
#endif
NSWindowCollectionBehavior behavior = [ this->window collectionBehavior ]; NSWindowCollectionBehavior behavior = [ this->window collectionBehavior ];
behavior |= NSWindowCollectionBehaviorFullScreenPrimary; behavior |= NSWindowCollectionBehaviorFullScreenPrimary;
[ this->window setCollectionBehavior:behavior ]; [ this->window setCollectionBehavior:behavior ];
@ -287,7 +262,6 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp)
[ this->window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary ]; [ this->window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenPrimary ];
} }
#endif
[ this->window setDriver:this ]; [ this->window setDriver:this ];
@ -303,10 +277,6 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp)
[ this->window setAcceptsMouseMovedEvents:YES ]; [ this->window setAcceptsMouseMovedEvents:YES ];
[ this->window setViewsNeedDisplay:NO ]; [ this->window setViewsNeedDisplay:NO ];
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
if ([ this->window respondsToSelector:@selector(useOptimizedDrawing:) ]) [ this->window useOptimizedDrawing:YES ];
#endif
delegate = [ [ OTTD_CocoaWindowDelegate alloc ] init ]; delegate = [ [ OTTD_CocoaWindowDelegate alloc ] init ];
[ delegate setDriver:this ]; [ delegate setDriver:this ];
[ this->window setDelegate:[ delegate autorelease ] ]; [ this->window setDelegate:[ delegate autorelease ] ];
@ -494,17 +464,8 @@ CGPoint WindowQuartzSubdriver::PrivateLocalToCG(NSPoint *p)
p->y = this->window_height - p->y; p->y = this->window_height - p->y;
*p = [ this->cocoaview convertPoint:*p toView:nil ]; *p = [ this->cocoaview convertPoint:*p toView:nil ];
*p = [ this->window convertRectToScreen:NSMakeRect(p->x, p->y, 0, 0) ].origin;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if ([ this->window respondsToSelector:@selector(convertRectToScreen:) ]) {
*p = [ this->window convertRectToScreen:NSMakeRect(p->x, p->y, 0, 0) ].origin;
} else
#endif
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
*p = [ this->window convertBaseToScreen:*p ];
#endif
}
p->y = this->device_height - p->y; p->y = this->device_height - p->y;
CGPoint cgp; CGPoint cgp;
@ -519,17 +480,7 @@ NSPoint WindowQuartzSubdriver::GetMouseLocation(NSEvent *event)
NSPoint pt; NSPoint pt;
if ( [ event window ] == nil) { if ( [ event window ] == nil) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 pt = [ this->cocoaview convertPoint:[ [ this->cocoaview window ] convertRectFromScreen:NSMakeRect([ event locationInWindow ].x, [ event locationInWindow ].y, 0, 0) ].origin fromView:nil ];
if ([ [ this->cocoaview window ] respondsToSelector:@selector(convertRectFromScreen:) ]) {
pt = [ this->cocoaview convertPoint:[ [ this->cocoaview window ] convertRectFromScreen:NSMakeRect([ event locationInWindow ].x, [ event locationInWindow ].y, 0, 0) ].origin fromView:nil ];
}
else
#endif
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
pt = [ this->cocoaview convertPoint:[ [ this->cocoaview window ] convertScreenToBase:[ event locationInWindow ] ] fromView:nil ];
#endif
}
} else { } else {
pt = [ event locationInWindow ]; pt = [ event locationInWindow ];
} }
@ -609,8 +560,8 @@ bool WindowQuartzSubdriver::WindowResized()
CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp) CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp)
{ {
if (!MacOSVersionIsAtLeast(10, 4, 0)) { if (!MacOSVersionIsAtLeast(10, 7, 0)) {
DEBUG(driver, 0, "The cocoa quartz subdriver requires Mac OS X 10.4 or later."); DEBUG(driver, 0, "The cocoa quartz subdriver requires Mac OS X 10.7 or later.");
return NULL; return NULL;
} }
@ -630,6 +581,5 @@ CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp)
} }
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 */
#endif /* ENABLE_COCOA_QUARTZ */ #endif /* ENABLE_COCOA_QUARTZ */
#endif /* WITH_COCOA */ #endif /* WITH_COCOA */