Wednesday 11 July 2012

XCode Text and QC Visualizer

OK, hold the horses.  OpenGL may be a bit of a sledgehammer for this scrolling text nut.  I may have jumped too far out going straight for openGL.  I have no immediate need of 3D graphics.  Once again my enthusiasm to get going meant I didn't necessarily consider all possible solutions and select the best one.  If systems engineering has taught me anything it should be to consider the requirements and many possible solutions before jumping down (often) the wrong leg of the solution trousers.



I have discovered two things that offer alternatives to the openGL solution.

1) XCode has three different ways of handling text:
NSString/NSAttributedString - convenient to use but wasteful of processing because it redraws everything;
NSCell - less convenient but less wasteful as it doesn't redraw everything;
NSLayoutManager - in depth control of how the text is rendered, when things are discarded (e.g. glyphs in memory) allows careful use of system resources.

2) Quartz Composer Visualizer, installed with QC itself, allows you to do a couple of useful things. You can spread your image/composition over a number of displays.  You can split the composition into two and run each on different machines.  This might allow the calculations to be done on one Mac and display on another.

I'm hoping NSLayoutManager will allow smooth scrolling by minimising set-up and redrawing calls to lower processing requirements so the string can scroll totally smoothly.  I should be able to process the set-up before drawing anything to screen and concentrate processing on the translation when the text is on the screen.  This should be fairly straight-forward Objective-C code.  The holy grail is smooth scrolling, I'll worry about user-friendliness/operator GUI later.

If that fails I could always buy another mac and have a control and display computer splitting the processing load of a Quartz Composition.

1 comment:

  1. This is a good start for anyone wanting to understand NSLayoutManager:

    https://developer.apple.com/library/mac/#samplecode/TextLayoutDemo/Listings/Controller_m.html#//apple_ref/doc/uid/DTS10004341-Controller_m-DontLinkElementID_8

    ReplyDelete