Hacking Santa Snaps
Cocoa Duel had a great holiday themed coding competition. One of the entries was Santa Snaps. Santa Snaps lets you take your camera’s input and overlay some holiday themed graphics like a santa hat or reindeer antlers. We all had a fun time at our house playing around with it before xmas, but I started thinking about how cool this would be for our upcoming “Party 2-007″ james bond themed party. I’m very grateful that John Casasanta decided to upload the source for Santa Snaps because even a newbie obj-c hacker like myself had a fairly easy time of locating the things I needed to in order to change the graphics to more bond-appropriate ones. You can too, check it out:
download the source here: http://macheist.com/SantaSnaps/SantaSnapsProject.zip, unzip it, and open it up in Xcode.

This one.. “SantaSnaps.xcodeproj”. If you have Xcode, you should be able to just double click the file.
Locate “Controller.m” in the classes folder as illustrated below….
See that there on line 26? @”santa hat”, @”santa glasses”, @”santa beard”, etc? This is the line you’re going to be changing.
Now, It doesn’t really matter how you generate your PNG files with their alpha channel in tact, as long as you do. I used to work for Adobe, so I use Photoshop. Take one of your photos that you took with SantaSnaps and open it up in whatever image editor you’re using. This will give you the frame size to use as well as a good indication as to where to place whatever new graphics you’re going to be placing. Then place your graphic where it should go, turn off the background layer, and save the file as a PNG file.



Back to Xcode. In controller.m, on line 26, change the name of the first item @”Santa Hat” to @”whatever your file name was”. Drag your new PNG file into the “Resources” folder inside of the santasnaps xcode window. I’ve illustrated several changes that all happen the same way. Change each item in the “NSArray arrayWithObjects” list, and drag the actual graphic file into the resources folder. The order corresponds to the button order in the interface, so… keep that in mind.
At this point you could hit that “Build and Go” button and when you hit the santa hat icon in the application, your new graphic should show up.
This is the majority of the hard part. The other part is to edit the nib file, which in my opinion is much easier to do than digging through code. To replace the existing buttons with ones that match your new graphics, you’ll need two states for each new button you want to change. The selected state and the unselected state.
unselected

selected

Find SantaSnaps.nib either in the project folder in Xcode or the finder and double click on it. It’ll look something like this:

Drag your two button graphics, one at a time, into the nib file’s graphics tab. It’ll say something like “you want to add this to santasnaps project, yeah?” Yeah, you do. See below for “grill_selected” and “grill_unselected” :

and then drag and drop your unselected state graphic to the corresponding button you want to change, as seen in the upper left corner of this graphic:

The last bit is to bring up the inspector palette and change the alt-icon state to the other graphic’s name. See below:

see above… Icon: grill_unselected
alt. Icon: (change from “Santa Hat Button Pressed” to:) grill_selected
That’s it! Easy!
Save the nib file and re-[build-and-go] from Xcode. Once you get the first one working, you’ll get into a regular rhythm for the other 8. Good luck! This is all I know, I don’t know anything else, I can’t help you any further.
Technorati Tags: xcode





