removed debug logging statements; enable multi touch on metal view to support touchscreen controls; fixed setting the metal view drawable size based on the view bounds size in pixels

This commit is contained in:
Yoshi Sugawara 2020-07-19 00:11:15 -10:00
parent eed84b3021
commit a19f1451cd
3 changed files with 15 additions and 21 deletions

View File

@ -501,12 +501,15 @@
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size - (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size
{ {
NSLog(@"mtkView drawableSizeWillChange to: %f x %f",size.width,size.height); NSLog(@"mtkView drawableSizeWillChange to: %f x %f",size.width,size.height);
// due to autolayout constraints? #ifdef HAVE_COCOATOUCH
if (size.width == INFINITY || size.height == INFINITY) { CGFloat scale = [[UIScreen mainScreen] scale];
NSLog(@"mtkView drawableSizeWillChange width or height is inifinity, skipping..."); // // due to autolayout constraints?
return; //// if (size.width == INFINITY || size.height == INFINITY) {
} // NSLog(@"mtkView drawableSizeWillChange width or height is infinity, flipping...");
[self setViewportWidth:(unsigned int)view.bounds.size.width*scale height:(unsigned int)view.bounds.size.height*scale forceFull:NO allowRotate:YES];
#else
[self setViewportWidth:(unsigned int)size.width height:(unsigned int)size.height forceFull:NO allowRotate:YES]; [self setViewportWidth:(unsigned int)size.width height:(unsigned int)size.height forceFull:NO allowRotate:YES];
#endif
} }
- (void)drawInMTKView:(MTKView *)view - (void)drawInMTKView:(MTKView *)view

View File

@ -31196,8 +31196,6 @@ bool video_driver_translate_coord_viewport(
int norm_vp_height = (int)vp->height; int norm_vp_height = (int)vp->height;
int norm_full_vp_width = (int)vp->full_width; int norm_full_vp_width = (int)vp->full_width;
int norm_full_vp_height = (int)vp->full_height; int norm_full_vp_height = (int)vp->full_height;
printf("yoshi debug: video size: %i, %i full size: %i, %i \n",norm_vp_width,norm_vp_height,norm_full_vp_width,norm_full_vp_height);
printf("yoshi debug: video_driver_translate_coord_viewport: incoming mouse coord: %i,%i \n",mouse_x,mouse_y);
if (norm_vp_width <= 0 || if (norm_vp_width <= 0 ||
norm_vp_height <= 0 || norm_vp_height <= 0 ||
norm_full_vp_width <= 0 || norm_full_vp_width <= 0 ||
@ -31235,7 +31233,6 @@ bool video_driver_translate_coord_viewport(
*res_y = scaled_y; *res_y = scaled_y;
*res_screen_x = scaled_screen_x; *res_screen_x = scaled_screen_x;
*res_screen_y = scaled_screen_y; *res_screen_y = scaled_screen_y;
printf("yoshi debug: translated coordinates: res: (%i,%i) res_screen:(%i,%i) \n",scaled_x,scaled_y,scaled_screen_x,scaled_screen_y);
return true; return true;
} }

View File

@ -129,8 +129,6 @@ static void handle_touch_event(NSArray* touches)
// continue; // continue;
coord = [touch locationInView:[touch view]]; coord = [touch locationInView:[touch view]];
NSLog(@"yoshi debug: handle_touch_event: coord = %f,%f , scaled = %f,%f",coord.x,coord.y,coord.x*scale,coord.y*scale);
if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled) if (touch.phase != UITouchPhaseEnded && touch.phase != UITouchPhaseCancelled)
{ {
apple->touches[apple->touch_count ].screen_x = coord.x * scale; apple->touches[apple->touch_count ].screen_x = coord.x * scale;
@ -350,6 +348,7 @@ enum
MetalView *v = [MetalView new]; MetalView *v = [MetalView new];
v.paused = YES; v.paused = YES;
v.enableSetNeedsDisplay = NO; v.enableSetNeedsDisplay = NO;
v.multipleTouchEnabled = YES;
_renderView = v; _renderView = v;
} }
break; break;
@ -365,8 +364,6 @@ enum
return; return;
} }
// _renderView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
// [_renderView setFrame:self.window.bounds];
_renderView.translatesAutoresizingMaskIntoConstraints = NO; _renderView.translatesAutoresizingMaskIntoConstraints = NO;
UIView *rootView = [CocoaView get].view; UIView *rootView = [CocoaView get].view;
[rootView addSubview:_renderView]; [rootView addSubview:_renderView];
@ -374,10 +371,6 @@ enum
[[_renderView.bottomAnchor constraintEqualToAnchor:rootView.bottomAnchor] setActive:YES]; [[_renderView.bottomAnchor constraintEqualToAnchor:rootView.bottomAnchor] setActive:YES];
[[_renderView.leadingAnchor constraintEqualToAnchor:rootView.leadingAnchor] setActive:YES]; [[_renderView.leadingAnchor constraintEqualToAnchor:rootView.leadingAnchor] setActive:YES];
[[_renderView.trailingAnchor constraintEqualToAnchor:rootView.trailingAnchor] setActive:YES]; [[_renderView.trailingAnchor constraintEqualToAnchor:rootView.trailingAnchor] setActive:YES];
// [self.window addSubview:_renderView];
// self.window.contentView.nextResponder = _listener;
} }
- (apple_view_type_t)viewType { - (apple_view_type_t)viewType {
@ -385,12 +378,13 @@ enum
} }
- (void)setVideoMode:(gfx_ctx_mode_t)mode { - (void)setVideoMode:(gfx_ctx_mode_t)mode {
// hmm might need some scaling factor...
MetalView *metalView = (MetalView*) _renderView; MetalView *metalView = (MetalView*) _renderView;
[metalView setDrawableSize:CGSizeMake(mode.width, mode.height)]; CGFloat scale = [[UIScreen mainScreen] scale];
NSLog(@"setVideoMode set drawable size to %i x %i",mode.width,mode.height); [metalView setDrawableSize:CGSizeMake(
// hardcoding test! _renderView.bounds.size.width * scale,
[metalView setDrawableSize:CGSizeMake(1242.0,2668.0)]; _renderView.bounds.size.height * scale
)
];
} }
- (void)setCursorVisible:(bool)v { - (void)setCursorVisible:(bool)v {