diff --git a/src/ios/iOSMiniFB.m b/src/ios/iOSMiniFB.m index 9538291..0f9716b 100644 --- a/src/ios/iOSMiniFB.m +++ b/src/ios/iOSMiniFB.m @@ -3,6 +3,7 @@ #include #include "iOSViewController.h" +#include "iOSViewDelegate.h" #include "WindowData_IOS.h" #include #include @@ -35,8 +36,7 @@ create_window_data(unsigned width, unsigned height) { window_data->window_width = [UIScreen mainScreen].bounds.size.width * scale; window_data->window_height = [UIScreen mainScreen].bounds.size.height * scale; - window_data->dst_width = width; - window_data->dst_height = height; + calc_dst_factor(window_data, width, height); window_data->buffer_width = width; window_data->buffer_height = height; @@ -191,6 +191,7 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y window_data->dst_offset_y = offset_y; window_data->dst_width = width; window_data->dst_height = height; + calc_dst_factor(window_data, window_data->window_width, window_data->window_height); float x1 = ((float) offset_x / window_data->window_width) * 2.0f - 1.0f; float x2 = (((float) offset_x + width) / window_data->window_width) * 2.0f - 1.0f; diff --git a/src/ios/iOSViewDelegate.m b/src/ios/iOSViewDelegate.m index ff01a4f..1e6fb65 100644 --- a/src/ios/iOSViewDelegate.m +++ b/src/ios/iOSViewDelegate.m @@ -240,9 +240,12 @@ NSString *g_shader_src = kShader( //------------------------------------- - (void) mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size { + (void) view; // Respond to drawable size or orientation changes here - window_data->window_width = size.width; - window_data->window_height = size.height; + float scale = [UIScreen mainScreen].scale; + + window_data->window_width = size.width * scale; + window_data->window_height = size.height * scale; resize_dst(window_data, size.width, size.height); kCall(resize_func, size.width, size.height); diff --git a/tests/ios/AppDelegate.m b/tests/ios/AppDelegate.m index d10f2c0..26e03cd 100644 --- a/tests/ios/AppDelegate.m +++ b/tests/ios/AppDelegate.m @@ -43,6 +43,7 @@ resize(struct mfb_window *window, int width, int height) { kUnused(window); g_width = width; g_height = height; + g_buffer = realloc(g_buffer, g_width * g_height * 4); NSLog(@"Resize %d, %d", width, height); } @@ -95,6 +96,9 @@ resize(struct mfb_window *window, int width, int height) { g_height = [UIScreen mainScreen].bounds.size.height * g_scale; g_window = mfb_open("noise", g_width, g_height); if(g_window != 0x0) { + g_width -= 100; + g_height -= 100; + mfb_set_viewport(g_window, 50, 50, g_width, g_height); g_buffer = malloc(g_width * g_height * 4); mfb_set_mouse_move_callback(g_window, mouse_move); mfb_set_mouse_button_callback(g_window, mouse_btn);