Skip to content

Commit 8218c43

Browse files
committed
Dump CGContext type
1 parent b790647 commit 8218c43

File tree

3 files changed

+94
-5
lines changed

3 files changed

+94
-5
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v2
1919
- name: Build
20-
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
20+
run: /usr/bin/clang++ info.mm -framework Cocoa -o test && ./test

.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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
CFShow(cg);
42+
printf("CGContextType: %d\n", CGContextGetType(cg));
43+
CGColorSpaceRef color = CGBitmapContextGetColorSpace(cg);
44+
CFShow(color);
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+
NSRect contentRect = NSMakeRect(400, 300, 300, 200);
75+
NSWindow* window = [[NSWindow alloc] initWithContentRect:contentRect
76+
styleMask:NSTitledWindowMask
77+
backing:NSBackingStoreBuffered
78+
defer:NO];
79+
80+
NSView* view = [[TestView alloc] initWithFrame:NSMakeRect(0, 0, contentRect.size.width, contentRect.size.height)];
81+
82+
[window setContentView:view];
83+
[window setDelegate:[[TerminateOnClose alloc] autorelease]];
84+
[NSApp activateIgnoringOtherApps:YES];
85+
[window makeKeyAndOrderFront:window];
86+
87+
[NSApp run];
88+
89+
[pool release];
90+
91+
return 0;
92+
}

0 commit comments

Comments
 (0)