Skip to content

Commit

Permalink
- fixed deprecation warnings in Cocoa backend
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Oct 18, 2021
1 parent 7741a93 commit 8ec6c21
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
92 changes: 46 additions & 46 deletions src/common/platform/posix/cocoa/i_input.mm
Expand Up @@ -284,32 +284,32 @@ uint8_t ModifierToDIK(const uint32_t modifier)
{
switch (modifier)
{
case NSAlphaShiftKeyMask: return DIK_CAPITAL;
case NSShiftKeyMask: return DIK_LSHIFT;
case NSControlKeyMask: return DIK_LCONTROL;
case NSAlternateKeyMask: return DIK_LMENU;
case NSCommandKeyMask: return DIK_LWIN;
case NSEventModifierFlagCapsLock: return DIK_CAPITAL;
case NSEventModifierFlagShift: return DIK_LSHIFT;
case NSEventModifierFlagControl: return DIK_LCONTROL;
case NSEventModifierFlagOption: return DIK_LMENU;
case NSEventModifierFlagCommand: return DIK_LWIN;
}

return 0;
}

int16_t ModifierFlagsToGUIKeyModifiers(NSEvent* theEvent)
{
const NSUInteger modifiers([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask);
return ((modifiers & NSShiftKeyMask ) ? GKM_SHIFT : 0)
| ((modifiers & NSControlKeyMask ) ? GKM_CTRL : 0)
| ((modifiers & NSAlternateKeyMask) ? GKM_ALT : 0)
| ((modifiers & NSCommandKeyMask ) ? GKM_META : 0);
const NSUInteger modifiers([theEvent modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask);
return ((modifiers & NSEventModifierFlagShift ) ? GKM_SHIFT : 0)
| ((modifiers & NSEventModifierFlagControl) ? GKM_CTRL : 0)
| ((modifiers & NSEventModifierFlagOption ) ? GKM_ALT : 0)
| ((modifiers & NSEventModifierFlagCommand) ? GKM_META : 0);
}

bool ShouldGenerateGUICharEvent(NSEvent* theEvent)
{
const NSUInteger modifiers([theEvent modifierFlags] & NSDeviceIndependentModifierFlagsMask);
return !(modifiers & NSControlKeyMask)
&& !(modifiers & NSAlternateKeyMask)
&& !(modifiers & NSCommandKeyMask)
&& !(modifiers & NSFunctionKeyMask);
const NSUInteger modifiers([theEvent modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask);
return !(modifiers & NSEventModifierFlagControl)
&& !(modifiers & NSEventModifierFlagOption)
&& !(modifiers & NSEventModifierFlagCommand)
&& !(modifiers & NSEventModifierFlagFunction);
}


Expand Down Expand Up @@ -373,7 +373,7 @@ void ProcessKeyboardEventInMenu(NSEvent* theEvent)

unichar realchar;
event.type = EV_GUI_Event;
event.subtype = NSKeyDown == [theEvent type] ? EV_GUI_KeyDown : EV_GUI_KeyUp;
event.subtype = NSEventTypeKeyDown == [theEvent type] ? EV_GUI_KeyDown : EV_GUI_KeyUp;
event.data2 = GetCharacterFromNSEvent(theEvent, &realchar);
event.data3 = ModifierFlagsToGUIKeyModifiers(theEvent);

Expand Down Expand Up @@ -505,8 +505,8 @@ void ProcessKeyboardEvent(NSEvent* theEvent)

if (k_allowfullscreentoggle
&& (kVK_ANSI_F == keyCode)
&& (NSCommandKeyMask & [theEvent modifierFlags])
&& (NSKeyDown == [theEvent type])
&& (NSEventModifierFlagCommand & [theEvent modifierFlags])
&& (NSEventTypeKeyDown == [theEvent type])
&& !isARepeat)
{
ToggleFullscreen = !ToggleFullscreen;
Expand All @@ -521,7 +521,7 @@ void ProcessKeyboardEvent(NSEvent* theEvent)
{
event_t event = {};

event.type = NSKeyDown == [theEvent type] ? EV_KeyDown : EV_KeyUp;
event.type = NSEventTypeKeyDown == [theEvent type] ? EV_KeyDown : EV_KeyUp;
event.data1 = KEYCODE_TO_DIK[ keyCode ];

if (0 != event.data1)
Expand All @@ -542,7 +542,7 @@ void ProcessKeyboardFlagsEvent(NSEvent* theEvent)
}

static const uint32_t FLAGS_MASK =
NSDeviceIndependentModifierFlagsMask & ~NSNumericPadKeyMask;
NSEventModifierFlagDeviceIndependentFlagsMask & ~NSEventModifierFlagNumericPad;

const uint32_t modifiers = [theEvent modifierFlags] & FLAGS_MASK;
static uint32_t oldModifiers = 0;
Expand Down Expand Up @@ -611,12 +611,12 @@ void ProcessMouseButtonEvent(NSEvent* theEvent)

switch (cocoaEventType)
{
case NSLeftMouseDown: event.subtype = EV_GUI_LButtonDown; break;
case NSRightMouseDown: event.subtype = EV_GUI_RButtonDown; break;
case NSOtherMouseDown: event.subtype = EV_GUI_MButtonDown; break;
case NSLeftMouseUp: event.subtype = EV_GUI_LButtonUp; break;
case NSRightMouseUp: event.subtype = EV_GUI_RButtonUp; break;
case NSOtherMouseUp: event.subtype = EV_GUI_MButtonUp; break;
case NSEventTypeLeftMouseDown: event.subtype = EV_GUI_LButtonDown; break;
case NSEventTypeRightMouseDown: event.subtype = EV_GUI_RButtonDown; break;
case NSEventTypeOtherMouseDown: event.subtype = EV_GUI_MButtonDown; break;
case NSEventTypeLeftMouseUp: event.subtype = EV_GUI_LButtonUp; break;
case NSEventTypeRightMouseUp: event.subtype = EV_GUI_RButtonUp; break;
case NSEventTypeOtherMouseUp: event.subtype = EV_GUI_MButtonUp; break;
default: break;
}

Expand All @@ -628,15 +628,15 @@ void ProcessMouseButtonEvent(NSEvent* theEvent)
{
switch (cocoaEventType)
{
case NSLeftMouseDown:
case NSRightMouseDown:
case NSOtherMouseDown:
case NSEventTypeLeftMouseDown:
case NSEventTypeRightMouseDown:
case NSEventTypeOtherMouseDown:
event.type = EV_KeyDown;
break;

case NSLeftMouseUp:
case NSRightMouseUp:
case NSOtherMouseUp:
case NSEventTypeLeftMouseUp:
case NSEventTypeRightMouseUp:
case NSEventTypeOtherMouseUp:
event.type = EV_KeyUp;
break;

Expand Down Expand Up @@ -694,36 +694,36 @@ void I_ProcessEvent(NSEvent* event)

switch (eventType)
{
case NSMouseMoved:
case NSEventTypeMouseMoved:
ProcessMouseMoveEvent(event);
break;

case NSLeftMouseDown:
case NSLeftMouseUp:
case NSRightMouseDown:
case NSRightMouseUp:
case NSOtherMouseDown:
case NSOtherMouseUp:
case NSEventTypeLeftMouseDown:
case NSEventTypeLeftMouseUp:
case NSEventTypeRightMouseDown:
case NSEventTypeRightMouseUp:
case NSEventTypeOtherMouseDown:
case NSEventTypeOtherMouseUp:
ProcessMouseButtonEvent(event);
break;

case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged:
case NSEventTypeLeftMouseDragged:
case NSEventTypeRightMouseDragged:
case NSEventTypeOtherMouseDragged:
ProcessMouseButtonEvent(event);
ProcessMouseMoveEvent(event);
break;

case NSScrollWheel:
case NSEventTypeScrollWheel:
ProcessMouseWheelEvent(event);
break;

case NSKeyDown:
case NSKeyUp:
case NSEventTypeKeyDown:
case NSEventTypeKeyUp:
ProcessKeyboardEvent(event);
break;

case NSFlagsChanged:
case NSEventTypeFlagsChanged:
ProcessKeyboardFlagsEvent(event);
break;

Expand Down
4 changes: 2 additions & 2 deletions src/common/platform/posix/cocoa/i_main.mm
Expand Up @@ -396,7 +396,7 @@ - (void)processEvents:(NSTimer*)timer

while (true)
{
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
NSEvent* event = [NSApp nextEventMatchingMask:NSEventMaskAny
untilDate:[NSDate dateWithTimeIntervalSinceNow:0]
inMode:NSDefaultRunLoopMode
dequeue:YES];
Expand Down Expand Up @@ -449,7 +449,7 @@ - (void)sendExitEvent:(id)sender
[[menu addItemWithTitle:@"Hide Others"
action:@selector(hideOtherApplications:)
keyEquivalent:@"h"]
setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
setKeyEquivalentModifierMask:NSEventModifierFlagOption | NSEventModifierFlagCommand];
[menu addItemWithTitle:@"Show All"
action:@selector(unhideAllApplications:)
keyEquivalent:@""];
Expand Down
4 changes: 2 additions & 2 deletions src/common/platform/posix/cocoa/i_video.mm
Expand Up @@ -121,8 +121,8 @@ - (void)enterFullscreenOnZoom
const NSInteger LEVEL_FULLSCREEN = NSMainMenuWindowLevel + 1;
const NSInteger LEVEL_WINDOWED = NSNormalWindowLevel;

const NSUInteger STYLE_MASK_FULLSCREEN = NSBorderlessWindowMask;
const NSUInteger STYLE_MASK_WINDOWED = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
const NSUInteger STYLE_MASK_FULLSCREEN = NSWindowStyleMaskBorderless;
const NSUInteger STYLE_MASK_WINDOWED = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable;
}


Expand Down
6 changes: 3 additions & 3 deletions src/common/platform/posix/cocoa/st_console.mm
Expand Up @@ -104,7 +104,7 @@
NSString* const title = [NSString stringWithFormat:@"%s %s - Console", GAMENAME, GetVersionString()];

[m_window initWithContentRect:initialRect
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable
backing:NSBackingStoreBuffered
defer:NO];
[m_window setMinSize:[m_window frame].size];
Expand Down Expand Up @@ -348,7 +348,7 @@ static void UpdateTimed(const Function& function)
NSTextField* titleText = [[NSTextField alloc] initWithFrame:titleTextRect];
[titleText setStringValue:[NSString stringWithCString:GameStartupInfo.Name.GetChars()
encoding:NSISOLatin1StringEncoding]];
[titleText setAlignment:NSCenterTextAlignment];
[titleText setAlignment:NSTextAlignmentCenter];
[titleText setTextColor:RGB(GameStartupInfo.FgColor)];
[titleText setBackgroundColor:RGB(GameStartupInfo.BkColor)];
[titleText setFont:[NSFont fontWithName:@"Trebuchet MS Bold" size:18.0f]];
Expand Down Expand Up @@ -434,7 +434,7 @@ static void UpdateTimed(const Function& function)
// Text with connected/total players count
m_netCountText = [[NSTextField alloc] initWithFrame:NSMakeRect(428.0f, 64.0f, 72.0f, 16.0f)];
[m_netCountText setAutoresizingMask:NSViewMinXMargin];
[m_netCountText setAlignment:NSRightTextAlignment];
[m_netCountText setAlignment:NSTextAlignmentRight];
[m_netCountText setDrawsBackground:NO];
[m_netCountText setSelectable:NO];
[m_netCountText setBordered:NO];
Expand Down
4 changes: 2 additions & 2 deletions src/common/platform/posix/osx/iwadpicker_cocoa.mm
Expand Up @@ -194,7 +194,7 @@ - (void)browseButtonPressed:(id) sender
[openPanel setResolvesAliases:YES];
[openPanel setAllowedFileTypes:GetKnownExtensions()];

if (NSOKButton == [openPanel runModal])
if (NSModalResponseOK == [openPanel runModal])
{
NSArray* files = [openPanel URLs];
NSMutableString* parameters = [NSMutableString string];
Expand Down Expand Up @@ -259,7 +259,7 @@ - (int)pickIWad:(WadStuff *)wads num:(int) numwads showWindow:(bool) showwin def
id windowTitle = [NSString stringWithFormat:@"%s %s", GAMENAME, GetVersionString()];

NSRect frame = NSMakeRect(0, 0, 440, 450);
window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO];
window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:NO];
[window setTitle:windowTitle];

NSTextField *description = [[NSTextField alloc] initWithFrame:NSMakeRect(18, 384, 402, 50)];
Expand Down

0 comments on commit 8ec6c21

Please sign in to comment.