Slashdot stories can be listened to in audio form via an RSS feed, as read by our own robotic overlord.

 



Forgot your password?
typodupeerror
PC Games (Games)

jcr's Journal: Comments on some of my Obsolete Sample Code

Journal by jcr

I wrote a number of Sample Code projects when I was at Apple, and we didn't have a way to mark them as superseded or obsolete, so let me just give you a few notes on them here. As far as I know, all of these samples work just fine on Mac OS X 10.4 (Tiger), but in many cases, the code in these samples is no longer necessary, or can be greatly reduced by using new features of Tiger.

Animated Slider
Back when I first wrote this sample, iTunes had just added a graphic equalizer, which does a spiffy trick of animating the motion of the sliders from one preset configuration to another. This sample demonstrated how simple it was to add this animation capability to all NSSliders in your app, but today, with the NSAnimation and NSViewAnimation classes it's even easier.

RGB Image
The purpose of this sample was to demonstrate how to use compositing to separate any image into its Red, Green and Blue components. This was superseded by...

RGB Value Transformers
In this program I refactored the compositing code into an NSValueTransformer subclass, called RGBTransformer. It's a much better way to organize the code than its predecessor, but today I would do this kind of thing with no code at all, using the Color Matrix patch in a Quartz Composer composition.

Polygons
This sample is mostly about how to add methods to NSBezierPath for shapes that you might want to draw often. If I were writing this example today, I'd use Bindings, and there would be a lot less glue code. In fact, I'd probably delete the Controller class altogether.

Tinted Image: this app is still handy for testing various combinations of colors and compositing modes. But, if you want to apply coloration to an image in your app, you should look into the much richer capabilities of CoreImage.

Transformed Image:
  Not much to say about this one. I added a category to NSAffineTransform to make shearing a little more obvious.

Monochrome Image:
This is completely obsolete in Tiger. Use the CoreImage monochrome filter, "CIColorMonochrome" instead.

Image Difference:
I was rather proud of this one at the time I wrote it. I was curious what the error was in JPEG images with various levels of compression, so I figured out how to subtract one image from another by compositing. I still had to do some manual bit-twiddling of the image data in the NSBitmapImageRep instances to generate the negative images, which I definitely would not do today. This is another of those things that Quartz Composer can do with no code at all.

Cropped Image
In the Cropped Image sample, I show how to use compositing to extract a portion of an image, and also a few ways to draw a selection indicator. If you have something like this to do today, consider putting the selection marker in its own layer, instead of drawing it over the source image as I did here. It would be far more efficient that way.

Color Sampler
Totally obsolete in Leopard and later. See the WWDC 2009 session on NSImage for how this kind of thing should be done today.

and, on any Mac with Xcode installed, at /Developer/Examples/CoreData/Stickies, you will find the first Core Data app I ever wrote. The Core Data team liked it enough to put it on the Developer Tools DMG.

There's a bug that appeared sometime before Leopard that prevents the sticky windows from resizing. The solution is to explicitly turn on mouseMoved events when there's a mouseDown in the resizing corner. To remedy this, add the following code to "StickyResizeCornerView.m", inside the implementation context:

// Fix for Leopard. Turning on MouseMoved events wasn't necessary before Leopard, but now it is for some reason. -jcr
- (void) mouseDown:(NSEvent *) theEvent { [[self window] setAcceptsMouseMovedEvents:YES]; }
- (void) mouseUp:(NSEvent *) theEvent { [[self window] setAcceptsMouseMovedEvents:NO]; }

This discussion has been archived. No new comments can be posted.

Comments on some of my Obsolete Sample Code

Comments Filter:

The clash of ideas is the sound of freedom.

Working...