Created
September 14, 2018 09:25
-
-
Save giraphics/f8912e9df7380b3e12c0e45519294215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <AppKit/AppKit.h> | |
#import <QuartzCore/CAMetalLayer.h> | |
@interface MyAppDelegate : NSObject <NSApplicationDelegate> | |
{ | |
NSWindow *window; | |
} | |
@end | |
@implementation MyAppDelegate | |
-(id) init | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
NSRect mainDisplayRect = [[NSScreen mainScreen] frame]; | |
NSRect windowRect = NSMakeRect(mainDisplayRect.origin.x + (mainDisplayRect.size.width) * 0.25, | |
mainDisplayRect.origin.y + (mainDisplayRect.size.height) * 0.25, | |
mainDisplayRect.size.width * 0.5, | |
mainDisplayRect.size.height * 0.5); | |
NSUInteger windowStyle = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask; | |
NSInteger windowLevel = NSMainMenuWindowLevel + 1; | |
window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO]; | |
[window setLevel:windowLevel]; | |
[window setOpaque:YES]; | |
[window setHasShadow:YES]; | |
[window setPreferredBackingLocation:NSWindowBackingLocationVideoMemory]; | |
[window setHidesOnDeactivate:NO]; | |
[window setBackgroundColor:[NSColor colorWithDeviceRed:200.0 / 255.0 green:10.0 / 255.0 blue:45.0 / 255.0 alpha:1.0f]]; | |
NSRect topLevelViewRect = NSMakeRect(50, 50, windowRect.size.width - 100, windowRect.size.height - 100); | |
NSView* windowNSview = [[NSView alloc] initWithFrame:topLevelViewRect]; | |
[windowNSview setWantsLayer:YES]; | |
windowNSview.layer.backgroundColor = [[NSColor colorWithDeviceRed:80.0 / 255.0 green:130.0 / 255.0 blue:245.0 / 255.0 alpha:1.0f] CGColor]; | |
[window.contentView addSubview:windowNSview]; | |
NSRect yellowViewRect = NSMakeRect(50, 50, topLevelViewRect.size.width * 0.5 - 50, topLevelViewRect.size.height - 100); | |
NSView* view = [[NSView alloc] initWithFrame:yellowViewRect]; | |
[view setWantsLayer:YES]; | |
view.layer.backgroundColor = [[NSColor colorWithDeviceRed:248.0 / 255.0 green:207.0 / 255.0 blue:96.0 / 255.0 alpha:1.0f] CGColor];; | |
[windowNSview addSubview:view]; | |
NSRect redViewRect =NSMakeRect(topLevelViewRect.size.width * 0.5, 50, topLevelViewRect.size.width * 0.5 - 50, topLevelViewRect.size.height - 100); | |
NSView* metalView = [[NSView alloc] initWithFrame:redViewRect]; | |
[metalView setWantsLayer:YES]; | |
[metalView setLayer:[CAMetalLayer layer]]; | |
metalView.layer.backgroundColor = [[NSColor colorWithDeviceRed:121.0 / 255.0 green:65.0 / 255.0 blue:106.0 / 255.0 alpha:1.0f] CGColor]; | |
[windowNSview addSubview:metalView]; | |
} | |
return self; | |
} | |
- (void)applicationWillFinishLaunching:(NSNotification *)notification{ [window makeKeyAndOrderFront:self]; } | |
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification{} | |
- (void)dealloc | |
{ | |
[window release]; | |
[super dealloc]; | |
} | |
@end | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool | |
{ | |
NSApplication *app = [NSApplication sharedApplication]; | |
[app setDelegate:[[[MyAppDelegate alloc] init] autorelease]]; | |
[app run]; | |
} | |
return 0; | |
} | |
// Command to build in TERMINAL | |
/*clang -framework Foundation -framework Cocoa -framework QuartzCore CALayers.mm -o CALayers.app*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment