update objective-C style

This commit is contained in:
scawful
2024-08-11 10:25:58 -04:00
parent f2015cd2f6
commit b249d30403
3 changed files with 63 additions and 63 deletions

View File

@@ -15,8 +15,8 @@
@property UIDocumentPickerViewController *documentPicker; @property UIDocumentPickerViewController *documentPicker;
@property (nonatomic, copy) void (^completionHandler)(NSString *selectedFile); @property (nonatomic, copy) void (^completionHandler)(NSString *selectedFile);
- (void)PresentDocumentPickerWithCompletionHandler:(void (^)(NSString *selectedFile))completionHandler;
- (void)presentDocumentPickerWithCompletionHandler:(void (^)(NSString *selectedFile))completionHandler;
@end @end

View File

@@ -22,7 +22,7 @@ static std::string selectedFile;
void ShowOpenFileDialogImpl(void (^completionHandler)(std::string)) { void ShowOpenFileDialogImpl(void (^completionHandler)(std::string)) {
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate presentDocumentPickerWithCompletionHandler:^(NSString *filePath) { [appDelegate PresentDocumentPickerWithCompletionHandler:^(NSString *filePath) {
selectedFile = std::string([filePath UTF8String]); selectedFile = std::string([filePath UTF8String]);
completionHandler(selectedFile); completionHandler(selectedFile);
}]; }];
@@ -35,11 +35,6 @@ std::string ShowOpenFileDialogSync() {
result = filePath; result = filePath;
}); });
// Check if the documentPicker is done
// while (result.empty()) {
// [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
// }
return result; return result;
} }
} }

View File

@@ -1,5 +1,5 @@
// yaze iOS Application // yaze iOS Application
// Uses SDL2, ImGui and Metal // Uses SDL2 and ImGui
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@@ -28,9 +28,9 @@
#include "imgui/backends/imgui_impl_metal.h" #include "imgui/backends/imgui_impl_metal.h"
#include "imgui/imgui.h" #include "imgui/imgui.h"
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// AppViewController // AppViewController
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@implementation AppViewController @implementation AppViewController
@@ -61,10 +61,10 @@
SDL_SetMainReady(); SDL_SetMainReady();
SDL_iOSSetEventPump(SDL_TRUE); SDL_iOSSetEventPump(SDL_TRUE);
int argc = NSProcessInfo.processInfo.arguments.count; int argc = NSProcessInfo.processInfo.arguments.count;
char** argv = new char*[argc]; char **argv = new char *[argc];
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
NSString* arg = NSProcessInfo.processInfo.arguments[i]; NSString *arg = NSProcessInfo.processInfo.arguments[i];
const char* cString = [arg UTF8String]; const char *cString = [arg UTF8String];
argv[i] = new char[strlen(cString) + 1]; argv[i] = new char[strlen(cString) + 1];
strcpy(argv[i], cString); strcpy(argv[i], cString);
} }
@@ -96,17 +96,22 @@
} }
_controller->SetupScreen(rom_filename); _controller->SetupScreen(rom_filename);
_hoverGestureRecognizer = [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverGesture:)]; _hoverGestureRecognizer =
[[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(HoverGesture:)];
[self.view addGestureRecognizer:_hoverGestureRecognizer]; [self.view addGestureRecognizer:_hoverGestureRecognizer];
_pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)]; _pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self
action:@selector(HandlePinch:)];
[self.view addGestureRecognizer:_pinchRecognizer]; [self.view addGestureRecognizer:_pinchRecognizer];
_longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; _longPressRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[self.view addGestureRecognizer:_longPressRecognizer]; [self.view addGestureRecognizer:_longPressRecognizer];
_swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; _swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
_swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft; action:@selector(HandleSwipe:)];
_swipeRecognizer.direction =
UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:_swipeRecognizer]; [self.view addGestureRecognizer:_swipeRecognizer];
return self; return self;
} }
@@ -170,9 +175,9 @@
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size { - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
} }
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Input processing // Input processing
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if TARGET_OS_OSX #if TARGET_OS_OSX
@@ -194,7 +199,7 @@
// multitouch correctly at all. This causes the "cursor" to behave very erratically // multitouch correctly at all. This causes the "cursor" to behave very erratically
// when there are multiple active touches. But for demo purposes, single-touch // when there are multiple active touches. But for demo purposes, single-touch
// interaction actually works surprisingly well. // interaction actually works surprisingly well.
- (void)updateIOWithTouchEvent:(UIEvent *)event { - (void)UpdateIOWithTouchEvent:(UIEvent *)event {
UITouch *anyTouch = event.allTouches.anyObject; UITouch *anyTouch = event.allTouches.anyObject;
CGPoint touchLocation = [anyTouch locationInView:self.view]; CGPoint touchLocation = [anyTouch locationInView:self.view];
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
@@ -209,61 +214,61 @@
} }
} }
io.AddMouseButtonEvent(0, hasActiveTouch); io.AddMouseButtonEvent(0, hasActiveTouch);
} }
- (void)hoverGesture:(UIHoverGestureRecognizer *)gesture { - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self UpdateIOWithTouchEvent:event];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self UpdateIOWithTouchEvent:event];
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self UpdateIOWithTouchEvent:event];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self UpdateIOWithTouchEvent:event];
}
- (void)HoverGesture:(UIHoverGestureRecognizer *)gesture {
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen); io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
// Cast to UIGestureRecognizer to UIGestureRecognizer to get locationInView // Cast to UIGestureRecognizer to UIGestureRecognizer to get locationInView
UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)gesture; UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)gesture;
if (gesture.zOffset < 0.50) { if (gesture.zOffset < 0.50) {
io.AddMousePosEvent([gestureRecognizer locationInView:self.view].x, [gestureRecognizer locationInView:self.view].y); io.AddMousePosEvent([gestureRecognizer locationInView:self.view].x,
[gestureRecognizer locationInView:self.view].y);
} }
} }
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { - (void)HandlePinch:(UIPinchGestureRecognizer *)gesture {
[self updateIOWithTouchEvent:event]; ImGuiIO &io = ImGui::GetIO();
} io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { io.AddMouseWheelEvent(0.0f, gesture.scale);
[self updateIOWithTouchEvent:event];
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self updateIOWithTouchEvent:event];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self updateIOWithTouchEvent:event];
} }
- (void)handlePinch:(UIPinchGestureRecognizer *)gesture { - (void)HandleSwipe:(UISwipeGestureRecognizer *)gesture {
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen); io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
io.AddMouseWheelEvent(0.0f, gesture.scale); if (gesture.direction == UISwipeGestureRecognizerDirectionRight) {
} io.AddMouseWheelEvent(1.0f, 0.0f); // Swipe Right
} else if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) {
- (void)handleSwipe:(UISwipeGestureRecognizer *)gesture { io.AddMouseWheelEvent(-1.0f, 0.0f); // Swipe Left
ImGuiIO &io = ImGui::GetIO(); }
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
if (gesture.direction == UISwipeGestureRecognizerDirectionRight) {
io.AddMouseWheelEvent(1.0f, 0.0f); // Swipe Right
} else if (gesture.direction == UISwipeGestureRecognizerDirectionLeft) {
io.AddMouseWheelEvent(-1.0f, 0.0f); // Swipe Left
}
} }
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture { - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture {
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen); io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
io.AddMouseButtonEvent(1, gesture.state == UIGestureRecognizerStateBegan); io.AddMouseButtonEvent(1, gesture.state == UIGestureRecognizerStateBegan);
} }
#endif #endif
@end @end
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// AppDelegate // AppDelegate
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if TARGET_OS_OSX #if TARGET_OS_OSX
@@ -316,7 +321,7 @@
SDL_Quit(); SDL_Quit();
} }
- (void)presentDocumentPickerWithCompletionHandler: - (void)PresentDocumentPickerWithCompletionHandler:
(void (^)(NSString *selectedFile))completionHandler { (void (^)(NSString *selectedFile))completionHandler {
self.completionHandler = completionHandler; self.completionHandler = completionHandler;
@@ -373,9 +378,9 @@
#endif #endif
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Application main() function // Application main() function
//----------------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if TARGET_OS_OSX #if TARGET_OS_OSX
int main(int argc, const char *argv[]) { return NSApplicationMain(argc, argv); } int main(int argc, const char *argv[]) { return NSApplicationMain(argc, argv); }