Skip to content

Commit 9959ec2

Browse files
committed
Dump CGContext type
1 parent b790647 commit 9959ec2

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ matrix:
2222
install:
2323
- rustup target add $TARGET
2424
script:
25-
- cargo build --all-targets --verbose --target $TARGET
26-
- cargo test --verbose --target $TARGET -- --nocapture
25+
- /usr/bin/clang++ info.mm -framework Cocoa -o test && ./test

info.mm

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* clang++ main.mm -framework Cocoa -o test && ./test
3+
**/
4+
5+
#import <Cocoa/Cocoa.h>
6+
7+
@interface TestView: NSView
8+
{
9+
}
10+
11+
@end
12+
13+
@implementation TestView
14+
15+
- (id)initWithFrame:(NSRect)aFrame
16+
{
17+
if (self = [super initWithFrame:aFrame]) {
18+
}
19+
return self;
20+
}
21+
extern "C" {
22+
typedef enum {
23+
kCGContextTypeUnknown,
24+
kCGContextTypePDF,
25+
kCGContextTypePostScript,
26+
kCGContextTypeWindow,
27+
kCGContextTypeBitmap,
28+
kCGContextTypeGL,
29+
kCGContextTypeDisplayList,
30+
kCGContextTypeKSeparation,
31+
kCGContextTypeIOSurface,
32+
kCGContextTypeCount
33+
} CGContextType;
34+
35+
36+
CGContextType CGContextGetType(CGContextRef);
37+
}
38+
- (void)drawRect:(NSRect)aRect
39+
{
40+
CGContextRef cg = NSGraphicsContext.currentContext.CGContext;
41+
printf("CGContextType: %d\n", CGContextGetType(cg));
42+
CGColorSpaceRef color = CGBitmapContextGetColorSpace(cg);
43+
CFShow(color);
44+
CFShow(cg);
45+
exit(1);
46+
for (int y = 0; y<20; y++) {
47+
for (int x = 0; x<20; x++) {
48+
CGContextSetRGBFillColor(cg, 0.2, 0.6, 1.0, 0.9);
49+
CGContextFillEllipseInRect(cg, CGRectMake(50+x*50, 30+30*y, 200, 130));
50+
}
51+
}
52+
}
53+
54+
@end
55+
56+
@interface TerminateOnClose : NSObject<NSWindowDelegate>
57+
@end
58+
59+
@implementation TerminateOnClose
60+
- (void)windowWillClose:(NSNotification*)notification
61+
{
62+
[NSApp terminate:self];
63+
}
64+
@end
65+
66+
int
67+
main (int argc, char **argv)
68+
{
69+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
70+
71+
[NSApplication sharedApplication];
72+
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
73+
74+
int style =
75+
NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable;
76+
NSRect contentRect = NSMakeRect(400, 300, 300, 200);
77+
NSWindow* window = [[NSWindow alloc] initWithContentRect:contentRect
78+
styleMask:style
79+
backing:NSBackingStoreBuffered
80+
defer:NO];
81+
82+
NSView* view = [[TestView alloc] initWithFrame:NSMakeRect(0, 0, contentRect.size.width, contentRect.size.height)];
83+
84+
[window setContentView:view];
85+
[window setDelegate:[[TerminateOnClose alloc] autorelease]];
86+
[NSApp activateIgnoringOtherApps:YES];
87+
[window makeKeyAndOrderFront:window];
88+
89+
[NSApp run];
90+
91+
[pool release];
92+
93+
return 0;
94+
}

0 commit comments

Comments
 (0)