1// Renders the pieces of 10.6's chrome that the Snow Leopard `--screenshot` samples, into
2// DIR as PNGs: the window buttons, and scrollers with their knob and without, each for a
3// key window and for another. `remote.sh art` fetches them into crates/snowbound/assets/snow-leopard.
4#import <AppKit/AppKit.h>
5#import <objc/runtime.h>
6
7@interface KeyWindow : NSWindow
8@end
9@implementation KeyWindow
10- (BOOL)isKeyWindow { return YES; }
11- (BOOL)isMainWindow { return YES; }
12@end
13
14// A scroller's track and arrows alone.
15@interface Track : NSScroller
16@end
17@implementation Track
18- (void)drawKnob {}
19@end
20
21static NSString *dir;
22
23static void save(NSView *view, NSRect rect, NSString *name) {
24 NSBitmapImageRep *rep = [view bitmapImageRepForCachingDisplayInRect:rect];
25 [view cacheDisplayInRect:rect toBitmapImageRep:rep];
26 [[rep representationUsingType:NSPNGFileType properties:nil]
27 writeToFile:[dir stringByAppendingPathComponent:name] atomically:YES];
28}
29
30static NSWindow *window(BOOL key) {
31 NSWindow *window = [[(key ? [KeyWindow class] : [NSWindow class]) alloc]
32 initWithContentRect:NSMakeRect(-10000, -10000, 500, 500)
33 styleMask:NSBorderlessWindowMask
34 backing:NSBackingStoreBuffered
35 defer:NO];
36 [window setOpaque:NO];
37 [window setBackgroundColor:[NSColor clearColor]];
38 return window;
39}
40
41int main(int argc, char **argv) {
42 NSAutoreleasePool *pool = [NSAutoreleasePool new];
43 if (argc != 2) {
44 fprintf(stderr, "usage: art DIR\n");
45 return 2;
46 }
47 [NSApplication sharedApplication];
48 dir = [NSString stringWithUTF8String:argv[1]];
49 [[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:NULL];
50 NSUInteger style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask
51 | NSResizableWindowMask | NSTexturedBackgroundWindowMask;
52 for (int key = 0; key < 2; key++) {
53 NSString *state = key ? @"key" : @"other";
54 NSView *content = [window(key) contentView];
55 // Close, minimize and zoom, side by side at their own size.
56 CGFloat x = 0, height = 0;
57 for (NSWindowButton kind = NSWindowCloseButton; kind <= NSWindowZoomButton; kind++) {
58 NSButton *button = [NSWindow standardWindowButton:kind forStyleMask:style];
59 [button setFrameOrigin:NSMakePoint(x, 0)];
60 [content addSubview:button];
61 x += [button frame].size.width;
62 height = [button frame].size.height;
63 }
64 save(content, NSMakeRect(0, 0, x, height), [NSString stringWithFormat:@"buttons-%@.png", state]);
65 [[content subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
66 for (int vertical = 0; vertical < 2; vertical++) {
67 NSString *axis = vertical ? @"vertical" : @"horizontal";
68 CGFloat width = [NSScroller scrollerWidth];
69 NSRect frame = vertical ? NSMakeRect(0, 0, width, 400) : NSMakeRect(0, 0, 400, width);
70 NSScroller *track = [[Track alloc] initWithFrame:frame];
71 [track setEnabled:YES];
72 [track setKnobProportion:0.25];
73 [content addSubview:track];
74 save(track, [track bounds], [NSString stringWithFormat:@"scroller-%@-track-%@.png", axis, state]);
75 [track removeFromSuperview];
76 NSScroller *scroller = [[NSScroller alloc] initWithFrame:frame];
77 [scroller setEnabled:YES];
78 [scroller setKnobProportion:0.25];
79 [scroller setDoubleValue:0.5];
80 [content addSubview:scroller];
81 save(scroller, [scroller bounds], [NSString stringWithFormat:@"scroller-%@-%@.png", axis, state]);
82 [scroller removeFromSuperview];
83 }
84 }
85 [pool drain];
86 return 0;
87}