Skip to content

Instantly share code, notes, and snippets.

@chamons chamons/example.m Secret
Created Oct 7, 2019

Embed
What would you like to do?
//
// 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
You can’t perform that action at this time.