Sunday, 18 December 2011

Java2D Stroke Rendering

Summary: converting all use of strokes to rectangles! Why? It seems Java2D strokes render around the co-ordinate system rather than from it.

This may seem intuitive to some, e.g. if you have a stroke thickness set to 4.0, then it renders 2.0 of that to the left of the x co-ordinate and 2.0 to the right. I searched as much documentation as I could to try and see if this was the case but couldn't see it anywhere. I hope this post helps some other newb at some point and prevents a waste of coding time.

I guess this isn't a problem if your project considers this and makes allowances if say for example the user is nudging a widget to the left of the drawing area. The code could ensures they don't go too far left by checking for the x co-ord equal to zero plus half the stroke thickness. I'm hoping my code will be more readable that that when I come back to it in a few years time - consider how to make sure the right width is returned for a widget, ensuring it doesn't go too far right in the drawing area and so on.

Maybe it's just the way I'm wired, I think it's more appropriate to know that x is the left edge of your widget not x - (strokeWidth / 2.0f).

Thursday, 8 December 2011

2 Years On

Looking back it's 2 years since I set out in earnest to learn how to write a GUI app in Java. Not just any GUI app, but a full drum music manuscript editing app.

Looking back through the posts I have learned so much, and had assumed I knew more than I did. I've not only had to finesse the nuances of the language but also learn and understand many of the class libraries that come with Java, and they're not all consistent in their approach. Some are just incomplete.

I've also learned more about the music theory itself, plus things like printers point sizes and all the competing factions for metric versus the many different interpretations. I've also learned about the many different music score related projects out there like Lilypond and MusicXML.

Overall I've confirmed my suspicions that it's really hard for someone to be a part time developer on a project like this - there's so many aspects to it from the file handling to mouse gestures to the music engraving or artwork. And when you've got a lot to learn about the patterns used in GUI software development and language specific approaches and limitations, you end up going down a few ratholes before realising the wrong approach was taken and a few backward steps need to be taken, coding reworked and then you might progress. Then repeat several times!

It's been very satisfying to get proficient again in a programming language, to get back to working that level of technical detail. The app itself is close to being useful, a good push this winter should see a prototype editing and rendering tool, plus hopefully an input method using something other than the computer keyboard :)

Onwards!