Development

Cocoa tip: using custom outline view cells designed in IB

I only started learning Objective-C and Cocoa in mid-May, and for the first time I think I actually have a tip to contribute to the wider community. It’s about using custom cells in NSOutlineView, but those which you want to design inside Interface Builder rather than drawing manually.

If you’re an iOS developer, you’ll be wondering why this deserves a blog post - it’s easy to do in Cocoa Touch! Well, yes it is easy on iOS, because Apple have specifically allowed you to design table view cells in Interface Builder. When targetting Mac OS X though, it’s actually pretty awkward, and here’s why: in Cocoa Touch, the class which draws the cells in a table is UITableViewCell, which is a subclass of UIView - meaning you can drag one onto the canvas in Interface Builder and lay stuff out right there. In Cocoa, in contrast, the cell is simply represented by NSCell, which is not an NSView subclass. This means Interface Builder will not let you play with them, you draw them by implementing drawWithFrame:inView: instead. I think Apple realised the problem with this design in time for Cocoa Touch but obviously felt they couldn’t break the existing Cocoa interfaces. There are also many differences between the instantiation of NSCell versus UITableViewCell - there’s only one NSCell for all rows in a table / outline view, compared to a type-indexed pool in Cocoa Touch.

The problem boiled down to this: if the contents of your table / outline cell is non-trivial, or if you just don’t want to write a bunch of layout code, it’s a PITA to implement a custom look in NSOutlineView, such as the one in the picture, especially if you want custom controls embedded in it. For my current Cocoa app, I really wanted to design my cells (and I have 2 different styles for group levels and detail levels) in Interface Builder to save me hassle, including using Cocoa Bindings to hook up some dynamic fields within. Many internet searches later, and mostly the answer I found was that it couldn’t be done. Luckily, I’m too stubborn to take no for an answer, and eventually I figured out a way to do it. Details are after the jump, with an example project to show it in action.

Read more →

OS X Localisation: incremental genstrings and UTF-8 files

I came across a couple of interesting issues when I came to do the first pass of writing the text for the user-visible strings I’d been setting up for a Cocoa app I’m writing (painfully slowly as I learn the nuances of the environment), and I thought I’d share them. Full details are after the jump, since I’ve embedded a large script in the post.

The basic principle for text localisation on OS X is that, like most systems, you externalise your user-visible strings in string tables and reference them by keyed aliases in code - in this case using NSLocalizedString. Apple provide a tool called ‘genstrings’ which extracts all these into a template strings file called Localizable.strings which you can then populate per language - localised files are kept in folders called en.lproj, fr.lproj etc and helpfully they’re picked up by default like this.  So far, so good.

Read more →

Taking a bite of the Apple

Giving up the leadership of OGRE was a sad moment for me, but in hindsight it has also been rather liberating. For 10 years I’d spent most of my energy on OGRE or on projects that were related to OGRE. There was an implicit understanding both from the community and from myself that everything I embarked on would in some way tie into OGRE - and indeed my business has always been based on a constant balancing act between how I can make a living while also promoting and advancing OGRE.

Read more →

Open source is most important to producers rather than consumers

Gartner haven’t exactly been the sharpest tools in the box when it comes to predicting open source trends over the last few years, vastly underestimating it until about 2008, by which time it didn’t exactly take a professional analyst to tell you that it was popular. Still, now they’ve woken up to its potential, occasionally they post something useful. In particular, I liked a recent blog post about how open source is “trending towards customer obscurity” - that is to say that while open source is incredibly important to producers of software, the vast majority of consumers don’t really care how their software is made any more than they care how their car was made.

Read more →

Dependencies to build Git from source on [K]Ubuntu 9.04

Git is picky when it comes to converting large, moderately complex Subversion repositories and so far the only option I’ve found that works reliably is using the very latest version on Linux. Forget about using 1.6.5 on Windows via msysGit, at least for the git-svn conversion it’s very, very unreliable. Similarly I found Git 1.5 on Linux very flaky for the svn conversion. This doesn’t give me the greatest confidence in Git but in order to properly explore all the angles, I’ve committed to making it work even if it means I have to monkey about a bit.

Read more →

Yay, OgreSpeedTree 2.0b is done

I’ve been pushing quite hard to get this done before I head off to Qt DevDays next week, and luckily it all came together in the last few days: Some of the notable back-of-the-box (if there was a box) items: Upgrade to SpeedTree v5 - supporting all the great new features. See the SpeedTree site for more details on this release. More lighting options - Ambient Occlusion, Ambient Contrast, Specular Lighting, Transmission Lighting, Global Light Scalar, HDR.

Read more →

Kaz doesn't understand (most) developers

Sony’s PR machine has been rather contrite of late, after some really quite stellar gaffes a few years ago, but comments from Kaz Harai in an interview recently are a firm return to the ‘what in Gods name were you thinking?’ school of PR. Ignoring the fanboy-baiting predictions of who’s going to ‘win’ (given the expansions in the game industry, does anyone have to ‘win’?), the bit that got my attention was when he talked about the (many would say unnecessary) complexity of developing for the PS3:

Read more →

Qt 4.5 will be available under the LGPL

I’m on the Qt (owned by Nokia now) mailing list since I have a commercial license for a client project, and I got a very interesting email today, telling me that on its release in March 2009, Qt 4.5 will be available under the LGPL. This is really big news. Up until the current Qt 4.4, your only licensing options are a per-seat and per-platform commercial license (which adds up if you have multiple developers and multiple target platforms, which you will do if you’re using Qt anyway), or alternatively the free option which means you use it under the GPL - meaning all your own code has to also be GPL, with an exception that allows you to publish / use software under other open source licenses too, but nevertheless it all has to be public.

Read more →