iOS: fix compile errors when SDL3 is used

This commit is contained in:
Sasha Szpakowski
2024-10-08 17:05:39 -03:00
parent 28393cdfd5
commit 8227b7bcba
4 changed files with 67 additions and 1 deletions
+31 -1
View File
@@ -35,9 +35,16 @@ using namespace love::apple;
#include <vector>
#if __has_include(<SDL3/SDL_events.h>)
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_video.h>
#include <SDL3/SDL_version.h>
#else
#include <SDL_events.h>
#include <SDL_video.h>
#include <SDL_syswm.h>
#include <SDL_version.h>
#endif
static NSArray *getLovesInDocuments();
static bool deleteFileInDocuments(NSString *filename);
@@ -167,14 +174,27 @@ static bool deleteFileInDocuments(NSString *filename)
return success;
}
static int dropFileEventFilter(void *userdata, SDL_Event *event)
#if SDL_VERSION_ATLEAST(3, 0, 0)
static bool
#else
static int
#endif
dropFileEventFilter(void *userdata, SDL_Event *event)
{
@autoreleasepool
{
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (event->type != SDL_EVENT_DROP_FILE)
#else
if (event->type != SDL_DROPFILE)
#endif
return 1;
#if SDL_VERSION_ATLEAST(3, 0, 0)
NSString *fname = @(event->drop.data);
#else
NSString *fname = @(event->drop.file);
#endif
NSFileManager *fmanager = [NSFileManager defaultManager];
if ([fmanager fileExistsAtPath:fname] && [fname.pathExtension isEqual:@"love"])
@@ -195,7 +215,9 @@ static int dropFileEventFilter(void *userdata, SDL_Event *event)
vc.gameList = [[NSMutableArray alloc] initWithArray:games copyItems:YES];
[vc.tableView reloadData];
#if !SDL_VERSION_ATLEAST(3, 0, 0)
SDL_free(event->drop.file);
#endif
return 0;
}
}
@@ -434,11 +456,19 @@ Rect getSafeArea(SDL_Window *window)
Rect rect = {};
SDL_GetWindowSize(window, &rect.w, &rect.h);
#if SDL_VERSION_ATLEAST(3, 0, 0)
SDL_PropertiesID props = SDL_GetWindowProperties(window);
UIWindow *window = (__bridge UIWindow *) SDL_GetPointerProperty(props, SDL_PROP_WINDOW_UIKIT_WINDOW_POINTER, nullptr);
if (window != nil)
{
UIView *view = window.rootViewController.view;
#else
SDL_SysWMinfo info = {};
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(window, &info))
{
UIView *view = info.info.uikit.window.rootViewController.view;
#endif
if (@available(iOS 11.0, tvOS 11.0, *))
{
UIEdgeInsets insets = view.safeAreaInsets;