|
|
@ -34,19 +34,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
@implementation ViewController
|
|
|
|
@implementation ViewController
|
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil
|
|
|
|
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil
|
|
|
|
{
|
|
|
|
{
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
|
|
|
|
|
|
|
|
_device = MTLCreateSystemDefaultDevice();
|
|
|
|
_device = MTLCreateSystemDefaultDevice();
|
|
|
|
_commandQueue = [_device newCommandQueue];
|
|
|
|
_commandQueue = [_device newCommandQueue];
|
|
|
|
|
|
|
|
|
|
|
|
if (!self.device)
|
|
|
|
if (!self.device)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NSLog(@"Metal is not supported");
|
|
|
|
NSLog(@"Metal is not supported");
|
|
|
|
abort();
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Setup Dear ImGui context
|
|
|
|
// Setup Dear ImGui context
|
|
|
|
// FIXME: This example doesn't have proper cleanup...
|
|
|
|
// FIXME: This example doesn't have proper cleanup...
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
@ -76,16 +76,16 @@
|
|
|
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
|
|
|
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
|
|
|
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
|
|
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
|
|
|
//IM_ASSERT(font != NULL);
|
|
|
|
//IM_ASSERT(font != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (MTKView *)mtkView
|
|
|
|
- (MTKView *)mtkView
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (MTKView *)self.view;
|
|
|
|
return (MTKView *)self.view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)loadView
|
|
|
|
- (void)loadView
|
|
|
|
{
|
|
|
|
{
|
|
|
|
self.view = [[MTKView alloc] initWithFrame:CGRectMake(0, 0, 1200, 720)];
|
|
|
|
self.view = [[MTKView alloc] initWithFrame:CGRectMake(0, 0, 1200, 720)];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -96,7 +96,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
self.mtkView.device = self.device;
|
|
|
|
self.mtkView.device = self.device;
|
|
|
|
self.mtkView.delegate = self;
|
|
|
|
self.mtkView.delegate = self;
|
|
|
|
|
|
|
|
|
|
|
|
#if TARGET_OS_OSX
|
|
|
|
#if TARGET_OS_OSX
|
|
|
|
// Add a tracking area in order to receive mouse events whenever the mouse is within the bounds of our view
|
|
|
|
// Add a tracking area in order to receive mouse events whenever the mouse is within the bounds of our view
|
|
|
|
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
|
|
|
|
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
|
|
|
@ -108,20 +108,17 @@
|
|
|
|
// If we want to receive key events, we either need to be in the responder chain of the key view,
|
|
|
|
// If we want to receive key events, we either need to be in the responder chain of the key view,
|
|
|
|
// or else we can install a local monitor. The consequence of this heavy-handed approach is that
|
|
|
|
// or else we can install a local monitor. The consequence of this heavy-handed approach is that
|
|
|
|
// we receive events for all controls, not just Dear ImGui widgets. If we had native controls in our
|
|
|
|
// we receive events for all controls, not just Dear ImGui widgets. If we had native controls in our
|
|
|
|
// window, we'd want to be much more careful than just ingesting the complete event stream, though we
|
|
|
|
// window, we'd want to be much more careful than just ingesting the complete event stream.
|
|
|
|
// do make an effort to be good citizens by passing along events when Dear ImGui doesn't want to capture.
|
|
|
|
// To match the behavior of other backends, we pass every event down to the OS.
|
|
|
|
NSEventMask eventMask = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged | NSEventTypeScrollWheel;
|
|
|
|
NSEventMask eventMask = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged | NSEventTypeScrollWheel;
|
|
|
|
[NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^NSEvent * _Nullable(NSEvent *event)
|
|
|
|
[NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^NSEvent * _Nullable(NSEvent *event)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
BOOL wantsCapture = ImGui_ImplOSX_HandleEvent(event, self.view);
|
|
|
|
ImGui_ImplOSX_HandleEvent(event, self.view);
|
|
|
|
if (event.type == NSEventTypeKeyDown && wantsCapture)
|
|
|
|
return event;
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return event;
|
|
|
|
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
ImGui_ImplOSX_Init();
|
|
|
|
ImGui_ImplOSX_Init();
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|