Skip to content

Commit

Permalink
Updates for Mac
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greenfire27 committed Jan 8, 2024
1 parent b724ae5 commit 1e4562a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 43 deletions.
1 change: 1 addition & 0 deletions engine/source/platform/platformInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Input
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();
Expand Down
15 changes: 14 additions & 1 deletion engine/source/platformOSX/osxInput.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
InputManager *Input::smManager = 0;
CursorManager *Input::smCursorManager = 0;
bool Input::smActive;
bool Input::smCursorGuard;

#pragma mark ---- Input Namespace Functions ----

Expand All @@ -42,6 +43,7 @@

smManager = NULL;
smActive = false;
smCursorGuard = true; //cursor starts visible

if (!smManager)
smManager = new osxInputManager();
Expand Down Expand Up @@ -349,7 +351,18 @@
// 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;
}


Expand Down
2 changes: 1 addition & 1 deletion engine/source/platformOSX/osxOpenGLDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
// 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
}

Expand Down
32 changes: 14 additions & 18 deletions engine/source/platformOSX/osxTorqueView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,14 @@ - (BOOL)acceptsFirstResponder
// 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];
}
Expand Down Expand Up @@ -210,16 +206,16 @@ - (void)getModifierKey:(U32&)modifiers event:(NSEvent *)event;

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;
}

Expand Down Expand Up @@ -374,13 +370,13 @@ - (void)mouseEntered:(NSEvent *)event
{
if (!Canvas->getUseNativeCursor())
{
[NSCursor hide];
Input::setCursorState(false);
}
}

-(void)mouseExited:(NSEvent *)event
{
[NSCursor unhide];
Input::setCursorState(true);
}
// Default otherMouseDown override
- (void)mouseMoved:(NSEvent *)event
Expand Down
4 changes: 2 additions & 2 deletions engine/source/platformOSX/osxWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ static void osxGetInitialResolution(U32 &width, U32 &height, U32 &bpp, bool &ful
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];

[tempWindow setBackgroundColor:[NSColor blackColor]];

// 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];
Expand Down
4 changes: 3 additions & 1 deletion engine/source/platformOSX/platformOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "math/mPoint.h"
#include "math/mRandom.h"

#define GL_SILENCE_DEPRECATION

@interface osxPlatState : NSObject
{
// Main application Window
Expand Down Expand Up @@ -135,4 +137,4 @@
- (U32)windowWidth;
- (U32)windowHeight;

@end
@end
22 changes: 2 additions & 20 deletions engine/source/platformOSX/platformOSX.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,14 @@ - (void)setWindowSize:(int)width height:(int)height
// 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
{
Expand All @@ -176,16 +161,13 @@ - (void)setWindowSize:(int)width height:(int)height
}

// 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];

}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 1e4562a

Please sign in to comment.