KAsiUNblog

Unkasoft's blog, where we talk about mobile games development, gaming industry, agile methodologies and all that matter we're handling every day

Friday, September 22, 2006

Tuning Up Battlewizard on MacosX

One important thing about Battlewizard is that can be run on any S.O. supporting Java 1.4 or above; this characteristic makes it suitable for any user, despite of if he uses Windows, Linux or even a Mac.
In this post, we will cover running up Battlewizard over a MacosX Tiger platform.
Anyone who uses MacosX will know that there are some important things much different from other operative systems; for example, menubars are always on the upper side of screen, just by the apple. With a few simple tweaks you can give your Java application a native look and feel so that Mac OS X users can install and run your application without being aware that they are running a cross-platform application.

It's important to notice that Battlewizard will have a launcher for MacosX systems that will make use of all this stuff.

1.- Using plain JVM
If we just launch Battlewizard with a plain JVM, our application will look like this:



2.- Setting MenuBar on its place

We will make some use of JVM system properties to achieve this; just add the following argument to the jvm arguments at battlewizard launching:

-Dapple.laf.useScreenMenuBar=true

And the result is as follows:


See how menubar now is on the upper zone??

3.- Changing that class name....

As you can see on the last picture, menubar now lays where it has to, but the name of the application is still the full name of the class, package names included.
This is far from style, so we will change it in order to see the name right there.
In this case, we use a special macosx jvm option instead of a system property:

-Xdock:name="Battlewizard"

And here comes what it results:


4.- Adding an "About" entry on the system menu

It's not really important, but every macosx application has one, so... why wouldn't we?
Using this system property:

-Dcom.apple.mrj.application.apple.menu.about.name=Battlewizard

will let us see the following menu option:


This option still have to be coded to be useful, but we have an "About Battlewizard" option on system menu....

5.- Graphic improvement
Well, maybe this should have be called downgrade graphics... but a little explanation will serve.
JVM by default enables Double Buffering for all its graphics. It results on smoother animations and flicker-free.
MacosX uses a graphic engine, called Quartz 2D, part of the Core Graphics framework, is an advanced, two-dimensional drawing engine that is resolution- and device-independent. Its powerful features include transparency layers, path-based drawing, offscreen rendering, advanced color management, as well as PDF document creation, display, and parsing.



This engine always do DoubleBuffering, so if we don't disable it on Java, we will have a double buffering of a doble buffered image. It still works, but will not see much improvement but less performance.

In order to disable Java double buffering, we'll use the following system property:

-Dawt.nativeDoubleBuffering=true


6.- Other options
Two more options can be used to change our application into a more esthetic and MacosX Look&Feel one.

-Dcom.apple.mrj.application.growbox.intrudes=false

The one above makes applications respect the growable area of a MacosX window. If this option is not used, window contents would invade growable area.




-Dcom.apple.macos.smallTabs=true

The last one is to the size of the tabs. It is hard to do cross platform GUI design if you try to set the size and location of components precisely. One obstruction is that the font size is different on different platforms. Apple allows you to choose between using big and small tabs. The default is for big tabs and which one you choose is merely a matter of judgement.

Conclusion

Although Java is a cross-platform development language, we've got to be aware that each of this platforms has subtle features that can be tweaked. It's good to know how to change them with little effort.

Comments:
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?