Create account / Log in

Set Background Color

Talk about module design ideas and techniques.

Moderators: uckelman, Tim M

Set Background Color

Postby drimmer » September 20th, 2020, 2:35 pm

In VASL, maps are surrounded by a white area, used for off-board counters and informational counters. The color of the background is set in Vassal.build.module.map but can be changed by changing its value in the VASL buildFile.

I would like to find an easier way to change the background, either via a preference or accessing the bgColor property in vassal.build.module.map.

VASL has a class ASLMap which extends vassal.build.module.map. ASLMap's constructor calls super(); as its first action. I tried the following after that call, but it did not work:

super.bgColor = Color.cyan;
repaint();

I have tried to access other methods from vassal.build.module.map with an equal lack of success.

Any thoughts would be greatly appreciated.
Doug
drimmer
 
Posts: 40
Joined: May 21st, 2014, 4:48 pm

Re: Set Background Color

Postby Cattlesquat » September 20th, 2020, 2:50 pm

Make it:

super.bgColor = Color.cyan;
super.clearMapBorder();
repaint();

And I think that should do it.

Best,

Brian
User avatar
Cattlesquat
 
Posts: 947
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: Set Background Color

Postby drimmer » September 20th, 2020, 11:55 pm

Cattlesquat wrote:Make it:

super.bgColor = Color.cyan;
super.clearMapBorder();
repaint();

And I think that should do it.

Best,

Brian


Thanks Brian

clearMapBorder() wants a Graphics parameter which I have not been able to provide.

Normally, it would be something like
Graphics g = XXX.creategraphics();
super.clearMapBorder(g);

But I don't know what the XXX should be. Should it be the viewport? In some examples I found it was a BufferedImage.

Appreciate the help.

Doug
Doug
drimmer
 
Posts: 40
Joined: May 21st, 2014, 4:48 pm

Re: Set Background Color

Postby Cattlesquat » September 21st, 2020, 12:28 am

Oh right! If you're already subclassing Map then I think you can just do

theMap.getGraphics()

Or more formally...

getComponent().getGraphics()

So...
super.bgColor = Color.cyan;
super.clearMapBorder(super.getComponent().getGraphics());
repaint();

I'm not certain you need as many explicit "super"'s there as I have put. Many/most/all can probably be omitted.

Like this might work--
bgColor = Color.cyan;
clearMapBorder(getComponent().getGraphics());
repaint();

Brian
User avatar
Cattlesquat
 
Posts: 947
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: Set Background Color

Postby uckelman » September 21st, 2020, 12:45 am

That will not work.

Map.clearMapBorder() is supposed to be called only when the Map component is being painted. It should not be called from anywhere else.

If you want to change the background color, you can do that by setting the BACKGROUND_COLOR property that Map has. Alternatively, bgColor is a protected member of Map and since ASLMap is a subclass, this means you have access to it and can set it directly: bgColor = Color.cyan;
User avatar
uckelman
Site Admin
 
Posts: 8989
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

Re: Set Background Color

Postby Cattlesquat » September 21st, 2020, 1:01 am

That's what he was trying in his first message to the thread and it wasn't working.

Maybe instead of directly calling clearMapBorder, the right thing to do is a full paint() of "the whole map"?

So:
bgColor = Color.cyan;
paint(getComponent().getGraphics());

So maybe that?

Of course then I don't understand why "repaint()" doesn't do it, but then again I'm on record as never understanding the difference between paint()/repaint()/update() in swing.
User avatar
Cattlesquat
 
Posts: 947
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: Set Background Color

Postby uckelman » September 21st, 2020, 12:09 pm

When you tried assigning to bgColor in the ASLMap ctor, did you check in a debugger where it's being reset after that?
User avatar
uckelman
Site Admin
 
Posts: 8989
Joined: December 10th, 2007, 9:48 am
Location: Durham, England

Re: Set Background Color

Postby drimmer » September 21st, 2020, 3:23 pm

uckelman wrote:When you tried assigning to bgColor in the ASLMap ctor, did you check in a debugger where it's being reset after that?


that did it. I was resetting the color too soon - in the ASLMap constuctor and it was getting overwritten when the Map class was being built. I moved it else where in ASLMap class and it worked perfectly: set the new color, call repaint().

Thanks for all the help from you both.

Doug
Doug
drimmer
 
Posts: 40
Joined: May 21st, 2014, 4:48 pm


Return to Module Design

Who is online

Users browsing this forum: No registered users and 2 guests