Skip to content

Commit 1e4562a

Browse files
committed
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.
1 parent b724ae5 commit 1e4562a

File tree

7 files changed

+37
-43
lines changed

7 files changed

+37
-43
lines changed

engine/source/platform/platformInput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class Input
147147
static U8 smModifierKeys; ///< Current Modifier Keys Pressed
148148
static bool smLastMouseActivated;
149149
static bool smLastJoystickActivated;
150+
static bool smCursorGuard; ///< Used by Mac to prevent over hiding the cursor
150151

151152
public:
152153
static void init();

engine/source/platformOSX/osxInput.mm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
InputManager *Input::smManager = 0;
2929
CursorManager *Input::smCursorManager = 0;
3030
bool Input::smActive;
31+
bool Input::smCursorGuard;
3132

3233
#pragma mark ---- Input Namespace Functions ----
3334

@@ -42,6 +43,7 @@
4243

4344
smManager = NULL;
4445
smActive = false;
46+
smCursorGuard = true; //cursor starts visible
4547

4648
if (!smManager)
4749
smManager = new osxInputManager();
@@ -349,7 +351,18 @@
349351
// Not yet implemented. Will resolve in the next platform update
350352
void Input::setCursorState(bool on)
351353
{
352-
on ? [NSCursor unhide] : [NSCursor hide];
354+
if(!smCursorGuard && on)
355+
{
356+
//We are turning on the native cursor
357+
[NSCursor unhide];
358+
}
359+
else if(smCursorGuard && !on)
360+
{
361+
//We are turning off the native cursor
362+
[NSCursor hide];
363+
}
364+
365+
smCursorGuard = on;
353366
}
354367

355368

engine/source/platformOSX/osxOpenGLDevice.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
// Send message to the window to resize/relocate
299299
[[platState window] setFrame:newFrame display:YES animate:NO];
300300
#else
301-
[[platState window] setStyleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask];
301+
[[platState window] setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable];
302302
#endif
303303
}
304304

engine/source/platformOSX/osxTorqueView.mm

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,14 @@ - (BOOL)acceptsFirstResponder
9797
// Called whent the parent finishes its live resizing
9898
- (void)windowFinishedLiveResize:(NSNotification *)notification
9999
{
100-
NSSize size = [[self window] frame].size;
101-
102-
[[osxPlatState sharedPlatState] setWindowSize:(S32)size.width height:(S32)size.height];
103-
104-
NSRect frame = NSMakeRect(0, 0, size.width, size.height);
105-
106-
S32 barHeight = frame.size.height;
107-
frame = [NSWindow frameRectForContentRect:frame styleMask:NSTitledWindowMask];
108-
barHeight -= frame.size.height;
109-
110-
NSRect viewFrame = NSMakeRect(0, barHeight, frame.size.width, frame.size.height);
111-
100+
NSSize actualWindowSize = [[self window] frame].size;
101+
NSRect frame = NSMakeRect(0, 0, actualWindowSize.width, actualWindowSize.height);
102+
frame = [NSWindow frameRectForContentRect:frame styleMask:NSWindowStyleMaskTitled];
103+
S32 barHeight = frame.size.height - actualWindowSize.height;
104+
S32 heightWithoutTitle = actualWindowSize.height - barHeight;
105+
[[osxPlatState sharedPlatState] setWindowSize:(S32)actualWindowSize.width height:heightWithoutTitle];
106+
107+
NSRect viewFrame = NSMakeRect(0, 0, frame.size.width, heightWithoutTitle);
112108
[self setFrame:viewFrame];
113109
[self updateContext];
114110
}
@@ -210,16 +206,16 @@ - (void)getModifierKey:(U32&)modifiers event:(NSEvent *)event;
210206

211207
U32 keyMods = (U32)[event modifierFlags];
212208

213-
if (keyMods & NSShiftKeyMask)
209+
if (keyMods & NSEventModifierFlagShift)
214210
modifiers |= SI_SHIFT;
215211

216-
if (keyMods & NSCommandKeyMask)
212+
if (keyMods & NSEventModifierFlagCommand)
217213
modifiers |= SI_ALT;
218214

219-
if (keyMods & NSAlternateKeyMask)
215+
if (keyMods & NSEventModifierFlagOption)
220216
modifiers |= SI_MAC_OPT;
221217

222-
if (keyMods & NSControlKeyMask)
218+
if (keyMods & NSEventModifierFlagControl)
223219
modifiers |= SI_CTRL;
224220
}
225221

@@ -374,13 +370,13 @@ - (void)mouseEntered:(NSEvent *)event
374370
{
375371
if (!Canvas->getUseNativeCursor())
376372
{
377-
[NSCursor hide];
373+
Input::setCursorState(false);
378374
}
379375
}
380376

381377
-(void)mouseExited:(NSEvent *)event
382378
{
383-
[NSCursor unhide];
379+
Input::setCursorState(true);
384380
}
385381
// Default otherMouseDown override
386382
- (void)mouseMoved:(NSEvent *)event

engine/source/platformOSX/osxWindow.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ static void osxGetInitialResolution(U32 &width, U32 &height, U32 &bpp, bool &ful
9292
NSRect frame = NSMakeRect(0, 0, [platState windowWidth], [platState windowHeight]);
9393

9494
NSWindow *tempWindow = [[[NSWindow alloc] initWithContentRect:frame
95-
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask
95+
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable
9696
backing:NSBackingStoreBuffered
9797
defer:NO] autorelease];
9898

9999
[tempWindow setBackgroundColor:[NSColor blackColor]];
100100

101101
// The full frame for a window must consider the title bar height as well
102102
// Thus, our NSWindow must be larger than the passed width and height
103-
frame = [NSWindow frameRectForContentRect:frame styleMask:NSTitledWindowMask];
103+
frame = [NSWindow frameRectForContentRect:frame styleMask:NSWindowStyleMaskTitled];
104104
[tempWindow setFrame:frame display:YES];
105105

106106
[platState setWindow:tempWindow];

engine/source/platformOSX/platformOSX.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "math/mPoint.h"
2929
#include "math/mRandom.h"
3030

31+
#define GL_SILENCE_DEPRECATION
32+
3133
@interface osxPlatState : NSObject
3234
{
3335
// Main application Window
@@ -135,4 +137,4 @@
135137
- (U32)windowWidth;
136138
- (U32)windowHeight;
137139

138-
@end
140+
@end

engine/source/platformOSX/platformOSX.mm

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,29 +132,14 @@ - (void)setWindowSize:(int)width height:(int)height
132132
// Get the window's current frame
133133
NSRect frame = NSMakeRect([_window frame].origin.x, [_window frame].origin.y, width, height);
134134

135-
// Get the starting position of the bar height
136-
F32 barOffset = frame.size.height;
137-
138135
// If we are not going to full screen mode, get a new frame offset that accounts
139136
// for the title bar height
140137
if (!_fullscreen)
141138
{
142-
frame = [NSWindow frameRectForContentRect:frame styleMask:NSTitledWindowMask];
139+
frame = [NSWindow frameRectForContentRect:frame styleMask:NSWindowStyleMaskTitled];
143140

144141
// Set the new window frame
145142
[_window setFrame:frame display:YES];
146-
147-
// Get the new position of the title bar
148-
barOffset -= frame.size.height;
149-
150-
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1070
151-
152-
// Update the frame of the torqueView to match the window
153-
frame = NSMakeRect([_window frame].origin.x, [_window frame].origin.y, width, height);
154-
NSRect viewFrame = NSMakeRect(0, 0, frame.size.width, frame.size.height);
155-
[_torqueView setFrame:viewFrame];
156-
[_torqueView updateContext];
157-
#endif
158143
}
159144
else
160145
{
@@ -176,16 +161,13 @@ - (void)setWindowSize:(int)width height:(int)height
176161
}
177162

178163
// Update the frame of the torqueView to match the window
179-
frame = NSMakeRect([_window frame].origin.x, [_window frame].origin.y, width, height);
180-
NSRect viewFrame = NSMakeRect(0, 0, frame.size.width, frame.size.height);
181-
164+
NSRect viewFrame = NSMakeRect(0, 0, width, height);
182165
[_torqueView setFrame:viewFrame];
183166

184167
[_torqueView updateContext];
185168

186169
[_window makeKeyAndOrderFront:NSApp];
187170
[_window makeFirstResponder:_torqueView];
188-
189171
}
190172

191173
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)