Skip to content

Instantly share code, notes, and snippets.

@ccgus
Created September 8, 2010 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccgus/570811 to your computer and use it in GitHub Desktop.
Save ccgus/570811 to your computer and use it in GitHub Desktop.
function main() {
var doc = [Acorn open:"/Volumes/srv/Users/gus/Dropbox/AcornStuff/more junk.acorn"];
var layer = [doc firstLayerNamed:"Background"];
var canvasSize = [doc canvasSize];
var inset = 40;
var image = [[[NSImage alloc] initWithSize:canvasSize] autorelease];
var canvasBounds = NSMakeRect(0, 0, 0, 0);
canvasBounds.size = canvasSize;
var pageBounds = NSMakeRect(inset, -inset, canvasSize.width - inset * 2, canvasSize.height);
[image lockFocus];
[[NSColor colorWithCalibratedWhite:0.908 alpha:1.000] set];
[NSBezierPath fillRect:canvasBounds];
var shadow = [[[NSShadow alloc] init] autorelease];
[shadow setShadowColor:[[NSColor blackColor] colorWithAlphaComponent:.5]];
[shadow setShadowBlurRadius:2];
[[NSGraphicsContext currentContext] saveGraphicsState];
[shadow set];
[[NSColor whiteColor] set];
var bp = [NSBezierPath bezierPathWithRoundedRect:pageBounds xRadius:16 yRadius:16];
[bp fill];
// get rid of our shadow
[[NSGraphicsContext currentContext] restoreGraphicsState];
pageBounds = NSInsetRect(pageBounds, 1, 1);
pageBounds.origin.x -= .5;
pageBounds.origin.y += .5;
pageBounds.size.width += 1;
bp = [NSBezierPath bezierPathWithRoundedRect:pageBounds xRadius:16 yRadius:16];
[[NSColor grayColor] set];
[bp setLineWidth:1];
[bp stroke];
[image unlockFocus];
[layer applyCIImageFromFilter:[image CIImage]];
}
// are we running in Acorn?
if ("com.flyingmeat.Acorn" == [[NSBundle mainBundle] bundleIdentifier]) {
main();
print("Done");
}
else { // If not, then tell Acorn to run this guy.
[[JSTalk application:"Acorn"] doJavaScript:[jstalk env].scriptURL.path()];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment