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 (nonatomic, copy) void (^completionHandler)(NSString *selectedFile);
- (void)PresentDocumentPickerWithCompletionHandler:(void (^)(NSString *selectedFile))completionHandler;
- (void)presentDocumentPickerWithCompletionHandler:(void (^)(NSString *selectedFile))completionHandler;
@end

View File

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

View File

@@ -1,5 +1,5 @@
// yaze iOS Application
// Uses SDL2, ImGui and Metal
// Uses SDL2 and ImGui
#import <Foundation/Foundation.h>
@@ -28,9 +28,9 @@
#include "imgui/backends/imgui_impl_metal.h"
#include "imgui/imgui.h"
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// AppViewController
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@implementation AppViewController
@@ -96,17 +96,22 @@
}
_controller->SetupScreen(rom_filename);
_hoverGestureRecognizer = [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverGesture:)];
_hoverGestureRecognizer =
[[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(HoverGesture:)];
[self.view addGestureRecognizer:_hoverGestureRecognizer];
_pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
_pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self
action:@selector(HandlePinch:)];
[self.view addGestureRecognizer:_pinchRecognizer];
_longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
_longPressRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[self.view addGestureRecognizer:_longPressRecognizer];
_swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
_swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
_swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(HandleSwipe:)];
_swipeRecognizer.direction =
UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:_swipeRecognizer];
return self;
}
@@ -170,9 +175,9 @@
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
}
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Input processing
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#if TARGET_OS_OSX
@@ -194,7 +199,7 @@
// multitouch correctly at all. This causes the "cursor" to behave very erratically
// when there are multiple active touches. But for demo purposes, single-touch
// interaction actually works surprisingly well.
- (void)updateIOWithTouchEvent:(UIEvent *)event {
- (void)UpdateIOWithTouchEvent:(UIEvent *)event {
UITouch *anyTouch = event.allTouches.anyObject;
CGPoint touchLocation = [anyTouch locationInView:self.view];
ImGuiIO &io = ImGui::GetIO();
@@ -209,39 +214,39 @@
}
}
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();
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
// Cast to UIGestureRecognizer to UIGestureRecognizer to get locationInView
UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)gesture;
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 {
[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)handlePinch:(UIPinchGestureRecognizer *)gesture {
- (void)HandlePinch:(UIPinchGestureRecognizer *)gesture {
ImGuiIO &io = ImGui::GetIO();
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
io.AddMouseWheelEvent(0.0f, gesture.scale);
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)gesture {
- (void)HandleSwipe:(UISwipeGestureRecognizer *)gesture {
ImGuiIO &io = ImGui::GetIO();
io.AddMouseSourceEvent(ImGuiMouseSource_TouchScreen);
if (gesture.direction == UISwipeGestureRecognizerDirectionRight) {
@@ -261,9 +266,9 @@
@end
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// AppDelegate
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#if TARGET_OS_OSX
@@ -316,7 +321,7 @@
SDL_Quit();
}
- (void)presentDocumentPickerWithCompletionHandler:
- (void)PresentDocumentPickerWithCompletionHandler:
(void (^)(NSString *selectedFile))completionHandler {
self.completionHandler = completionHandler;
@@ -373,9 +378,9 @@
#endif
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Application main() function
//-----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#if TARGET_OS_OSX
int main(int argc, const char *argv[]) { return NSApplicationMain(argc, argv); }