Crossfire JXClient, Trunk  R20561
DarknessColors.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.map;
23 
25 import java.awt.Color;
26 import org.jetbrains.annotations.NotNull;
27 
32 public class DarknessColors {
33 
38  private static final float MAX_DARKNESS_ALPHA = 0.7F;
39 
43  @NotNull
44  public static final Color FOG_OF_WAR_COLOR = new Color(0, 0, 0.5F, 0.5F);
45 
50  @NotNull
51  private final Color[] darknessColors = new Color[256];
52 
58  @NotNull
59  public Color getDarknessColor(final int darkness) {
60  synchronized (darknessColors) {
61  if (darknessColors[darkness] == null) {
62  final float alpha = MAX_DARKNESS_ALPHA*(CfMapSquare.DARKNESS_FULL_BRIGHT-darkness)/CfMapSquare.DARKNESS_FULL_BRIGHT;
63  darknessColors[darkness] = new Color(0, 0, 0, alpha);
64  }
65 
66  return darknessColors[darkness];
67  }
68  }
69 
70 }
Color getDarknessColor(final int darkness)
Returns an overlay color for a darkness value.
Represents a square in a CfMap.
Implements the map model which is shown in the map and magic map views.
Definition: CfMap.java:22
final Color [] darknessColors
Cache to lookup darkness overlay colors.
static final float MAX_DARKNESS_ALPHA
The minimum darkness alpha value; it is used for completely black tiles.
static final Color FOG_OF_WAR_COLOR
The color to use for overlaying fog-of-war tiles.
Utility class for converting darkness values into colors.
static final int DARKNESS_FULL_BRIGHT
The darkness value for a full bright square.