My experiments with SWT have been pretty much fruitless. Initially I wanted to use SWT for all content editing tools - the level editors, sprite editors and possibly more interactive tools if things went well.
I did manage to get a LWJGL game up and running inside a SWT window and make it handle input and rendering without major problems but I realised that building a fully fledged level editor using SWT would be a very time consuming task. Not a time saver at all!

SWT with a LWJGL view inside.
I needed something more agile. So I turned my attention back to the basics. I was already using the principles of the Immediate mode GUI, as described in the infamous Molly Rocket video (mollyrocket.com/forums/vie…), so I decided to work further in that direction. The code was pretty rough, since it had been used only for very basic UI elements so far.
The most time consuming task had always been arranging various buttons, inputs, frames and other widgets on the screen. An endless cycle of adjusting values in Java code and restarting the game to see the results. Edit, restart, edit, restart. Very boring!
The first thing I did was to add code that used roughly estimated hard-coded values as defaults and saved them into a text file at the same time. Next time it would load these values from the file and ignore the defaults. That's a pretty pointless change by itself since it just moves the hard-coded values from Java code into the text file. But wait.
The second thing I did was to add a global keyboard shortcut that activated the new "layout editing mode". This mode disables the default behaviour of all widgets and turns them into dumb draggable rectangles. Mouse dragging moves, shift-drag changes the dimensions and another hotkey saves the layout back into the file.
Here's a chunk of pseudo-code to show what happens. First the default behaviour:

And this happens when the editing mode is enabled:

And that's pretty much it. The real code is about 300 lines, including support for unlimited undo/redo. I can now adjust any part of the UI directly inside the game, with instant feedback. Even if it's an custom animated bobbing button above a game character's head - as long as it uses the Button.process() routine to register mouse clicks, I can press F4 and edit it in realtime, while the game is still running. Neat, isn't it?
I did manage to get a LWJGL game up and running inside a SWT window and make it handle input and rendering without major problems but I realised that building a fully fledged level editor using SWT would be a very time consuming task. Not a time saver at all!

SWT with a LWJGL view inside.
I needed something more agile. So I turned my attention back to the basics. I was already using the principles of the Immediate mode GUI, as described in the infamous Molly Rocket video (mollyrocket.com/forums/vie…), so I decided to work further in that direction. The code was pretty rough, since it had been used only for very basic UI elements so far.
The most time consuming task had always been arranging various buttons, inputs, frames and other widgets on the screen. An endless cycle of adjusting values in Java code and restarting the game to see the results. Edit, restart, edit, restart. Very boring!
The first thing I did was to add code that used roughly estimated hard-coded values as defaults and saved them into a text file at the same time. Next time it would load these values from the file and ignore the defaults. That's a pretty pointless change by itself since it just moves the hard-coded values from Java code into the text file. But wait.
The second thing I did was to add a global keyboard shortcut that activated the new "layout editing mode". This mode disables the default behaviour of all widgets and turns them into dumb draggable rectangles. Mouse dragging moves, shift-drag changes the dimensions and another hotkey saves the layout back into the file.
Here's a chunk of pseudo-code to show what happens. First the default behaviour:

And this happens when the editing mode is enabled:

And that's pretty much it. The real code is about 300 lines, including support for unlimited undo/redo. I can now adjust any part of the UI directly inside the game, with instant feedback. Even if it's an custom animated bobbing button above a game character's head - as long as it uses the Button.process() routine to register mouse clicks, I can press F4 and edit it in realtime, while the game is still running. Neat, isn't it?


