Post

Replies

Boosts

Views

Activity

Reply to Beginner help (obj-c, metal, reading inputs)
I think I've found a way through this after discovering this bit of text in the docs for NSViewController: In addition, in macOS 10.10 and later, a view controller participates in the responder chain. You can implement action methods directly in the view controller. Corresponding actions that originate in the view controller’s view proceed up the responder chain and are handled by those methods. So I can just implement mouseDown etc. directly in the view controller and it just works! Great, but I'd still like to know why the other options didn't work and overall how the app is working. Nib files, storyboards, etc. -- is there a good overview somewhere?
Topic: Graphics & Games SubTopic: Metal Tags:
Apr ’23
Reply to Input with Metal-CPP, overriding MTK::View
Hey Hipreme (or anyone else), on the chance that you see this. I'm trying to get this working in the default metal kit 3D rendering sample. My GameViewController looks like this: #import "GameViewController.h" #import "Renderer.h" @interface InputView : NSView @end @implementation InputView - (BOOL)acceptsFirstResponder{ return YES; } - (void)mouseDown:(NSEvent*)event { printf("mouse down"); } - (void)keyDown:(NSEvent *)event { printf("key down"); } @end @implementation GameViewController { MTKView *_view; InputView *_input_view; Renderer *_renderer; } - (void)viewDidLoad { [super viewDidLoad]; _view = (MTKView *)self.view; _view.device = MTLCreateSystemDefaultDevice(); if(!_view.device) { NSLog(@"Metal is not supported on this device"); self.view = [[NSView alloc] initWithFrame:self.view.frame]; return; } _renderer = [[Renderer alloc] initWithMetalKitView:_view]; [_renderer mtkView:_view drawableSizeWillChange:_view.bounds.size]; _view.delegate = _renderer; _input_view = [[InputView alloc] initWithFrame:_view.frame]; BOOL fr = [_input_view becomeFirstResponder]; printf("fr %d\n", fr); } @end becomeFirstResponder is returning true, but I'm not getting and logging from mouseDown or keyDown. I've tried a few other configurations of this same approach with similar results. I'm brand new to obj-c and Apple dev in general. Any suggestions?
Topic: Graphics & Games SubTopic: General Tags:
Apr ’23
Reply to Beginner help (obj-c, metal, reading inputs)
I think I've found a way through this after discovering this bit of text in the docs for NSViewController: In addition, in macOS 10.10 and later, a view controller participates in the responder chain. You can implement action methods directly in the view controller. Corresponding actions that originate in the view controller’s view proceed up the responder chain and are handled by those methods. So I can just implement mouseDown etc. directly in the view controller and it just works! Great, but I'd still like to know why the other options didn't work and overall how the app is working. Nib files, storyboards, etc. -- is there a good overview somewhere?
Topic: Graphics & Games SubTopic: Metal Tags:
Replies
Boosts
Views
Activity
Apr ’23
Reply to Input with Metal-CPP, overriding MTK::View
Hey Hipreme (or anyone else), on the chance that you see this. I'm trying to get this working in the default metal kit 3D rendering sample. My GameViewController looks like this: #import "GameViewController.h" #import "Renderer.h" @interface InputView : NSView @end @implementation InputView - (BOOL)acceptsFirstResponder{ return YES; } - (void)mouseDown:(NSEvent*)event { printf("mouse down"); } - (void)keyDown:(NSEvent *)event { printf("key down"); } @end @implementation GameViewController { MTKView *_view; InputView *_input_view; Renderer *_renderer; } - (void)viewDidLoad { [super viewDidLoad]; _view = (MTKView *)self.view; _view.device = MTLCreateSystemDefaultDevice(); if(!_view.device) { NSLog(@"Metal is not supported on this device"); self.view = [[NSView alloc] initWithFrame:self.view.frame]; return; } _renderer = [[Renderer alloc] initWithMetalKitView:_view]; [_renderer mtkView:_view drawableSizeWillChange:_view.bounds.size]; _view.delegate = _renderer; _input_view = [[InputView alloc] initWithFrame:_view.frame]; BOOL fr = [_input_view becomeFirstResponder]; printf("fr %d\n", fr); } @end becomeFirstResponder is returning true, but I'm not getting and logging from mouseDown or keyDown. I've tried a few other configurations of this same approach with similar results. I'm brand new to obj-c and Apple dev in general. Any suggestions?
Topic: Graphics & Games SubTopic: General Tags:
Replies
Boosts
Views
Activity
Apr ’23