Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More iOS fixes #19224

Merged
merged 4 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Common/Render/Text/draw_text_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ void Destroy() {
return false;
}

std::string printable = ReplaceAll(str, "&&", "&");
NSString* string = [[NSString alloc] initWithBytes:printable.data() length:printable.length() encoding: NSUTF8StringEncoding];

auto iter = fontMap_.find(fontHash_);
if (iter == fontMap_.end()) {
return false;
}

// INFO_LOG(SYSTEM, "Rasterizing %.*s", (int)str.length(), str.data());

NSString* string = [[NSString alloc] initWithBytes:str.data() length:str.length() encoding: NSUTF8StringEncoding];

NSDictionary* attributes = iter->second->attributes;
NSAttributedString* as = [[NSAttributedString alloc] initWithString:string attributes:attributes];

Expand Down
6 changes: 2 additions & 4 deletions SDL/CocoaBarItems.mm
Original file line number Diff line number Diff line change
Expand Up @@ -645,13 +645,11 @@ -(void)openRecentItem: (NSMenuItem *)item {

-(void)openSystemFileBrowser {
int g = 0;
DarwinDirectoryPanelCallback callback = [g] (bool succ, Path thePathChosen) {
DarwinDirectoryPanelCallback panelCallback = [g] (bool succ, Path thePathChosen) {
if (succ)
System_PostUIMessage(UIMessage::REQUEST_GAME_BOOT, thePathChosen.c_str());
};

DarwinFileSystemServices services;
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true);
DarwinFileSystemServices::presentDirectoryPanel(panelCallback, /* allowFiles = */ true, /* allowDirectorites = */ true);
}

-(void)openMemstickFolder {
Expand Down
6 changes: 2 additions & 4 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,8 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
g_requestManager.PostSystemFailure(requestId);
}
};
DarwinFileSystemServices services;
BrowseFileType fileType = (BrowseFileType)param3;
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false, fileType);
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false, fileType);
return true;
}
case SystemRequestType::BROWSE_FOR_FOLDER:
Expand All @@ -287,8 +286,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
g_requestManager.PostSystemFailure(requestId);
}
};
DarwinFileSystemServices services;
services.presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
return true;
}
#endif
Expand Down
8 changes: 5 additions & 3 deletions UI/DarwinFileSystemServices.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ typedef std::function<void (bool, Path)> DarwinDirectoryPanelCallback;
class DarwinFileSystemServices {
public:
/// Present a panel to choose a file or directory.
void presentDirectoryPanel(
DarwinDirectoryPanelCallback,
static void presentDirectoryPanel(
DarwinDirectoryPanelCallback panelCallback,
bool allowFiles = false,
bool allowDirectories = true,
BrowseFileType fileType = BrowseFileType::ANY);

static Path appropriateMemoryStickDirectoryToUse();
static void setUserPreferredMemoryStickDirectory(Path);

static void ClearDelegate();
private:
static Path __defaultMemoryStickPath();
#if PPSSPP_PLATFORM(IOS)
// iOS only, needed for UIDocumentPickerViewController
void *__pickerDelegate = NULL;
static void *__pickerDelegate;
#endif // PPSSPP_PLATFORM(IOS)
};

Expand Down
46 changes: 29 additions & 17 deletions UI/DarwinFileSystemServices.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,38 @@
#include <UIKit/UIKit.h>

@interface DocumentPickerDelegate : NSObject <UIDocumentPickerDelegate>
@property DarwinDirectoryPanelCallback callback;
@property DarwinDirectoryPanelCallback panelCallback;
@end

void *DarwinFileSystemServices::__pickerDelegate = nullptr;

void DarwinFileSystemServices::ClearDelegate() {
// TODO: Figure out how to free the delegate.
// CFRelease((__bridge DocumentPickerDelegate *)__pickerDelegate);
__pickerDelegate = NULL;
}

@implementation DocumentPickerDelegate
-(instancetype)initWithCallback: (DarwinDirectoryPanelCallback)callback {
-(instancetype)initWithCallback: (DarwinDirectoryPanelCallback)panelCallback {
if (self = [super init]) {
self.callback = callback;
self.panelCallback = panelCallback;
}
return self;
}

- (void)didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
if (urls.count >= 1)
self.callback(true, Path(urls[0].path.UTF8String));
self.panelCallback(true, Path(urls[0].path.UTF8String));
else
self.callback(false, Path());
self.panelCallback(false, Path());

INFO_LOG(SYSTEM, "Callback processed, pre-emptively hide keyboard");
[sharedViewController hideKeyboard];
DarwinFileSystemServices::ClearDelegate();
}

- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller {
self.callback(false, Path());
self.panelCallback(false, Path());

INFO_LOG(SYSTEM, "Picker cancelled, pre-emptively hide keyboard");
[sharedViewController hideKeyboard];
Expand All @@ -56,7 +65,7 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
#endif // __has_include(<UIKit/UIKit.h>)

void DarwinFileSystemServices::presentDirectoryPanel(
DarwinDirectoryPanelCallback callback,
DarwinDirectoryPanelCallback panelCallback,
bool allowFiles, bool allowDirectories,
BrowseFileType fileType) {
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -86,14 +95,17 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
}
// if (!allowFiles && allowDirectories)
// panel.allowedFileTypes = @[(__bridge NSString *)kUTTypeFolder];

NSModalResponse modalResponse = [panel runModal];
INFO_LOG(SYSTEM, "Mac: Received response from modal");
if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) {
callback(true, Path(panel.URLs.firstObject.path.UTF8String));
} else if (modalResponse == NSModalResponseCancel) {
callback(false, Path());
}
NSModalResponse modalResponse = [panel runModal];
if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) {
INFO_LOG(SYSTEM, "Mac: Received OK response from modal");
panelCallback(true, Path(panel.URLs.firstObject.path.UTF8String));
} else if (modalResponse == NSModalResponseCancel) {
INFO_LOG(SYSTEM, "Mac: Received Cancel response from modal");
panelCallback(false, Path());
} else {
WARN_LOG(SYSTEM, "Mac: Received unknown responsde from modal");
panelCallback(false, Path());
}
#elif PPSSPP_PLATFORM(IOS)
UIViewController *rootViewController = UIApplication.sharedApplication
.keyWindow
Expand All @@ -116,7 +128,7 @@ - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
UIDocumentPickerViewController *pickerVC = [[UIDocumentPickerViewController alloc] initWithDocumentTypes: types inMode: pickerMode];
// What if you wanted to go to heaven, but then God showed you the next few lines?
// serious note: have to do this, because __pickerDelegate has to stay retained as a class property
__pickerDelegate = (void *)CFBridgingRetain([[DocumentPickerDelegate alloc] initWithCallback:callback]);
__pickerDelegate = (void *)CFBridgingRetain([[DocumentPickerDelegate alloc] initWithCallback:panelCallback]);
pickerVC.delegate = (__bridge DocumentPickerDelegate *)__pickerDelegate;
[rootViewController presentViewController:pickerVC animated:true completion:nil];
#endif
Expand Down
14 changes: 12 additions & 2 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ void CreditsScreen::DrawForeground(UIContext &dc) {
"",
"",
cr->T("tools", "Free tools used:"),
#ifdef __ANDROID__
#if PPSSPP_PLATFORM(ANDROID)
"Android SDK + NDK",
#endif
#if defined(USING_QT_UI)
Expand All @@ -990,6 +990,17 @@ void CreditsScreen::DrawForeground(UIContext &dc) {
"CMake",
"freetype2",
"zlib",
"rcheevos",
"SPIRV-Cross",
"armips",
"Basis Universal",
"cityhash",
"zstd",
"glew",
"libchdr",
"minimp3",
"xxhash",
"naett-http",
"PSP SDK",
"",
"",
Expand All @@ -1011,7 +1022,6 @@ void CreditsScreen::DrawForeground(UIContext &dc) {
cr->T("info5", "PSP is a trademark by Sony, Inc."),
};


// TODO: This is kinda ugly, done on every frame...
char temp[256];
if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {
Expand Down
5 changes: 5 additions & 0 deletions ios/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
#include "Core/HLE/sceUsbCam.h"
#include "Core/HLE/sceUsbGps.h"

#if !__has_feature(objc_arc)
#error Must be built with ARC, please revise the flags for ViewController.mm to include -fobjc-arc.
#endif

class IOSGLESContext : public GraphicsContext {
public:
IOSGLESContext() {
Expand Down Expand Up @@ -424,6 +428,7 @@ -(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
- (void)uiStateChanged
{
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
[self hideKeyboard];
}

- (UIView *)getView {
Expand Down
5 changes: 3 additions & 2 deletions ios/ViewControllerMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ - (void)loadView {

- (void)viewDidLoad {
[super viewDidLoad];
[self hideKeyboard];

[[DisplayManager shared] setupDisplayListener];

INFO_LOG(SYSTEM, "Metal viewDidLoad");
Expand Down Expand Up @@ -414,8 +416,6 @@ - (void)viewDidLoad {
locationHelper = [[LocationHelper alloc] init];
[locationHelper setDelegate:self];

[self hideKeyboard];

UIScreenEdgePanGestureRecognizer *mBackGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:) ];
[mBackGestureRecognizer setEdges:UIRectEdgeLeft];
[[self view] addGestureRecognizer:mBackGestureRecognizer];
Expand Down Expand Up @@ -500,6 +500,7 @@ -(UIRectEdge)preferredScreenEdgesDeferringSystemGestures
- (void)uiStateChanged
{
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
[self hideKeyboard];
}

- (void)bindDefaultFBO
Expand Down
6 changes: 2 additions & 4 deletions ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
g_requestManager.PostSystemFailure(requestId);
}
};
DarwinFileSystemServices services;
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false);
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false);
return true;
}
case SystemRequestType::BROWSE_FOR_FOLDER:
Expand All @@ -443,8 +442,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
g_requestManager.PostSystemFailure(requestId);
}
};
DarwinFileSystemServices services;
services.presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
DarwinFileSystemServices::presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
return true;
}
case SystemRequestType::CAMERA_COMMAND:
Expand Down
Loading