diff --git a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java index 5c6b35a4..f4adf8d2 100644 --- a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java +++ b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java @@ -633,19 +633,35 @@ public class GLFW // Generated stub callback methods public static GLFWCharCallback glfwSetCharCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWcharfun") GLFWCharCallbackI cbfun) { - return mGLFWCharCallback = GLFWCharCallback.createSafe(nglfwSetCharCallback(window, memAddressSafe(cbfun))); + GLFWCharCallback lastCallback = mGLFWCharCallback; + if (cbfun == null) mGLFWCharCallback = null; + else mGLFWCharCallback = GLFWCharCallback.createSafe(nglfwSetCharCallback(window, memAddressSafe(cbfun))); + + return lastCallback; } public static GLFWCharModsCallback glfwSetCharModsCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWcharmodsfun") GLFWCharModsCallbackI cbfun) { - return mGLFWCharModsCallback = GLFWCharModsCallback.createSafe(nglfwSetCharModsCallback(window, memAddressSafe(cbfun))); + GLFWCharModsCallback lastCallback = mGLFWCharModsCallback; + if (cbfun == null) mGLFWCharModsCallback = null; + else mGLFWCharModsCallback = GLFWCharModsCallback.createSafe(nglfwSetCharModsCallback(window, memAddressSafe(cbfun))); + + return lastCallback; } public static GLFWCursorEnterCallback glfwSetCursorEnterCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWcursorenterfun") GLFWCursorEnterCallbackI cbfun) { - return mGLFWCursorEnterCallback = GLFWCursorEnterCallback.createSafe(nglfwSetCursorEnterCallback(window, memAddressSafe(cbfun))); + GLFWCursorEnterCallback lastCallback = mGLFWCursorEnterCallback; + if (cbfun == null) mGLFWCursorEnterCallback = null; + else mGLFWCursorEnterCallback = GLFWCursorEnterCallback.createSafe(nglfwSetCursorEnterCallback(window, memAddressSafe(cbfun))); + + return lastCallback; } public static GLFWCursorPosCallback glfwSetCursorPosCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWcursorposfun") GLFWCursorPosCallbackI cbfun) { - return mGLFWCursorPosCallback = GLFWCursorPosCallback.createSafe(nglfwSetCursorPosCallback(window, memAddressSafe(cbfun))); + GLFWCursorPosCallback lastCallback = mGLFWCursorPosCallback; + if (cbfun == null) mGLFWCursorPosCallback = null; + else mGLFWCursorPosCallback = GLFWCursorPosCallback.createSafe(nglfwSetCursorPosCallback(window, memAddressSafe(cbfun))); + + return lastCallback; } public static GLFWDropCallback glfwSetDropCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWdropfun") GLFWDropCallbackI cbfun) { @@ -665,17 +681,17 @@ public class GLFW } public static GLFWFramebufferSizeCallback glfwSetFramebufferSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWframebuffersizefun") GLFWFramebufferSizeCallbackI cbfun) { + GLFWFramebufferSizeCallback lastCallback = mGLFWFramebufferSizeCallback; + if (cbfun == null) mGLFWFramebufferSizeCallback = null; + else mGLFWFramebufferSizeCallback = GLFWFramebufferSizeCallback.createSafe(nglfwSetFramebufferSizeCallback(window, memAddressSafe(cbfun))); + mGLFWFramebufferSizeCallback = GLFWFramebufferSizeCallback.createSafe(nglfwSetFramebufferSizeCallback(window, memAddressSafe(cbfun))); - if (mGLFWFramebufferSizeCallback != null) { - try { + + try { mGLFWFramebufferSizeCallback.invoke(window, mGLFWWindowWidth, mGLFWWindowHeight); - } catch (Throwable th) { th.printStackTrace(); } - } else { - mGLFWFramebufferSizeCallback = new GLFWFramebufferSizeCallback() { - @Override public void invoke(long window, int width, int height) {}; - }; - } - return mGLFWFramebufferSizeCallback; + } catch (Throwable th) {} + + return lastCallback; } public static GLFWJoystickCallback glfwSetJoystickCallback(/* @NativeType("GLFWwindow *") long window, */ @Nullable @NativeType("GLFWjoystickfun") GLFWJoystickCallbackI cbfun) { @@ -687,7 +703,11 @@ public class GLFW } public static GLFWKeyCallback glfwSetKeyCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWkeyfun") GLFWKeyCallbackI cbfun) { - return mGLFWKeyCallback = GLFWKeyCallback.createSafe(nglfwSetKeyCallback(window, memAddressSafe(cbfun))); + GLFWKeyCallback lastCallback = mGLFWKeyCallback; + if (cbfun == null) mGLFWKeyCallback = null; + else mGLFWKeyCallback = GLFWKeyCallback.createSafe(nglfwSetKeyCallback(window, memAddressSafe(cbfun))); + + return lastCallback; } public static GLFWMonitorCallback glfwSetMonitorCallback(@Nullable @NativeType("GLFWmonitorfun") GLFWMonitorCallbackI cbfun) { @@ -699,11 +719,19 @@ public class GLFW } public static GLFWMouseButtonCallback glfwSetMouseButtonCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWmousebuttonfun") GLFWMouseButtonCallbackI cbfun) { - return mGLFWMouseButtonCallback = GLFWMouseButtonCallback.createSafe(nglfwSetMouseButtonCallback(window, memAddressSafe(cbfun))); + GLFWMouseButtonCallback lastCallback = mGLFWMouseButtonCallback; + if (cbfun == null) mGLFWMouseButtonCallback = null; + else mGLFWMouseButtonCallback = GLFWMouseButtonCallback.createSafe(nglfwSetMouseButtonCallback(window, memAddressSafe(cbfun))); + + return lastCallback; } public static GLFWScrollCallback glfwSetScrollCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWscrollfun") GLFWScrollCallbackI cbfun) { - return mGLFWScrollCallback = GLFWScrollCallback.createSafe(nglfwSetScrollCallback(window, memAddressSafe(cbfun))); + GLFWScrollCallback lastCallback = mGLFWScrollCallback; + if (cbfun == null) mGLFWScrollCallback = null; + else mGLFWScrollCallback = GLFWScrollCallback.createSafe(nglfwSetScrollCallback(window, memAddressSafe(cbfun))); + + return lastCallback; } public static GLFWWindowCloseCallback glfwSetWindowCloseCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowclosefun") GLFWWindowCloseCallbackI cbfun) { @@ -746,7 +774,11 @@ public class GLFW } public static GLFWWindowPosCallback glfwSetWindowPosCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowposfun") GLFWWindowPosCallbackI cbfun) { - return mGLFWWindowPosCallback = GLFWWindowPosCallback.createSafe(nglfwSetWindowPosCallback(window, memAddressSafe(cbfun))); + GLFWWindowPosCallback lastCallback = mGLFWWindowPosCallback; + if (cbfun == null) mGLFWWindowPosCallback = null; + else mGLFWWindowPosCallback = GLFWWindowPosCallback.create(cbfun); + + return lastCallback; } public static GLFWWindowRefreshCallback glfwSetWindowRefreshCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowrefreshfun") GLFWWindowRefreshCallbackI cbfun) { @@ -758,17 +790,17 @@ public class GLFW } public static GLFWWindowSizeCallback glfwSetWindowSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowsizefun") GLFWWindowSizeCallbackI cbfun) { + GLFWWindowSizeCallback lastCallback = mGLFWWindowSizeCallback; + if (cbfun == null) mGLFWWindowSizeCallback = null; + else mGLFWWindowSizeCallback = GLFWWindowSizeCallback.createSafe(nglfwSetWindowSizeCallback(window, memAddressSafe(cbfun))); + mGLFWWindowSizeCallback = GLFWWindowSizeCallback.createSafe(nglfwSetWindowSizeCallback(window, memAddressSafe(cbfun))); - if (mGLFWWindowSizeCallback != null) { - try { + + try { mGLFWWindowSizeCallback.invoke(window, mGLFWWindowWidth, mGLFWWindowHeight); - } catch (Throwable th) { th.printStackTrace(); } - } else { - mGLFWWindowSizeCallback = new GLFWWindowSizeCallback() { - @Override public void invoke(long window, int width, int height) {}; - }; - } - return mGLFWWindowSizeCallback; + } catch (Throwable th) {} + + return lastCallback; } static boolean isGLFWReady; public static boolean glfwInit() { diff --git a/Natives/JavaGUIViewController.m b/Natives/JavaGUIViewController.m index e7855fab..383d3075 100644 --- a/Natives/JavaGUIViewController.m +++ b/Natives/JavaGUIViewController.m @@ -1,4 +1,5 @@ #import "JavaGUIViewController.h" +#import "LauncherPreferences.h" #import "ios_uikit_bridge.h" #include "utils.h" @@ -76,9 +77,10 @@ void _CGDataProviderReleaseBytePointerCallback(void *info,const void *pointer) { int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height); + float resolution = ((NSNumber *)getPreference(@"resolution")).floatValue / 100.0; - savedWidth = roundf(width * screenScale); - savedHeight = roundf(height * screenScale); + savedWidth = roundf(width * screenScale * resolution); + savedHeight = roundf(height * screenScale * resolution); UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; scrollView.delegate = self; diff --git a/Natives/JavaLauncher.m b/Natives/JavaLauncher.m index dea1e29c..6918cf25 100644 --- a/Natives/JavaLauncher.m +++ b/Natives/JavaLauncher.m @@ -95,6 +95,10 @@ void init_migrateToPlist(char* prefKey, char* filename) { void init_checkPlist() { + if (!getPreference(@"resolution")) { + setPreference(@"resolution", @(100)); + } + if (!getPreference(@"button_scale")) { setPreference(@"button_scale", @(100)); } diff --git a/Natives/LauncherPreferences.m b/Natives/LauncherPreferences.m index 04cf1fee..39d7e3bc 100644 --- a/Natives/LauncherPreferences.m +++ b/Natives/LauncherPreferences.m @@ -10,6 +10,7 @@ void loadPreferences() { NSFileManager *fileManager = [NSFileManager defaultManager]; if (![fileManager fileExistsAtPath:prefPath]) { prefDict = [[NSMutableDictionary alloc] init]; + prefDict[@"resolution"] = @(100); prefDict[@"button_scale"] = @(100); prefDict[@"selected_version"] = @"1.7.10"; prefDict[@"vertype_release"] = @YES; diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index a0ee51ce..cd81b67c 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -18,10 +18,6 @@ @implementation LauncherPreferencesViewController -UITextField* rendTextField; -UITextField* jargsTextField; -UITextField* jhomeTextField; - - (void)viewDidLoad { [super viewDidLoad]; @@ -33,6 +29,7 @@ UITextField* jhomeTextField; int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height) - self.navigationController.navigationBar.frame.size.height; + CGFloat currY = 14.0; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; [self.view addSubview:scrollView]; @@ -56,7 +53,7 @@ UITextField* jhomeTextField; [scrollView addSubview:btnsizeTextView]; DBNumberedSlider *buttonSizeSlider = [[DBNumberedSlider alloc] initWithFrame:CGRectMake(8.0 + btnsizeTextView.frame.size.width, 8.0, self.view.frame.size.width - btnsizeTextView.frame.size.width - 12.0, btnsizeTextView.frame.size.height)]; - buttonSizeSlider.tag = 1; + buttonSizeSlider.tag = 98; [buttonSizeSlider addTarget:self action:@selector(sliderMoved:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; [buttonSizeSlider setBackgroundColor:[UIColor clearColor]]; buttonSizeSlider.minimumValue = 50.0; @@ -65,14 +62,34 @@ UITextField* jhomeTextField; buttonSizeSlider.value = ((NSNumber *) getPreference(@"button_scale")).floatValue; [scrollView addSubview:buttonSizeSlider]; - UILabel *jargsTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, 54.0, 0.0, 0.0)]; + UILabel *resolutionTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, currY+=40.0, 0.0, 30.0)]; + resolutionTextView.text = @"Resolution (%)"; + resolutionTextView.numberOfLines = 0; + resolutionTextView.textAlignment = NSTextAlignmentCenter; + [resolutionTextView sizeToFit]; + tempRect = resolutionTextView.frame; + tempRect.size.height = 30.0; + resolutionTextView.frame = tempRect; + [scrollView addSubview:resolutionTextView]; + + DBNumberedSlider *resolutionSlider = [[DBNumberedSlider alloc] initWithFrame:CGRectMake(8.0 + resolutionTextView.frame.size.width, currY, self.view.frame.size.width - resolutionTextView.frame.size.width - 12.0, resolutionTextView.frame.size.height)]; + resolutionSlider.tag = 99; + [resolutionSlider addTarget:self action:@selector(sliderMoved:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; + [resolutionSlider setBackgroundColor:[UIColor clearColor]]; + resolutionSlider.minimumValue = 25; + resolutionSlider.maximumValue = 100; + resolutionSlider.continuous = YES; + resolutionSlider.value = ((NSNumber *) getPreference(@"resolution")).intValue; + [scrollView addSubview:resolutionSlider]; + + UILabel *jargsTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, currY+=40.0, 0.0, 0.0)]; jargsTextView.text = @"Java arguments "; jargsTextView.numberOfLines = 0; [jargsTextView sizeToFit]; [scrollView addSubview:jargsTextView]; - jargsTextField = [[UITextField alloc] initWithFrame:CGRectMake(buttonSizeSlider.frame.origin.x + 3, 54.0, width - jargsTextView.bounds.size.width - 8.0, 30)]; - [jargsTextField addTarget:self action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; + UITextField *jargsTextField = [[UITextField alloc] initWithFrame:CGRectMake(buttonSizeSlider.frame.origin.x + 3, currY, width - jargsTextView.bounds.size.width - 8.0, 30)]; + [jargsTextField addTarget:jargsTextField action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; jargsTextField.tag = 100; jargsTextField.delegate = self; jargsTextField.placeholder = @"Specify arguments..."; @@ -81,14 +98,14 @@ UITextField* jhomeTextField; jargsTextField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [scrollView addSubview:jargsTextField]; - UILabel *rendTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, 94.0, 0.0, 0.0)]; + UILabel *rendTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, currY+=40.0, 0.0, 0.0)]; rendTextView.text = @"Renderer"; rendTextView.numberOfLines = 0; [rendTextView sizeToFit]; [scrollView addSubview:rendTextView]; - rendTextField = [[UITextField alloc] initWithFrame:CGRectMake(buttonSizeSlider.frame.origin.x + 3, 94.0, width - jargsTextView.bounds.size.width - 8.0, 30)]; - [rendTextField addTarget:self action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; + UITextField *rendTextField = [[UITextField alloc] initWithFrame:CGRectMake(buttonSizeSlider.frame.origin.x + 3, currY, width - jargsTextView.bounds.size.width - 8.0, 30)]; + [rendTextField addTarget:rendTextField action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; rendTextField.tag = 101; rendTextField.delegate = self; rendTextField.placeholder = @"Override renderer..."; @@ -97,14 +114,14 @@ UITextField* jhomeTextField; rendTextField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [scrollView addSubview:rendTextField]; - UILabel *jhomeTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, 134.0, 0.0, 0.0)]; + UILabel *jhomeTextView = [[UILabel alloc] initWithFrame:CGRectMake(4.0, currY+=40.0, 0.0, 0.0)]; jhomeTextView.text = @"Java home"; jhomeTextView.numberOfLines = 0; [jhomeTextView sizeToFit]; [scrollView addSubview:jhomeTextView]; - jhomeTextField = [[UITextField alloc] initWithFrame:CGRectMake(buttonSizeSlider.frame.origin.x + 3, 134.0, width - jargsTextView.bounds.size.width - 8.0, 30)]; - [jhomeTextField addTarget:self action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; + UITextField *jhomeTextField = [[UITextField alloc] initWithFrame:CGRectMake(buttonSizeSlider.frame.origin.x + 3, currY, width - jargsTextView.bounds.size.width - 8.0, 30)]; + [jhomeTextField addTarget:jhomeTextField action:@selector(resignFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit]; jhomeTextField.tag = 102; jhomeTextField.delegate = self; jhomeTextField.placeholder = @"Override Java path..."; @@ -151,7 +168,7 @@ UITextField* jhomeTextField; setPreference(@"renderer", textField.text); } else if (textField.tag == 102) { setPreference(@"java_home", textField.text); - if (![jhomeTextField.text containsString:@"java-8-openjdk"]) { + if (![textField.text containsString:@"java-8-openjdk"]) { UIAlertController *javaAlert = [UIAlertController alertControllerWithTitle:@"Java version is not Java 8" message:@"Minecraft versions below 1.6, modded below 1.16.4, and the mod installer will not work unless you have Java 8 installed on your device."preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; [self presentViewController:javaAlert animated:YES completion:nil]; @@ -205,8 +222,11 @@ UITextField* jhomeTextField; - (void)sliderMoved:(DBNumberedSlider *)sender { switch (sender.tag) { - case 1: - setPreference(@"button_scale", @(sender.value)); + case 98: + setPreference(@"button_scale", @((int)sender.value)); + break; + case 99: + setPreference(@"resolution", @((int)sender.value)); break; default: NSLog(@"what does slider %ld for? implement me!", sender.tag); diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index d56dfd19..1062cd96 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -36,7 +36,6 @@ int togglableVisibleButtonIndex = -1; ControlButton* togglableVisibleButtons[100]; -UIView *touchView; #ifdef DEBUG_VISIBLE_TEXT_FIELD UILabel *inputLengthView; #endif @@ -46,11 +45,14 @@ int inputTextLength; BOOL shouldTriggerClick = NO; int notchOffset; +float resolutionScale; + // TODO: key modifiers impl @interface SurfaceViewController () { } +@property(nonatomic, strong) MGLKView* surfaceView; @property(nonatomic, strong) MGLContext *context; @property(nonatomic, strong) NSMutableDictionary* cc_dictionary; @@ -72,16 +74,20 @@ int notchOffset; UIEdgeInsets insets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets; + resolutionScale = ((NSNumber *)getPreference(@"resolution")).floatValue / 100.0; + int width = (int) roundf(screenBounds.size.width); int height = (int) roundf(screenBounds.size.height); - + savedWidth = roundf(width * screenScale); savedHeight = roundf(height * screenScale); - MGLKView *surfaceView = [[MGLKView alloc] initWithFrame:self.view.frame]; - self.view = surfaceView; - - touchView = [[UIView alloc] initWithFrame:self.view.frame]; + self.surfaceView = [[MGLKView alloc] initWithFrame:CGRectMake((width - width * resolutionScale) / 2, (height - height * resolutionScale) / 2, width * resolutionScale, height * resolutionScale)]; + [self.view addSubview:self.surfaceView]; + self.surfaceView.enableSetNeedsDisplay = NO; + self.surfaceView.delegate = self; + self.surfaceView.controller = self; + self.surfaceView.transform = CGAffineTransformMakeScale(1.0 / resolutionScale, 1.0 / resolutionScale); notchOffset = insets.left; width = width - notchOffset * 2; @@ -93,13 +99,13 @@ int notchOffset; tapGesture.numberOfTapsRequired = 1; tapGesture.numberOfTouchesRequired = 1; tapGesture.cancelsTouchesInView = NO; - [touchView addGestureRecognizer:tapGesture]; + [self.surfaceView addGestureRecognizer:tapGesture]; UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(surfaceOnLongpress:)]; longpressGesture.delegate = self; longpressGesture.minimumPressDuration = ((NSNumber *)getPreference(@"time_longPressTrigger")).floatValue / 1000; - [touchView addGestureRecognizer:longpressGesture]; + [self.surfaceView addGestureRecognizer:longpressGesture]; UIPanGestureRecognizer *scrollPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(surfaceOnTouchesScroll:)]; @@ -107,12 +113,10 @@ int notchOffset; scrollPanGesture.allowedTouchTypes = @[@(UITouchTypeDirect)]; scrollPanGesture.minimumNumberOfTouches = 2; scrollPanGesture.maximumNumberOfTouches = 2; - [touchView addGestureRecognizer:scrollPanGesture]; + [self.surfaceView addGestureRecognizer:scrollPanGesture]; - [self.view addSubview:touchView]; - if (@available(iOS 13.4, *)) { - [touchView addInteraction:[[UIPointerInteraction alloc] initWithDelegate:self]]; + [self.surfaceView addInteraction:[[UIPointerInteraction alloc] initWithDelegate:self]]; UIPanGestureRecognizer *mouseWheelGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(surfaceOnMouseScroll:)]; mouseWheelGesture.delegate = self; @@ -121,7 +125,7 @@ int notchOffset; mouseWheelGesture.cancelsTouchesInView = NO; mouseWheelGesture.delaysTouchesBegan = NO; mouseWheelGesture.delaysTouchesEnded = NO; - [touchView addGestureRecognizer:mouseWheelGesture]; + [self.surfaceView addGestureRecognizer:mouseWheelGesture]; } #ifndef DEBUG_VISIBLE_TEXT_FIELD @@ -197,8 +201,8 @@ int notchOffset; viewController = self; - surfaceView.drawableDepthFormat = MGLDrawableDepthFormat24; - surfaceView.enableSetNeedsDisplay = YES; + self.surfaceView.drawableDepthFormat = MGLDrawableDepthFormat24; + self.surfaceView.enableSetNeedsDisplay = YES; // [self setPreferredFramesPerSecond:1000]; // Init GLES @@ -209,10 +213,7 @@ int notchOffset; NSLog(@"Failed to create ES context"); } - surfaceView.context = self.context; -#ifndef USE_EGL - glContext = self.context; -#endif + self.surfaceView.context = self.context; [MGLContext setCurrentContext:self.context]; @@ -239,9 +240,11 @@ int notchOffset; - (void)setupGL { [MGLContext setCurrentContext:self.context]; - callback_SurfaceViewController_launchMinecraft(savedWidth, savedHeight); + [self.surfaceView display]; + callback_SurfaceViewController_launchMinecraft(savedWidth * resolutionScale, savedHeight * resolutionScale); } +/* BOOL isNotifRemoved; - (void)mglkView:(MGLKView *)view drawInRect:(CGRect)rect { @@ -265,6 +268,7 @@ BOOL isNotifRemoved; // Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(NULL, NULL, location.x * screenScale, location.y * screenScale); } +*/ #pragma mark - Input: send touch utilities @@ -286,8 +290,8 @@ BOOL isNotifRemoved; } } - if ([touchEvent view] == touchView) { - CGPoint locationInView = [touchEvent locationInView:touchView]; + if (touchEvent.view == self.surfaceView) { + CGPoint locationInView = [touchEvent locationInView:self.surfaceView]; [self sendTouchPoint:locationInView withEvent:event]; } @@ -346,7 +350,7 @@ BOOL isNotifRemoved; - (void)surfaceOnHover:(UIHoverGestureRecognizer *)sender API_AVAILABLE(ios(13.0)) { if (@available(iOS 13.0, *)) { - CGPoint point = [sender locationInView:touchView]; + CGPoint point = [sender locationInView:self.surfaceView]; // NSLog(@"Mouse move!!"); // NSLog(@"Mouse pos = %d, %d", point.x, point.y); switch (sender.state) { @@ -438,7 +442,7 @@ BOOL isNotifRemoved; - (UIPointerRegion *)pointerInteraction:(UIPointerInteraction *)interaction regionForRequest:(UIPointerRegionRequest *)request defaultRegion:(UIPointerRegion *)defaultRegion API_AVAILABLE(ios(13.4)) API_AVAILABLE(ios(13.4)) API_AVAILABLE(ios(13.4)){ if (request != nil) { - CGPoint origin = touchView.bounds.origin; + CGPoint origin = self.surfaceView.bounds.origin; CGPoint point = request.location; point.x -= origin.x; @@ -449,7 +453,7 @@ BOOL isNotifRemoved; // TODO FIXME callback_SurfaceViewController_onTouch(ACTION_DOWN, (int)point.x, (int)point.y); } - return [UIPointerRegion regionWithRect:touchView.bounds identifier:nil]; + return [UIPointerRegion regionWithRect:self.surfaceView.bounds identifier:nil]; } - (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region API_AVAILABLE(ios(13.4)){ diff --git a/Natives/egl_bridge.m b/Natives/egl_bridge.m index 38aa2962..7a4bcb54 100644 --- a/Natives/egl_bridge.m +++ b/Natives/egl_bridge.m @@ -110,7 +110,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* } debug("EGLBridge: Trigger an initial swapBuffers"); - [viewController resume]; + [viewController.view.subviews[0] display]; // Test #ifdef GLES_TEST @@ -147,7 +147,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglCreateContext(JNIEnv * localContext = [[MGLContext alloc] initWithAPI:kMGLRenderingAPIOpenGLES3 sharegroup:sharegroup]; debug("EGLBridge: Created CTX pointer=%p, shareCTX=%p, thread=%d", localContext, (void *)contextSrc, (int)tid); } else { - localContext = viewController.glView.context; + localContext = ((MGLKView *)viewController.view.subviews[0]).context; } [[NSThread currentThread] threadDictionary][@"gl_context"] = localContext; debug("EGLBridge: Created CTX pointer=%p, shareCTX=%p, thread=%d", localContext, (void *)contextSrc, (int)tid); diff --git a/Natives/resources/Frameworks/MetalANGLE.framework/Headers/MGLKView.h b/Natives/resources/Frameworks/MetalANGLE.framework/Headers/MGLKView.h index f9f1bbe7..c99c4833 100644 --- a/Natives/resources/Frameworks/MetalANGLE.framework/Headers/MGLKView.h +++ b/Natives/resources/Frameworks/MetalANGLE.framework/Headers/MGLKView.h @@ -10,6 +10,7 @@ #import "MGLContext.h" @class MGLKView; +@class MGLKViewController; @protocol MGLKViewDelegate @@ -46,6 +47,9 @@ // Might not necessary be zero. @property(readonly) uint32_t defaultOpenGLFrameBufferID; +// private property +@property(nonatomic, weak) MGLKViewController *controller; + #if TARGET_OS_IOS || TARGET_OS_TV // Enable setNeedsDisplay method. @property(nonatomic) BOOL enableSetNeedsDisplay;