Skip to content

Instantly share code, notes, and snippets.

@chamons
Created October 7, 2019 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/f5c6c234204632bb15c0fa693481754e to your computer and use it in GitHub Desktop.
Save chamons/f5c6c234204632bb15c0fa693481754e to your computer and use it in GitHub Desktop.
//
// ViewController.m
// PopupTest
//
// Created by Chris Hamons on 10/7/19.
// Copyright © 2019 Chris Hamons. All rights reserved.
//
@import MetalKit;
#import "ViewController.h"
@implementation ViewController
NSTextView * textView;
NSDate *lastTick;
- (void)viewDidLoad {
[super viewDidLoad];
MTKView * timer = [[MTKView alloc] initWithFrame:CGRectMake(0, 0, 10, 10) device:MTLCreateSystemDefaultDevice()];
timer.clearColor = MTLClearColorMake(1, 0, 0, 1);
timer.delegate = self;
[self.view addSubview:timer];
textView = [[NSTextView alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
[self.view addSubview:textView];
lastTick = [NSDate date];
NSMenuItem *first = [[NSMenuItem alloc] initWithTitle:@"1" action:NULL keyEquivalent:@""];
NSMenuItem *second = [[NSMenuItem alloc] initWithTitle:@"2" action:NULL keyEquivalent:@""];
NSMenuItem *third = [[NSMenuItem alloc] initWithTitle:@"3" action:NULL keyEquivalent:@""];
NSPopUpButton *button = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50, 50, 50, 50)pullsDown:YES];
[button.menu addItem:first];
[button.menu addItem:second];
[button.menu addItem:third];
[self.view addSubview:button];
}
- (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size{
}
- (void)drawInMTKView:(nonnull MTKView *)view {
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:lastTick];
NSString *intervalString = [NSString stringWithFormat:@"%f", timeInterval];
textView.string = intervalString;
lastTick = [NSDate date];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment