Browse Source

Updates for Mac

Fixed a number of technical debt issues with the Mac build. Fixed an issue with the cursor not appearing outside of window and a problem where window resize causes incorrect canvas placement.
Greenfire27 1 year ago
parent
commit
1e4562a71c

+ 1 - 0
engine/source/platform/platformInput.h

@@ -147,6 +147,7 @@ protected:
     static U8 smModifierKeys; ///< Current Modifier Keys Pressed
     static bool smLastMouseActivated;
     static bool smLastJoystickActivated;
+	static bool smCursorGuard; ///< Used by Mac to prevent over hiding the cursor
 
 public:
     static void init();

+ 14 - 1
engine/source/platformOSX/osxInput.mm

@@ -28,6 +28,7 @@
 InputManager *Input::smManager = 0;
 CursorManager *Input::smCursorManager = 0;
 bool Input::smActive;
+bool Input::smCursorGuard;
 
 #pragma mark ---- Input Namespace Functions ----
 
@@ -42,6 +43,7 @@ void Input::init()
 
     smManager = NULL;
     smActive = false;
+	smCursorGuard = true; //cursor starts visible
 
     if (!smManager)
         smManager = new osxInputManager();
@@ -349,7 +351,18 @@ void Input::setCursorPos(S32 x, S32 y)
 // Not yet implemented. Will resolve in the next platform update
 void Input::setCursorState(bool on)
 {
-    on ? [NSCursor unhide] : [NSCursor hide];
+	if(!smCursorGuard && on)
+	{
+		//We are turning on the native cursor
+		[NSCursor unhide];
+	}
+	else if(smCursorGuard && !on)
+	{
+		//We are turning off the native cursor
+		[NSCursor hide];
+	}
+
+	smCursorGuard = on;
 }
 
 

+ 1 - 1
engine/source/platformOSX/osxOpenGLDevice.mm

@@ -298,7 +298,7 @@ bool osxOpenGLDevice::setScreenMode( U32 width, U32 height, U32 bpp, bool fullSc
         // Send message to the window to resize/relocate
         [[platState window] setFrame:newFrame display:YES animate:NO];
 #else
-        [[platState window] setStyleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask];
+		[[platState window] setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable];
 #endif
     }
 

+ 14 - 18
engine/source/platformOSX/osxTorqueView.mm

@@ -97,18 +97,14 @@
 // Called whent the parent finishes its live resizing
 - (void)windowFinishedLiveResize:(NSNotification *)notification
 {
-    NSSize size = [[self window] frame].size;
-
-    [[osxPlatState sharedPlatState] setWindowSize:(S32)size.width height:(S32)size.height];
-    
-    NSRect frame = NSMakeRect(0, 0, size.width, size.height);
-    
-    S32 barHeight = frame.size.height;
-    frame = [NSWindow frameRectForContentRect:frame styleMask:NSTitledWindowMask];
-    barHeight -= frame.size.height;
-    
-    NSRect viewFrame = NSMakeRect(0, barHeight, frame.size.width, frame.size.height);
-    
+	NSSize actualWindowSize = [[self window] frame].size;
+	NSRect frame = NSMakeRect(0, 0, actualWindowSize.width, actualWindowSize.height);
+	frame = [NSWindow frameRectForContentRect:frame styleMask:NSWindowStyleMaskTitled];
+	S32 barHeight = frame.size.height - actualWindowSize.height;
+	S32 heightWithoutTitle = actualWindowSize.height - barHeight;
+	[[osxPlatState sharedPlatState] setWindowSize:(S32)actualWindowSize.width height:heightWithoutTitle];
+	
+	NSRect viewFrame = NSMakeRect(0, 0, frame.size.width, heightWithoutTitle);
     [self setFrame:viewFrame];
     [self updateContext];
 }
@@ -210,16 +206,16 @@
     
     U32 keyMods = (U32)[event modifierFlags];
     
-    if (keyMods & NSShiftKeyMask)
+	if (keyMods & NSEventModifierFlagShift)
         modifiers |= SI_SHIFT;
     
-    if (keyMods & NSCommandKeyMask)
+	if (keyMods & NSEventModifierFlagCommand)
         modifiers |= SI_ALT;
     
-    if (keyMods & NSAlternateKeyMask)
+	if (keyMods & NSEventModifierFlagOption)
         modifiers |= SI_MAC_OPT;
     
-    if (keyMods & NSControlKeyMask)
+	if (keyMods & NSEventModifierFlagControl)
         modifiers |= SI_CTRL;
 }
 
@@ -374,13 +370,13 @@
 {
     if (!Canvas->getUseNativeCursor())
     {
-        [NSCursor hide];
+		Input::setCursorState(false);
     }
 }
 
 -(void)mouseExited:(NSEvent *)event
 {
-    [NSCursor unhide];
+	Input::setCursorState(true);
 }
 // Default otherMouseDown override
 - (void)mouseMoved:(NSEvent *)event

+ 2 - 2
engine/source/platformOSX/osxWindow.mm

@@ -92,7 +92,7 @@ void Platform::initWindow(const Point2I &initialSize, const char *name)
     NSRect frame = NSMakeRect(0, 0, [platState windowWidth], [platState windowHeight]);
     
     NSWindow *tempWindow = [[[NSWindow alloc] initWithContentRect:frame
-                                              styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask
+														styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable
                                               backing:NSBackingStoreBuffered
                                               defer:NO] autorelease];
     
@@ -100,7 +100,7 @@ void Platform::initWindow(const Point2I &initialSize, const char *name)
 
     // The full frame for a window must consider the title bar height as well
     // Thus, our NSWindow must be larger than the passed width and height
-    frame = [NSWindow frameRectForContentRect:frame styleMask:NSTitledWindowMask];
+	frame = [NSWindow frameRectForContentRect:frame styleMask:NSWindowStyleMaskTitled];
     [tempWindow setFrame:frame display:YES];
 
     [platState setWindow:tempWindow];

+ 3 - 1
engine/source/platformOSX/platformOSX.h

@@ -28,6 +28,8 @@
 #include "math/mPoint.h"
 #include "math/mRandom.h"
 
+#define GL_SILENCE_DEPRECATION
+
 @interface osxPlatState : NSObject
 {
     // Main application Window
@@ -135,4 +137,4 @@
 - (U32)windowWidth;
 - (U32)windowHeight;
 
-@end
+@end

+ 2 - 20
engine/source/platformOSX/platformOSX.mm

@@ -132,29 +132,14 @@ static osxPlatState * tempSharedPlatState = nil;
     // Get the window's current frame
     NSRect frame = NSMakeRect([_window frame].origin.x, [_window frame].origin.y, width, height);
     
-    // Get the starting position of the bar height
-    F32 barOffset = frame.size.height;
-    
     // If we are not going to full screen mode, get a new frame offset that accounts
     // for the title bar height
     if (!_fullscreen)
     {
-        frame = [NSWindow frameRectForContentRect:frame styleMask:NSTitledWindowMask];
+		frame = [NSWindow frameRectForContentRect:frame styleMask:NSWindowStyleMaskTitled];
         
         // Set the new window frame
         [_window setFrame:frame display:YES];
-        
-        // Get the new position of the title bar
-        barOffset -= frame.size.height;
-        
-#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1070
-        
-        // Update the frame of the torqueView to match the window
-        frame = NSMakeRect([_window frame].origin.x, [_window frame].origin.y, width, height);
-        NSRect viewFrame = NSMakeRect(0, 0, frame.size.width, frame.size.height);
-        [_torqueView setFrame:viewFrame];
-        [_torqueView updateContext];
-#endif
     }
     else
     {
@@ -176,16 +161,13 @@ static osxPlatState * tempSharedPlatState = nil;
     }
     
     // Update the frame of the torqueView to match the window
-    frame = NSMakeRect([_window frame].origin.x, [_window frame].origin.y, width, height);
-    NSRect viewFrame = NSMakeRect(0, 0, frame.size.width, frame.size.height);
-    
+    NSRect viewFrame = NSMakeRect(0, 0, width, height);
     [_torqueView setFrame:viewFrame];
     
     [_torqueView updateContext];
     
     [_window makeKeyAndOrderFront:NSApp];
     [_window makeFirstResponder:_torqueView];
-    
 }
 
 //-----------------------------------------------------------------------------