The basic glyphs at the moment are
- RectangleGlyph – fill a rectangle with a specific Paint
- LineGlyph – draw a line with a specific Stroke and Paint
- TextGlyph – a string with a Font and Paint
- ImageGlyph – a image.
- GroupGlyph – a composite which can be used to apply transforms (and possibly effects) to a set of Glyphs
The advantage of this model over previous style sheet based methods is that each Glyph knows its size, position and visual state. Therefore it can exist without requiring a lot of context information. I might take the graphics state (Paint, Stroke, Font) out into a style object to allow sharing and setting of global effects more easily.
It is really important to me that the model be a plain Java object. It shouldn’t have to implement any special interfaces in order to be part of a GUI.
The controller at the moment is looking like 2 parts.
The main event loop looks like
Event e = getEvent();
dispatchEventToHandlers( e );
I’ve taken another look at the View side of things. My preference is now a display tree modelled after SVG.
Uses Glyph as the metaphor (not sure about this), but it seems lightweight enough.
The Glyph draws its contents and reports damage up to its parent. At the root the damage is collected, then repaints are performed within the damaged region.
Currently developing this on a PIII which is good for spotting performance problems quickly.
The biggest one seems to be with Java image drawing performance.The solution is to make sure that all images are created in a screen compatible BufferedImage format.
From a design point of view I’d like to use immutable objects to represent the bounds, etc but the expense of creating objects when transforming up the Glyph hierarchy might be too much. This really needs to be very fast, as it will be called all the time in the most performance critical part of the code.
Got some great feedback from the guys at eXtreme Wednesday. The main points were that reflection based APIs are really difficult to learn, you can’t use the code completion features of IDEs etc.
They did seem convinced that the concept is good – which was a relief.
The main concept is – “View controls repaint”
I’m finally showing some of the stuff I developed to others tomorrow. Hopefully they will be impressed.