blob: b2c59516e0e92fc693a9735d805c3758a847ad9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <crt_externs.h>
#import <Cocoa/Cocoa.h>
#include "SkApplication.h"
#include "SkGraphics.h"
#include "SkNSView.h"
@interface MainView : SkNSView {
}
- (id)initWithFrame: (NSRect)frame ;
- (void)dealloc;
- (void)begin;
@end
@implementation MainView : SkNSView
- (id)initWithFrame: (NSRect)frame {
self = [super initWithFrame:frame];
return self;
}
- (void)dealloc {
delete self.fWind;
[super dealloc];
}
- (void)begin {
self.fWind = create_sk_window(self, *_NSGetArgc(), *_NSGetArgv());
[self setUpWindow];
}
@end
@interface AppDelegate : NSObject<NSApplicationDelegate, NSWindowDelegate> {
}
- (id)init;
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication;
@end
#
@implementation AppDelegate : NSObject
- (id)init {
self = [super init];
return self;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
return TRUE;
}
@end
int main(int argc, char *argv[]) {
SkGraphics::Init();
signal(SIGPIPE, SIG_IGN);
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSApplication* app = [NSApplication sharedApplication];
NSUInteger windowStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask);
NSRect windowRect = NSMakeRect(100, 100, 1000, 1000);
NSWindow* window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO];
NSRect rect = [NSWindow contentRectForFrameRect:windowRect styleMask:windowStyle];
MainView* customView = [[MainView alloc] initWithFrame:rect];
[customView setTranslatesAutoresizingMaskIntoConstraints:NO];
NSView* contentView = window.contentView;
[contentView addSubview:customView];
NSDictionary *views = NSDictionaryOfVariableBindings(customView);
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[customView]|"
options:0
metrics:nil
views:views]];
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[customView]|"
options:0
metrics:nil
views:views]];
[customView begin];
[customView release];
[window makeKeyAndOrderFront:NSApp];
AppDelegate * appDelegate = [[[AppDelegate alloc] init] autorelease];
app.delegate = appDelegate;
NSMenu* menu=[[NSMenu alloc] initWithTitle:@"AMainMenu"];
NSMenuItem* item;
NSMenu* subMenu;
//Create the application menu.
item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:NULL keyEquivalent:@""];
[menu addItem:item];
subMenu=[[NSMenu alloc] initWithTitle:@"Apple"];
[menu setSubmenu:subMenu forItem:item];
[item release];
item=[[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
[subMenu addItem:item];
[item release];
[subMenu release];
//Add the menu to the app.
[app setMenu:menu];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
[app run];
[menu release];
[appDelegate release];
[window release];
[pool release];
return EXIT_SUCCESS;
}
|