22 package com.realtime.crossfire.jxclient.gui.map;
29 import java.awt.Graphics;
30 import java.util.Arrays;
31 import javax.swing.ImageIcon;
32 import org.jetbrains.annotations.NotNull;
85 private static final int[]
DX = {
100 private static final int[]
DY = {
195 private final boolean[]
done =
new boolean[8];
226 public void paintSmooth(@NotNull
final Graphics graphics,
final int x,
final int y,
final int px,
final int py,
final int layer, @NotNull
final CfMap map,
final int tileSize) {
227 final int level = map.getSmooth(x, y, layer);
231 for (
int deltaX = 0; deltaX <= 2; deltaX++) {
232 for (
int deltaY = 0; deltaY <= 2; deltaY++) {
233 if (deltaX != 0 || deltaY != 0) {
234 final CfMapSquare mapSquare = map.getMapSquare(x+deltaX-1, y+deltaY-1);
237 layerNode[deltaX][deltaY] = mapSquare.
getSmooth(layer) > 0 ? mapSquare : null;
242 for (
int i = 0; i < 8; i++) {
248 final int smoothlevel = node.
getSmooth(layer);
249 if (smoothlevel <= level) {
253 smoothValue[i] = smoothlevel;
263 Arrays.fill(done,
false);
266 for (
int i = 0; i < 8; i++) {
267 if (smoothValue[i] > 0 && !done[i] && (lowest < 0 || smoothValue[i] < smoothValue[lowest])) {
276 final int currentSmoothFace = smoothFace[lowest];
282 for (
int i = 0; i < 8; i++) {
283 if (smoothValue[i] == smoothValue[lowest] && smoothFace[i] == currentSmoothFace) {
285 weight += BORDER_WEIGHT[i];
286 weightC &= ~BORDER_CORNER_EXCLUDE[i];
288 weightC &= ~CORNER_WEIGHT[i];
291 if (currentSmoothFace == 0) {
295 final ImageIcon imageIcon = facesProvider.
getImageIcon(currentSmoothFace, isUnknownImage);
296 if (isUnknownImage[0]) {
297 map.squarePendingFace(x, y, currentSmoothFace);
300 drawImage(graphics, px, py, tileSize*weight, 0, imageIcon, tileSize);
303 drawImage(graphics, px, py, tileSize*weightC, tileSize, imageIcon, tileSize);
320 private static void drawImage(@NotNull
final Graphics graphics,
final int dstX,
final int dstY,
final int srcX,
final int srcY, @NotNull
final ImageIcon imageIcon,
final int tileSize) {
321 graphics.drawImage(imageIcon.getImage(), dstX, dstY, dstX+tileSize, dstY+tileSize, srcX, srcY, srcX+tileSize, srcY+tileSize, null);
static final int [] DY
Y offset for map coordinate calculation.
static final int CORNER_SOUTHWEST
Corner weight for southwest.
Represents a square in a CfMap.
int getSmooth(final int layer)
Returns the smooth value of this square.
Represents a map (as seen by the client).
static final int [] CORNER_WEIGHT
Weight (x coordinate) in smoothing face of a corner.
final FacesProvider facesProvider
The FacesProvider for looking up faces.
ImageIcon getImageIcon(int faceNum, @Nullable boolean[] isUnknownImage)
Returns the face for a face ID.
static void drawImage(@NotNull final Graphics graphics, final int dstX, final int dstY, final int srcX, final int srcY, @NotNull final ImageIcon imageIcon, final int tileSize)
Draws a.
final SmoothFaces smoothFaces
The SmoothFaces to use.
final CfMapSquare [][] layerNode
Surrounding CfMapSquaremap squares} having non-zero smooth levels.
Implements the map model which is shown in the map and magic map views.
final int [] smoothFace
Face index of the smooth face corresponding to layerNode.
SmoothingRenderer(@NotNull final SmoothFaces smoothFaces, @NotNull final FacesProvider facesProvider)
Creates a new instance.
Manages image information ("faces") needed to display the map view, items, and spell icons...
void paintSmooth(@NotNull final Graphics graphics, final int x, final int y, final int px, final int py, final int layer, @NotNull final CfMap map, final int tileSize)
Draw the smoothing information at given position of map, for a given limit smoothlevel, at a given layer.
static final int [] DX
X offset for map coordinate calculation.
static final int BORDER_EAST
Border weight for east.
Interface for face providers.
static final int BORDER_WEST
Border weight for west.
static final int BORDER_NORTH
Border weight for north.
static final int [] BORDER_CORNER_EXCLUDE
Corner excludes due to borders.
int getSmoothFace(final int face)
Returns the smoothing face associated with a given face.
final boolean [] done
Marks the indexes that have been painted.
static final int CORNER_NORTHWEST
Corner weight for northwest.
static final int CORNER_NORTHEAST
Corner weight for northeast.
Renderer for painting smoothed faces into map views.
Face getFace(final int layer)
Returns the face of a layer.
static final int [] BORDER_WEIGHT
Weight (x coordinate) in smoothing face of a corner.
final boolean [] isUnknownImage
Temporary variable.
final int [] smoothValue
Smooth values corresponding to layerNode.
static final int CORNER_SOUTHEAST
Corner weight for southeast.
static final int BORDER_SOUTH
Border weight for south.
int getFaceNum()
Returns the unique face id.
Maintains smoothing information received from the Crossfire server.