Create account / Log in

HiDPI issues with java.awt

Support for existing Vassal modules. Ask here if you need help with a specific module.

Moderators: uckelman, Tim M

HiDPI issues with java.awt

Postby Mu0n » August 2nd, 2020, 9:46 pm

Hey,

in the latest patch notes, I read: "If you are the maintainer of such a module, let us know and we can advise you about what needs updating for 3.3 in your code."

So here I am, the maintainer of the popular Star Wars X-Wing Miniatures module. I have java 8 code that uses java.awt to draw blinking shapes when ships collide against other ships or asteroids. The main thing that has been hit according to some users is a custom mouse interface that draws .png images neatly organized in a user interface layout and triggers the many....many... game effects that have been introduced since 2012 in this "living" miniatures game. I'm getting reports from users that they can't work it at all or as well as they did back with Vassal 3.2.17.

I'm dreading have to modify my code but I'm up for it if it's reasonable and as time goes on, the proportion of HiDPI owners can only increase.

The only major hurdle to all of this is: I don't own a PC monitor that lets me display above 1080p. I don't have a HiDPI monitor. I really don't look forward to do this by trial and error and would really appreciate having some pro tips from the dev team here. Thanks in advance!
Mu0n
 
Posts: 52
Joined: September 5th, 2013, 5:01 pm

Re: HiDPI issues with java.awt

Postby Cattlesquat » August 3rd, 2020, 2:45 pm

Joel's reply somehow went to the wrong forum -- just copying it in here:

Subject: Re: [messages] [Module Support] HiDPI issues with java.awt
In-reply-to: <1596404783.63050.39308.bridge@www.vassalengine.org>
References: <1596404783.63050.39308.bridge@www.vassalengine.org>
Comments: In-reply-to Mu0n
message dated "Sun, 02 Aug 2020 21:46:23 -0000."
--------
Thus spake Mu0n:
> Hey,
>
> in the latest patch notes, I read: "If you are the maintainer of such a
> module, let us know and we can advise you about what needs updating for
> 3.3 in your code."
>
> So here I am, the maintainer of the popular Star Wars X-Wing Miniatures
> module. I have java 8 code that uses java.awt to draw blinking shapes
> when ships collide against other ships or asteroids. The main thing that
> has been hit according to some users is a custom mouse interface that
> draws .png images neatly organized in a user interface layout and
> triggers the many....many... game effects that have been introduced
> since 2012 in this "living" miniatures game. I'm getting reports from
> users that they can't work it at all or as well as they did back with
> Vassal 3.2.17.
>
> I'm dreading have to modify my code but I'm up for it if it's reasonable
> and as time goes on, the proportion of HiDPI owners can only increase.
>
> The only major hurdle to all of this is: I don't own a PC monitor that
> lets me display above 1080p. I don't have a HiDPI monitor. I really
> don't look forward to do this by trial and error and would really
> appreciate having some pro tips from the dev team here. Thanks in
> advance!

You don't need a HiDPI monitor for testing. You can set the UI scale
factor on the command line if you run the Player in standalone mode:

java -Dsun.java2d.uiScale=2 -classpath path/to/Vengine.jar VASSAL.launch.Player --standalone yourmodule.vmod

That's how I did all my own testing, both for VASSAL and VASL. Switching
between 1 and 2 for the scale factor will let you see if your changes are
working.

What changes you need to make depends on how you're doing the drawing.
Is your code available somewhere?

--
J.
User avatar
uckelman
Site Admin

Posts: 8757
Joined: December 10th, 2007, 4:48 am
Location: Durham, England
User avatar
Cattlesquat
 
Posts: 890
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: HiDPI issues with java.awt

Postby uckelman » August 3rd, 2020, 2:48 pm

I think I accidentally obliterated the subject, which is used for matching. Thanks.
User avatar
uckelman
Site Admin
 
Posts: 8847
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

Re: HiDPI issues with java.awt

Postby Mu0n » August 3rd, 2020, 4:17 pm

Cattlesquat wrote:What changes you need to make depends on how you're doing the drawing.
Is your code available somewhere?


Yep, it's right here, line 819 (draw function):

https://github.com/Mu0n/XWVassal/blob/m ... wable.java

The rest of the code is here (but it might not be necessary to dive into... I think?)

https://github.com/Mu0n/XWVassal/tree/m ... ic/src/mic
Mu0n
 
Posts: 52
Joined: September 5th, 2013, 5:01 pm

Re: HiDPI issues with java.awt

Postby uckelman » August 3rd, 2020, 4:54 pm

Thus spake Mu0n:
> Yep, it's right here, line 819 (draw function):

There are three coordinate systems: map, component, and drawing.

* Map coordinates are the ones used by the map, pieces, etc.

* Component coordinates are used by the UI.

* Drawing coordinates are used for painting things to the screen.

The difference between component and drawing coordinates is the display
scale factor. On standard pixel density displays, that scale factor is
usually 1 (and was always 1 before VASSAL 3.3, regardless). On HiDPI
displays or if the user has set the display scale factor, it could be
something other than 1. (2 is a common value in that case.)

The draw methods of Drawables and GamePieces receive a Graphics which
is set to operate in drawing coordinates, and all the coordinates passed
to those methods (if any) will be drawing coordinates.

Drawing using drawing coordinates will in most cases do the right thing.

If you're trying to draw something which does not scale along with the
map---then you will have to make some changes to the way you're painting.

There are examples of both kinds of thing in the changes I contributed
to VASL for 3.3 compatiblity:

https://github.com/vasl-developers/vasl/pull/669

The changes to ASLDiceOverlay in particular would be relevant if you're
painting some sort of non-scaling GUI-like thing over the map.

If you're painting somethign that scales with the map and you're getting
the scale factor from the map, you may not need to do more than multiply
the device scale factor by the map's scale factor and use that. Here's
how you get the device scale factor:

final double os_scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX();

--
J.
User avatar
uckelman
Site Admin
 
Posts: 8847
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

Re: HiDPI issues with java.awt

Postby Mu0n » August 7th, 2020, 5:17 pm

Thank you, your suggestions have worked. I dedicated my laptop environment to testing out your suggestions, here are the changes I've gone through to make everything work:

1) Go from JDK 8 to JDK 11; must do since Vassal.launch.player will complain that my module is full of v52 (java 8) classes while the launcher is v55 (jdk 11)
2) update my gradle-wrapper from 4.2 to 5.1.1 or it will complain about some stuff, inside my intellij installation

There were only a few handful places where I was using an AffineTransform method to deal with scaling (map zoom was my main concern, but now the uiScale as well).
Mu0n
 
Posts: 52
Joined: September 5th, 2013, 5:01 pm

Re: HiDPI issues with java.awt

Postby Flint1b » August 7th, 2020, 11:01 pm

Mu0n wrote:2) update my gradle-wrapper from 4.2 to 5.1.1 or it will complain about some stuff, inside my intellij installation


You use gradle-wrapper, that's good, look out for new changes regarding our packaging, we will soon have the vassal.jar available as a maven module.

We have an alpha version already, try to add "http://www.vassalengine.org/maven/" as a repository and "org.vassalengine:vassal-app:3.3.3-alpha1" as the dependency.
User avatar
Flint1b
 
Posts: 461
Joined: May 19th, 2020, 12:27 am
Location: Colonia Agrippina


Return to Module Support

Who is online

Users browsing this forum: No registered users and 3 guests